akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int M,D;
    cin >> M >> D;
    int ans = 0;
    for (int i = 1; i <= M; i++)
    {
        for (int j = 22; j <= D; j++)
        {
            if(j%10 >= 2 && (j/10)*(j%10) == i) ans++;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
  int n,i;
  cin>>n;
  vector<int>h(n);
  for(i=0;i<n;i++)
  {
    cin>>h[i];
  }
  vector<int>dp(n);
  dp[0]=0;dp[1]=abs(h[1]-h[0]);
  for(i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
  }
  cout<<dp[n-1];
}


Measured memory_bytes: 1024
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
B = lr()
C = lr()
temp = 0
answer = 0
for i in range(N):
    answer += B[A[i] - 1]
    if 0 < i and A[i] - A[i-1] == 1:
        if A[i] - 1 <= N-1:
            answer += C[A[i-1] - 1]

print(answer)


Measured memory_bytes: 3064
K = int(input())
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j, K+1):
            if (i == j and j == k):
                ans += i
            elif (i == j or j == k):
                ans += math.gcd(i, k)*3
            else:
                ans += gcd(i, j, k)*6
print(ans)

Measured memory_bytes: 9636
#include<bits/stdc++.h>
using namespace std;
#if defined __has_include
# if __has_include(<bits/debug_aamir.h>)
#  define dbg(...) DEBUG(#__VA_ARGS__, __VA_ARGS__);
#  include<bits/debug_aamir.h>
# else
#  define dbg(...)
# endif
#endif

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll, ll> pll;
#define sz(x) int(x.size())
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define rep(i, begin, end) for(__typeof(end) i=begin; i<end; i++)
#define per(i, begin, end) for(__typeof(end) i=begin; i>=end; i--)
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;


template<typename T>
T gcd(T a, T b){	return b ? gcd(b, a%b): a; }
template<typename T>
T lcm(T a, T b){	return a/gcd(a, b) * b;		}

const int nax=3005;
vector<vector<double>> dp(nax, vector<double>(nax));
vector<double> p(nax);

int main()
{
	fastio;
	int n;
	cin >> n;
	rep(i, 0, n)	cin >> p[i];
	dp[0][0] = 1 - p[0];
	dp[0][1] = p[0];
	rep(i, 0, n-1){
		rep(j, 0, n){
			dp[i+1][j] += dp[i][j] * (1-p[i+1]);
			dp[i+1][j+1] += dp[i][j] * p[i+1];
		}
	}
	double ans = 0;
	rep(i, (n+1)/2, n+1)
		ans += dp[n-1][i];
	dbg(p);
	rep(i, 0, n)
		dbg(dp[i]);
	printf("%.10lf\n", ans);
}



Measured memory_bytes: 74480
#include <bits/stdc++.h>
#define il inline
#define ll long long
const int N=105,P=1e9+7;

int n,h[N],A=1;
struct node{int a,b;}B;

il int ksm(int a,int b)
{
    int res=1;
    for ( ; b; b>>=1,a=(ll)a*a%P) if (b&1) res=(ll)res*a%P;
    return res;
}

il node sol(int l,int r,int x)
{
    node t; int i,cnt,mn=1e9+1,a=1,b=1,L=0,R=r-l+1;
    for (i=l; i<=r; i++)
        if (h[i]<mn) mn=h[i],cnt=1;
        else if (h[i]==mn) cnt++;
    if (cnt==R) return (node){(ksm(2,R)-2+P)%P,ksm(2,mn-x-1)};
    for (i=l; i<r+2; i++)
         if (!L&&h[i]>mn) L=i;
         else if (L&&(h[i]<=mn||i>r))
         {
             R-=i-L,t=sol(L,i-1,mn),L=0;
             a=(ll)a*(t.a+4ll*t.b)%P,b=2ll*b*t.b%P;
         }
    a=(a-b+P)%P;
    return (node){((ll)a*ksm(2,R)+(ll)b*(ksm(2,R)-2+P))%P,(ll)b*ksm(2,mn-x-1)%P};
}

