akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define mod 1000000007
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
//const long long INFLL = (ll)INF * (ll)INF;
const ld EPS = 10e-9;
const int MAX = 1e6;

int main(){
    ios_base:: sync_with_stdio(0); 
    cin.tie(0);
    
    int R, G;
    cin >> R >> G;
    cout << 2*G - R;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n,k;
    string s;
    cin>>n>>k>>s;
    int cnt=0;
    for(int i=0;i<n-1;i++)
        cnt+=s[i]!=s[i+1];
    cnt-=2*k;
    cnt=max(cnt,0ll);
    cout<<n-1-cnt;
}


Measured memory_bytes: 512
<?php

$count = (int)trim(fgets(STDIN));
$array = explode(' ', trim(fgets(STDIN)));
$amount = 1;
foreach ($array as $num) {
    if ((int)$num === 0) {
        $amount = 0;
        break;
    }
    $amount *= (int)$num;
}
if ($amount === 0) {
    echo 0;
} else {
    echo ($amount <= pow(10, 18)) ? $amount : -1;
}

Measured memory_bytes: 25656
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

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

	cin >> H >> W;
	vector<bitset<300>>v(H);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> K;
			if (K)v[i].flip(j);
		}
	}
	vector<int>used(H);
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			if (used[j])continue;
			if (!v[j].test(i))continue;
			used[j] = 1;
			for (int k = 0; k < H; k++) {
				if (k == j)continue;
				if (v[k].test(i)) {
					v[k] ^= v[j];
				}
			}
		}
	}
	K = accumulate(used.begin(), used.end(), 0);
	cout << (power(2, K, MOD) - 1) * power(2, W - 1, MOD) % MOD*power(2, H - K, MOD) % MOD << endl;
}

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

template<typename Monoid>
struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

    int sz;
    vector<Monoid> seg;

    const F f;
    const Monoid M1;

    SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2 * sz, M1);
    }

    void set(int k, const Monoid &x) {
        seg[k + sz] = x;
    }

    void build() {
        for(int k = sz - 1; k > 0; k--) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    void update(int k, const Monoid &x) {
        k += sz;
        seg[k] = x;
        while(k >>= 1) {
            seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
        }
    }

    Monoid query(int a, int b) {
        Monoid L = M1, R = M1;
        for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
            if(a & 1) L = f(L, seg[a++]);
            if(b & 1) R = f(seg[--b], R);
        }
        return f(L, R);
    }

    Monoid operator[](const int &k) const {
        return seg[k + sz];
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    int p[200005];
    SegmentTree<int> l(n, [](int a, int b){return min(a, b);}, n);
    SegmentTree<int> r(n, [](int a, int b){return max(a, b);}, -1);
    for(int i = 0; i < n; i++){
        cin >> p[i];
        l.set(i, p[i]);
        r.set(i, p[i]);
    }
    l.build();
    r.build();
    int c[200005];
    c[n - 1] = 1;
    for(int i = n - 2; i >= 0; i--){
        if(p[i] > p[i + 1]) c[i] = 1;
        else c[i] = c[i + 1] + 1;
    }
    int ans = 1;
    bool f = false;
    if(c[0] >= k) f = true;
    for(int i = 0; i < n - k; i++){
        if((l.query(i, i + k + 1) != p[i] || r.query(i, i + k + 1) != p[i + k]) && (c[i + 1] < k || !f)) ans++;
        if(c[i + 1] >= k) f = true;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            String line;
            while ((line = Console.ReadLine()) != null) {
                string[] strs = line.Split(' ');
                int w = int.Parse(strs[0]);
                int h = int.Parse(strs[1]);
                if (w == 0 ) { break; }
                int[,] maze = new int[w+1, h+1];
                strs = Console.ReadLine().Split(' ');
                int xs = int.Parse(strs[0]), ys = int.Parse(strs[1]);
                strs = Console.ReadLine().Split(' ');
                int xg = int.Parse(strs[0]), yg = int.Parse(strs[1]);
                int n = int.Parse(Console.ReadLine());
                for (int i = 0; i < n; i++) {
                    strs = Console.ReadLine().Split(' ');
                    int n0 = int.Parse(strs[0]);
                    int n1 = int.Parse(strs[1]);
                    int n2 = int.Parse(strs[2]);
                    int n3 = int.Parse(strs[3]);
                    if (n1 == 0) {//Yoko ni Nagai
                        maze[n2, n3] = n0; maze[n2 + 1, n3] = n0;
                        maze[n2 + 2, n3] = n0; maze[n2 + 3, n3] = n0;
                        maze[n2, n3 + 1] = n0; maze[n2 + 1, n3 + 1] = n0;
                        maze[n2 + 2, n3 + 1] = n0; maze[n2 + 3, n3 + 1] = n0;
                    }
                    else {
                        maze[n2, n3] = n0; maze[n2 + 1, n3] = n0;
                        maze[n2, n3+1] = n0; maze[n2 + 1, n3+1] = n0;
                        maze[n2, n3 + 2] = n0; maze[n2 + 1, n3 + 2] = n0;
                        maze[n2 , n3 + 3] = n0; maze[n2 + 1, n3 + 3] = n0;                    
                    }                
                }
                if (solvable(maze, xs, ys, xg, yg, maze[xs, ys])) {
                    Console.WriteLine("OK");
                }
                else {
                    Console.WriteLine("NG");
                }

            }

        }

        static bool solvable(int[,] maze, int x, int y, int xg, int yg, int color) {
            if(x==0||x==maze.GetLength(0)||y==0||y==maze.GetLength(1)){return false;}
            if (maze[x, y] != color) { return false; }
            if (x == xg && y == yg) { return true; }
            maze[x, y] = -1;
            if (solvable(maze, x + 1, y,xg, yg, color)) { return true; }
            if (solvable(maze, x , y+1, xg, yg, color)) { return true; }
            if (solvable(maze, x - 1, y, xg, yg, color)) { return true; }
            if (solvable(maze, x , y-1, xg, yg, color)) { return true; }
            return false;
        }
    }
}

