akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, x;
  cin >> n >> x;
  int ans;
  cin >> ans;
  ans = abs(ans - x);
  while (--n) {
    int v;
    cin >> v;
    chmin(ans, __gcd(ans, abs(v - x)));
  }
  cout << ans << endl;
}


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

#define int long long
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int a,b,x;
	cin >> a >> b >> x;

	int ans = b/x - a/x + (a%x==0);
	cout << ans;
}







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

int main()
{
	int N = 0, i = 0, j = 0, k = 0, ans = 0, wrong = 0;
	string W[100] = {};
	char last = 0, first = 0;

	//// 入力
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> W[i];
	}

	//// 演算
	// 末尾・頭文字比較
	for (i = 1; i < N; i++) {
		for (j = 1; j < 10; j++) {
			if (W[i - 1][j] == 0) break;
		}
		last = W[i - 1][j - 1];
		first = W[i][0];

		if (last != first) { wrong = 1; break; }
	}

	// 重複チェック
	if (!wrong) {
		for (i = 1; i < N; i++) {
			for (j = 0; j < i; j++) {
				if (i != j) {
					//					cout << "W[" << i << "] " << W[i] << " vs. W[" << j << "] " << W[j] << endl;
					for (k = 0; k < 10; k++) {
						//						cout << "W[" << i << "][" << k << "] " << W[i][k];
						//						cout << " vs. W[" << j << "][" << k << "] " << W[j][k] << endl;
						if (W[i][k] != W[j][k]) break;
					}
					if (k == 10) { wrong = 2; break; }
				}
			}
			if (wrong) break;
		}
	}

	// 判定
	if (wrong == 1) {
		ans = 0;
		//		cout << "末尾・頭文字違反" << endl;
	}
	else if (wrong == 2) {
		ans = 0;
		//		cout << "重複チェック違反" << endl;
	}
	else
		ans = 1;

	//// 出力
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	//	cin >> i;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        long long int sum=0;
        int a[200005],b[200005];
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&a[i]);
            b[i]=a[i]-(i+1);
        }
        sort(b,b+n);
        for(int i=0;i<n/2;i++)
            sum=sum+abs(b[i]-b[n-1-i]);
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    ll c=1;
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    if(n%2==0){
        vector<int>ans;
        for(int i=1;i<=n/2;i++){
            ans.push_back(i*2-1);
            ans.push_back(i*2-1);
        }
        if(a!=ans){
            cout<<0;
            return 0;
        }
    }else{
        vector<int>ans;
        ans.push_back(0);
        for(int i=1;i<=n/2;i++){
            ans.push_back(i*2);
            ans.push_back(i*2);
        }
        if(a!=ans){
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n/2;i++){
        c*=2;
        c%=1000000007;           
    }
    cout<<c;
    return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = 1e18;
const int N = 20;
map<ll, ll> fr;

void solve(int t)
{
	ll l, r, d;
	cin >> l >> r >> d;
	l--;
	cout << r / d - l / d << endl;

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);



	int t = 1;
	//cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long X;
    cin >> X;
    long long P = 100, step = 0;
    while(P < X)
    {
        P += P / 100;
        step++;
    }
    cout << step << endl;
    return 0;
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
import sys
buff_readline = sys.stdin.buffer.readline


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def slv(N, P):
    M = N+2
    cost = [0] * M**2
    occupy = [1] * M**2
    for i in range(N):
        im = i*M + M + 1
        for j in range(N):
            cost[im+j] = min(i, j, N-i-1, N-j-1)

    ds = [-1, 1, -M, M]
    ans = 0
    for p in P:
        p -= 1
        x = p // N
        y = p % N
        p = x * M + y + M + 1
        ans += cost[p]
        occupy[p] = 0
        s = []
        s.append(p)
        while s:
            pi = s.pop()
            for d in ds:
                ni = pi + d
                nc = cost[pi] + occupy[pi]
                if nc < cost[ni]:
                    cost[ni] = nc
                    s.append(ni)
    return ans


def main():
    N = read_int()
    P = read_int_n()
    print(slv(N, P))


if __name__ == '__main__':
    main()


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

def main():
    N = int(input())
    SP = []
    for i in range(N):
        s, p = input().split()
        SP.append((s, -int(p), i+1))
            
    X = map(lambda x:str(x[2]), sorted(SP))
    print('\n'.join(X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
#include<time.h>
#include<map>
#include<set>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;
vector<ll>a[100000];

int main(void) {
	ll n, x;
	cin >> n >> x;
	vector<int>l(n);
	for (int i = 0;i < n;i++)cin >> l[i];
	int ans = 1, d = 0;
	for (int i = 0;i < n;i++) {
		d += l[i];
		if (d <= x)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

template <typename T>
struct KMP{
	vector<int> A;
	KMP(T &s){
		A.resize(s.size()+1,-1);
		int x = -1;
		for(int i=0;i<s.size();i++){
			while(x>=0&&s[i]!=s[x]){
				x=A[x];
			}
			x++;
			if(i!=s.size()-1){
				if(s[i+1] == s[x]) {
					A[i+1] = A[x];
					continue;
				}
			}
			A[i+1] = x;
		}
	}

	
	//文字列[0,pos]の接尾辞と接頭辞が何文字一致しているか
	//(i+1)-get_length(i)で[0,i]の最小周期
	int get_length(int pos){
		return A[pos+1];
	}
	
};


int main(){
	
	int N;
	cin>>N;
	
	vector<int> a(N),b(N);
	
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	
	for(int i=0;i<N;i++){
		scanf("%d",&b[i]);
	}
	
	vector<vector<int>> ans(30,vector<int>(N,-1));
	
	for(int i=0;i<30;i++){
		vector<int> X;
		for(int j=0;j<N;j++){
			X.push_back((b[j]>>i)&1);
		}
		X.push_back(2);
		for(int j=0;j<2;j++){
			for(int k=0;k<N;k++){
				X.push_back((a[k]>>i)&1);
			}
		}
		
		KMP<vector<int>> K(X);
		
		for(int j=0;j<N;j++){
			if(K.get_length(2*N+j)==N)ans[i][j] = 0;
		}
		
		for(int j=N+1;j<X.size();j++){
			X[j] ^= 1;
		}
		
		KMP<vector<int>> K2(X);
		
		for(int j=0;j<N;j++){
			if(K2.get_length(2*N+j)==N)ans[i][j] = 1;
		}
	}
	
	vector<pair<int,int>> P;
	
	for(int i=0;i<N;i++){
		int now = 0;
		for(int j=0;j<30;j++){
			if(ans[j][i]==-1){
				now=-1;
				break;
			}
			now ^= (ans[j][i]<<j);
		}
		
		if(now!=-1){
			P.emplace_back(i,now);
		}
	}
	
	sort(P.begin(),P.end());
	
	for(int i=0;i<P.size();i++){
		printf("%d %d\n",P[i].first,P[i].second);
	}
	
	
    return 0;
}


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

int N, Q;
const int MAX_N = 2.0e5 + 100;
vector<int> tree[MAX_N];
bool visited[MAX_N];
ll ans[MAX_N];

void rec(int v) {
    for (int i = 0; i < tree[v].size(); i++) {
        if (!visited[tree[v][i]]) {
            ans[tree[v][i]] += ans[v];
            visited[tree[v][i]] = true;
            rec(tree[v][i]);
        }
    }
    return;
}

int main() {
    cin >> N >> Q;
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    memset(ans, 0, sizeof(ans));
    memset(visited, false, sizeof(visited));
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        ans[p] += x;
    }

    visited[1] = true;
    rec(1);
    
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 24448
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;
const ll mod=998244353;

ll mod_pow(ll a,ll x){
    ll ans=1;
    for(int i=0;i<63;i++){
        if(x>>i&1){ans*=a; ans%=mod;}
        a*=a;
        a%=mod;
    }
    return ans;
}

ll R(ll a){
    return mod_pow(a,mod-2);
}


vector<ll> F={1,1};

ll c(ll n,ll k){
    if(n==0 || k==0){return 1;}
    if(n<k){return 0;}
    return F[n]*R(F[n-k])%mod*R(F[k])%mod;
}




int main(){
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    for(ll i=2;i<1e6;i++){F.push_back(F[i-1]*i%mod);}
    ll ans=0;
    for(ll i=0;i<=n;i++){
        ll K=k-i*a;
        if(K<0){break;}
        if(K%b==0){
            ans+=c(n,i)*c(n,K/b)%mod;
            ans%=mod;
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    int r, g; cin >> r >> g;
    cout << 2*g - r;
}


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

using namespace std;

#define endl "\n"
typedef long long int ll;
#define f first
#define s second

inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}

//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;

ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("debug.txt", "w", stderr);
    #endif
    fastio();
    
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    int ans = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            for(int k = j + 1; k < n; ++k){
                bool c0 = (i != j) && (j != k) && (i != k);
                bool c1 = (a[i] == a[j]) || (a[j] == a[k]) || (a[i] == a[k]);
                bool c2 = (a[i] + a[j]) > a[k];
                bool c3 = (a[i] + a[k]) > a[j];
                bool c4 = (a[j] + a[k]) > a[i];
                if (c0 && !c1 && c2 && c3 && c4){
                    cerr << i << " " << j << " " << k << endl;
                    ++ ans;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int h,w,d; cin >> h >> w >> d;
    vector<vector<int>> f(h+1, vector<int>(w+1));
    vector<int> dist(h*w);
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            cin >> f[i][j];
        }
    }

    vector<pii> id((h*w)+1);
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            id[f[i][j]].first = i;
            id[f[i][j]].second = j;
        }
    }

    for(int i = d+1; i <= h*w; i++){
        dist[i] = dist[i-d] + abs(id[i].first - id[i-d].first) + abs(id[i].second - id[i-d].second);
    }

    int q; cin >> q;
    rep(i,q){
        int ans = 0;
        int l,r; cin >> l >> r;
        ans = dist[r] - dist[l];
        cout << ans << endl;
    }
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{   
	int X,K;
	cin>>K>>X;
	for(int t=1;t<=2*(K-1)+1;t++) 
	{
		if(K!=t)
		cout<<X-K+t<<" ";
		else
		cout<<X<<" ";
	} 
	return 0; 		
}	

Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
//cout<<fixed<<setprecision(15)<<ans;
 
template <typename T>
void printvec(vector<T>& vec){
	for(int i=0;i<vec.size();i++){
		cout<<vec[i]<<" ";
	}
	cout<<endl;
}


int a[12345];
int main(){
    std::ios::sync_with_stdio(false);
    int n,x;
    cin>>n>>x;
    int i;
    int cnt=0;
    rep(i,n){
    	cin>>a[i];
    }
    sort(a,a+n);
    rep(i,n){
    	if(x<a[i]){
    		x=0;
    		break;
    	}
    	x-=a[i];
    	cnt++;
    }
    if(x!=0)
    	cnt--;
    cout<<cnt<<endl;
    return 0;   
}



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

using namespace std;

int main(int, char**) {
	int k;
	cin >> k;
	queue<long long> que;
	for (int i=1; i<10; i++) {
		que.push(i);
	}
	long long n;
	for (int i=0; i<k; i++) {
		n = que.front();
		que.pop();
		if (n%10 != 0) que.push(10 * n + n%10 - 1);
		que.push(10 * n + n%10);
		if (n%10 != 9) que.push(10 * n + n%10 + 1);
	}
	cout << n << endl;
	return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

// End of Template //

int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cou((a == c ? 0 : 1));


}

Measured memory_bytes: 256
#include <stdio.h>

int d[1010][2];

int main(){
	
	int i,j,k;
	int n,m;
	int p,cnt;
	
	while(scanf("%d %d",&n,&m)){
		if(n==0 && m==0)break;
		
		for(i=0;i<=n;i++){
			d[i][0]=i-1;
			d[i][1]=i+1;
		}
		d[1][0]=n;
		d[n][1]=1;
		
		p=n;
		cnt=n;
		
		while(cnt>1){
			for(i=0;i<m;i++){
				p=d[p][1];
			}
			d[d[p][0]][1]=d[p][1];
			d[d[p][1]][0]=d[p][0];
			
			cnt--;
		}
		printf("%d\n",d[p][1]);
		
	}
	
	return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	int N, M; cin >> N >> M;
	vector<bool> result(N+1, false);
	vector<int> status(N+1, 0);


	REP(i,M){
		int p;
		string S;
		cin >> p >> S;
		p--;
		if(S == "AC") result[p] = true;
		if(S == "WA" and result[p] == false) status[p]++;

	}

	int a = 0, b = 0;
	REP(i,N+1){
		if(result[i]){ 
			a++;
			b += status[i];
		}
	}

	cout << a << ' ' << b << endl;


	return 0;

}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	string p;
	cin >> p;

	int m = 1000000007;

	vector<int> d(13);
	d[0] = 1;
	long long int x = 1;
	reverse(p.begin(), p.end());

	for (int i = 0; i < p.size(); i++) {
		vector<int>r(13);
		if (p[i] == '?') {
			for (int k = 0; k < 10; k++) {
				long long int t = x*k;
				//t %= m;
				for (int j = 0; j < 13; j++) {
					r[(t + j) % 13] += d[j];
					r[(t + j) % 13] %=m;
				}
			}
		}
		else {
			long long int t = (p[i] - '0');
			t *= x;
			for (int j = 0; j < 13; j++) {
				r[(t + j) % 13] += d[j];
				r[(t + j) % 13] %= m;
			}
		}
		x *= 10;
		x %= 13;
		d = r;
	}
	
	cout << d[5] << endl;
	return 0;

}

Measured memory_bytes: 512
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll A,B,C,D;cin>>A>>B>>C>>D;
    bool WIN=false;
    REP(i,1000){
        //cout<<"a:"<<A<<" c:"<<C<<"\n";
        if(A<=0){
            WIN=false;
            break;
        }
        if(C<=0){
            WIN=true;
            break;
        }
        if(i%2==0){
            C-=B;
        }else{
            A-=D;
        }
    }
    if(WIN)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 3624
#include<stdio.h>
long long int gcm(long long int a,long long int b)
{
	long long int r=a%b;
	while(r>0)
	{
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}
int main()
{
	int n;
	scanf("%d",&n);
	int i;
	long long int ans;
	scanf("%lld",&ans);
	long long int t;
	for(i=1;i<n;i++)
	{
		scanf("%lld",&t);
		ans=ans*(t/gcm(ans,t));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        insertionSort(arr);
    }
    public static void insertionSort(int[] arr) {
        out_put(arr);
        for(int i = 1; i < arr.length; i++)
        {
            int key = arr[i];
            int j = i - 1;

            while(j >= 0 && arr[j] > key)
            {
                arr[j + 1] = arr[j];
                j = j - 1;
            }
            arr[j + 1] = key;
            out_put(arr);
        }
    }
    
    private static void out_put(int array[]){

        System.out.printf("%d", array[0]);

        for(int i = 1; i < array.length; i++){
            System.out.printf(" %d", array[i]);
        }
        System.out.printf("\n");
    }
}



Measured memory_bytes: 48328
#include <stdio.h>
int main(){
      int i,j=0,k=0,N;

      scanf("%d",&N);
      char s[N+1];
      scanf("%s",s);

      for(i=0;s[i]!='\0';i++){
            if(s[i]=='R'){
                  j++;
            }else{
                  k++;
            }
      }
      if(j>k){
            printf("Yes");
      }else{
            printf("No");
      }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n,ans = 0;
  string s,ss,sss;
  cin>>s;
  if(s[1] == 'B')cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
  return 0;
}


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

int main() {
  int a,b,W,ans; cin >> W >> a >> b;
  if (a >= b + W) ans = a - b - W;
  else if (b >= a + W) ans = b - W - a;
  else ans =0;
  cout << ans << endl;
}
  

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

int main(void){
    char w[3][10] = {"Sunny", "Cloudy", "Rainy"};
    char s[10];
    scanf("%s", s);
    for(int i=0; i<3; i++){
        if(strcmp(s, w[i])==0){
            printf("%s", w[(i+1)%3]);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N;
    long long ans=0;
    cin>>N;
    vector<long long> a(3*N);
    for(int i=0;i<3*N;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<N;i++){
        ans+=a[i*2+1];
    }
    cout<<ans<<endl;
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int X, A; cin >> X >> A;
  if(X < A) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
p = [deque([]) for _ in range(N)]

for i in range(N-1):
    a, b, c = [int(x) for x in input().strip().split()]
    p[a-1].append((b, c))
    p[b-1].append((a, c))

Q, K = [int(x) for x in input().strip().split()]

c = [-1] * N
f = [False] * N

def search(cp, cost):
    f[cp-1] = True
    for np, cos in p[cp-1]:
        if f[np-1]:
            continue
        c[np-1] = cost + cos
        f[np-1] = True
        search(np, cost + cos)

search(K, 0)
for q in range(Q):
    x, y = [int(x) for x in input().strip().split()]
    print(c[x-1]+c[y-1])

Measured memory_bytes: 190344
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N,K;
	cin >> N >>K;
	int ans = 0;
	int div = 1;
	while (true) {
		if (N < div)break;
		else {
			div *= K;
			ans++;
		}
	}
	print(ans);
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<string> > s(h, vector<string>(w));
    string temp;
    string Alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    for (int i = 1; i <= h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> temp;
            if (temp == "snuke") {
                cout << Alph.at(j) << i << endl;
            }
        }
    }

}

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

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	vector<vector<int>> A(2, vector<int>(n)), dp = A;
	for (auto &vec: A) {
		for (int &x: vec) {
			scanf("%d", &x);
		}
	}
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = A[i][j] + max(i ? dp[i - 1][j] : 0, j ? dp[i][j - 1] : 0);
		}
	}
	int ans = dp[1][n - 1];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
//ΔATCODER C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 111111;
vector<int> v[N];
int vis[N],col[N];
int n,m;
void dfs(int u){
	vis[u]=1;
	int i,s,x;
	s=v[u].size();
	for(i=0;i<s;i=i+1){
		x=v[u][i];
		if(col[x]==col[u]){
			cout<<(LL)n*(n-1)/2-m<<endl;
			exit(0);
		}
		if(!vis[x]){
			col[x]=col[u]^1;
			dfs(x);
		}
	}
}
int main()
{
	int i,x,y;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i=i+1)
		col[i]=-1;
	for(i=1;i<=m;i=i+1){
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	col[1]=1;
	dfs(1);
	x=0,y=0;
	for(i=1;i<=n;i=i+1){
		if(col[i]==0)
			x++;
		else
			y++;
	}
	cout<<(LL)x*y-m<<endl;
	return 0;
}

Measured memory_bytes: 7168
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))
value=0
last=100

for dish in A:
  value+=B[dish-1]
  if dish==last+1:
    value+=C[last-1]
  #print(dish,last,value)
  last=dish
  
print(value)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, d;
	cin>>n>>d;
	long long x, y;
	long long ans=0;
	for (int i=1; i<=n; i++) {
		cin>>x>>y;
		if ((x*x+y*y)<=d*d) {
			ans++;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <math.h>

int isprime(int x){
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  int i;
  for(i=3;i<=sqrt(x);i+=2)
    if(x%i==0)
      return 0;
  return 1;  
}

int main(void){

  int n,x,i,num=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&x);
    if(isprime(x))num++;
  }
  
  printf("%d\n",num);

  return 0;
}

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

using namespace std;

int main() {
  long long x,k,d;
  cin>>x>>k>>d;
  if(x<0){
    x=-x;
  }
  long long t=x%d;
  long long s=(x/d);
  if(x>0&&x/d>=k){
    cout<<x-k*d<<endl;
    return 0;
  }
  
  if(s%2==k%2){
    cout<<t<<endl;
    return 0;
  }
  
    cout<<d-t<<endl;
  
  
  
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static List<int[]>[] costs;
        static long[] dis;
        static bool[] reach;
        static void Main(string[] args)
        {
            var N = ReadInt();
            costs = new List<int[]>[N + 1];
            for (int i = 0; i < N + 1; i++) costs[i] = new List<int[]>();
            for (int i = 0; i < N - 1; i++)
            {
                var input = ReadArrayInt();
                var a = input[0];
                var b = input[1];
                var c = input[2];
                costs[a].Add(new int[] { b, c });
                costs[b].Add(new int[] { a, c });
            }
            dis = Enumerable.Repeat(long.MaxValue, N + 1).ToArray();
            reach = new bool[N + 1];
            var QK = ReadArrayInt();
            var Q = QK[0];
            var K = QK[1];
            Dfs(K, -1, 0);
            for (int i = 0; i < Q; i++)
            {
                var xy = ReadArrayInt();
                Console.WriteLine(dis[xy[0]] + dis[xy[1]]);
            }

            Console.WriteLine();
            Console.ReadLine();
        }

        static void Dfs(int v, int p, long d)
        {
            dis[v] = d;
            reach[v] = true;
            for (int i = 0; i < costs[v].Count; i++)
            {
                if (!reach[costs[v][i][0]])
                {
                    if (costs[v][i][0] == p) continue;
                    Dfs(costs[v][i][0], v, d + costs[v][i][1]);
                }
            }
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 46980
n, y = map(int, input().split())

a = 0  # 1000
b = 0  # 5000
c = 0  # 10000

c = y//10000
b = (y - c*10000)//5000
a = (y - c*10000 - b*5000)//1000

flag = True

while (a+b+c) <= n:
    num = a+b+c
#    print(num)
#    print(c,b,a)
    if num == n:
        flag = False
        break
    else:
        if num + 9 <= n and c > 0:
            c -= 1
            a += 10
            continue
        elif num + 4 <= n and b > 0:
            b -= 1
            a += 5
            continue
        elif num + 1 <= n and c > 0:
            c -= 1
            b += 2
            continue
        else:
            break
if flag:
    print(-1, -1, -1)
else:
    print(c, b, a)




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

int main(){
    int a, p;
    cin >> a >> p;
    cout << (3*a + p)/2 << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

void solve(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  string s;
  cin >> s;

  vector<ll> t;
  for(int i=n-1; i>=0; i--){
    ll tmp = a[i];
    if(s[i]== '1'){
      for(auto it:t){
        tmp = min(tmp, tmp^it);
      }
      if(tmp!=0){ cout << 1 << ln; return; }
    } else {
      for(auto it:t){
        tmp = min(tmp, tmp^it);
      }
      if(tmp!=0){ t.emplace_back(tmp); }
    }
  }
  cout << 0 << ln;
}

int main(){
  int q; cin >> q;
while(q--){
  solve();
}
  return 0;
}

Measured memory_bytes: 3644
n, k = map(int, input().split())
x = list(map(int, input().split()))
pos, nega = [], []
for v in x:
    if v >= 0:pos.append(v)
    else:nega.append(-v)
nega.sort()
ans = 10**9
if k <= len(pos):ans = min(ans, pos[k-1])
if k <= len(nega):ans = min(ans, nega[k-1])
for i in range(k):
    if i < len(pos) and 0 <= k - i - 2 < len(nega):
        ans = min(ans, 2 * pos[i] + nega[k-i-2])
    if i < len(nega) and 0 <= k - i - 2 < len(pos):
        ans = min(ans, 2 * nega[i] + pos[k-i-2])
print(ans)

Measured memory_bytes: 20460
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline-------------------------------------------
    N = int(input())
    v = list(map(int,input().split()))
    v.sort()
    a = (v[0]+v[1])/2
    if N == 2:
        print(a)
        exit()
    for i in range(2,N):
        a = (a+v[i])/2
    print(a)

if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 5168
// MAGRANT - GNC20 - TEMPLATE 3.3
// 2017/8/26 - AtCoder Grand Contest 019 - Beta

// FOR COMPATIBILITY:
#define _CRT_SECURE_NO_WARNINGS

// UNIVERSAL DEFINITIONS:
#define N (1<<18)
#define MODULO (1000000007)
#define HA1 (2420609)
#define HA2 (19260817)

// FREQUENT HEADER FILES:
#include <cstdio>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <complex>
using namespace std;

// TEMPLATE BEGINS HERE.
//#define MAGRANT_ALLOWS_CTMP
// IMPORTANT: DO NOT OPEN UNLESS AS CONTESTANT.
// CAUTION: BEWARE OF CONFLICT.
#ifdef MAGRANT_ALLOWS_CTMP
namespace CTMP
{
	// ELEMENTARY MATHEMATICAL COMPUTATIONS:
	long long fact[N], inv[N];
	long long KissMe(long long xx, long long yy)
	{
		if (yy == 0LL)
		{
			return 1LL;
		}
		long long Res = KissMe((xx*xx) % (long long)MODULO, yy >> 1);
		if (yy % 2LL == 1LL)
		{
			Res *= xx;
			Res %= (long long)MODULO;
		}
		return Res;
	}
	inline void InitFactInv()
	{
		fact[0] = 1LL;
		for (int i = 1;i < N - 4;i++)
		{
			fact[i] = fact[i - 1] * (long long)i;
			fact[i] %= (long long)MODULO;
		}
		inv[N - 5] = KissMe(fact[N - 5], (long long)(MODULO - 2));
		for (int i = N - 6;i >= 0;i--)
		{
			inv[i] = inv[i + 1] * (long long)(i + 1);
			inv[i] %= (long long)MODULO;
		}
	}
	inline long long Choose(int xx, int yy)
	{
		if (xx < yy)
		{
			return 0LL;
		}
		else if (xx == yy)
		{
			return 1LL;
		}
		long long Res = fact[xx];
		Res *= inv[yy];
		Res %= (long long)MODULO;
		Res *= inv[xx - yy];
		Res %= (long long)MODULO;
		return Res;
	}
	inline long long GridWays(int fx, int fy, int sx = 0, int sy = 0)
	{
		fx -= sx, fy -= sy;
		if (fx < 0 || fy < 0)
		{
			return 0LL;
		}
		long long Res = fact[fx + fy];
		Res *= inv[fx];
		Res %= (long long)MODULO;
		Res *= inv[fy];
		Res %= (long long)MODULO;
		return Res;
	}
}
#endif
// TEMPLATE FINISHES HERE.

int n;
char s[N];
long long Ans;
int cnt[30];

int main()
{
	// IMPORTANT: DO NOT OPEN UNLESS AS CONTESTANT.
	// CAUTION: BEWARE OF CONFLICT.
	//using namespace CTMP;

	// REAFFIRM THE FOLLOWING BEFORE CODING.
	// 1. THE ALGORITHM IS CORRECT.
	// 2. THE COMPLEXITY IS PROPER.
	// 3. THE ALGORITHM CANNOT BE SIMPLER.
	// 4. CODING DETAILS WERE CONSIDERED.

	scanf("%s", s);
	n = strlen(s);
	Ans = 1LL + ((long long)n)*((long long)(n + 1)) / 2LL;
	for (int i = 0;i < n;i++)
	{
		cnt[s[i] - 'a']++;
	}
	for (int i = 0;i < 26;i++)
	{
		Ans -= ((long long)(cnt[i]))*((long long)(cnt[i] + 1)) / 2LL;
	}
	printf("%lld\n", Ans);

	// REAFFIRM THE FOLLOWING BEFORE SUBMITTING.
	// 1. THE ARRAYS ARE IN PROPER SIZE.
	// 2. THE CORNER CASES WILL NOT LEAD TO VIOLATION.
	// 3. NO TYPO LIKE N->M EXISTS.
	// 4. THE INPUT/OUTPUT IS IN THE SPECIFIED FORMAT.
	// 5. ALL CATEGORIES DO NOT INTERSECT.
	//system("pause");
	return 0;
}


Measured memory_bytes: 384
/**
 *    author: gxfireball       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;

void solve(){
   ll n;
   cin >> n;
    ll temp = n%10;
   
    if(temp == 2 || temp == 4 || temp == 5 || temp == 7 || temp == 9){
        cout << "hon";
    }
    else if(temp == 0 || temp == 1 || temp == 6 || temp == 8){
        cout << "pon";
    }
    else if(temp == 3){
        cout << "bon";
    }

}

int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    while(t--){
    	solve();
    }
    return 0;
}



Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;



 class Main{
	 
	 
	 
	

	public static void main(String[] args) throws IOException {
		
		
		FastScanner sc=new FastScanner();
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		long hi[] = new long[n+1];
		for(int i=0; i<n; i++)
			hi[i+1] = sc.nextLong();
		long dp[] = new long[n+1];
		
		dp[1] = 0;
		
		
		for(int i=2; i<n+1; i++) {
			long res = Long.MAX_VALUE;
			if(i-k >= 0) {
				for(int j=1; j<=k; j++) {
					res = Math.min(dp[i-j] + Math.abs(hi[i]-hi[i-j]),res);
				}
				
			}
			else {
				for(int j=1; j<i; j++) {
					res = Math.min(dp[i-j] + Math.abs(hi[i]-hi[i-j]),res);
				}
			}
			dp[i] = res;
		}
		
		System.out.println(dp[n]);
		
				
	}
	
	
	
	
 
	static void sort(int[] a) {
		ArrayList<Integer> l=new ArrayList<>();
		for (int i:a) l.add(i);
		Collections.sort(l);
		for (int i=0; i<a.length; i++) a[i]=l.get(i);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long[] readArrayLong(int n) {
        	long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
        }
		long nextLong() {
			return Long.parseLong(next());
		}
		String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
	}
}


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

int main() {

	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	if (a[0] == 0) {
		cout << 0 << endl;
		return 0;
	}
	const ll u = 1000000000000000000LL;
	ll prod = 1;
	for (int i = 0; i < n; i++) {
		if (prod <= u / a[i]) {
			prod *= a[i];
		}
		else {
			prod = -1;
			break;
		}
	}
	cout << prod << endl;
	return 0;
}

Measured memory_bytes: 3936
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << ' ' << b << ' ' << c << endl;
  return 0;
}


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

#define ll long long
#define ar array

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> stones(n);
    for (ll i = 0; i < n; i++) {
        cin >> stones[i];
    }
    vector<ll> dp(n, 1e9 + 5);
    dp[0] = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j <= i + k; j++) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(stones[i] - stones[j]));
            }
        }
    }
    cout << dp[n - 1] << "\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long rec(long long n, long long x, bool init)
{
	long long y = init ? n-x : n;
	if (x > y) swap(x, y);
	long long ret = init ? x+y : 0;
	long long p = y / x, q = y % x;
	if (q == 0) return ret+(p-1)*2LL*x+x;
	return ret+p*2LL*x+rec(x, q, 0);
}
int main()
{
	scanf("%lld%lld", &n, &x);
	long long ans = rec(n, x, 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
n=gets.chomp.to_i
h = {}
prev = gets.chomp
h[prev] = 1
(n-1).times do
    w = gets.chomp
    if w[0] != prev[-1]
        puts "No"
        exit
    end
    if h.has_key?(w)
        puts "No"
        exit
    end
    prev = w
    h[prev] = 1
end
puts "Yes"


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

int main() {
  // input
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n-1));
  rep(i,n) {
    rep(j,n-1) {
      cin >> a[i][j];
      a[i][j]--;
    }
    reverse(a[i].begin(), a[i].end());
  }

  // Add to queue if matches are the same
  vector<P> q;
  auto check = [&](int i){
    if (a[i].size() == 0) return;
    int j = a[i].back();
    if (a[j].back() == i) {
      P p(i,j);
      if (p.first > p.second) swap(p.first, p.second);
      q.push_back(p);
    }
  };
  
  // initialization
  rep(i,n) {
    check(i);
  }

  // The process is repeated untill the queue for the next match is empty.
  int day = 0;
  while (q.size() > 0) {
    day++;
    sort(q.begin(), q.end());
    q.erase(unique(q.begin(), q.end()), q.end());
    vector<P> prevQ;
    swap(prevQ, q);
    for (P p : prevQ) {
      int i = p.first, j = p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    for (P p : prevQ) {
      int i = p.first, j = p.second;
      check(i);
      check(j);
    }
  }

  // output
  rep(i,n) {
    if (a[i].size() != 0) {
      puts("-1");
      return 0;
    }
  }
  cout << day << endl;
  return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;

    if ((A+B)%2==1) cout << "IMPOSSIBLE" << endl;
    else cout << (A+B)/2 << endl;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC144A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            if(a>9||b>9)
            {
                Console.WriteLine(-1);
            }
            else
            {
                Console.WriteLine(a * b);
            }
            Console.ReadKey();
        }
    }
}


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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

void failure(){cout<<-1<<lf;exit(0);}

vector<int> e[_];
int n,ed[_]={0},via[_]={0};

int dfs(int x,int who)
{
	if(ed[x]==who)return 0;
	ed[x]=who;
	for(auto b:e[x])if(!via[b] || dfs(via[b],who)){via[b]=x;return 1;}
	return 0;
}

int es[_]={0};

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty();
	for(int i=1;i<n;i++)for(int j=ty();j>=1;j--)e[ty()].emplace_back(i);
	for(int i=2;i<=n;i++)if(!dfs(i,i))failure();

	queue<int> q;
	q.emplace(1);
	for(int i=1;i<=n;i++)
	{
		if(q.empty())failure();
		int a=q.front();q.pop();
		for(auto b:e[a])if(!es[b])es[b]=a,q.emplace(via[b]);
	}
	for(int i=1;i<n;i++)cout<<es[i]<<' '<<via[i]<<lf;

	return 0;
}


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

const int divisor = 1000000007;

int main(){
	vector<int> ansvec;

	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;
		
		//まず0番目の単語を入れておく
		for (int i = 0; i < N; i++) word[i] = i + 1;

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
				--it;
			}
			else {
				bubblenum = (--it)->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			map<int, int>::iterator it2 = bubblehist.insert(it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (++it2; it2 != bubblehist.end(); it2++) ++(it2->second);

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}
		ansvec.push_back((int)ans);
	}

	for (vector<int>::iterator it = ansvec.begin(); it != ansvec.end(); it++) cout << *it << "\n";

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816