int main()
{
    scanf("%d",&n); int i;
    for (i=1; i<=n; i++) scanf("%d",h+i);
    if (n==1) return printf("%d",ksm(2,h[1])),0;

    for (i=1; i<=n; i++) if (h[i]>h[i-1]&&h[i]>h[i+1])
        A=(ll)A*ksm(2,h[i]-std::max(h[i-1],h[i+1]))%P,h[i]=std::max(h[i-1],h[i+1]);
    B=sol(1,n,0),printf("%d",(ll)A*(B.a+2ll*B.b)%P);

    return 0;
}

Measured memory_bytes: 3844
import math
N = int(input())
result = []
count = 0
i = 2


def isPrime(x):
    if x == 1:
        return False
    else:
        for i in range(2, x):
            if x % i == 0:
                return False
        return True


while True:
    n = 5 * i + 1
    if isPrime(n):
        result.append(n)
        count += 1
    if count == N:
        break
    i += 1

print(" ".join(map(str, result)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int x,N;
    cin>>x>>N;
    int n;
    int i=x;int j=x;
    set<int>s;
    int k=0;
    rep(k,N){
        cin>>n;
        s.insert(n);
    }
    while(1){
        if(s.count(i)){
            i--;
        }else{
            cout<<i<<endl;
            break;
        }
        if(s.count(j)){
            j++;
        }else{
            cout<<j<<endl;
            break;
        }
    }
}

Measured memory_bytes: 3632
N = gets.to_i
S = gets.chomp.chars
Q = gets.to_i.times.map{ gets.split }

A_ORD = 'a'.ord
L = 1 << (N - 1).bit_length
ST = Array.new(2 * L, 0)
S.each_with_index do |c,i|
  ST[L + i] = (1 << (c.ord - A_ORD))
end
(1 ... L).each do |i|
  j = L - i
  ST[j] = (ST[2 * j] | ST[2 * j + 1])
end

class << ST
  def update(i, c)
    self[L + i] = (1 << (c.ord - A_ORD))
    j = (L + i) / 2
    while j > 0
      self[j] = self[2 * j] | self[2 * j + 1]
      j /= 2
    end
  end
  def kind(a, b)
    _query(a, b, 1, 0, L).to_s(2).count('1')
  end
  def _query(a, b, k, l, r)
    return 0 if r <= a || l >= b
    return self[k] if a <= l && r <= b
    mid = (l + r) / 2
    return _query(a, b, 2 * k, l, mid) | _query(a, b, 2 * k + 1, mid, r)
  end
end


Q.each do |q|
  t = q.shift.to_i
  if t == 1
    i = q.shift.to_i - 1
    c = q.shift
    ST.update(i, c)
    S[i] = c
  else
    a = q.shift.to_i - 1
    b = q.shift.to_i - 1
    puts ST.kind(a, b + 1)
  end
end



Measured memory_bytes: 46012
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <functional>
#include <array>
#include <climits>
//#include "debug.h"
using namespace std;
 
#define A first
#define B second
 
typedef long long ll;
constexpr int MOD = 1e9 + 7;

inline int mulmd(ll a, ll b){
  ll ret = (a * b) % MOD;
  return (int) ret;
}

inline int power(ll x, ll y, int m){
  ll res = 1;
  x = x % m;
  while(y > 0){
    if(y & 1){
      res = mulmd(res, x);
    }
    y = y >> 1;
    x = mulmd(x, x);
  }
  return (int) res;
}
inline int submd(ll a, ll b){
  ll ret = (a - b);
  if(ret < 0) ret += MOD;
  return (int) ret;
}

inline int addmd(ll a, ll b){
  ll ret = (a + b) % MOD;
  return (int) ret;
}

inline int invPow(ll a){
  return power(a, MOD - 2, MOD);
}

inline int divmd(ll a, ll b){
  ll ret = mulmd(a, invPow(b));
  return (int) ret;
}

void solve() {
  int N;
  cin >> N;
  ll ans = submd(addmd(power(10, N, MOD), power(8, N, MOD)), addmd(power(9, N, MOD), power(9, N, MOD)));
  cout << ans;
}
 
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}

Measured memory_bytes: 3552
#define MOD_TYPE 2

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#if 0
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using Int = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;
#endif
#if 1
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9 + 10;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