Measured memory_bytes: 5520
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cmath>
using namespace std;
int main(){
    double S,L,h,c;
    int a,b,C;
    int deg;
    double rad;
    cin >>a>>b>>C;
    double PI = acos(-1);  // PI = 3.141593...
    rad = C* PI / 180;
    
    S = a*b*sin(rad)/2;
    c=(a*a+b*b)-2*a*b*cos(rad);
    L=a+b+sqrt(c);
    h=2*S/a;
    //fixed で少数点以下６けたおk
   cout<<fixed<<S<<' '<<L<<" "<<h<<endl;
   
    return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
void solution(){
    char a;
    cin>>a;
    if(a<='Z') cout<<"A\n";
    else cout<<"a\n";
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(); cout.tie();
    int t;
    t=1;
    while(t--) solution();
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char ch[200005];
int main()
{
	scanf("%s",&ch);
	int n=strlen(ch);
	int i;
	if(ch[0]=='?') ch[0]='D';
	for(i=1;i<n;i++)
	{
		if(ch[i]=='?')
		{
			if(ch[i-1]=='P') ch[i]='D';
			else ch[i]='D';
		}
	}
	for(i=0;i<n;i++) cout<<ch[i];
	return 0;
 } 

Measured memory_bytes: 3956
n, k = map(int, input().split())
p = list(map(int,input().split()))
val = 0
atai = 0
val2 = 0
for i in range(k):
    val2 += p[i]
#print(val2)
val = val2
for i in range(k,n):
    if val < val2:
        val = val2
        atai = i-k+1
    #print(i,p[i],p[i-k])
    val2 += p[i]
    if i==k:
        val2 == 0
    else:
        val2 -= p[i-k]
    #print(val2)
    if val < val2:
        val = val2

        atai = i-k+1
#print(atai)

#print(atai)
ans = 0
for i in range(k):
    ans += (p[atai]+1)/2
    atai += 1
    #print(atai)
    #print(kitai)
print(ans)

Measured memory_bytes: 71792
while True:
    n, r = map(int, input().split())
    if n == 0 and r == 0:
        break
    deck = [i + 1 for i in range(n)]
    for shuffle in range(r):
        p, c = map(int, input().split())
        # print("start: {}, end: {}".format(len(deck) - p - c + 1, len(deck) - p + 1))
        hoge = deck[len(deck) - p - c + 1 : len(deck) - p + 1]
        del deck[len(deck) - p - c + 1 : len(deck) - p + 1]
        deck.extend(hoge)
        # print("現在の山札: {}".format(deck))
    print(deck[-1])



Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    string  s;
    cin >> s;
    ll k;
    cin >> k;
    ll d = 0;
    while (s[d] == '1') {
        d++;
    }
    if (d >= k) {
        cout << 1 << endl;
        return 0;
    }
    else {
        cout << s[d] << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include "bits/stdc++.h"
using namespace std;

vector<int> h;
vector<int> dp;
int N;

int main()
{
  cin >> N;
  h.resize(N);
  dp.resize(N);
  for (int i = 0; i < N; i++)
  {
    cin >> h[i];
  }

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; i++)
  {
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[N - 1] << endl;
}

int min(int a, int b)
{
  if (b < a)
  {
    return b;
  }
  return a;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int N, K, Q;
	while(cin >> N >> K >> Q){
		vector<int> A(N);
		for(int& t : A) cin >> t;
		vector<int> thr = A;
		thr.push_back(0);
		sort(thr.begin(), thr.end());
		thr.erase(unique(thr.begin(), thr.end()), thr.end());
		vector<int> part; part.reserve(N);
		vector<int> cur; cur.reserve(N);
		long long res = 1LL << 60;
		for(const auto& wall : thr){
			part.clear();
			cur.clear();
			auto pushPart = [&](){
				if(part.empty()) return;
				sort(part.begin(), part.end());
				for(int j=0;j<(int)part.size()-K+1;j++){
					cur.push_back(part[j]);
				}
				part.clear();
			};
			for(int i=0;i<N;i++){
				if(A[i] <= wall){
					pushPart();
				} else {
					part.push_back(A[i]);
				}
			}
			if(!part.empty()){
				pushPart();
			}
			if(cur.size() < Q) break;
			sort(cur.begin(), cur.end());
			res = min(res, (long long)cur[Q-1] - cur[0]);
		}
		cout << res << endl;
	}
}

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

#define N 200005

int n,a[N],q,top,stc[N];
bool vis[N];
long long sig[N];
vector<int>query[N];

template<typename Drake>
void read(Drake &x){
	x=0;char ch=getchar();bool f=1;
	while(!isdigit(ch)){
		if(ch=='-')f^=1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	x*=(2*f-1);
}

template<typename Drake>
void write(Drake x){
	if(x<0){x=-x;putchar('-');}
	if(x>9)write(x/10);
	putchar(x%10+'0');
}

template<typename Drake>
void writeln(Drake x){
	write(x);
	puts("");
}

void init(){
	int a,b;
	read(a);
	read(b);
	writeln(a*b-a-b+1);
}

int main(){
	init();
	
	return 0;
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=(1<<20)+5;
int n,K,ans1,ans2;
int f[21][N];
int nx[21][N];
char s[N];
int main(){
	scanf("%d%d",&n,&K);
	For(i,0,n){
		scanf("%s",s);
		For(j,0,(1<<i)-1)
			f[i][j]=s[j]-'0';
	}
	For(i,0,n)
		For(j,0,(1<<i)-1){
			int fl=(j&1),p=0;
			for (;p<i&&!(((j>>p)&1)^fl);++p);
			nx[i][j]=(p>=i?-1:p);
		}
	For(i,0,n)
		For(j,1,n-i)
			For(k,0,(1<<(i+j))-1){
				f[i][k&((1<<i)-1)]+=f[i+j][k];
				int t=nx[j][k>>i];
				if (t==-1) continue;
				f[i+j-t][(k&((1<<i)-1))|((k>>(i+t))<<i)]+=f[i+j][k];
			}
	ans1=1<<30;
	For(i,0,n)
		For(j,0,(1<<i)-1){
			if (f[i][j]>=K)
				if (i>ans2||(i==ans2&&j<=ans1))
					ans1=j,ans2=i;
		}
	Rep(i,ans2-1,0)
		putchar('0'+((ans1>>i)&1));
}

Measured memory_bytes: 98688
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)


ll N,Q,k[80];
char S[1010101];

ll D[1010101];
ll DM[1010101];
ll M[1010101];
ll DMC[1010101];
vector<ll> C;

ll i,j;

int main(){
    scanf("%lld%s%lld", &N,S,&Q);
    
    fornum(i,0,N){
        switch(S[i]){
            case 'D':
                D[i]++;
                break;
            case 'M':
                M[i]++;
                DM[i]+=D[i];
                break;
            case 'C':
                C.push_back(i);
                break;
        }
        D[i + 1] = D[i];
        M[i + 1] = M[i];
        DM[i + 1] = DM[i];
        DMC[i + 1] = DMC[i + 1];
        //printf("%lld %lld %lld %lld\n", D[i], M[i], DM[i], C.size());
    }
    fornum(i,0,Q){
        scanf("%lld", &k[i]);
        ll ans = 0;
        for (j = 0; j < C.size();j++){
            ll c = C[j];
            if(c<k[i]){
                ans += DM[c];
            }else{
                ans += DM[c] - DM[c - k[i] + 1] - D[c - k[i]] * (M[c] - M[c - k[i] + 1]);
            }
        }
        printf("%lld\n", ans);
    }

    
    

    return 0;
}

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

int main() {
  long N;
  cin >> N;
  pair<pair<string,int>,int> p[N];

  for(int i=0;i<N;i++){
    string name;
    int t;
    cin>>name>>t;
    p[i]=make_pair(make_pair(name,-t),i);
  }
  //sort(p.begin(),p.end());
  sort(p,p+N);
  for(int i=0;i<N;i++){
    cout<<p[i].second+1<<endl;
  }
  }


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

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

ll fact[100001];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0){
		return res*(p-fact[n%p])%p;
	}
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}

int n;
vector<int> G[100001];
bool used[100001];
ll twopow[100001];
bool check[100001];
int cnt=0;
int last=0;
int a[100001];
bool flag;

void dfs(int v){
	used[v]=true;
	cnt++;
	last=v;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]){
			dfs(G[v][i]);
		}
	}
}

