akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    int opnum;
    cin>>S;
    cin>>opnum;
    deque<char> strdeq;
    int reversed=0;
    for(int i=0;i<S.length();i++)
        strdeq.push_back(S[i]);
    while(opnum>0)
    {
        int optype;
        cin>>optype;
        if(optype==1)
            reversed=(reversed+1)%2;
        if(optype==2)
        {
            int pos;
            char c;
            cin>>pos;
            cin>>c;
            //插入頭
            if(pos==1)
             {
                 if(reversed==0)
                    strdeq.push_front(c);
                 else
                    strdeq.push_back(c);
             }
            //插入尾
            if(pos==2)
            {
                if(reversed==0)
                    strdeq.push_back(c);
                 else
                    strdeq.push_front(c);
            }

        }
        opnum--;
    }
    string res="";
    if(reversed==0)
        for(int i=0;i<strdeq.size();i++)
            res+=strdeq[i];
    else
        for(int i=strdeq.size()-1;i>=0;i--)
            res+=strdeq[i];
    cout<<res;
    return 0;
}

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

int a[500];
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    for(int i=A;i<B;i++){
        a[i]=1;
    }
    int ans = 0;
    for(int i=C;i<D;i++){
        if(a[i])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

int num(int x, int& n){
  if(x < 0) x += n;
  if(x > (n-1)/2) return n-x;
  return x;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(!n) break;
    set<int> x;
    for(int i=1; i<n; ++i) x.insert((i*i)%n);
    vector<int> ans((n-1)/2+1, 0);
    for(set<int>::iterator it=x.begin(); it!=x.end(); ++it){
      for(set<int>::iterator jt=it; jt!=x.end(); ++jt){
	if(jt == it) continue;
	++ans[num(*it-*jt, n)];
	++ans[num(*jt-*it, n)];
      }
    }
    for(int i=1; i<ans.size(); ++i) cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1448
N = int(input())
l = input().split()
ans = 0
if N%2 ==0:
    for i in range(N//2):
        if int(l[2*i])%2 == 1:
            ans += 1
    print(ans)

else:
    for i in range(N//2+1):
        if int(l[2*i])%2 == 1:
            ans += 1
    print(ans)


Measured memory_bytes: 9120
"use strict";
// inputに入力データ全体が入る
const main = (input) => {
  const [a, b, c, d] = input.trim().split(" ");
  const first = a * b;
  const second = c * d;
  if (first === second) {
    return first;
  } else if (first < second) {
    return second;
  } else {
    return first;
  }
};

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log(main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 29520
def move(dice, order):
  if order == "E":
    temp = dice[0]
    dice[0] = dice[3]
    dice[3] = dice[5]
    dice[5] = dice[2]
    dice[2] = temp
  elif order == "N":
    temp = dice[0]
    dice[0] = dice[1]
    dice[1] = dice[5]
    dice[5] = dice[4]
    dice[4] = temp
  elif order == "S":
    temp = dice[0]
    dice[0] = dice[4]
    dice[4] = dice[5]
    dice[5] = dice[1]
    dice[1] = temp
  elif order == "W":
    temp = dice[0]
    dice[0] = dice[2]
    dice[2] = dice[5]
    dice[5] = dice[3]
    dice[3] = temp
  else:
    pass
  return dice
 
def roll(dice):
  temp = dice[1]
  dice[1] = dice[2]
  dice[2] = dice[4]
  dice[4] = dice[3]
  dice[3] = temp
  return dice
 
dice = list(map(int, input().split()))
q = int(input())
for i in range(q):
  up, front = map(int, input().split())
  cnt = 0
  while (dice[0] != up and cnt <= 3):
    dice = move(dice, "E")
    cnt += 1
  while dice[0] != up:
    dice = move(dice, "N")
  while dice[1] != front:
    dice = roll(dice)
  print(dice[2])


Measured memory_bytes: 5608
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i * i <= n; ++i) {
        if(n%i != 0) continue;
        ll j = n / i;
        if(j - i > 1) ans += j-1;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
    ll n,m; cin>>n>>m;
    vector<bool> res(n);
    vector<int> pe(n);
    rep(i,n) res[i] = false;
    ll ansa = 0,answ = 0;
    rep(i,m){
        int p; cin>>p; p--;
        string s; cin>>s;
        if(res[p] == false){
            if(s == "WA") ++pe[p];
            else{
                ++ansa;
                res[p] = true;
            }
        }
    }
    rep(i,n){
        if(res[i] == true) answ+=pe[i];
    }
    cout<<ansa<<" "<<answ<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n,K;
    cin>>n>>K;
    vector<ll> v;
    rep(i,n){
        ll a;
        cin>>a;
        v.push_back(a);
    }
    ll ans=0;
    vector<ll> onway;
    rep(i,n+1){   //iが取り出す数
        if(i>K) break;
        rep(j,i+1){
            rep(k,j){
                onway.push_back(v[k]);
            }
            for(int k=n-1; k>=n-(i-j); k--){
                onway.push_back(v[k]);
            }
            if(!onway.empty()){
                sort(onway.begin(),onway.end());
                rep(k,K-i){ //中に入れる
                    if(onway[k]>=0) break;
                    else onway[k]=0;
                }
                ll sum=0;
                rep(k,i){
                    sum+=onway[k];
                }
                ans=max(ans,sum);
            
                onway.clear();
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#define NIL -1

int FindDepth (int );
void output(int );

typedef struct{
  int parent;
  int left;
  int right;
}vertex;

vertex V[100000];
int D[100000];
int n,degree[100000];
int childsoe,maesoe;
main()
{
  int a,i,j;
 
  scanf("%d",&n);

  /*????????¢?????????????????§?§?????????????????????¨??????NIL?????£??\??????*/
  for(i=0;i<n;i++)
    {
      V[i].parent = V[i].left = V[i].right = NIL;
    }

  for(i=0;i<n;i++)
    {
      scanf("%d",&a);/*vertex number*/
      scanf("%d",&degree[i]);/*degree*/
    
      for(j=0;j<degree[i];j++)
	{
	  scanf("%d",&childsoe);
	  if(j == 0)
	    {
	      V[a].left = childsoe;
	      V[childsoe].parent = a;
	      maesoe = childsoe;  /*????????????*/
	    }
	  else {
	    V[maesoe].right = childsoe;/*??????childsoe????????£??????*/
	    V[childsoe].parent = a;
	    maesoe = childsoe; /*????????????????????£??????right???NIL????????£?????????*/
	  }

	}/*degree??¨???*/
      
    }/*????????§?????????????????????????????£??\?????????*/

  for(i=0;i<n;i++)
    {
      D[i] = FindDepth(i);
    }

  for(i=0;i<n;i++)
    {
      output(i);/*????????????*/
    }
  
  return 0;
}

int FindDepth(int i)
{
  int d = 0,u = 0;
  while(1){
    if(V[i].parent == NIL)break;
    d++;
    i = V[i].parent;
  }

  return d;
}


void output(int p)
{
  int i,j,c;

  printf("node %d: parent = %d, depth = %d, ",p,V[p].parent,D[p]);
  if(V[p].left== NIL && V[p].parent!=NIL)
    {
      printf("leaf, [");
    }
  else if(V[p].parent==NIL )
    {
      printf("root, [");
    }
  else printf("internal node, [");

  
  c = V[p].left;
  if(c != NIL)
    {
      while(1)
	{
	  if(V[c].right == NIL)
	    {
	      printf("%d",c);
	      break;
	    }
	  else{
	    printf("%d, ",c);
	    c = V[c].right;
	  }
	}
    }
 
      
      
    
  printf("]\n");

}

Measured memory_bytes: 2564
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807

typedef long long ll;

int main(){
    int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N = int(input())
a = list(map(int, input().split()))
nums = collections.defaultdict(int)
ans=0

for i in range(N):
    nums[a[i]] += 1

num_flag = list(nums.keys())
    
for i in range(len(num_flag)):
    if nums[num_flag[i]] >= num_flag[i]:
        ans += nums[num_flag[i]] - num_flag[i]
    else:
        ans += nums[num_flag[i]]

print(ans)

Measured memory_bytes: 18676
// AOJ 2434: Audition
// 2017.12.30 bal4u@uu

#include <stdio.h>

#define A 0.66666666666666666666666666666667

int n, m;
int vi[2002], da[2002], vo[2002];
double s[2002], e[3][2002];
double dp[4][2002]; char mk[4][2002];
char buf[25], *p;

int in()
{
	int n = 0;
	while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

void calc(double *e, int *a, int x)
{
	int i, j, k, t;
	double p, q[4], r;

	for (i = 0; i <= m; i++) {
		p = 1, q[0] = 1, q[1] = q[2] = q[3] = 0;
		for (j = 1; j < n; j++) {
			t = (a[0] * i + a[j] - 1)/a[j] - 1;
			r = 0;
			if (t >= 0) if (t < m) r = s[t]; else r = s[m];

			p *= 1-r;
			for (k = 2; k >= 0; k--) q[k+1] += q[k] * (1-r), q[k] *= r;
		}
		e[i] = (q[0] + q[1] + q[2]) * x - p;
	}
}

int main()
{
	int i, j, k;
	
	fgets(p=buf, 15, stdin), n = in(), m = in();

	s[0] = 1;
	for (i = 0; i < m; i++) {
		for (j = i; j >= 0; j--) s[j+1] += s[j] / 3, s[j] *= A;
	}
	for (i = 0; i < m; i++) s[i+1] += s[i];

	for (i = 0; i < n; i++) {
		fgets(p=buf, 25, stdin);
		vi[i] = in(), da[i] = in(), vo[i] = in();
	}
	calc(e[0], vi, 5), calc(e[1], da, 3), calc(e[2], vo, 2);

	dp[0][0] = 0, mk[0][0] = 1;
	for (i = 0; i < 3; i++) for (j = 0; j <= m; j++) if (mk[i][j]) {
		for (k = 0; k <= m-j; k++) {
			double t = dp[i][j] + e[i][k];
			if (mk[i+1][j+k] && dp[i+1][j+k] > t) t = dp[i+1][j+k];
			dp[i+1][j+k] = t, mk[i+1][j+k] = 1;
		}
	}
	printf("%.9f\n", dp[3][m]);
	return 0;
}

Measured memory_bytes: 1872
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <cstdio>
using namespace std;
int main(int argc, char const *argv[]) {
int N,K;
cin>>N>>K;
vector<int> A(200000);
for(int i=0;i<N;i++){
int temp;
cin>>temp;
A[temp]++;
}
sort(A.rbegin(),A.rend());
int ans=0;
for(int i=K;i<A.size();i++){
ans+=A[i];
}
cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <map>
#include <vector>
#include <iostream>
using namespace std;
vector<int> solve(int N, long long K, vector<int> A) {
	vector<int> nxt(N);
	map<int, int> d;
	for (int i = 2 * N - 1; i >= 0; --i) {
		if (i < N) nxt[i] = d[A[i]] - i;
		d[A[i % N]] = i;
	}
	vector<long long> used(N, -1);
	long long pos = 0;
	bool flag = false;
	while (used[pos % N] == -1) {
		used[pos % N] = pos;
		long long prepos = pos;
		pos += nxt[pos % N] + 1;
		if (pos > N * K) {
			pos = prepos;
			flag = true;
			break;
		}
	}
	if (!flag && pos != N * K) {
		pos = pos + (1LL * N * K - 1 - pos) / (pos - used[pos % N]) * (pos - used[pos % N]);
		while (true) {
			long long prepos = pos;
			pos += nxt[pos % N] + 1;
			if (pos > N * K) {
				pos = prepos;
				flag = true;
				break;
			}
		}
	}
	vector<int> arr;
	map<int, int> parity;
	for (long long i = pos; i < N * K; ++i) {
		if (parity[A[i % N]] == 0) {
			parity[A[i % N]] = 1;
			arr.push_back(A[i % N]);
		}
		else {
			parity[A[i % N]] = 0;
			while (arr.back() != A[i % N]) parity[arr.back()] = 0, arr.pop_back();
			arr.pop_back();
		}
	}
	return arr;
}
vector<int> solve_easy(int N, long long K, vector<int> A) {
	vector<int> arr;
	map<int, int> parity;
	for (long long i = 0; i < N * K; ++i) {
		if (parity[A[i % N]] == 0) {
			parity[A[i % N]] = 1;
			arr.push_back(A[i % N]);
		}
		else {
			parity[A[i % N]] = 0;
			while (arr.back() != A[i % N]) parity[arr.back()] = 0, arr.pop_back();
			arr.pop_back();
		}
	}
	return arr;
}
#include <random>
#include <string>
#include <iostream>
using namespace std;
mt19937 mt(1907212116);
int rand_rng(int l, int r) {
	uniform_int_distribution<int> p(l, r - 1);
	return p(mt);
}
string stringify(vector<int> arr) {
	int n = arr.size();
	string ans = "[";
	for (int i = 0; i < n; ++i) {
		if (i) ans += ", ";
		ans += to_string(arr[i]);
	}
	ans += "]";
	return ans;
}
int main() {
	int N; long long K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	vector<int> ans = solve(N, K, A);
	for (int i = 0; i < ans.size(); ++i) {
		if (i) cout << ' ';
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    cout<<fixed<<setprecision(10);

    int k,x;cin>>k>>x;

    rep2(i,-1000000,2000002){
        if(i>x-k&&i<k+x){
            cout<<i<<endl;
        }
    }

}



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

int main() {
  int s;
  cin >> s;
  int mae = s/100;
  int ushiro = s%100;
  bool mb = false;
  bool ub = false;
  
  if (1 <= mae && mae <= 12){
    mb = true;
  }
  if (1 <= ushiro && ushiro <= 12){
    ub = true;
  }
  
  if (mb == true && ub == true){
    cout << "AMBIGUOUS" << endl;
  }
  if (mb == true && ub == false){
    cout << "MMYY" << endl;
  }
  if (mb == false && ub == true){
    cout << "YYMM" << endl;
  }
  if (mb == false && ub == false){
    cout << "NA" << endl;
  }

}

Measured memory_bytes: 3644
S = list(input())

i = 0
answer = 0
b_count = 0

while i < len(S)-1:
	i_color = S[i]
	j_color = S[i+1]
	if i_color == 'B' and j_color == 'B':
		b_count += 1
	elif i_color == 'B' and j_color == 'W':
		S[i] = 'W'
		S[i+1] = 'B'
		answer = answer + b_count + 1
	else:
		b_count = 0

	i += 1

print(answer)

Measured memory_bytes: 4840
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<stdlib.h>

using namespace std;

vector<string> ans;

int main(){
	int n;
	cin >> n;
	string mcxi = "mcxi";
	
	for(int t = 0;t < n;t++){
		string st1,st2;
		cin >> st1 >> st2;
		
		map<char,int> mcxi1;
		map<char,int> mcxi2;
		map<char,int> mcxians;
		
		for(int i = 0;i < 4;i++){
			mcxi1[mcxi[i]] = 0;
			mcxi2[mcxi[i]] = 0;
			mcxians[mcxi[i]] = 0;
		}
		
		for(int i = st1.size()-1;i >= 0;i--){
			if(i-1 >= 0){
				int tn = st1[i-1] - '0';
				if(tn >= 10)mcxi1[st1[i]] = 1;
				else{mcxi1[st1[i]] = tn; i--;}
			}else{
				mcxi1[st1[i]] = 1;
			}
		}
		
		for(int i = st2.size()-1;i >= 0;i--){
			if(i-1 >= 0){
				int tn = st2[i-1] - '0';
				if(tn >= 10)mcxi2[st2[i]] = 1;
				else{mcxi2[st2[i]] = tn; i--;}
			}else{
				mcxi2[st2[i]] = 1;
			}
		}
		
		for(int i = 3;i >= 0;i--){
			mcxians[mcxi[i]] += mcxi1[mcxi[i]] + mcxi2[mcxi[i]];
			if(i != 0){
				mcxians[mcxi[i-1]] += mcxians[mcxi[i]] / 10;
				mcxians[mcxi[i]] = mcxians[mcxi[i]] % 10;
			}else{
				mcxians[mcxi[i]] = mcxians[mcxi[i]] % 10;
			}
		}
		
		string tans = "";
		for(int i = 0;i < 4;i++){
			int tn = mcxians[mcxi[i]];
			if(tn > 0){
				char c = '0' + tn;
				string s(1,c);
				if(tn == 1){
					tans += mcxi[i];
				}else{
					tans += s + mcxi[i];
				}
			}
		}
		
		ans.push_back(tans);
	}
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3180
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
max = 0
for i in range(1, N + 1):
  if sum(a[:i]) <= x:
    max = i
if sum(a[:N + 1]) < x:
  print(N - 1)
else:
  print(max)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

int n;
double a[3005];
double dp[3001][1600];

double solve(int idx,int tail){
    if(idx==n)
        return 1.0;
    if(dp[idx][tail]!=-1)
        return dp[idx][tail];
    dp[idx][tail]=1.0;
    dp[idx][tail]=a[idx]*solve(idx+1,tail);
    if(tail>0){
        dp[idx][tail]+=(1.0-a[idx])*solve(idx+1,tail-1);
    }
    return dp[idx][tail];
}



int main(){
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    for(int i=0;i<3001;++i){
        for(int j=0;j<1600;++j){
            dp[i][j]=-1.0;
        }
    }
    pd(solve(0,n/2));
    p();
    return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

template<std::uint_fast64_t Mod>
struct modint{
  using u64=int_fast64_t;
  u64 a;
  constexpr modint(const u64 x=0) noexcept:a(x%Mod){}
  constexpr u64 &value() noexcept{return a;}
  constexpr const u64 &value() const noexcept{return a;}
  constexpr modint operator+(const modint rhs)const noexcept{
    return modint(*this)+=rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept{
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept{
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept{
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept{
    a+=rhs.a;
    if(a>=Mod)a-=Mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept{
    if(a<rhs.a)a+=Mod;
    a-=rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept{
    a=a*rhs.a%Mod;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept{
    u64 exp=Mod-2;
    while(exp){
      if(exp%2)*this*=rhs;
      rhs*=rhs;
      exp/=2;
    }
    return *this;
  }
};

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

  int N;
  cin>>N;
  vector<ll>x(N);
  for(int i=0;i<N;i++)cin>>x[i];
  vector<modint<MOD>>f(N);
  f[0]=f[1]=1;
  for(int i=2;i<N;i++)f[i]=f[i-1]*(i%MOD);
  vector<modint<MOD>>C(N,1);
  for(int i=1;i<N;i++)C[i]=C[i-1]+modint<MOD>(1)/modint<MOD>(i+1);
  modint<MOD>ans=0;
  for(int i=0;i<N-1;i++)ans+=modint<MOD>(x[i+1]-x[i])*C[i];
  ans*=f[N-1];
  cout<<ans.a<<endl;

  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a;
cin>>b;
a>0;
b>0;
a<14;
b<14;
if(a==1 and b>1) cout<<"Alice";
if(b==1 and a>1) cout<<"Bob";
if(b>1 and a>b) cout<<"Alice";
if(a>1 and b>a) cout<<"Bob";
if(a==b) cout<<"Draw";
system("pause");
return 0;
}

Measured memory_bytes: 504
# AOJ 2304 Reverse Roads
# Python3 2018.7.21 bal4u

# *******************************************
# Dinic's Max Flow Algorithm
# *******************************************
INF = 0x7fffffff

class Donic:
    def __init__(self, V):
        self.V = V
        self.level = [0] * V
        self.iter = [0] * V
        self.edge = [[] for i in range(V)]

    def add_edge(self, frm, to, cap):
        f, t = len(self.edge[frm]), len(self.edge[to])
        self.edge[frm].append([to, cap, t])
        self.edge[to].append([frm, cap, f])

    def bfs(self, s):
        self.level = [-1] * self.V
        self.level[s] = 0
        Q = []
        Q.append(s)
        while Q:
            v = Q.pop()
            for to, cap, rev in self.edge[v]:
                if cap > 0 and self.level[to] < 0:
                    self.level[to] = self.level[v] + 1
                    Q.append(to)

    def dfs(self, v, t, f):
        if v == t: return f
        k = self.iter[v]
        while k < len(self.edge[v]):
            to, cap, rev = self.edge[v][k]
            if cap > 0 and self.level[v] < self.level[to]:
                d = self.dfs(to, t, f if f <= cap else cap)
                if d > 0:
                    self.edge[v][k][1] -= d
                    self.edge[to][rev][1] += d
                    return d
            self.iter[v] += 1
            k += 1
        return 0

    def maxFlow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.level[t] < 0: break
            self.iter = [0] * self.V
            while True:
                f = self.dfs(s, t, INF)
                if f <= 0: break
                flow += f
        return flow

N, M = map(int, input().split())
dir = [[0 for j in range(N)] for i in range(N)]
id =  [[0 for j in range(N)] for i in range(N)]
d = Donic(N)
for i in range(M):
	x, y = map(int, input().split())
	x, y = x-1, y-1
	dir[y][x] = 1
	id[y][x] = i+1
	d.add_edge(x, y, 1)
S, T = map(int, input().split())
print(d.maxFlow(S-1, T-1))

ans = []
for i in range(N):
	for to, cap, rev in d.edge[i]:
		if cap < 1 and dir[i][to]: ans.append(id[i][to])
ans.sort()
print(len(ans))
if len(ans) > 0: print(*ans, sep='\n')



Measured memory_bytes: 7404
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	double n;
	cin >> n;
	vector<double> vl(n);
	rep(i, n) {
		cin >> vl[i];
	}
	sort(vl.begin(), vl.end());
	double ans = vl[0];
	rep(i, n) {
		ans += vl[i];
		ans /= 2;
	}
	cout << fixed << setprecision(10) << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}


Measured memory_bytes: 3768
n = int(input())
i = 1


def f(x):
    if not x:
        return

    x //= 10
    if x % 10 == 3:
        print(" {}".format(i), end="")
        return

    return f(x)


for i in range(1, n + 1):
    x = i
    if x % 3 == 0 or x % 10 == 3:
        print(" {}".format(i), end="")
        continue
    f(x)

print("")


Measured memory_bytes: 5872
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int n;
	cin >> n;
	int ans = n % 10;
	if (ans == 2 || ans == 4 || ans == 5 || ans == 7 || ans == 9) {
		cout << "hon" << endl;
		return 0;
	}
	if (ans == 0 || ans == 1 || ans == 6 || ans == 8) {
		cout << "pon" << endl;
		return 0;
	}
	cout << "bon" << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
#define rep(i,a,n) for(int i=a; i<n; i++)

int main() {
int n;
while(cin >> n) {
int cnt = 0;
rep(a,0,10) rep(b,0,10) rep(c,0,10) rep(d,0,10) {
if(a + b + c + d == n) cnt++;
}
cout << cnt << endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    int n; cin >> n;
    vector<int> w(n);
    int left = 0, right = 0;
    rep(i, n) {cin >> w[i]; right+=w[i];}
    int min = right;
    rep(i, n){
        if(min > abs(right-left))
            min = abs(right-left);
        left += w[i];
        right -= w[i];
    }
    cout << min;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
  vector<char> v;
  char c;
  while(cin >> c){
    if(c=='0') v.push_back('0');
    else if(c=='1') v.push_back('1');
    else if(c=='B'){
      if(!v.empty()) v.pop_back();
    }
  }
  for(int i=0;i<v.size();i++) cout << v[i];
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;

int main() {
	string s;
	cin >> s;
	if (s == "SUN") {
		cout << 7 << endl;
	}
	else if (s == "MON") {
		cout << 6 << endl;
	}
	else if (s == "TUE") {
		cout << 5 << endl;
	}
	else if (s == "WED") {
		cout << 4 << endl;
	}
	else if (s == "THU") {
		cout << 3 << endl;
	}
	else if (s == "FRI") {
		cout << 2 << endl;
	}
	else {
		cout << 1 << endl;
	}
	return 0;
}

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

int main() {
    // 入力
    int N;
    cin >> N;
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];

    // 答え
    vector<long long> S(N+1, 0); // S[N] = 0 を番兵としておく
    for (int i = N-1; i >= 0; --i) {
        A[i] += S[i+1]; // とりあえず前回分を足しておく
        long long amari = A[i] % B[i];
        long long need = 0;
        if (amari != 0) need = B[i] - amari; // 追加で必要な分
        S[i] = S[i+1] + need;
    }
    cout << S[0] << endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    int AB[N][2];
    vector<P> V(N);
    rep(i,0,N){
        cin >> AB[i][0] >> AB[i][1];
        V[i] = P(AB[i][0] + AB[i][1], i);
    }
    sort(V.rbegin(), V.rend());
    ll sum = 0;
    rep(i,0,N)sum += AB[V[i].second][i%2] * (i % 2 ? -1 : 1);
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string x;
    cin >> x;

    if ( x == "a" || x == "i" || x == "u"||x == "e" ||x == "o") {

        cout << "vowel" << endl;

    } else {

        cout << "consonant" << endl;
    }
}

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

struct puzzle {
	int f[8], space, cnt;
	bool operator<(const puzzle&p)const {
		rep(i, 8) {
			if (f[i] == p.f[i])continue;
			return f[i] < p.f[i];
		}
		return false;
	}
};
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
map<int, int>ans;
queue<puzzle>que;
map<puzzle, bool>mp;

int main() {
	puzzle p = { { 0, 1, 2, 3, 4, 5, 6, 7 }, 0, 0 };
	ans[1234567] = 0;
	puzzle u, v;
	que.push(p);
	mp[p] = true;
	while (!que.empty()) {
		u = que.front(); que.pop();
		int s = 0, I = 10000000;
		rep(i, 8) {
			s += I * u.f[i];
			I /= 10;
		}
		if (s != 1234567 && ans[s] == 0)ans[s] = u.cnt;
		int sx = u.space / 4;
		int sy = u.space % 4;
		rep(i, 4) {
			int nx = sx + dx[i];
			int ny = sy + dy[i];
			if (nx < 0 || ny < 0 || nx >= 2 || ny >= 4)continue;
			v = u;
			swap(v.f[u.space], v.f[nx * 4 + ny]);
			v.space = nx * 4 + ny;
			if (!mp[v]) {
				mp[v] = true;
				v.cnt++;
				que.push(v);
			}
		}
	}
	while (1) {
		int s = 0, I = 10000000;
		rep(i, 8) {
			int d;
			if (!(~scanf("%d", &d)))return 0;
			s += I*d;
			I /= 10;
		}
		printf("%d\n", ans[s]);
	}
}

Measured memory_bytes: 6112
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    ll x;
    cin >> x;
    for(int i=1; i<=x; i++){
        if(i*(i+1)/2 >= x){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
	int N, i, count0 = 0, count1 = 0, ans;
	char S[100000];

	scanf("%s", S);

	N = strlen(S);
	for (i = 0; i < N; i++) {
		if (S[i] == '0') {
			count0++;
		}
		else {
			count1++;
		}
	}

	if (count0 < count1) {
		ans = count0 * 2;
	}
	else {
		ans = count1 * 2;
	}

	printf("%d", ans);

	return 0;
}

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


int main() {
  long long N , K ; 
  cin >> N >> K ; 
  
  if( N % K <= K - (N%K)){
    cout << N%K << endl ; 
  }

  else  {
    cout << K-(N%K) << endl ; 
    
  }

  
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

long long cnt = 0;

void insertion(int a[], int n, int g)
{
	int i, j, v;
	for (i = g; i < n; i++)
	{
		v = a[i];
		j = i - g;
		while (j >= 0 && a[j] > v)
		{
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

int make(int g[], int n)
{
	g[0] = 1;
	int i;
	for (i = 1;; i++)
	{
		g[i] = 3 * g[i - 1] + 1;
		if (g[i] > n)
		{
			return i;
		}
	}
}

int main()
{
	int n, a[1000000];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	int m, g[35];
	m = make(g, n);
	for (int i = m - 1; i >= 0; i--)
	{
		insertion(a, n, g[i]);
	}
	cout << m << endl << g[m - 1];
	for (int i = m - 2; i >= 0; i--)cout << " " << g[i];
	cout << endl << cnt << endl;
	for (int i = 0; i < n; i++)cout << a[i] << endl;
    return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, T; cin >> N >> T;
  vector<ll> t(N, 0);
  REP(i, N){
    cin >> t[i];
  }
  ll ans = 0, start = 0, stop = 0;
  REP(i, N){
    if(stop >= t[i]){
      stop = t[i] + T;
    }else{
      ans += stop - start;
      start = t[i];
      stop = t[i] + T;
    }
  }
  ans += stop - start;
  cout << ans << endl;
}


Measured memory_bytes: 1792
N = int(input())

def standard(n, cur):
  if n == 0:
    print(''.join(cur))
  else:
    newC = chr(ord(sorted(cur)[-1]) + 1)
    for c in sorted(set(cur + [newC])):
      standard(n - 1, cur + [c])

standard(N - 1, ['a'])

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }

typedef long long ll;
string const invalid = string(1, '0'-10);

struct number {
  string s;
  number() {};
  number(string const& s): s(s) {};
  bool operator < (number const& r) const {
    if (s.size() != r.s.size()) return s.size() < r.s.size();
    return s < r.s;
  }
  bool operator == (const number &x) const {
    return s == x.s;
  }
};
  
ostream& operator << (ostream& ost, number const& r) {
  return ost << r.s;
}

string s;
number dp[55][55];

string nine(string s) {
  const int n = s.size();
  rep(i, n) if(s[i] == '?') s[i] = '9';
  if(n > 1 && s[0] == '0') return invalid;
  return s;
}

#define srange s.begin()+l, s.begin()+r

number solve(int l, int r) {

  auto& ret = dp[l][r];
  if(!ret.s.empty()) return ret;

  ret = invalid;

  bool dcheck = 1;
  REP(i, l, r) dcheck &= isdigit(s[i]) || s[i] == '?';
  if(dcheck) return ret = nine(string(srange));

  if((s[l] == 'L' || s[l] == 'R' || s[l] == '?') &&
     (s[l + 1] == '(' || s[l + 1] == '?') &&
     (s[r - 1] == ')' || s[r - 1] == '?')) {
    REP(i, l + 3, r - 2) {
      if(s[i] != '?' && s[i] != ',') continue;
      auto L = solve(l + 2, i);
      auto R = solve(i + 1, r - 1);
      if(L == invalid) continue;
      if(R == invalid) continue;
      if(s[l] == 'L' || s[l] == '?') ret = max(ret, L);
      if(s[l] == 'R' || s[l] == '?') ret = max(ret, R);
    }
  }

  return ret;
}

int main() {
  cin >> s;
  auto r = solve(0, s.size());
  if(r == invalid) cout << "invalid\n";
  else cout << r << endl;
  return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
void go();
int main() {
#ifdef tokitsukaze
    freopen("TEST.txt", "r", stdin);
#endif
    go();
    return 0;
}

/*********************************  head  *********************************/


int n,a,m;

LL ans;
void go() {
    cin>>n;
    m=-1;
    for(int i=1;i<10;++i){
        if(n%i==0){
            m=i;
        }
    }
    if(m==-1 || n/m >9 ){
        puts("No");
    }else{
        puts("Yes");
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>

using namespace std;

int main()
{
    long long int n, k;

    cin >> n >> k;

    cout << min(n%k, abs(k-(n%k))) << endl;
}


Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    n = 0
    b0 = 0

    for a, b in zip(A[:-1], B):
        n2 = min(a, b0)
        n += n2

        a -= n2
        n3 = min(a, b)
        n += n3

        b0 = b - n3

    n += min(b0, A[-1])
    print(n)




if __name__ == '__main__':
    main()


Measured memory_bytes: 19244
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N, K;
	cin >> N >> K;

	vector<ll> sunuke(N, 0);
	REP(i, K) {
		ll d;
		cin >> d;
		REP(j, d) {
			ll A;
			cin >> A;
			sunuke[A - 1]++;
		}
	}

	ll ans = 0;
	REP(i, N) {
		if (sunuke[i] == 0) ans++;
	}

	cout << ans << endl;
	return 0;
}


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

int main(){
    int n,ans=0;
    cin>>n;
    vector<string> g(n),g2(n);
    rep(i,n)cin>>g[i];
    rep(i,n){
        rep(j,n)g2[(j+i)%n]=g[j];
        bool f=true;
        rep(p,n){rep(q,p){if( g2[p][q] != g2[q][p]){f=false;break;}}}
        if(f)ans += n;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1000000000; 

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  int s = 0;
  
  for(int i=0; i<n; i++){
    cin >> a[i];
   s += a[i];
  }
  sort(a.begin(),a.end());
  double b = double(s)/(4.0*double(m));
  //cout << fixed << setprecision(10) << b << endl;
  int cnt = 0 ;
  for(int i=0; i<n; i++){
    if(a[i] >= b) cnt++;
  }
  if(cnt >= m){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import heapq
import itertools


class UnionFind:

    def __init__(self, size: int):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.size = size
        self.parent = [-1] * size

    def find(self, x: int) -> int:
        """
        xを含む集合の代表を求める
        """
        if self.parent[x] < 0:
            return x
        # 集合の代表にリンクを繋ぎ変える
        same_group_items = []
        while self.parent[x] >= 0:
            same_group_items.append(x)
            x = self.parent[x]
        for child in same_group_items:
            self.parent[child] = x
        return x

    def unite(self, x: int, y: int):
        """
        xを含む集合とyを含む集合を併合する
        """
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x != root_y:
            if self.parent[root_x] >= self.parent[root_y]:
                self.parent[root_x] += self.parent[root_y]
                self.parent[root_y] = root_x
            else:
                self.parent[root_y] += self.parent[root_x]
                self.parent[root_x] = root_y

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def count_group(self) -> int:
        """
        集合の数を数える。
        """
        count = 0
        for i in range(self.size):
            if self.parent[i] < 0:
                count += 1
        return count


n, m = map(int, input().split())
a = list(map(int, input().split()))

if n-1 == m:
    print(0)
    exit()
if n < 2*(n-m-1):
    print('Impossible')
    exit()


uf = UnionFind(n)
for _ in range(m):
    x, y = map(int, input().split())
    uf.unite(x, y)

hs = [[] for i in range(n)]
for i in range(n):
    p = uf.find(i)
    heapq.heappush(hs[p], a[i])
cost = 0
for i in range(n):
    if len(hs[i]) > 0:
        cost += heapq.heappop(hs[i])
hs = list(itertools.chain.from_iterable(hs))
heapq.heapify(hs)
for i in range(uf.count_group(), 2*(n-m-1)):
    cost += heapq.heappop(hs)
print(cost)


Measured memory_bytes: 23796
#!/usr/bin/env ruby

(n, h, w) = gets.chomp.split(/ /).map(&:to_i)
goukin = []
n.times do
  (a, b) = gets.chomp.split(/ /).map(&:to_i)
  goukin << [a, b]
end

goukin.select!{|g| g[0] >= h && g[1] >= w}

puts goukin.size

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 k;
    cin >> k;
    vector<int32> a(k);
    REP(i,k)cin >> a[i];
    if(a[k-1] != 2){
        cout << -1 << endl;
        return 0;
    }
    int32 mn = 2;
    FORR(i,k-2,0){
        int32 k = (mn - 1) / a[i] + 1;
        // while(a[i] * k < mn)k++;
        mn = a[i] * k;
    }
    int32 mx = 3;
    FORR(i,k-2,0){
        int32 k = mx / a[i] + 1;
        // while(a[i] * k <= mx)k++;
        mx = a[i] * k - 1;
    }
    if(mn > mx){
        cout << -1 << endl;
    }else{
        cout << mn << " " << mx << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int P = sc.nextInt();//A to B
        int Q = sc.nextInt();//B to C
        int R = sc.nextInt();//C to A

        int PQ = P+Q;
        int QR = Q+R;
        int RP = R+P;

        int m1 = Math.min(PQ,QR);
        int m2 = Math.min(QR,RP);
        int m3 = Math.min(m1,m2);

        System.out.println(m3);
        

    }
}


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

struct edge{ int to, cost; };
typedef pair<int, int> P;

int m, n;

int main()
{
    while(cin >> n >> m && n) {
        int a,b,cost;
        vector<vector<edge> > es(n);
        for(int i = 0; i < m; i++) {
            cin >> a >> b >> cost;
            es[a].push_back((edge){b, cost});
            es[b].push_back((edge){a, cost});
        }

        int ans = 0;
        priority_queue< P, vector<P>, greater<P> > que;
        que.push(P(0, 0));
        bool visit[n];
        fill(visit, visit + n, false);
        while(!que.empty()) {
            P p = que.top(); que.pop();
            if(visit[p.second]) 
                continue;
            
            visit[p.second] = true;
            ans += p.first;
            
            for(int i = 0; i < es[p.second].size(); i++)
                que.push(P(es[p.second][i].cost, es[p.second][i].to));
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n==1) cout << "Hello World";
    if(n==2)
    {
        int a,b;
        cin >> a >> b;
        cout << a+b;
    }
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    
    int ans = 0;
    int cnt = 0;
    REP(i, n){
        if(cnt == 0) cnt++;
        else if(a[i-1] == a[i]) cnt++;
        else{
            ans += cnt / 2;
            cnt = 1;
        }
    }
    ans += cnt/2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<unsigned long long int>;

int main(void) {
    Int n;
    cin >> n;
    VI v(n);
    for (Int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    Int result = 0;
    for (Int i = 0; i < n; ++i) {
        result += v[i];
        --result;
    }
    cout << result << endl;
    return 0;
}



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

int main() {

string S;

cin >> S;

if(S == "ABC"){
cout << "ARC";
}else{
cout << "ABC";
}

return 0;

}

Measured memory_bytes: 3628
def f_knapsack_for_all_segments(MOD=998244353):
    # 参考: https://maspypy.com/atcoder-参加感想-2019-03-22abc-159
    import numpy as np
    N, S = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ans = 0
    f = np.zeros(S + 1, np.int64)  # f[k]: 多項式の x**k の項の係数
    for a in A:
        # f で表される多項式に対して (f + 1)(1 + x**a) を新しい f とする
        f[0] += 1  # f + 1
        f[a:] += f[:-a].copy()  # 1 + x**a を掛ける
        f %= MOD
        # x**S の項の係数を解に加える
        ans += f[S]
        ans %= MOD
    return ans

print(f_knapsack_for_all_segments())

Measured memory_bytes: 12436
#include<stdio.h>
int main(void)
{
  char s[1000];
  scanf("%s",s);

  int i,h=0;
  for(i=0;i<3;i++){
    if(s[i] == s[i+1]) h=1;
  }
  if(h==1) printf("Bad\n");
  else printf("Good\n");

  return 0;
}

Measured memory_bytes: 128
#include <map>
#include <stdio.h>
using namespace std;
typedef long long ll;
map<ll, ll> dp[100];
ll min(ll x, ll y) {
	return x > y ? y : x;
}
ll max(ll x, ll y) {
	return x < y ? y : x;
}
int main() {
	int n, a[80];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	// for (int i = 0; i <= n; i++) {
	// 	for (int j = 0; j < MAXK; j++) {
	// 		dp[i][j] = -1;
	// 	}
	// }
	dp[0][0] = 1000;
	for (int i = 0; i < n; i++) {
		for (auto itr = dp[i].begin(); itr != dp[i].end(); ++itr) {
			ll nowMoney = itr->second;
			ll nowKabu = itr->first;
			ll cnt = nowMoney / a[i];
			dp[i + 1][nowKabu + cnt] =
				max(dp[i + 1][nowKabu + cnt], nowMoney - a[i] * cnt);
			dp[i + 1][0] = max(dp[i + 1][0], nowMoney + a[i] * nowKabu);
			dp[i + 1][nowKabu] = max(dp[i + 1][nowKabu], nowMoney);
		}
	}
	ll ans = 0;
	// for (int i = 0; i <= n; i++) {
	// 	for (int j = 0; j < MAXK; j++) {
	// 		if (dp[i][j] == -1) {
	// 			printf("%d ", j);
	// 			break;
	// 		}
	// 	}
	// }
	for (auto itr = dp[n].begin(); itr != dp[n].end(); ++itr) {
		ans = max(ans, itr->second);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3480
#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, m;
char x[50][51];
int w[51];
int b[51];
int r[51];

int main(){
	scanf("%d%d", &n, &m);
	rep(i, n){
		scanf("%s", x[i]);
	}

	rep(i, n){
		int c[3] = {0, 0, 0};
		rep(j, m){
			char p = x[i][j];
			++c[p == 'R' ? 2 : p == 'B'];
		}
		w[i + 1] = c[0] + w[i];
		b[i + 1] = c[1] + b[i];
		r[i + 1] = c[2] + r[i];
	}

	int ans = n * m;
	for(int i = 1; i <= n - 2; ++i){
		for(int j = 1; i + j <= n - 1; ++j){
			int k = n - i - j;
			int f = i * m - w[i];
			int g = j * m - (b[i + j] - b[i]);
			int h = k * m - (r[i + j + k] - r[i + j]);
			ans = min(f + g + h, ans);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2768
#include <bits/stdc++.h>
using namespace std;
long long A[3];
int main()
{
long long a,b,i,c=1,d=0,n,m,t,j;
string s;
cin>>s;
for(i=0;i<s.size();i++)
{
  if(s[i]=='9')
  {
    cout<<"Yes"<<endl;
    return 0;
  }
}
std::cout << "No" << '\n';
return 0;
}


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

int main()
{
    int n;
    scanf("%d", &n);
    int prev = -1, cnt = 101, ans = 0;
    for (int i = 0; i < n; ++i) {
        int x; scanf("%d", &x);
        if (x == prev) {
            x = ++cnt;
            ++ans;
        }
        prev = x;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256