akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<n+1;i++)

using namespace std;
using std::swap;

//vector<long long int> p;
vector<long long int> v;
vector<long long int> w;



int main() {
	int N,b;
	v.resize(9);
	w.resize(9);
	rep(i, 9) {
		cin >> v[i];
		w[i] = 0;
	}
	cin >> N ;
	rep(i, N) {
		cin >> b;
		rep(j, 9) {
			if (b == v[j])w[j] = 1;
		}
	}
	if (w[0] == 1) {
		if (w[1] == 1 && w[2] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}else if (w[3] == 1 && w[6] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
		else if (w[4] == 1 && w[8] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
	} 
	if (w[1] == 1) {
		if (w[4] == 1 && w[7] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
	} 
	if (w[2] == 1) {
		if (w[4] == 1 && w[6] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
		else if (w[5] == 1 && w[8] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
	} 
	if (w[3] == 1) {
		if (w[4] == 1 && w[5] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
	}
	if (w[6] == 1) {
		if (w[7] == 1 && w[8] == 1) {
			cout << "Yes" << "\n";
			return 0;
		}
	}
	cout << "No" << "\n";

	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  ll n,a[100000],b[100000];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  ll s=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=s;
    s+=(b[i]-a[i]%b[i])%b[i];
  }
  
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{   int a,b,cnt=0,i;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++){
        if(i/10000==i%10&&(i/1000)%10==(i%100)/10){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int N,A[100],i,j,a,minj,count=0,temp;

  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  for(j=0;j<N;j++){
    minj=j;
    for(i=j;i<N;i++){
      if(A[i] < A[minj]){
	minj=i;
      }
    }
    if(A[j] > A[minj]){
      temp=A[minj];
      A[minj]=A[j];
      A[j]=temp;
      count++;
    }
  }

  for(i=0;i<N-1;i++)
    printf("%d ",A[i]);

  printf("%d\n",A[i]);

  printf("%d\n",count);

  return 0;

}

    
  



Measured memory_bytes: 2112
#include<iostream>
using namespace std;
typedef long long ll;
ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    cout<<a[n-1];
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin>>a[i];
	double d = 0;
	for (int i : a) {
		double c = (double) 1 / (double) i;
		d += c;
	}
	double an = (double) 1/d;
	printf("%0.7f", an);
	return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int,input().split())
s_list=[['#' for _ in range(w+2)]]
for i in range(h):
    s_list.append(['#'] + list(input()) + ['#'])
s_list.append(['#' for _ in range(w+2)])



def bfs(x, y):
    temp_maps =  [[None if s == '.' else -1 for s in s_row] for s_row in s_list]
    temp_maps[x][y] = 0
    que = deque()
    que.append((x,y))
    while que:
        i, j = que.popleft()
        for val_added_i, val_added_j in ((0,1),(0,-1),(1,0),(-1,0)):
            if temp_maps[i + val_added_i][j + val_added_j] is None:
                temp_maps[i + val_added_i][j + val_added_j] = temp_maps[i][j] + 1
                que.append((i + val_added_i, j + val_added_j))
    return max(max(maps_row)  for maps_row in temp_maps)


max_value = 0

for i in range(1, h+1):
    for j in range(1, w+1):
        if s_list[i][j] == '.':
            val = bfs(i, j)
            max_value = max(max_value, val)

print(max_value)

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

int main()
{
    int n, k;
    int i, j = 0, l, num = 0, key = 0, ans = 0;
    
    cin >> n >> k;
    
    int a[n];
    int count[n];
    
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    sort(a, a+n);
    
    do {
        num++;
        
        if(a[j] != a[j+1]) {
            count[key] = num;
            key++;
            num = 0;
        }
        
        j++;
    } while(j < n);
    
    sort(count, count+key);
    
    if(key <= k) {
        cout << "0\n";
    } else {
        for(l = 1; l <= k; l++) {
            ans = ans + count[key-l];
        }
    
        cout << n - ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 1792
// 2014/06/26 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int N;
		cin >> N;

		if(N==0)
			break;

		int cnt0 = 0;		// 0個残っている景品の数
		int cnt1 = 0;		// 1個残っている景品の数
		for(int i=0; i<N; i++){
			int k;
			cin >> k;

			if(k==0){
				cnt0++;
			}
			else if(k==1){
				cnt1++;
			}
		}

		if(cnt0+cnt1==N){
			cout << "NA" << endl;
		}
		else{
			cout << N-cnt0+1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
for _ in range(int(input())):
    x, y, w, h = map(int,input().split())
    c = 0
    for _ in range(int(input())):
        a, b = map(int,input().split())
        if x <= a and a <= x + w and y <= b and b <= y + h:c += 1
    print(c)


Measured memory_bytes: 5616
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ls l,mid
#define rs mid+1,r
#define lc p<<1
#define rc p<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
const int N=200010;
const int inf=0x3f3f3f3f;
template<typename T>inline T chkmax(T A,T B){return A>B?A:B;}
template<typename T>inline T chkmin(T A,T B){return A<B?A:B;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,a[N],p[N],len;
int t[N<<2][2],b[N],tot;
inline void Build_tree(int l,int r,int p,int x)
{
	if(l==r)
	{
		t[p][x]=a[l*2-x];
		//printf("%d (%d %d) %d\n",p,l,r,t[p][x]);
		return;
	}
	int mid=(l+r)>>1;
	Build_tree(ls,lc,x);
	Build_tree(rs,rc,x);
	t[p][x]=chkmin(t[lc][x],t[rc][x]);
	//printf("%d (%d %d) %d\n",p,l,r,t[p][x]);
}
inline int Query(int l,int r,int p,int x,int y,int z)
{
	if(x<=l&&r<=y)return t[p][z];
	int mid=(l+r)>>1,Min=inf;
	if(x<=mid)Min=chkmin(Min,Query(ls,lc,x,y,z));
	if(y> mid)Min=chkmin(Min,Query(rs,rc,x,y,z));
	return Min;
}
struct node
{
	int l,r,x,y;
	node(){}
	node(int l,int r,int x,int y):l(l),r(r),x(x),y(y){}
};
inline bool operator<(node A,node B){return a[A.x]>a[B.x];}
int main()
{
	read(n);
	For(i,1,n)read(a[i]),p[a[i]]=i;
	len=n/2;
	Build_tree(1,len,1,0);
	Build_tree(1,len,1,1);
	priority_queue<node>q;
	node now;
	now.l=1;now.r=n;
	now.x=p[Query(1,len,1,1,len,1)];
	now.y=p[Query(1,len,1,(now.x+1)/2,len,0)];
	q.push(now);
	while(!q.empty())
	{
		node now=q.top();q.pop();
		//printf("%d %d %d %d\n",now.l,now.r,now.x,now.y);
		b[++tot]=a[now.x];b[++tot]=a[now.y];
		node nxt;
		nxt.l=now.l;
		nxt.r=now.x-1;
		if(nxt.l<nxt.r)
		{
			if(nxt.l&1)
			{
				nxt.x=p[Query(1,len,1,(nxt.l+1)>>1,(nxt.r)>>1,1)];
				nxt.y=p[Query(1,len,1,(nxt.x+1)>>1,(nxt.r)>>1,0)];
			}
			else
			{
				nxt.x=p[Query(1,len,1,nxt.l>>1,nxt.r>>1,0)];
				nxt.y=p[Query(1,len,1,(nxt.x+2)>>1,(nxt.r+1)>>1,1)];
			}
			q.push(nxt);
		}
		nxt.l=now.x+1;
		nxt.r=now.y-1;
		if(nxt.l<nxt.r)
		{
			if(nxt.l&1)
			{
				nxt.x=p[Query(1,len,1,(nxt.l+1)>>1,(nxt.r)>>1,1)];
				nxt.y=p[Query(1,len,1,(nxt.x+1)>>1,(nxt.r)>>1,0)];
			}
			else
			{
				nxt.x=p[Query(1,len,1,nxt.l>>1,nxt.r>>1,0)];
				nxt.y=p[Query(1,len,1,(nxt.x+2)>>1,(nxt.r+1)>>1,1)];
			}
			q.push(nxt);
		}
		nxt.l=now.y+1;
		nxt.r=now.r;
		if(nxt.l<nxt.r)
		{
			if(nxt.l&1)
			{
				nxt.x=p[Query(1,len,1,(nxt.l+1)>>1,(nxt.r)>>1,1)];
				nxt.y=p[Query(1,len,1,(nxt.x+1)>>1,(nxt.r)>>1,0)];
			}
			else
			{
				nxt.x=p[Query(1,len,1,nxt.l>>1,nxt.r>>1,0)];
				nxt.y=p[Query(1,len,1,(nxt.x+2)>>1,(nxt.r+1)>>1,1)];
			}
			q.push(nxt);
		}
	}
	For(i,1,tot)printf("%d ",b[i]);
	return 0;
}


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

int main() {
    int m, n;
    while (cin >> m >> n) {
        int max = 0;
        for (int i = 0; i < m; i++) {
            int solved = 0;
            for (int j = 0; j < n; j++) {
                int a;
                cin >> a;
                solved += a;
            }
            if (max < solved) {
                max = solved;
            }
        }
        cout << max << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n>0)
	{
		if(n%10==9)
		{
			cout<<"Yes"<<endl;
			break;	
		}
		if(n%10!=9&&n/10==0)
		{
			cout<<"No"<<endl;
			break;
		}
		n=n/10;
	}
	return 0;
}


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

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

  int n;
  cin >> n;
  string ans = "Three";
  for (int i = 0; i < n; ++i) {
    string a;
    cin >> a;
    if (a == "Y") {
      ans = "Four";
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  for (int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < M; i++) {
    cin >> x.at(i) >> y.at(i) >> c.at(i);
  }

  int result = 100000 + 100000;

  for (int i = 0; i < M; i++) {
    result = min (result, a.at(x.at(i) - 1) + b.at(y.at(i) - 1) - c.at(i));
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  result = min(result, a.at(0) + b.at(0));

  cout << result << endl;

}

Measured memory_bytes: 2176
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if( a<=b && b<=c )
        cout << a << " " << b << " " << c << endl;
    else if(a<=c && c<=b)
        cout << a << " " << c << " " << b << endl;
    else if(b<=a && a<=c)
        cout << b << " " << a << " " << c << endl;
    else if(b<=c && c<=a)
        cout << b << " " << c << " " << a << endl;
    else if(c<=a && a<=b)
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3112
#include<stdio.h>
int main(void)
{
    int n,k,d,temp;
    scanf("%d",&n);
    scanf("%d",&k);
    int a[n];
    for(int i=0;i<n;i++)
    {
        a[i] = 0;
    }
    
    for(int i=0;i<k;i++)
    {
        scanf("%d",&d);
        for(int j=0;j<d;j++)
        {
            scanf("%d",&temp);
            a[temp-1] = 1;
        }
    }
    int count =0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==0)
        count++;
    }
    printf("%d",count);
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 200001


int main(){	
	
	int n;
	cin>>n;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}map<long long int,int>mp;
	mp[1+a[1]]+=1;
	long long int ans=0;
	for(int i=2;i<=n;i++){
		if(i-a[i]>0)
			ans+=mp[i-a[i]];
		mp[i+a[i]]+=1;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 17556
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


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

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
//#define int long long
#define ll long long
#define all(x) x.begin(),x.end()
#define endl '\n'
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18

int h[100005];
int dp[100005];
int solve(int n, int i, int k){
    if(i>=n)
        return 0;
    //int a=INT_MAX,b=INT_MAX;
    //if(i+1<=n)
    if(dp[i]!=-1)
        return dp[i];
    dp[i] = solve(n,i+1,k) + abs(h[i]-h[i+1]) ;
     int j = 2;
     while(j<=k && i+j<=n){
         int b = solve(n,i+j,k);
        dp[i] = min(dp[i],b+abs(h[i]-h[i+j]));
        j++;
     }

    //dp[i] a + abs(h[i]-h[i+1]);
    return dp[i];
}

signed main(){
IOS;
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++){
    cin>>h[i];dp[i]=-1;
}


    /*
    dp[n]=0;
    for(int i=n-1;i>=1;i--){
        dp[i]=dp[i+1] + abs(h[i]-h[i+1]);
        if(i+2 <= n){
            dp[i]=min(dp[i],dp[i+2]+abs(h[i]-h[i+2]));
        }
    }
    cout << dp[1] <<endl;
    */
 cout << solve(n,1,k);
return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

int d_sum(int n)
{
    if (n < 10)
        return n;
    return d_sum(n / 10) + n % 10;
}

int main()
{
    int N, sum;
    cin >> N;
    if (N % d_sum(N) == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
        int r,l,count,n,w;
        string s;
        while(1) {
                count=0;
                r=0;
                l=0;
                w=0;
                cin>>n;

                if(n==0) {
                        break;
                }

                for(int i=0; i<n; i++) {
                        cin>>s;
                        if(w==0) {
                                if(s=="lu") {
                                        l=1;
                                }else if(s=="ld") {
                                        l=0;
                                }else if(s=="ru") {
                                        r=1;
                                }else if(s=="rd") {
                                        r=0;
                                }
                                if(r==1&&l==1) {
                                        count++;
                                        w=1;
                                }
                        }else{
                                if(s=="lu") {
                                        l=1;
                                }else if(s=="ld") {
                                        l=0;
                                }else if(s=="ru") {
                                        r=1;
                                }else if(s=="rd") {
                                        r=0;
                                }
                                if(r==0&&l==0) {
                                        count++;
                                        w=0;
                                }
                        }

                }


                cout<<count<<endl;
        }
}



Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long
#define MOD 1000000007

using namespace std;

int main(){
    string S;
    cin >> S;
    for(int i=0;i<S.size();i++){
        if(i==3){
            cout << 8;
        }
        else{
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

int main() {
	cout << fixed << setprecision(12);	
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	int ret = n;
	for (int i = 0; i < n - m + 1; i++) {
		int cur = 0;
		for (int j = 0; j < m; j++) {
			if (s[i + j] != t[j]) {
				cur++;
			}
		}
		ret = min(ret, cur);
	}
	cout << ret << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int N, K, Y, X;
    int sum;
    cin >> N >> K >> X >> Y;


    if (N > K){
        int M = N - K;
        sum = K * X;
        sum += M * Y;
    }
    else {
        sum = N * X;
    }

    cout << sum << endl;

}

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

int main(){
  int n;
  long long ans;
  string s;
  cin >> n >> s;
  int r=0,g=0,b=0;
  rep(i,n){
    if(s.at(i) == 'R') r++;
    else if(s.at(i) == 'G') g++;
    else b++;
  }
  ans = r*g;
  ans *= b;
  rep(i,n-2){
    for(int j=1;j<(n-i+1)/2;j++){
      bool a = true;
      if(s.at(i) == s.at(i+j))a = false;
      if(s.at(i+j) == s.at(i+2*j))a = false;
      if(s.at(i+2*j) == s.at(i))a = false;
      if(a) ans -= 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
n = int(input())
h = list(map(int, input().split()))
i = 0
ans = 0
c = 0
while True:
    if h[i] == 0:
        i += 1
        c += 1
        if c == n:
            break
        if i == n:
            i = 0
            c = 0
    else:
        cnt = 0
        ans += 1
        while h[i + cnt] != 0:
            h[i + cnt] -= 1
            cnt += 1
            if i + cnt == n:
                break
        i += cnt
        if i == n:
            i = 0
            c = 0
print(ans)

Measured memory_bytes: 9168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int trans(string s, char c) {
  int cur = 0;
  int hi = 0;
  REP(i, 0, s.length()) {
    int tmp = s[i] == c ? 1 : -1;
    cur += tmp;
    hi = max(hi, cur);
  }
  return hi;
}

int main(void){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int hi = trans(s, ')');
  REP(i, 0, hi) {
    s = "(" + s;
  }
  int lo = 0;
  REP(i, 0, s.length()) {
    int tmp = s[i] == '(' ? 1 : -1;
    lo += tmp;
  }
  REP(i, 0, lo) {
    s = s + ")";
  }
  cout << s << endl;
}


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

    int n;
    cin >> n;

    rep(i, 50000){
        int tmp = i*1.08;
        if(tmp == n){
            cout << i;
            return 0;
        }
    }

    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	if (k % 2 == 1) {
		ll a = n / k;
		ans = a*a*a;
	}
	else {
		ll x = n / k;
		ll y = 2*n / k - x;
		ans += x*x*x + y*y*y;
		
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N, ac = 0, wa = 0, tle = 0, re = 0;
  string a;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a;
    if(a == "AC")
      ac++;
    else if(a == "WA")
      wa++;
    else if(a == "TLE")
      tle++;
    else if(a == "RE")
      re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int n,m,k,i,j;
  long long f,t,u=0,res;
  string s;
  cin >> s >> k;
  n=s.size();
  j=n;
  if(k==1){
    f=stoi(s.substr(0,1));
    res=9*(n-1)+f;
  }else if(k==2){
    f=stoi(s.substr(0,1));
    for(i=1;i<n;i++){
      t=stoi(s.substr(i,1));
      if(t>0) break;
    }
    res=81*(n-1)*(n-2)/2+(f-1)*9*(n-1)+t+9*max(n-i-1,0);
  }else{
    f=stoi(s.substr(0,1));
    for(i=1;i<n;i++){
      t=stoi(s.substr(i,1));
      if(t>0)
        if(u==0){
          u=t;
          j=i;
        }else{
          break;
        }
    }
    res=729*(n-1)*(n-2)*(n-3)/6+(f-1)*81*(n-1)*(n-2)/2;
    m=max(n-j,1);
    res+=81*(m-1)*(m-2)/2+(u-1)*9*(m-1)+t+9*max(n-i-1,0);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 101;
int n;
double arr[MAXN];
int main(){
  cin >> n;
  double sum = 0;
  for (int i = 1; i<=n; i++){
    cin >> arr[i];
    sum += ((double)1/arr[i]);
  }
  cout << (double)1/sum << endl;
  return 0;
}

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

typedef long long ll;
 
int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	vector<ll> a(n+1);
	for (int i=0; i<=n; i++) cin >> a[i];
	ll ans=0, rest=0,m;
	for (int i=0;i<n; i++)
	{
		ll b;
		cin >> b;
		m=min(a[i], rest);
		ans+=m;
		ll r=min(a[i]-m, b);
		ans+=r;
		cerr << "rest=" << rest  << " b=" << b << " m=" << m << " r=" << r<< endl;  
		rest =b-r;
	}
	m=min(a[n],rest);
	ans+=m;

	cout << ans;
	return 0;
}



Measured memory_bytes: 1024
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                int[] a = new int[n];
                int yono = 10000000;
                for(int i = 0 ; i < n ; i++){
                        a[i] = sc.nextInt();
                        int pct = 0;
                        while(a[i] % 2 == 0){
                                pct++;
                                a[i] /= 2;
                        }
                        yono = Math.min(yono , pct);
                }
                System.out.println(yono);
        }
}
//鶏になれ

Measured memory_bytes: 36128
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    MIN,MAX=1,n
    for i in 1:m
        l,r=parseMap(split(readline()))
        MIN=max(l,MIN)
        MAX=min(r,MAX)
    end
    println(max(MAX-MIN+1,0))
end
main()

Measured memory_bytes: 153916
import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)

Measured memory_bytes: 78296
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 1e9+7;
bool m1=0,m2=0;

bool checkMM(char a, char b){
	if(a=='0'){
		if(b=='0')	return false;
		else		return true;
	}
	else if(a=='1'){
		if(b>='0' && b<='2')	return true;
		else					return false;
	}
	else	return false;
}

int main(){
	string s;
	cin>>s;
	m1 = checkMM(s[0],s[1]);
	m2 = checkMM(s[2],s[3]);
	if(m1&&m2)	cout<<"AMBIGUOUS"<<endl;
	else if(m1 && !m2)	cout<<"MMYY"<<endl;
	else if(!m1 && m2)	cout<<"YYMM"<<endl;
	else	cout<<"NA"<<endl;
	return 0;
}

Measured memory_bytes: 256
#ifndef _WIN32
#include<iostream>
#endif

using namespace std;
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<iomanip>
#include<stack>
#include<set>
#include<functional>
#include<map>

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int dr[] = { 0, 1, 0, -1 };
const int dc[] = { 1, 0, -1, 0 };

typedef pair<int, int> P;
int main(){
	int N; cin >> N;
	REP(_, N){
		set<string> memo;
		string s;
		cin >> s;
		int len = s.size();
		FOR(i, 1, len){
			string a = s.substr(0,i);
			string b = s.substr(i, len - i);
			auto c = a;
			auto d = b;
			reverse(ALL(c));
			reverse(ALL(d));
			memo.insert(a + b);
			memo.insert(a + d);
			memo.insert(c + b);
			memo.insert(c + d);
			memo.insert(b + a);
			memo.insert(d + a);
			memo.insert(b + c);
			memo.insert(d + c);


		}
		cout << memo.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 3180
N, M = map(int, input().split())
sc = []
for _ in range(M):
    s, c = map(int, input().split())
    sc.append((s - 1, str(c)))

ans = -1
for i in map(str, range(10 ** (N - 1) if N > 1 else 0, 10 ** N)):
    for s, c in sc:
        if i[s] != c:
            break
    else:
        ans = i
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int h;
    cin>>h;
    long long monster=1;
    long long count=0;
    while(h>0)
    {
       
            count=count+monster;
            h=ceil(h/2);
            monster=monster*2;
            
        
    }
    cout<<count;
    
    
}


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

int main() {
  int r,c,k;
  cin>>r>>c>>k;
  int64_t item[r][c];
  for(int i=0; i<r; i++) {
    for(int j=0; j<c; j++) {
      item[i][j] = 0;
    }
  }
  for(int i=0; i<k; i++) {
    int a,b;
    int64_t v;
    cin>>a>>b>>v;
    item[a-1][b-1] = v;
  }

  vector<vector<vector<int64_t>>> table;
  // for(int i=0; i<c; i++) {
  //   for(int j=0; j<4; j++) table[0][i].push_back(0);
  // }
  for(int i=0; i<r; i++) {
    vector<vector<int64_t>> tmp;
    for(int j=0; j<c; j++) {
      tmp.push_back({0,0,0,0});
    }
    table.push_back(tmp);
  }
  table[0][0][1] = item[0][0];

  for(int i=1; i<c; i++) {
    table[0][i][0] = table[0][i-1][0];
    table[0][i][1] = max(table[0][i-1][1], table[0][i-1][0]+item[0][i]);
    table[0][i][2] = max(table[0][i-1][2], table[0][i-1][1]+item[0][i]);
    table[0][i][3] = max(table[0][i-1][3], table[0][i-1][2]+item[0][i]);
  }

  for(int i=1; i<r; i++) {
    table[i][0][0] = *max_element(table[i-1][0].begin(), table[i-1][0].end());
    table[i][0][1] = table[i][0][0] +item[i][0];
    // table[i][0][2] = 0;
    // table[i][0][3] = 0;
    for(int j=1; j<c; j++) {
      table[i][j][0] = max(*max_element(table[i-1][j].begin(), table[i-1][j].end()), table[i][j-1][0]);
      int64_t tmp2 = max(*max_element(table[i-1][j].begin(), table[i-1][j].end())+item[i][j], table[i][j-1][1]);
      table[i][j][1] = max(tmp2, table[i][j-1][0]+item[i][j]);
      table[i][j][2] = max(table[i][j-1][2], table[i][j-1][1]+item[i][j]);
      table[i][j][3] = max(table[i][j-1][3], table[i][j-1][2]+item[i][j]);
    }
  }

  int64_t ans = *max_element(table[r-1][c-1].begin(), table[r-1][c-1].end());

  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 706044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  long long x,y;
  cin >> x >> y;
  vector<long long> arr(114514);
  fill(arr.begin(),arr.end(), 0);
  rep(i,x){
      long long a,b;
      cin >> a >> b;
      arr[a] += b;
  }
  rep(j,arr.size()){
      if(y<=arr[j]){
          cout << j << endl;
          break;
      }else{
          y -= arr[j];
      }
  }
}


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

int main(){
    int N;
    cin >> N;
    vector<int>H(N);
    for(int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int cnt = 0;
    int ans = 0;
    for(int i = 1; i < N; i++) {
        if(H[i] <= H[i-1]) {
            cnt++;
        }
        else {
            cnt = 0;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
} 


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

int main() {
ll x; cin>>x;
  ll cnt=0;
  cnt+=2*(x/11);
  if(1<=x%11&&x%11<=6){
    cnt++;}
  if(7<=x%11&&x%11<=10){
    cnt+=2;}
  
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18
#define MOD ((ll)1e9+7)
ll cal(ll n,ll m){
	return -m*(m+1)*(2*m+1)/6+(n+1)*m*(m+1)/2+m;
}
int main(){
	ll n; cin>>n;
	ll k; cin>>k;
	ll ans=0;
	ans=(cal(n,n+1)-cal(n,k-1))%MOD;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3644
X = int(input())
n = 1
while(X > n**5):
    n += 1
#A>B
#A**5+B**5
for i in range(1,n+1):
    for j in range(0,i+1):
        test = i**5+j**5
        if(X == test):
            print(i,-j)
            exit()
#A**5-B**5
for i in range(n,200):
    for j in range(0,i+1):
        test = i**5-j**5
        if(X == test):
            print(i,j)
            exit()

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
int main() {
  int h, w, n, a;
  cin >> h >> w >> n;
  a = (h > w) ? h : w;
  a = n / a + (n % a != 0 ? 1 : 0);
  cout << a;
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, sum = 0, cnt = 0, a[N];
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 1; i <= n; i++){
		if(sum <= 4 * m * a[i]){
			cnt++;
			continue;
		}
	}
	if(cnt >= m){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}

Measured memory_bytes: 256
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int m = 0, ans = 0;
        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
            m = Math.max(p[i], m);
            ans += p[i];
        }
        ans -= m/2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 21588
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n;cin>>n;
	string s;cin>>s;
	int r=0,b=0;
	for(int i=0;i<n;i++)
	if(s[i]=='R')r++;
	else b++;
	if(r>b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

namespace AtCoderTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Calc();
        }

        void Calc()
        {            
            // read
            int n = int.Parse(Console.ReadLine());

            if(n > 999)
            {
                Console.WriteLine("ABD");
            }
            else
            {
                Console.WriteLine("ABC");
            }



        }


    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll n;
    cin>>n;
    ve <ll> arr(n);
    map <ll,ll> m1;
    ll sum=0;
    rep (i,0,n)
    {
        cin>>arr[i];
        sum+=arr[i];
        m1[arr[i]]++;
    }
    ll q;
    cin>>q;
    while (q--)
    {
        ll b,c;
        cin>>b>>c;
        sum-=b*m1[b];
        sum+=c*m1[b];
        m1[c]+=m1[b];
        m1[b]=0;
        cout<<sum<<"\n";
    }
}


Measured memory_bytes: 10064
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <limits>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N, T;
    scan(N, T);

    auto a = new int[](N);
    auto b = new int[](N);

    foreach (i ; 0 .. N) {
        scan(a[i], b[i]);
    }

    sort(zip(a, b));

    enum lim = 6001;

    auto dp = new long[](lim);

    foreach (i ; 0 .. N) {
        foreach_reverse (j ; a[i] .. lim) {
            if (j - a[i] < T) chmax(dp[j], dp[j - a[i]] + b[i]);
        }
    }

    auto ans = dp.reduce!max;
    writeln(ans);
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 2428
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
using namespace std;

int n;
int a[100000];

int func(int first)
{
	int cnt = 0;
	int sum = first;
	bool prev_plus = first > 0;
	for (int i = 1; i < n; i++)
	{
		int temp = sum + a[i];
		
		if (prev_plus)
		{
			if (temp >= 0)
			{
				cnt += temp + 1;
				sum = -1;
			}
			else
			{
				sum = temp;
			}
		}
		else
		{
			if (temp <= 0)
			{
				cnt += -temp + 1;
				sum = 1;
			}
			else
			{
				sum = temp;
			}
		}
		prev_plus = !prev_plus;
	}

	return cnt;
}

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

	//+ first
	int cnt1 = (a[0] > 0) ? func(a[0]) : (func(1) + abs(a[0]) + 1);
	int cnt2 = (a[0] < 0) ? func(a[0]) : (func(-1) + abs(a[0]) + 1);

	cout << MIN(cnt1, cnt2);
}


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

bool isPrime(int N){
    for(int i = 2; i*i <= N; i++){
        if(N%i == 0) return false;
    }
    return true;
}

int main(){
    int x;
    cin >> x;
    while(x > 0){
        if(isPrime(x)){
            cout << x << endl;
            return 0;            
        }
        x ++;
    }
}

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

int main(){
  long n;
  cin >> n;
  long i,j;
  char temp;
  long count=0;

  vector<char> c(n);

  for(long a=0;a<n;a++){
    cin >> c.at(a);
  }
  i=0;j=n-1;

  while(c.at(i)!='W'&&i<=j){
    i++;
    if(i>=n)break;
  }
  while(c.at(j)!='R'&&j>i){
    j--;
  }

  while(i<j){
    temp=c.at(i);
    c.at(i)=c.at(j);
    c.at(j)=temp;
    count++;

    while(c.at(i)!='W'&&i<=j){
      i++;
      if(i>=n)break;
    }
    while(c.at(j)!='R'&&j>i){
      j--;
    }
  }

  cout << count <<endl;

  return(0);
}


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

int main(){
	int n;
	while(cin>>n,n){
		int y;
		cin>>y;
		
		int ans;
		double money=0;
		for(int i=0;i<n;i++){
			double a,b,c;
			cin>>a>>b>>c;
			
			if(c==1){
				double r=y*b/100;
				r+=1;
				if(money<r){
					money=r;
					ans=a;
					}	
			}
			
			else{
			double r=b/100;
			r+=1;
			double k=r;
			for(int j=1;j<	y;j++){
				r*=k;
				}
				
			if(money<r){
				money=r;
				ans=a;
				}	
			}
		}
		cout<<ans<<endl;
	}
		return 0;
	}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 1e5+5;
int arr[N];

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,ans=0;
    cin>>n;
    FOR(i, 0, n) {
    	cin>>arr[i]; arr[i]--;
    }
    FOR(i, 0, n) {
    	if(arr[i] == i) {
    		ans++;
    		if(i != n-1) {
    			swap(arr[i], arr[i+1]);
    		} else {
    			swap(arr[i], arr[i-1]);
    		}
    	}
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func rs() string {
	sc.Scan()
	return sc.Text()
}

func min(a []int) (x, y int) {
	x = a[0]
	for i, v := range a {
		if v < x {
			x = v
			y = i
		}
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	// x := []int{n, 0, 0, 0, 0, 0}
	// fmt.Println(n)

	// a, b, c, d, e := ri(), ri(), ri(), ri(), ri()
	// fmt.Println(a, b, c, d, e)
	vehicle := []int{ri(), ri(), ri(), ri(), ri()}
	// fmt.Println(x)
	// fmt.Println(vehicle)

	// fmt.Println("============")

	mincap, idx := min(vehicle)
	// fmt.Println(mincap, idx)
	// fmt.Println("============")

	ans := 0
	ans += idx // 1s

	ans += (5 - idx)
	if n%mincap == 0 {
		ans += (n/mincap - 1)
	} else {
		ans += (n/mincap + 1 - 1)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
# B
S = input()
K = 'keyence'
k = 0
for i in range(1,len(K)):
    n = S.find(K[:i])
    #print(S[n+i:],K[i:])#
    m = S[n+i:].find(K[i:])
    #print(n, m)#
    #if n>=0 and m>=0:
    #if (n==0 and m>=0) or (n>0 and S[n+i:]==K[i:]):
    #if (n==0 and m==0) or (n==0 and m>0 and S[n+i+m:]==K[i:]) or \
    if (n==0 and m==0) or (n==0 and m>0 and S[-len(K[i:]):]==K[i:]) or \
        (n>0 and S[n+i:]==K[i:]):
        
        res = 'YES'
        break
else: res = 'NO'        
print(res)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll n,m,b[1005][1005],a[1005][1005],ans,fix[1005][1005];
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    queue<pair<int,int> >q;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            char x;
            cin >> x;
            a[i][j] = (x == '#');
            if(a[i][j]){
                q.push(mp(i,j));
                fix[i][j] = 1;
            }
        }
    }
    
    while(q.size()){
        pair<ll,ll>p = q.front();
        q.pop();
        ans = max(ans,b[p.f][p.s]);
        if(p.f + 1 <= n && !fix[p.f+1][p.s]){
            b[p.f+1][p.s] = b[p.f][p.s] + 1;
            fix[p.f+1][p.s] = 1;
            q.push(mp(p.f+1,p.s));
        }
        if(p.f - 1 >= 1 && !fix[p.f-1][p.s]){
            fix[p.f-1][p.s] = 1;
            b[p.f-1][p.s] = b[p.f][p.s] + 1;
            q.push(mp(p.f-1,p.s));
        }
        if(p.s + 1 <= m && !fix[p.f][p.s+1]){
            fix[p.f][p.s+1] = 1;
            b[p.f][p.s+1] = b[p.f][p.s] + 1;
            q.push(mp(p.f,p.s+1));
        }
        if(p.s - 1 >=1 && !fix[p.f][p.s-1]){
            fix[p.f][p.s-1] = 1;
            b[p.f][p.s-1] = b[p.f][p.s] + 1;
            q.push(mp(p.f,p.s-1));
        }
    }
    
    
    cout << ans;
    
    
    return 0;
}


Measured memory_bytes: 28672
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define vz(x) x.size()
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
// const int N = ;
const int INF = 1e9 + 50;
const int MOD = 1e9 + 7;
string s;

int main() {
  cin >> s;
  if (s[s.length() - 1] == 's') {
    s += "es";
  } else {
    s.push_back('s');
  }
  cout << s << endl;
  return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3632
n = int(input())
l = [0, 0, 0, 0]
for _ in range(n):
  s = input()
  if s == 'AC':
    l[0] += 1
  elif s == 'WA':
    l[1] += 1
  elif s == 'TLE':
    l[2] += 1
  else:
    l[3] += 1
print("AC x " + str(l[0]))
print("WA x " + str(l[1]))
print("TLE x " + str(l[2]))
print("RE x " + str(l[3]))

Measured memory_bytes: 9148