void dfs2(int v,int p){
	check[v]=true;
	int cc=0;
	for(int i=0;i<G[v].size();i++){
		if(!check[G[v][i]]){
			dfs2(G[v][i],v);
			cc++;
		}else{
			if(p!=G[v][i]){
				flag=false;
			}
		}
	}
	if(cc>1){
		flag=false;
	}
}

int main(void){
	twopow[0]=1;
	fact[0]=1;
	for(int i=1;i<=100000;i++){
		twopow[i]=twopow[i-1]*2LL%MOD;
		fact[i]=(ll)fact[i-1]*i%MOD;
	}
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			G[i].clear();
		}
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
			a[i]--;
		}
		for(int i=0;i<n;i++){
			if(a[a[i]]!=i || i<a[i]){
				G[i].push_back(a[i]);
				G[a[i]].push_back(i);
			}
		}
		memset(used,false,sizeof(used));
		memset(check,false,sizeof(check));
		int sum=0;
		flag=true;
		int v1=0,v2=0;
		for(int i=0;i<n;i++){
			if(!used[i]){
				cnt=0;
				dfs(i);
				sum++;
				dfs2(last,-1);
				if(cnt==2){
					v1++;
				}else{
					v2++;
				}
			}
		}
		if(!flag){
			printf("0\n");
		}else if(v2>0){
			ll res=0;
			for(int i=0;i<=v1;i++){
				ll val=(i/2)+1;
				ll val2=mod_comb(v1+v2-i-2,v1-i,MOD)*(v1+v2-i-1)%MOD;
				ll val3=2LL*mod_comb(v1+v2-i-1,v1-i,MOD)%MOD;
				if(v2>=2)res=(res+(val*val2%MOD))%MOD;
				res=(res+(val*val3%MOD))%MOD;
			}
			res=res*twopow[v1+v2]%MOD;
			res=res*fact[v1]%MOD;
			res=res*fact[v2]%MOD;
			printf("%lld\n",res);
		}else{
			ll res=twopow[v1];
			res=res*(v1/2LL+1LL)%MOD;
			res=res*fact[v1]%MOD;
			printf("%lld\n",res);
		}
	}
	return 0;
}