struct io_init
{
  io_init()
  {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(30) << setiosflags(ios::fixed);
  };
} io_init;
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept
{
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int x;
  cin >> x;
  cout << !x << "\n";
}

int main()
{
  solve();
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(long i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,m;
    cin >> n >> m;
    int maxl,minr;
    maxl = 0;
    minr = n;
    int l,r;
    rep(i,m){
        cin >> l >> r;
        maxl = max(maxl,l);
        minr = min(minr,r);
    }
    cout << max(-1,minr-maxl) +1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    int k,s;
    cin >>k >>s;
    intf cnt=0;

    rep(h,k+1){
        rep(i,k+1){
            if(s-(h+i)<=k && s-h-i>=0){
              //  std::cout << h <<i<<endl;
                cnt++;
            }    
        }
    }
    std::cout << cnt<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <functional>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

int main() {
	for (int n; (n = in());) {
		vector<pair<int, int>> I(n);
		int s {};
		for (auto &i: I) {
			i = {in(), in()};
			s += i.first;
		}
		function<bool(int, int, long)> visit = [&](int i, int b, long v) {
			if (i == n)
				return true;
			for (int j: range(n))
				if (!(v & 1L << j) && I[j].second >= b)
					return visit(i + 1, b - I[j].first, v | 1L << j);
			return false;
		};
		outl(visit(0, s, 0) ? "Yes": "No");
	}
}


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, n)
    {
        cout << s[i];
        cout << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int x[5];
    int answer=0;

    for (int i=0;i<5;i++){
        cin >> x[i];
    } 
    for (int i=0;i<5;i++){
        if(x[i] != i+1){
            answer=i+1;
            break;
        }
    } 
    cout << answer << endl;
    return 0;

}

Measured memory_bytes: 3156
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,t;
    cin>>n>>a>>b;
    t=n*a;
    if(t<b)
    {
        cout<<t<<endl;
    }
    else
    {
        cout<<b<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using lint=long long;

int main()
{
   cin.tie(0);
   ios::sync_with_stdio(false);

   int N; cin>>N;
   bool ok=true;
   for(int i=0;i<N;i++){
      int a; cin>>a;
      if(a%2==0){
         if(a%3!=0 and a%5!=0) ok=false;
      }
   }
   cout<<(ok? "APPROVED":"DENIED")<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    bool c=0;
    for(int i=a;i<=b;i++){
        if(i%k==0){ c=1;
        break;
        }
    }
    cout<<(c==0?"NG":"OK")<<endl;
}

Measured memory_bytes: 3632
import std.stdio;
import std.string;
import std.conv;
import std.array;
import std.algorithm;
import std.range;

void main(){
	auto Q=readln.split.to!(int[]),a=Q[0],b=Q[1],c=Q[2];
	if(b-a==c-b)writeln("YES");
	else writeln("NO");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(void) {
	int a, b, c, work, i;
	cin >> a >> b >> c;
	for (i = 0; i < 2; i++) {
		if (b > c) {
			work = b;
			b = c;
			c = work;
		}
		if (a > b) {
			work = a;
			a = b;
			b = work;
		}
	}
	cout << a << ' ' << b << ' ' << c << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cassert>

using namespace std;

constexpr int64_t kMod = 1e9+7;

int main() {
    std::vector<int64_t> v;

    int n;
    cin >> n;

    int64_t answer = 0;
    cin >> answer;
    if (n == 1) {
        cout << answer << endl;
        return 0;
    }
    for (int i = 0; i < n - 1; i++) {
        char c;
        int x;
        cin >> c >> x;
        int new_x = x * (c == '+' ? 1 : -1);
        if (v.empty()) {
            v.push_back(new_x);
        } else {
            if (new_x > 0 && v.back() >= 1) {
                v.back() += new_x;
                continue;
            }
            if ((new_x > 0 && v.back() < 0) || (new_x < 0 && v.back() > 0)) {
                v.push_back(new_x);
                continue;
            }
            v.push_back(0);
            v.push_back(new_x);
        }
    }
    if (v.back() < 0) {
        v.push_back(0);
    }
    if (v.size() && v[0] > 0) {
        answer += v[0];
        v.erase(v.begin());
    }

    int64_t sum = 0;
    for (int i = 0; i < (int)v.size(); i++) {
        sum += v[i];
    }
    int64_t best_ans = sum;
    int64_t cur_sum = 0;

    for (int i = (int)v.size() - 1; i >= 0; i--) {
        assert(v[i] >= 0);
        assert(i > 0);
        assert(v[i - 1] < 0);

        sum -= v[i];
        sum -= v[i - 1];
        best_ans = max(best_ans, cur_sum -v[i] + v[i - 1] + sum);
        cur_sum += v[i];
        cur_sum -= v[i - 1];
        i--;
    }
    cout << best_ans + answer << endl;

    return 0;
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,i,k=0;
  cin >> N;
  vector<int> a(N);
  for(i=0;i<N;++i){
    cin >> a.at(i);
    --a.at(i);
  }
  i=0;
  do{
    ++k;
    i=a.at(i);
    if(i==1)
      break;
  }while(--N);
  if(N)
    cout << k << endl;
  else
    cout << -1 << endl;
    
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;

int b1, b2, b3;
int c[10][10];

int main(void){
  // Here your code !
  for (int i = 1; i <= 3; ++i) for (int j = 1; j <= 3; ++j) {
    scanf("%d", &(c[i][j]));
  }


  for (int a1 = 0; a1 <= 100; ++a1) for (int a2 = 0; a2 <= 100; ++a2) for (int a3 = 0; a3 <= 100; ++a3) {
    if ((c[1][1] - a1 == c[2][1] - a2) && (c[2][1] - a2 == c[3][1] - a3) &&
        (c[1][2] - a1 == c[2][2] - a2) && (c[2][2] - a2 == c[3][2] - a3) &&
        (c[1][3] - a1 == c[2][3] - a2) && (c[2][3] - a2 == c[3][3] - a3)) {
          printf("Yes\n");
          return 0;
        }
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<int> a(N);

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    cout << a.back() - a.front() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod = 1e9+7;

int main(){
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i=1;i<=9;i++){
    	for(int j=1;j<=9;j++){
    		if(i*j==n){
    			cout << "Yes\n";
    			return 0;
			}
		}
	}
	cout << "No\n";

	return 0;
} 


Measured memory_bytes: 256
a,b,c,d = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

lcm = c*d//gcd(c,d)

b_num = b - b//c - b//d + b//lcm
a_num = (a-1) - (a-1)//c - (a-1)//d + (a-1)//lcm


ans = b_num - a_num

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define i64 long long
#define N (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;
bool cmp(char c1,char c2){
	return c1>c2;
}
bool solve(string s,string t){
	//if(s.compare(t)==0) return false;
	sort(all(s)); sort(all(t),cmp);
	return(s.compare(t) < 0);
}
int main(){
	string s,t;
	cin>>s>>t;
	printf("%s\n", solve(s,t) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int K;
    cin >> K;
    int n = s.size();
    for (int i = 0; i < n-1; i++) {
        if (s[i] == 'a') continue;
        int need = 'z' - s[i] + 1;
        if (need <= K) {
            s[i] = 'a';
            K -= need;
        }
    }
    K %= 26;
    int last = (s[n-1]-'a' + K) % 26;
    s[n-1] = (char)('a'+last);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include "lib.h"
using namespace std;
#define LLINF LLONG_MAX-100
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define MAXN 100006
#define rep(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
#define bg(ms) *ms.begin()
#define addedge(a, b, c) v[a].pb(pi(b, c)); v[b].pb(pi(a, c))
#define ph push
typedef long long ll;
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll N, X, A[MAXN];
ll absll(ll x)
{
	return x > (-x) ? x : -x;
}
ll gcd(ll a, ll b)
{
	if(a==0)return b;
	if(b==0)return a;
	if(a>b)return gcd(a%b, b);
	else return gcd(a, b%a);
}
int main()
{
	cin >> N >> X;
	for(ll i = 0; i < N; i++)
	{
		ll temp;
		cin >> temp;
		A[i] = absll(X-temp);
	}
	for(ll i = 0; i < N-1; i++)
	{
		A[i+1] = gcd(A[i+1], A[i]);
	}
	cout << A[N-1] << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define M 1000'000'007
int s;
ll dp[2009][2009];

int main() {
    cin >> s;
    scanf("%d", &s);
    reps(i, s) repc2(j, 3, s) dp[i][j] = (1 + dp[i][j - 3] + dp[i][j - 1]) % M;
    printf("%lld\n", (dp[s][s] - dp[s][s - 1] + M) % M);
    return 0;
}

Measured memory_bytes: 35104
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int w, h;
	cin >> w >> h;
	int center_x, center_y, r;
	cin >> center_x >> center_y >> r;
	if (center_x - r<0 || center_x + r>w || center_y - r<0 || center_y + r>h)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3100
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,a,b,c,d = LI()
    s = "#" + S()
    ans = True
    if a<b and b<c and c<d:
        ans &= "##" not in  s[b:d]
        ans &= "##" not in  s[a:c]
    elif a<b and b<d and d<c:
        ans &= "##" not in  s[b:d]
        ans &= "..." in s[b-1:d+2]
        ans &= "##" not in  s[a:c]
    elif a<c and c<b and b<d:
        ans &= "##" not in  s[b:d]
        ans &= "##" not in  s[a:c]
    
    print("Yes" if ans else "No")
    
main()            


Measured memory_bytes: 75412
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    string s;
    cin>>s;
    int left,right,dec=0,n=s.length();
    for(int i=0;i<(int)s.length()-1;i++){
        if(s[i]=='S'&&s[i+1]=='T'){
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            dec+=2;
            i-=2;
        }
    }
    out(n-dec);
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll func(ll a){
    ll ans = 0;

    //i桁目について
    //入力に対してオーバーな分は0になるので気にしない
    for(int i=0;i<50;i++){
        //周期
        ll lp = (1LL<<(i+1));
        
        //既に迎えた周期*その半分が1の個数
        //0の帳尻合わせでaに1加算
        ll cnt = (a+1)/lp * (lp/2);

        //現在いる周期分の加算
        //0...0部分にいる時は0個
        ll d = (a+1)%lp - lp/2;
        if(d>0) cnt += d;

        //答えの作成は直接2のi乗を加算してやる
        if(cnt%2==1) ans += 1LL << i;
    }
    return ans;
}

int main(void){
    ll a,b;
    cin >> a >> b;

    //例えば4-8範囲C求めるときに、A:0-3,B:0-8としておくと
    //A xor C = B <=> A xor B = C
    //と変形できる。Aの逆元がA自身なのがポイント。
    ll ans = func(b) ^ func(a-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;

int a[N],sum=0,n,q;

int32_t main()
{
   IOS;
   
   cin >> n;
   
   for(int i=1; i<=n; i++)
   {
      int x;
      cin >> x;
      sum+=x;
      a[x]++;
   }

   cin >> q;
   while(q--)
   {
      int b,c;
      cin >> b >> c;

      sum= sum- a[b]*b;
      a[c]= a[c]+a[b];
      sum= sum+ a[b]*c;
      a[b]=0;

      cout << sum << endl;
   }




   return 0;
}




 


Measured memory_bytes: 4364
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#define countbits __builtin_popcount
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, m, a[305][305];
bool selected[305];
int cnt[305];
int calc() {
	memset(cnt,0,sizeof(cnt));
	rep(i,1,n) {
		rep(j,1,m) {
			if (selected[a[i][j]]) {
				cnt[a[i][j]]++;break;
			}
		}
	}
	int x=1;
	rep(i,2,m) if (cnt[i]>cnt[x]) x=i;
	return x;
}
int main() {
	n=readint(),m=readint();
	rep(i,1,n) rep(j,1,m) a[i][j]=readint();
	memset(selected,1,sizeof(selected));
	int minans=cnt[calc()];
	rep(i,1,m-1) {
//		rep(j,1,m) cerr<<selected[j]<<' ';cerr<<cnt[calc()]<<endl;
		selected[calc()]=false;
		minans=min(minans,cnt[calc()]);
	}
	printint(minans);
	return 0;
}


Measured memory_bytes: 640
import itertools

N, C = map(int, input().split())
D = [ [ int(x) for x in input().split() ] for _ in range(C) ]
CC = [ [ int(x)-1 for x in input().split() ] for _ in range(N) ]
cost = [ [ 0 for _ in range(C) ] for _ in range(3) ]

for c in range(C):
    for i in range(N):
        for j in range(N):
            cost[(i+j) % 3][c] += D[CC[i][j]][c]

ans = float("inf")
for c in itertools.permutations(range(C), 3):
    tmp = 0
    for j in range(3):
        tmp += cost[j][c[j]]

    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 43996
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce

N,X = map(int, input().split())
A = list(map(int, input().split()))

A.append(X)
A.sort()

B = [0] *(N)
for i in range(N):
    B[i] = A[i+1] - A[i]

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(B))

Measured memory_bytes: 25024
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int h,r;
	cin>>h>>r;
	if(h+r==0){
		cout<<"0"<<endl;
	}
	else if(h+r>0){
		cout<<"1"<<endl;
	}
	else{
		cout<<"-1"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> a[i][j];

	vector<vector<int>> b(h, vector<int>(w));
	b = a;

	int ans = 0;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				if (j == w - 1 && b[i][j] % 2 == 1 && i + 1 < h) {
					b[i][j]--;
					b[i + 1][j]++;
					ans++;
				}
				else if (b[i][j] % 2 == 1 && j + 1 < w) {
					b[i][j]--;
					b[i][j + 1]++;
					ans++;
				}
			}
		}
		else {
			for (int j = w - 1; j >= 0; j--) {
				if (j == 0 && b[i][j] % 2 == 1 && i + 1 < h) {
					b[i][j]--;
					b[i + 1][j]++;
					ans++;
				}
				else if (b[i][j] % 2 == 1 && j - 1 >= 0) {
					b[i][j]--;
					b[i][j - 1]++;
					ans++;
				}
			}
		}
	}

	cout << ans << endl;
	
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				if (j == w - 1 && a[i][j] % 2 == 1 && i + 1 < h) {
					a[i][j]--;
					a[i + 1][j]++;
					cout << i + 1 << ' ' << j + 1 << ' ' << i + 2 << ' ' << j + 1 << endl;
				}
				else if (a[i][j] % 2 == 1 && j + 1 < w) {
					a[i][j]--;
					a[i][j + 1]++;
					cout << i + 1 << ' ' << j + 1 << ' ' << i + 1 << ' ' << j + 2 << endl;
				}
			}
		}
		else {
			for (int j = w - 1; j >= 0; j--) {
				if (j == 0 && a[i][j] % 2 == 1 && i + 1 < h) {
					a[i][j]--;
					a[i + 1][j]++;
					cout << i + 1 << ' ' << j + 1 << ' ' << i + 2 << ' ' << j + 1 << endl;
				}
				else if (a[i][j] % 2 == 1 && j - 1 >= 0) {
					a[i][j]--;
					a[i][j - 1]++;
					cout << i + 1 << ' ' << j + 1 << ' ' << i + 1 << ' ' << j << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4224
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	a := make([]int,n)
	
	for i,_ := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
  	fmt.Println(a[n-1]-a[0])
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int n, a, b;
	int ans = 0;
	int dig;
	int sum = 0;
	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++){
		int num = i;
		while(num){
			dig = num % 10;
			sum = sum + dig;
			num = num / 10;
		}
		if(sum >= a && sum <= b){
			ans += i;
		}
		dig = 0;
		sum = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 764
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let S = rl().chars().vec();
    let T = rl().chars().vec();

    for i in 0..S.len() {
        let mut ok = true;

        for j in 0..T.len() {
            if S[(i + j) % S.len()] == T[j] {
                continue;
            }

            ok = false;
            break;
        }

        if ok {
            println!("Yes");
            return;
        }
    }
    println!("No");

    return;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0);

  int N;
  scanf("%d", &N);
  vector<int> B;
  REP(i,N) {
    int b;
    scanf("%d", &b);
    B.pb(b);
  }

  vector<int> res;
  REP(i,N) {
    FORD(i,B.size(),0) {
      if (B[i] == i + 1) {
        res.pb(i+1);
        B.erase(B.begin() + i);
        break;
      }
    }
  }
  if (res.size() < N) {
    printf("-1\n");
    return 0;
  }
  FORD(i,N,0) printf("%d\n", res[i]);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
// clang-format on

int calc(int a) {
    int ans = 0;
    do {
        ans++;
        a /= 10;
    } while (a);
    return ans % 2;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    REP(i, 1, n + 1) {
        ans += calc(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long ll;

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, b[102], a[102];
  cin >> n;
  rep(i, n-1) cin >> b[i];

  int ans = 0;

  a[0] = b[0];
  REP(i, n){
    if(i == n-1){
      a[n-1] = b[n-2];
      break;
    }
    a[i] = min(b[i], b[i-1]);
  }
  rep(i, n) {
    ans += a[i];
  }

  cout << ans << endl;
}


/*





















*/


Measured memory_bytes: 256
open System

let a, b, h, m = stdin.ReadLine().Split() |> fun [| a; b; h; m; |] ->a, b, h, m

/// HMを用い角度を求める
let angle h m =
    let hm = float h + float m / 60.0
    2.0 * Math.PI * hm * (1.0 - 1.0 / 12.0)

/// 余弦定理を用いた長さの計算
let length a b angle =
    a * a + b * b - 2.0 * a * b * Math.Cos(angle) |> Math.Sqrt 
    
angle (float h) (float m) |> length (float a) (float b) |> stdout.WriteLine 

Measured memory_bytes: 29512
def mm(n):
	global S
	if n==0:
		S=0
	elif n%2==0:
		mm(n/(-2))
		S=S*10
	elif n==1:
		S=1
	elif n%2==1:
		mm((n-1)/(-2))
		S=S*10+1

import sys
sys.setrecursionlimit(10000)
N=int(input())
mm(N)
print(S)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  
  int n, q, b, e, k;
  
  cin >> n;
  vector<int> A(n);
  vector<int>::iterator a = A.begin();
  for(int i = 0;i < n;i++) cin >> A[i];
  
  cin >> q;
  for(int i = 0;i < q;i++){
    cin >> b >> e >> k;
    cout << count(a + b, a + e, k) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  bool flag = true;
  rep(i, n){
    if(v[i] % 2 == 0 && (v[i] % 3 != 0 && v[i] % 5 != 0)) flag = false;
  }
  if(flag) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();
    string str;
    cin>>str;

    if(str[0]==str[1]  || str[1]==str[2] || str[2]==str[3])
        cout<<"Bad\n";
    else
        cout<<"Good\n";


}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
#define int long long
typedef long long ll;
#define MAXN 306
int n , m , q , l;
int G[MAXN][MAXN] , P[MAXN][MAXN];
signed main() {
    cin >> n >> m >> l;
    memset( G , 0x3f , sizeof G ) , memset( P , 0x3f , sizeof P );
    for( int i = 0 , u , v , w ; i < m ; ++ i ) {
        scanf("%lld%lld%lld",&u,&v,&w);
        G[u][v] = G[v][u] = w;
    }
    for( int i = 1 ; i <= n ; ++ i ) G[i][i] = P[i][i] = 0;
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
    for( int i = 1 ; i <= n ; ++ i )
        for( int j = 1 ; j <= n ; ++ j ) if( i != j )
            P[i][j] = G[i][j] > l ? 0x3f3f3f3f : 1;
    for (int k = 1; k <= n; k++)
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
                P[i][j] = min(P[i][j], P[i][k] + P[k][j]);
    cin >> q; int u , v;
    while( q --> 0 ) {
        scanf("%lld%lld",&u,&v);
        printf("%lld\n",P[u][v] == 0x3f3f3f3f ? -1 : P[u][v] - 1);
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main() {
	string s;
	while(cin >> s) { 
	int joi = 0, ioi = 0;
		rep(i, s.size() - 2) {
			if(s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') ++joi;
			if(s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') ++ioi;
		}
		printf("%d\n%d\n", joi, ioi);
	}
	return 0;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;

uint_fast32_t N, M, a[101010], A;

constexpr uint_fast32_t z = static_cast<uint_fast32_t>('0'), n = static_cast<uint_fast32_t>('9');
template<class T>
void uread(T& x){
    do{
        x = static_cast<T>(fgetc(stdin));
    }while(z > x || x > n);
    x -= z;
    T c = static_cast<T>(fgetc(stdin));
    while(z <= c && c <= n){
        x = x * 10 + c - z;
        c = static_cast<T>(fgetc(stdin));
    }
}

int main(){
    scanf("%u%u", &N, &M);
    for(int i = 1; i <= N; ++i){
        uread(a[i]);
        a[i] += a[i - 1];
        a[i] %= M;
    }
    sort(a, a + N + 1);
    for(int i = 1, j = 0; i <= N; ++i){
        if(a[i] != a[i - 1])j = -1;
        A += ++j;
    }
    cout << A << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>

using namespace std;
#define FILE "dealing"
#define up(i,j,n) for(ll i=j;i<=n;i++)
#define ll long long
#define db double 
#define ull unsigned ll
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define pb push_back

ll read(){
	ll f=1,x=0,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}

const ll maxn=100010,limit=100000,inf=100000000,mod=1e9+7;
ll add(ll a,ll b){return (a+=b)>=mod?a-mod:a;}
ll sub(ll a,ll b){return (a-=b)<  0?a+mod:a;}
ll mul(ll a,ll b){return 1LL*a*b%mod;}
pii a[maxn],b[maxn],t[maxn];
ll n,xid[maxn],yid[maxn],id[maxn];
bool cmp(const pii& a,const pii& b){return a.se<b.se;}
bool vis[maxn];
ll ans=0,d[maxn];
priority_queue<pii ,vector< pii > ,greater< pii > > q;

void updata(ll x,ll dis){
	if(x<1||x>n)return;
	if(d[x]>dis&&!vis[x]){
		d[x]=dis;
		q.push(mp(dis,x));
	}
}
void solve(){
	q.push(mp(0,1));
	memset(d,10,sizeof(d));d[1]=0;
	while(!q.empty()){
		ll x=q.top().se;
		if(vis[x]){q.pop();continue;}
		ans+=q.top().fi;q.pop();
		vis[x]=1;
		updata(x-1,a[x].fi-a[x-1].fi);
		updata(x+1,a[x+1].fi-a[x].fi);
		updata(id[yid[x]-1],a[x].se-a[id[yid[x]-1]].se);
		updata(id[yid[x]+1],a[id[yid[x]+1]].se-a[x].se);
	}
	cout<<ans;
}

int main(){
	//freopen(FILE".in","r",stdin);
	//freopen(FILE".out","w",stdout);
	n=read();
	up(i,1,n)a[i].fi=read(),a[i].se=read();
	sort(a+1,a+n+1);
	up(i,1,n)b[i].fi=a[i].se,b[i].se=i;
	sort(b+1,b+n+1);
	up(i,1,n)yid[b[i].se]=i,xid[i]=i;
	up(i,1,n)id[yid[i]]=i;
	solve();
	return 0;
}






Measured memory_bytes: 10356
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x "=" << (x) << "\n"
#define dbgv(x) \
    cerr << #x << "\n"; \
    reps(y, x) { cerr << y << " "; } \
    cerr << "\n"

int main() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    rep(i, x) { cin >> a[i]; }
    rep(i, y) { cin >> b[i]; }
    rep(i, z) { cin >> c[i]; }
    vector<ll> ab, abc;
    rep(i, x) {
        rep(j, y) { ab.push_back(a[i] + b[j]); }
    }
    sort(all(ab), greater<ll>());
    rep(i, min(3000ll, x * y)) {
        rep(j, z) { abc.push_back(ab[i] + c[j]); }
    }
    sort(all(abc), greater<ll>());
    rep(i, k) { cout << abc[i] << endl; }
}

Measured memory_bytes: 43240
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int a, b;

int main(void) {
  // Here your code !
  scanf("%d %d", &a, &b);
  
  if (b % a == 0) {
    printf("%d\n", a + b);
  }
  else {
    printf("%d\n", b - a);    
  }

  return 0;
}

Measured memory_bytes: 256