Measured memory_bytes: 10868
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  char s[3];
  rep(i,3){
    cin >> s[i];
  }
  if(s[0]==s[1]&&s[1]==s[2]){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,k;
    cin>>n>>k;
    ll tmp=k;
    ll ans=1;
    while(true){
        if(tmp>n){
            cout<<ans<<endl;
            return 0;
        }else{
            tmp*=k;
            ++ans;
        }
    }
}


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

int main(){
    int N;
    cin >> N;
    int W[N];
    int sum=0;
    for(int i=0;i<N;i++){
        cin >> W[i];
        sum+=W[i];
    }
    int a=0;
    int ans;
    for(int i=0;i<N;i++){
        if(i==0){
            if(sum>=2*W[0]){
                a+=W[0];
                ans=sum-2*W[0];
            }else{
                cout << W[0] << endl;
                break;
            }
        }else{
            a+=W[i];
            if(sum>=2*a){
                 ans=min(ans,sum-2*a);
            }else{
                int answer=2*a-sum;
                 ans=min(ans,answer);
                 cout << ans << endl;
                 return 0;
            }
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 3600
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
using namespace std;
constexpr int64_t MOD = 1000000007;

int32_t calc_farthest(vector<int32_t>& distT, vector<int32_t>& distA) {
  int32_t farA = 0;
  int32_t minSame = 0;
  for (int32_t i = 0; i < (int32_t)distA.size(); i++) {
    if(farA < distA[i] && distA[i] > distT[i]) {
      //cout << i << "," << distA[i] << "," << distT[i] << endl;
      if (distA[i] > distT[i]) {
        farA = distA[i];
      }
    } else if (distA[i] == distT[i]) {
      if (minSame == 0) {
        minSame = distA[i];
      } else {
        minSame = min(minSame, distA[i]);
      }
    }
  }
  if (minSame > farA - 1) {
    return minSame;
  } else {
    return farA - 1;
  }
}

void set_dist(vector<vector<int32_t>>& graph, vector<int32_t>& dist, int32_t start) {
  vector<bool> visited(dist.size(), false);
  queue<pair<int32_t,int32_t>> q;
  q.push(make_pair(start, 0));
  while (!q.empty()) {
    pair<int32_t,int32_t> cur = q.front();
    q.pop();
    if(visited[cur.first] == true) {
      continue;
    } else {
      visited[cur.first] = true;
      dist[cur.first] = cur.second;
    }
    if (!graph[cur.first].empty()) {
      for (auto next : graph[cur.first]) {
        if(!visited[next]) {
          q.push(make_pair(next, cur.second + 1));
        }
      }
    }
  }
  return;
}

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

  int32_t N, u, v;
  cin >> N >> u >> v;
  if (u == v) {
    cout << 0 << endl;
    return 0;
  }
  vector<vector<int32_t>> graph(N);
  for (int i = 0; i < N-1; i++) {
    int s,t;
    cin >> s >> t;
    graph[s-1].push_back(t-1);
    graph[t-1].push_back(s-1);
  }
  vector<int32_t> distT(N, INT_MAX);
  vector<int32_t> distA(N, INT_MAX);
  set_dist(graph, distT, u-1);
  set_dist(graph, distA, v-1);
  int32_t dist = calc_farthest(distT, distA);
  cout << dist << endl;

  return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  int key;
  struct node *next;
  struct node *prev;
}node;

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur;
  cur=nil->next;
  while(cur!=nil && cur->key!=key)
    {
      cur=cur->next;
    }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t==nil)
    return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  }

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
  x=listSearch(key);
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}  

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

template<unsigned mod=1000000007>struct fp {
   unsigned v;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=v,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0){x+=mod;} return x;
   }
   fp():v(0){}
   fp(ll x):v(x>=0?x%mod:mod+(x%mod)){}
   fp operator-()const{return fp(-v);}
   fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;}
   fp& operator+=(const fp& x){if((v+=x.v)>=mod)v-=mod; return *this;}
   fp& operator-=(const fp& x){if((v+=mod-x.v)>=mod)v-=mod; return *this;}
   fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;}
   fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;}
   fp operator+(const fp& x)const{return fp(*this)+=x;}
   fp operator-(const fp& x)const{return fp(*this)-=x;}
   fp operator*(const fp& x)const{return fp(*this)*=x;}
   fp operator/(const fp& x)const{return fp(*this)/=x;}
   bool operator==(const fp& x)const{return v==x.v;}
   bool operator!=(const fp& x)const{return v!=x.v;}
}; using Fp=fp<>;

Fp dp[5010][5010];

int main(){
   int n,m; cin>>n>>m;
   rep(i,1,m+1)dp[1][i]=Fp(2).pow(i);
   rep(i,1,n){
      Fp add=0;
      rep(j,1,m+1){
         dp[i+1][j]+=dp[i][j]*(j+1)+add;
         add=add*2+dp[i][j]*j;
      }
   }
   cout<<dp[n][m].v<<endl;
   return 0;
}

Measured memory_bytes: 101720
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int p[n];
    rep(i,n)cin >> p[i];
    int cnt = 0;
    int minx = 200001;
    rep(i,n){
        minx = min(minx,p[i]);
        if(minx == p[i]){
            cnt++;
            //cout << "cnt" << endl;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main() {
	int n;
	string team[10];
	int tokuten[10][4];
	string kari;
	int karikari;
	int counter = 0;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		if (counter != 0) {
			cout << endl;
		}
		for (int i = 0; i < n; i++) {
			cin >> team[i] >> tokuten[i][0] >> tokuten[i][1] >> tokuten[i][2];
			tokuten[i][3] = 3 * tokuten[i][0] + tokuten[i][2];
		}

		for (int i = n-1; i > 0; i--) {
			for (int j = 0; j < i; j++) {
				if (tokuten[j][3] < tokuten[j+1][3]) {
					kari = team[j];
					team[j] = team[j+1];
					team[j+1] = kari;
					karikari = tokuten[j][3];
					tokuten[j][3] = tokuten[j+1][3];
					tokuten[j+1][3] = karikari;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			cout << team[i] << "," << tokuten[i][3] << endl;
		}
		counter = 1;
	}
	return 0;
}

Measured memory_bytes: 1212
using System;
using System.Linq;

namespace Range
{
    class Range
    {
        public static void Main()
        {
            string[] s = Console.ReadLine().Split();
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);

            if (a < b && b < c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}



Measured memory_bytes: 15988
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>> &G,int v,vector<long long> &ans,vector<bool> &seen){
  seen[v-1]=true;
  for(auto next : G[v-1]){
  if(seen[next-1]) continue;
    ans[next-1]+=ans[v-1];
    dfs(G,next,ans,seen);
  }
}
int main(){
  int n,q;
  cin>>n>>q;
  vector<vector<int>> G(n,vector<int>(0));
  vector<long long> ans(n);
  vector<bool> seen(n,false);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b);
    G[b-1].push_back(a);
  }
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    ans[a-1]+=b;
  }
  dfs(G,1,ans,seen);
  for(int i=0;i<n;i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}


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

using ll = long long;

using namespace std;
template<int mod>
struct ModComb {
	using ll = long long;
	vector<ll> fact;
	vector<ll> facti;
	ModComb(int n) {
		init(n);
	}
	void init(int n) {
		fact.resize(n);
		facti.resize(n);
		fact[0] = 1;
		for (int i = 1; i < n; i++) {
			fact[i] = fact[i-1] * i % mod;
		}
		facti[n-1] = po(fact[n-1], mod - 2);
		for (int i = n-2; i >= 0; i--) {
			facti[i] = facti[i+1] * (i + 1) % mod;
		}
	}
	ll nCr(int a, int b) {
		return (fact[a] * facti[b] % mod) * facti[a-b] % mod;
	}
	ll po(ll next, int cnt) {
		ll res = 1;
		if (cnt == 0) return 1;
		if (cnt & 1) res = res * next % mod;
		return res * po(next * next % mod, cnt >> 1) % mod;
	}
};
using modcomb = ModComb<1000000007>;

ll calc(ll H, ll W, int K)
{
  if (K <= 1) return 0;
  modcomb m(H * W + 100);
  ll res = 0;
  ll HH = H * H % 1000000007;
  for (int i = 1; i < W; i++) {
    ll t = HH * i % 1000000007;
    res += m.nCr(H * W - 2, K - 2) * t % 1000000007 * (W - i);
    res %= 1000000007;
  }
  return res;
}

int main()
{
  int H, W, K;
  cin >> H >> W >> K;
  cout << (calc(H, W, K) + calc(W, H, K)) % 1000000007 << endl;
}

Measured memory_bytes: 3400
n = gets.to_i
h={}
x = nil
n.times do
 str,v = gets.split(' ')
 h[str]=v.to_i
end
x = gets.chomp

ans = 0
flg = false
h.each do |(s, t)|
  if flg
    ans += t
  end
  if s == x
    flg = true
  end
end

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,s;
    cin>>a>>b>>c;
    s=a;
    d=0;
    while(d<c&&s<=b)
    {
        s+=a;
            d++;
    }
    cout<<d<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x[11];
int main(){
	int a;
	for(int i = 1 ; i <= 3; i++){
		cin >> a;
		x[a]++;
	}
	if(x[5] == 2 && x[7] == 1)puts("YES");
	else puts("NO");
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;
const int   mod = 998244353;

int mul(int a,int b)    {
    return  1ll * a * b % mod;
}

typedef pair<int,int>   ii;

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

    int n;      cin >> n;
    string s;   cin >> s;

    int ans = 1;
    int cnt[8];

    memset(cnt,0,sizeof cnt);

    for(char c : s) {
        int t = 0;
        if (c == 'R')   t = 1;
        if (c == 'G')   t = 2;
        if (c == 'B')   t = 4;

        if (cnt[t ^ 7]) {
            ans = mul(ans,cnt[t ^ 7]);
            cnt[t ^ 7]--;
        }
        else    {
            bool found = 0;

            for(int i = 1 ; i < 8 ; i *= 2) if (cnt[i] && i != t)   {
                ans = mul(ans,cnt[i]);
                cnt[i]--;
                cnt[i ^ t]++;
                found = 1;
            }
            if(!found)
                cnt[t]++;
        }
    }
    for(int i = 1 ; i <= n ; ++i)
        ans = mul(ans,i);

    cout << ans << endl;
}


Measured memory_bytes: 720
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long int a;
    double b;
    scanf("%ld %lf", &a, &b);
    long int b0 = (long int)(b * 100 + 0.5);
    long int N = a * b0;
    N /= 100;
  
    printf("%ld", N);
  
    return 0;
}


Measured memory_bytes: 3252
from collections import deque, Counter
#from heapq import heapify, heappop, heappush
#from bisect import insort, bisect_left
#import sys
#sys.setrecursionlimit(10**9)
#from math import gcd
#from decimal import Decimal
#mod = 1000000007
#mod = 998244353
N = int(input())
#N, K = map(int, input().split())
#S = input()
A = list(map(int, input().split()))
#flag = False
#ans = 0
o = []
e = []
for k in range(N):
  if k%2 == 0:
    e.append(A[k])
  else:
    o.append(A[k])
e = Counter(e)
o = Counter(o)
e = e.most_common()
o = o.most_common()
e.append(('1', 0))
o.append(('2', 0))
if e[0][0] != o[0][0]:
  ans = N - e[0][1] - o[0][1]
else:
  ans = N - e[0][1] - o[1][1]
  ans = min(ans, N - e[1][1] - o[0][1]) 
print(ans)
#print('Yes')
#print('No')

Measured memory_bytes: 98912
#include<bits/stdc++.h>
#include<algorithm>
 
#define  pb push_back
#define  mp make_pair
#define ll long long
#define vi vector<ll>
#define ff first
#define ss second
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=a-1;i>b;i--)
#define MOD 10e9+7
#define fastScan ios_base::sync_with_stdio(0); cin.tie(NULL)
#define s(v) sort(v.begin(),v.end())

 
using namespace std;
 
//vector<bool> s(1000000,true);

//vector<ll> a;
 
/*void prime(){
    FORor(ll i=2;i<1000000;i++){
        if(s[i] == true) a.pb((ll)i);
        ll j=2*i;
        while(j<1000000){
            if(s[j]!=FORalse) s[j]=FORalse;
            j+=i;
        }
    }
}
ll bs(ll s, ll l,ll h){
    ll m;
    while(l<=h){
        m = (l+h)>>1;
        if(a[m] < s) l= m+1;
        else h = m-1;
    }
    return l;
}
 
bool isprime(ll s, ll l,ll h){
    ll m;
    while(l<=h){
        m = (l+h)>>1;
        if(a[m]==s)return true;
        if(a[m] < s) l= m+1;
        else h = m-1;
    }
    return FORalse;
}
 
bool comp(pair<ll,ll> a, pair<ll,ll> b) {
    if(a.FORirst == b.FORirst)  return a.second<b.second;
    else return a.FORirst < b.FORirst;
}
 
ll FORact(ll n){
    if(n==1) return 1;
    else return n*FORact(n-1);
}

ll gcd(ll a,ll b){
    if(a==0)return b;
    return (b%a,a);
}*/

void solve(){
   ll n;
   cin >> n ;
   ll a[n][3],dp[n][3];
    
    for(ll i=0;i<n;i++)cin >> a[i][0] >> a[i][1] >> a[i][2];
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for(ll i=1;i<n;i++){
        dp[i][0] = a[i][0] + max(dp[i-1][1] , dp[i-1][2]);
        dp[i][1] = a[i][1] + max(dp[i-1][0] , dp[i-1][2]);
        dp[i][2] = a[i][2] + max(dp[i-1][1] , dp[i-1][0]);
    }
    ll ans  = max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]));
    cout << ans << endl;
    return;
}
 
int main(){
    fastScan;
    ll T=1;
    //cin >> T;
    while(T--){
        solve();
    }
    
    return 0;
}  

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var swr = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(swr);
            double n = double.Parse(Console.ReadLine());
            double ans = 0;
            for (double i = 1; i <= n; i++)
            {
                if (Math.Truncate(i * 1.08) == n)
                {
                    ans = i;
                    break;
                }
            }
            if (ans == 0)
            {
                Console.WriteLine(":(");
            }
            else
            {
                Console.WriteLine(ans);
            }
            Console.Out.Flush();
        }
    }
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int a;
int onec,twoc,threec;
int ans;
int main(){
  cin >> n;
  onec = 0;
  twoc = 0;
  threec = 0;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%3==0) threec++;
    if(a%3==1) onec++;
    if(a%3==2) twoc++;
  }
  if(onec==0&&twoc==0){
    cout << 1 << endl;
    return 0;
  }else{
    ans += threec;
    if(onec>twoc){
      ans++;
      onec--;
      while(true){
	if(onec==0){
	  if(twoc!=0) ans++;
	  break;
	}
	ans++;
	onec--;
	if(twoc==0){
	  if(onec!=0) ans++;
	  break;
	}
	ans++;
	twoc--;
      }
    }else if(onec==1&&twoc==1){
      ans+=2;
    }else{
      ans++;
      twoc--;
      while(true){
	if(twoc==0){
	  if(onec!=0) ans++;
	  break;
	}
	ans++;
	twoc--;
	if(onec==0){
	  if(twoc!=0) ans++;
	  break;
	}
	ans++;
	onec--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, num, even = 0, odd = 0;
    cin >> n;
    while(n--){
		cin >> num;
		if(num%2==0)even+=num;
		else odd+=num;
	}
	if((even+odd)%2==0)cout <<"YES";
	else cout <<"NO";
    return 0;
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

int main() {
	int n, k;
	cin >> n >> k;
	VI a(n);
	rep(i, n) cin >> a[i];

	ll minv = 1e18;
	ll c, b;
	rep(i, n-k+1) {
		b = abs(a[i]) + abs(a[k + i-1] - a[i]);
		c = abs(a[k+i-1]) + abs(a[k + i-1] - a[i]);
		/*cout << a[i] << " " << a[k + i - 1] << " " <<endl;
		cout << b << " " << c << endl;
		cout << "\n";*/
		minv = min({ b,c,minv });
	}
	if (minv == 1e18) minv = 0;
	cout << minv << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

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

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

int main()
{
    ll x,now = 0,ans;
    cin >> x;
    rep(i, x + 1){
        now += i;
        if (now >= x) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}



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

const int N = 200005;
int n, g, a[2][N], r[2];
string x;

int F(int a) {
	if(a == 0) return 0;
	return F(a % (int)__builtin_popcount(a)) + 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> x;
	for(int i = 0; i < n; ++i) {
		if(x[i] == '1') {
			++g;
		}
	}
	if(g != 1) a[0][n - 1] = 1 % (g - 1);
	a[1][n - 1] = 1 % (g + 1);
	for(int i = n - 2; i >= 0; --i) {
		if(g != 1) a[0][i] = a[0][i + 1] * 2 % (g - 1);
		a[1][i] = a[1][i + 1] * 2 % (g + 1);
	}
	for(int i = 0; i < n; ++i) {
		if(x[i] == '1') {
			if(g != 1) (r[0] += a[0][i]) %= (g - 1);
		    (r[1] += a[1][i]) %= (g + 1);
		}
	}
	for(int i = 0; i < n; ++i) {
		int y = 0;
		if(x[i] == '1') {
			y = r[0] - a[0][i];
			if(y < 0) y += g - 1;
		} else {
			y = r[1] + a[1][i];
			if(y >= g + 1) y -= g + 1;
		}
		if(x[i] == '1' && g == 1) {
			cout << 0 << "\n";
		} else {
			cout << F(y) + 1 << "\n";
		}
	}
	return 0;
}


Measured memory_bytes: 5336
k = int(input())
s = input()
mod = 10**9 + 7
"""
組み合わせ大好きなのにFとけなかったくやしいいいいいいいいいいいいいいいい
"""

def cmb(n, r, mod):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n-r)
	return fact[n]*factinv[r]*factinv[n-r]%mod

N = 2*10**6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N+1):
	fact.append((fact[-1]*i)%mod)
	inv.append((-inv[mod%i]*(mod//i))%mod)
	factinv.append((factinv[-1]*inv[-1])%mod)

ans = 0
for i in range(k+1):
	ans = (ans + cmb(len(s)-1+k-i, len(s)-1, mod)*pow(25, k-i, mod)*pow(26, i, mod)) % mod
print(ans)

Measured memory_bytes: 197232
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
using namespace std;


int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;

    ll arr[n];
    ll g;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(i==0){
            g=arr[i];
            continue;
        }
        else{
            g=__gcd(arr[i],g);
        }
    }
    cout<<g;
}


Measured memory_bytes: 1024
N,A,B = map(int,input().split())
l = list(input())
num = 0
count = 0
for i in range(N):
  if l[i] == 'a' and A + B > num:
    print('Yes')
    num += 1
  elif l[i] == 'b' and (A + B > num):
    count += 1
    if count <= B:
      print('Yes')
      num += 1
    else:
      print('No')
  else:
    print('No')

Measured memory_bytes: 9976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		StringBuilder sb = new StringBuilder(str);

		String string = sc.nextLine();
		int q = Integer.parseInt(string);

		for (int i = 0; i < q; i++) {
			String line = sc.nextLine();
			String[] order = line.split(" ");
			int a = Integer.parseInt(order[1]);
			int b = Integer.parseInt(order[2]) + 1;

			if (order[0].equals("print")) {
				System.out.println(sb.substring(a, b));
			} else if (order[0].equals("reverse")) {
				StringBuilder SB = new StringBuilder(sb.substring(a, b));
				sb.replace(a, b, (SB.reverse().toString()));
			} else if (order[0].equals("replace")) {
				sb.replace(a, b, order[3]);
			}
		}
	}

}

Measured memory_bytes: 28612
#include <bits/stdc++.h>
#define INF 1000000007
#define MOD 998244353
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(lp, vec.size()) cout << vec[lp] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;

void Main(){

	ll x;
	cin >> x;
	if(x) print(0);
	else print(1);
	
}

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
	
}





Measured memory_bytes: 3648
#include<stdio.h>
int main(void)
{
	int n,a,x,y;
	scanf("%d",&n);
	scanf("%d",&a);
	x=n%500;
	if(a>=x){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
import collections

N = int(input())
A = list(map(int, input().split()))
A = collections.Counter(A)
B = []
C = []
for i in A:
    if A[i] == 1:
        B.append(i)
    else:
        C.append(i)
B = sorted(B)
if len(B) == 0:
    print(0)
    exit()
mb = B[-1]
ok = [True] * (mb+1)

if len(C) > 0:
    C = sorted(C)
    for c in C:
        if c > mb:
            continue
        if not ok[c]:
            continue
        k = 2
        while k*c <= mb:
            ok[k*c] = False
            k += 1

for b in B:
    if not ok[b]:
        continue
    k = 2
    while k*b <= mb:
        ok[k*b] = False
        k += 1

ans = 0
for b in B:
    if ok[b]:
        ans += 1

print(ans)


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



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

    long long a, b, k;
    cin >> a >> b >> k;
    long long ramas = max(0LL, k - a);

    cout << max(0LL, a - k) << " ";
    cout << max(0LL, b - ramas);


    return 0;
}

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

#define ALL(obj) (obj).begin(),(obj).end()
template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = 1'000'000'000LL + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    ll ans = 0;
    for(int i = 1; i < N; ++i) {
        if(A[i-1]>A[i]) {
            ans += A[i-1]-A[i];
            A[i]=A[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4720
# coding: utf-8
import sys
import numpy as np

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

N = ir()
A = np.array(lr())
answer = 0
while np.any(A%2==0):
    answer += (A%2==0).sum()
    A[A%2==0] //= 2

print(answer)


Measured memory_bytes: 14076