akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef vector <bool> v_bool;
typedef vector <ll> v_ll;
typedef vector <vector <ll> > vv_ll;
typedef vector < pair <ll,ll> > vp_ll;
typedef pair <ll,ll> p_ll;

bool TEST=false;
ll MOD = 1000000007;

void show(){if (TEST){cout << endl;}}
void show(string x){if (TEST){cout << x;}}
void show(string x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(ll x){if (TEST){cout << x;}}
void show(ll x,bool enter){
  if (TEST){if (enter) cout << "<#> " << x << endl;else cout << x;}
}
void show(p_ll p){
  if (TEST){cout << "{ ";show(p.first);cout << " ";show(p.second);cout << " }";}
}
void show(v_ll v){
  if (TEST){
    cout << "<begin> ";
    for (ll i=0;i<v.size();i++){show(v[i]); cout << " ";}cout <<"<end>"<< endl;
}}
void show(vv_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}
void show(vp_ll v){
  if (TEST){
    cout << "//////////" << endl;
    for (ll i=0;i<v.size();i++){
      show(v[i]); cout << endl;
}}}

ll mod(ll x){
  ll n=MOD;
  ll ret=x%n;
  if (ret<0)ret+=n;
  return ret;
}
void mod_self(ll &x){
  x=mod(x);
}
ll mod_inv(ll x){
  ll n=MOD;
  ll y = x,z = n-2, ret=1;
  y=mod(y);
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  return ret;
}
ll mod_pow(ll x,ll a){
  ll y = x,z = a,ret=1;
  y=mod(y);
  if (z<0)z=-z;
  while (z>0){
    if(z%2==1) ret=mod(ret*y);
    y=mod(y*y);
    z/=2;
  }
  if (a<0) ret=mod_inv(ret);
  return ret;
}
v_ll mod_nck(ll n){
  v_ll nck(n+1,0);
  nck[0]=1;
  for (ll i=1;i<=n;i++){
    nck[i]=mod(nck[i-1]*(n+1-i));
    nck[i]=mod(nck[i]*mod_inv(i));
  }
  return nck;
}
v_ll mod_factorial(ll n){
  v_ll fct(n+1,0);
  fct[0]=1;
  for (ll i=1;i<=n;i++){
    fct[i]=mod(fct[i-1]*i);
  }
  return fct;
}

ll N;
v_ll A,B,C;
int main(){
  cin >> N;
  A.assign(N+10,0);
  B.assign(N+10,0);
  for (ll i=1;i<=N;i++){
    cin >> A[i];
  }
  for (ll i=N;i>=1;i--){
    if (A[i]!=B[i]){
      C.push_back(i);
      for (ll j=1;j*j<=i;j++){
        if (i%j==0){
          B[j]=1-B[j];
          if (j!=i/j)B[i/j]=1-B[i/j];
        }
      }
    }
  }
  cout << C.size() << endl;
  for (ll i=0;i<C.size();i++){
    if (i!=0) cout << " ";
    cout << C[i];
  }
  if (C.size()>0) cout << endl;
}


Measured memory_bytes: 5108
#include <stdio.h>

int main()
{
	int a,b,c,d,e,f;
	while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF){
	
	double x = (double)(c*e-b*f)/(a*e-b*d);
	double y = (double)(c*d-f*a)/(b*d-a*e);
	
	if((int)(x * 10000) % 10 >= 5.0){
      x += 0.001;
    }
    if((int)(y * 10000) % 10 >= 5.0){
      y += 0.001;
    }
    if(x == -0.000){
      x = 0.000;
    }
    if(y == -0.000){
      y = 0.000;
    }
	
	printf("%.3lf %.3lf\n",x,y);
	
	}
	
	return 0;
}

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

int x[6];
int n,c;string S;

int hantei(){
	int A,B,C,D;
	if(S=="North"){
		A=x[0];
		B=x[1];
		C=x[5];
		D=x[4];
		x[0]=B;
		x[1]=C;
		x[5]=D;
		x[4]=A;
	}
	if(S=="South"){
		A=x[0];
		B=x[1];
		C=x[5];
		D=x[4];
		x[0]=D;
		x[1]=A;
		x[5]=B;
		x[4]=C;
	}
	if(S=="East"){
		A=x[0];
		B=x[2];
		C=x[5];
		D=x[3];
		x[0]=D;
		x[2]=A;
		x[5]=B;
		x[3]=C;
	}
	if(S=="West"){
		A=x[0];
		B=x[2];
		C=x[5];
		D=x[3];
		x[0]=B;
		x[2]=C;
		x[5]=D;
		x[3]=A;
	}
	if(S=="Left"){
		A=x[1];
		B=x[2];
		C=x[4];
		D=x[3];
		x[1]=D;
		x[2]=A;
		x[4]=B;
		x[3]=C;
	}
	if(S=="Right"){
		A=x[1];
		B=x[2];
		C=x[4];
		D=x[3];
		x[1]=B;
		x[2]=C;
		x[4]=D;
		x[3]=A;
	}
	return x[0];
}

int main(){
	while(true){
		cin>>n;
		if(n==0){break;}
		x[0]=1;x[1]=2;x[2]=3;x[3]=4;x[4]=5;x[5]=6;c=1;
		for(int i=0;i<n;i++){
			cin>>S;
			c+=hantei();
		}
		cout<<c<<endl;
	}
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std ; 
const int MAXN = 2000 + 100 ; 

int n , k , res  , dp[MAXN] , ans = MAXN; 
vector<int>adj[MAXN] ; 

void dfs(int u , int par=-1 , int h=0 )
{
	if(h>(k/2))
		res++ ;
	if(k%2 == 1 && h == (k/2)+1)
		dp[u] ++ ; 
	
	for(auto v : adj[u])
	{
		if(v == par)
			continue ; 
		dfs(v , u , h+1) ; 
		dp[u] += dp[v] ; 
	}
}

int main()
{
	cin >> n >> k ; 
	for(int i=0 ; i<n-1 ; i++)
	{
		int u , v ; 
		cin >> u >> v ; 
		u-- , v-- ;
		adj[u].push_back(v) ;
		adj[v].push_back(u) ; 
	}
	
	for(int i=0 ; i<n  ;i++)
	{
		dfs(i) ; 
		if(k%2 == 1)
		{
			int mx = 0  ;
			for(auto x : adj[i])
			{
				mx = max(mx , dp[x]) ;
			}
			res-=mx;
		}
		ans= min(ans , res) ; 
		res = 0 ; 
		for(int j=0 ; j<n ; j++)
			dp[j] = 0  ; 
	}
	cout << ans << endl ; 
}

Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		long N=sc.nextLong();
		long A=sc.nextLong();
		long B=sc.nextLong();
		
		long t=A+B;
		long f=N-2;
		long t1=t+A*f;
		long t2=t+B*f;
		
		if(t2-t1+1<0)p(0);
		else p(t2-t1+1);
		
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int main(){
 int a,b,c,d;
 cin>>a>>b>>c>>d;
 
 int sum1=min(a,b);
 int sum2=min(c,d);
  
 int sum=sum1+sum2;
 cout<<sum<<endl;

return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;

	if (b / a >= c) ans = c;
	else ans = b / a;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
using namespace std;

void solve(int test){
	string s;
	ll cnt = 0;
	cin>>s;
	for (int i = 0; i < s.size(); ++i)
	{
		cnt += (s[i] - '0');
		cnt %= 9;
	}
	if(!cnt){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

Measured memory_bytes: 3928
def ispalindrome(s):
	#print(s)
	l=len(s)
	for i in range(l//2):
		if s[i]!=s[l-i-1]:
			return False
	return True
s=input()
l=len(s)
if ispalindrome(s) and ispalindrome(s[:l//2]) and ispalindrome(s[(l+1)//2:]):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 38256
N = int(input())
bs = list(map(int,input().split()))

list_a= [bs[0]]

for i in range(1,len(bs)):
    a = min(bs[i-1],bs[i])
    list_a.append(a)
    
list_a.append(bs[len(bs)-1])

print(sum(list_a))
    

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
int main(){
  int64_t N, K;
  cin >> N >> K;
  int64_t result = K;
  for(int i = 0; i < N-1; i++){
   result *= K - 1;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
N = int(input())
a_list = list(map(int,input().split()))
first = 0
for i in range(len(a_list)):
    if i%2 == 0:
        first += a_list[i]
    else:
        first -= a_list[i]
        
ans_list = [first]
for i in range(0,len(a_list)-1):
    ans_list.append(2*(a_list[i]-int(ans_list[i]/2)))
    
print(*ans_list)

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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;


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

    int arr[5];
    int k;

    for(int i = 0; i < 5; i++)
        cin >> arr[i];
    cin >> k;

    bool nconsegue = false;
    for(int i = 0; i < 5; i++) {
        for(int j = i+1; j < 5; j++) {
            if(abs(arr[i]-arr[j]) > k)
                nconsegue = true;
        }
    }
    if(nconsegue)
        cout << ":(" << endl;
    else 
        cout << "Yay!" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    
    int c = 0;
    int table[303][303] = {0};
    
    rep(i, h) {
        cin >> s[i];
        rep(j, w) {
            if (s[i][j] == '#') {
                c++;
                rep3(k, j, w) {
                    if (k != j && s[i][k] == '#') break;
                    table[i][k] = c;
                }
                for (int k = j; k >= 0; --k) {
                    if (k != j && s[i][k] == '#') break;
                    table[i][k] = c;
                }
            }
        }
    }
    // rep(i, h) { rep(j, w) cout << table[i][j] << " "; cout << endl; }
    
    rep(i, h) rep(j, w) {
        if (table[i][j]) {
            rep3(k, i + 1, h) {
                if (table[k][j] == 0) {
                    table[k][j] = table[i][j];
                } else break;
            }
            for (int k = i - 1; k >= 0; --k) {
                if (table[k][j] == 0) {
                    table[k][j] = table[i][j];
                } else break;
            }
        }
    }
    
    rep(i, h) { rep(j, w) cout << table[i][j] << " "; cout << endl; }
    
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)

using ll = long long;
using ull = unsigned long long;
constexpr ll mod = 1e9 + 7;
using namespace std;

int main() {

	int N, K; cin >> N >> K;
	string S; cin >> S;
	ll score = 0;
	rep(i, N - 1)if (S[i] == S[i + 1])score++;
	ll ans = min((ll)score + 2 * K, (ll)N - 1);

	cout << ans;

	return 0;

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define ld long double
#define pb push_back
#define bp __builtin_popcount
#define sz size()
#define ff first
#define ss second
#define vll vector<ll>
#define vbool vector<bool>
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define vllv vector<vector<ll>>
#define setpri(x) cout<<setprecision(x)<<fixed;
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){if(n%x==0)return n/x; else return (n/x)+1;}
ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}
ll pow1(ll n,ll k,ll mm){
    if(k==0)return 1;
    if(k%2==0)return (pow1((n%mm)*(n%mm),k/2,mm))%mm;
    return ((n%mm)*(pow1((n%mm)*(n%mm),k/2,mm)%mm))%mm;
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;
}
ll modinv(ll A,ll M){return pow1(A,M-2,M);}
ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
ll factmod(ll n,ll mod){ll s=1; for(ll i=1;i<=n;i++){s*=i;s%=mod;} return s;}
vll fact1tonmod(ll n,ll mod){vll  ans(n+1);ans[0]=ans[1]=1;
    for(ll i=2;i<=n;i++)ans[i]=(ans[i-1]*i)%mod;
    return ans;
}
ll ncrmod(ll n,ll r,ll mod){
    ll ans=((((factmod(n,mod)%mod)*(modinv(factmod(r,mod),mod)%mod))%mod)*(modinv(factmod(n-r,mod),mod)))%mod;
    return ans;
}
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
    ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
bool isprime(ll n){if(n==1 || (n!=2 && n%2==0))return false; if(n==2)return true; 
        for(ll i=3;i<=sqrt(n);i+=2)if(n%i==0)return false; return true; }
bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
    if(a.ff != b.ff)return a.ff < b.ff;
    return a.ss > b.ss;
}
void solve(){
    ll i,j,k,n,l,m,x,y,z,r;
    cin>>n>>m;
    ll sum=0;
    for(i=0;i<m;i++){
    	cin>>x;
    	sum+=x;
    }
    if(sum>n){
    	cout<<-1<<endl;
    }else{
    	cout<<n-sum<<endl;
    }
}
int main(){
    // FS;
    ll i,j,k,n,m,x,y,z,q;
    q=1;
	// cin>>q;
    while(q--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int main() {
	int T;cin>>T;
	while (T--) {
		int N,X,Y;cin>>N>>X>>Y;
		int in_x, in_y; cin >> in_x >> in_y;
		vector<pair<int,int>>ps;
		for (int i = 0; i < N; ++i) {
			int x,y;cin>>x>>y;
			ps.emplace_back(x,y);
		}
		vector<vector<int>>edges(N);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i != j) {
					int dis=(ps[i].first-ps[j].first)*(ps[i].first-ps[j].first)+
						(ps[i].second-ps[j].second)*(ps[i].second-ps[j].second);
					if (dis <= 2500) {
						edges[i].push_back(j);
					}
				}
			}
		}
		int time=0;
		vector<int>pres(N, -1000);
		vector<int>nowsays;
		for (int i = 0; i < N; ++i) {
			int dis=(ps[i].first-in_x)*(ps[i].first-in_x)+(ps[i].second-in_y)*(ps[i].second-in_y);
			if (dis <= 100) {
				nowsays.push_back(i);
				pres[i]=-1;
			}
		}
		int w_count=(Y)/X;
		bool ok = true;
		while (!nowsays.empty()) {
			vector<int>flags(N);
			for (auto ns : nowsays) {
				for (auto e : edges[ns]) {
					flags[e]=true;
				}
			}
			vector<int>nextsays;
			for (int i = 0; i < N; ++i) {
				if (flags[i]) {
					if (pres[i] == -1000) {
						nextsays.push_back(i);
						pres[i]=time;
					}else{
						if (pres[i] + w_count+1 < time) {
							ok=false;
						}else{
						}
					}
				}
			}
			nowsays=nextsays;
			time++;
			if(!ok)break;
		}
		if (ok) {
			cout<<time*X<<endl;
		}else{
			cout<< "You're always welcome!"<<endl;
		}

	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] h = new long[n];
		long ans = 0;
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextLong();
		}
		if(k < n) {
			Arrays.parallelSort(h);
			for (int i = 0; i < n-k; i++) {
				ans += h[i];
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 65264
#include<iostream>
#include<cstring>
#include<math.h>
#include<algorithm>
#include<queue>
#include<list>
#include<vector>

#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;


int main(){

    int r,g,b,n;
    cin >> r >> g >> b >> n;

    long long ans = 0;
    for(int i=0;i<=n/r;i++){
        for(int j=0;j<=n/g;j++){
            if((n-r*i-g*j)%b==0 && n>=r*i+g*j){
//cout << i << "," << j << endl;
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Cake {
    int w,d;
    int p;
    Cake(int w=0,int d=0,int p=0) : w(w),d(d),p(p) {}
    bool operator<(const Cake &obj) const {
        if(this->p!=obj.p) return this->p<obj.p;
        else return this->w*this->d<obj.w*obj.d;
    }
    bool operator==(const Cake &obj) const {
        return this->p==obj.p;
    }
};

int n,w,d;
vector<Cake> cakes;

void solve() {
    int turn=0;
    cakes.clear();
    cakes.pb(Cake(w,d,1));

    while(n--) {
        turn++;
        int p,s;
        int cnt=0;
        cin>>p>>s;
        p--;
        // printf("[input] %d %d\n",p,s);
        Cake cake = cakes[p];
        // printf("[debug]%d : %d %d %d %d\n",n,cakes.size(),cake.w,cake.d,cake.p);
       
        cakes.erase(cakes.begin()+p);
        while(s>0) {
            if(cnt%2==0) s-=cake.w;
            else s-=cake.d;
            cnt++;
        }
        // cout<<cnt<<endl;
        s=abs(s);
        if(cnt%2==1) {
            int w1=cake.w-s;
            int w2=s;
            w1=abs(w1);
            if(w2<w1) swap(w1,w2);

            cakes.pb(Cake(w1,cake.d,turn));
            cakes.pb(Cake(w2,cake.d,turn));
        }
        else {
            int d1=cake.d-s;
            int d2=s;
            d1=abs(d1);
            if(d2<d1) swap(d1,d2);

            cakes.pb(Cake(cake.w,d1,turn));
            cakes.pb(Cake(cake.w,d2,turn));
        }
        sort(all(cakes));
    }
    vector<int> ans;
    ans.reserve(cakes.size());
    for(auto &cake : cakes) {
        ans.pb(cake.w*cake.d);
    }
    sort(all(ans));
    rep(i,ans.size()) {
        cout<<(i==0?"":" ")<<ans[i];
    }
    cout<<endl;
}

int main() {
    while(cin>>n>>w>>d) {
        if(n+w+d==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1220
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

unsigned long long dp[301][301];

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


	int N, M;
	scanf("%d %d", &N, &M);

	int xm[301][4], xM[301][4];
	rep1(i, N) {
		xm[i][1] = N;
		xm[i][2] = N;
		xM[i][2] = -1;
		xM[i][3] = -1;
	}
	rep(i, M) {
		int l, r, x;
		scanf("%d %d %d", &l, &r, &x);
		chmin(xm[r][x], l);
		chmax(xM[r][x], l);
	}

	const int mod = 1e9 + 7;
	dp[0][0] = 1;
	int mj = 0;
	int mk = 0;
	unsigned long long yabai = 1;
	rep1(i, N) {
		for (int j = i - 1; j >= mj; j--) {
			auto dpj = dp[j];
			for (int k = i - 1; k >= max(j, mk); k--) {
				dpj[i] += dpj[k];
				dp[k][i] += dpj[k];
			}
		}
		yabai *= i + 1;
		for (int j = i; j > xm[i][2]; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xm[i][2]; j > max(xM[i][3], mj - 1); j--) {
			for (int k = i; k > max(max(xm[i][1], mk - 1), j - 1); k--) dp[j][k] = 0;
			if (yabai > 61081934018905800) {
				for (int k = xm[i][1]; k > max(max(xM[i][2], mk - 1), j - 1); k--) {
					dp[j][k] %= mod;
				}
			}
			for (int k = xM[i][2]; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		for (int j = xM[i][3]; j >= mj; j--) {
			for (int k = i; k >= max(j, mk); k--) dp[j][k] = 0;
		}
		if (yabai > 61081934018905800) {
			yabai = mod;
		}
		if (mj <= xM[i][3]) mj = xM[i][3] + 1;
		if (mk <= xM[i][2]) mk = xM[i][2] + 1;
	}

	ll kotae = 0;
	rep(j, N + 1) rep(k, N + 1) {
		kotae += dp[j][k] % mod;
	}
	printf("%lld", kotae% mod);

	Would you please return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second

using Graph = vector<vector<int>>;

vector<int>dx={-1,-1,-1,0,0,1,1,1};
vector<int>dy={-1,0,1,-1,1,-1,0,1};

void dfs(vector<vector<int>>&c,vector<vector<int>>&d, int x, int y,int w,int h){
    d[x][y]=1;
    for(int i=0;i<8;i++){
        int newx=x+dx[i];
        int newy=y+dy[i];
        if(newx<0 || newx>=h || newy<0 || newy>=w)continue;
        if(d[newx][newy]==0 && c[newx][newy]==1){
            dfs(c,d,newx,newy,w,h);
        }
    }
}

int main() {
    while(true){
        int w,h;
        cin>>w>>h;
        if(w==0 && h==0)break;
        vector<vector<int>>c(h,vector<int>(w));
        vector<vector<int>>d(h,vector<int>(w));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>c[i][j];
                d[i][j]=0;
            }
        }
        int ans=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(d[i][j]==0 && c[i][j]==1){
                    ans++;
                    dfs(c,d,i,j,w,h);
                }
            }
        }
        cout<<ans<<endl;
    }


    return 0;
}



Measured memory_bytes: 3336
import numpy as np

s=np.array(list((map(int,input()))))

a=[0,1]*(int(len(s)/2))
b=[1,0]*(int(len(s)/2))

if len(s)%2==1:
    a.append(0)
    b.append(1)

acount=a^s
bcount=b^s

ca=np.count_nonzero(acount)
cb=np.count_nonzero(bcount)

print(min(ca,cb))


Measured memory_bytes: 17056
#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>;

int main(){
    int n,k; cin>>n>>k;
    int ans[n+1];
    rep(i,n+1) ans[i]=0;
    for(int i=0;i<k;i++){
        int d; cin>>d;
        for(int j=0;j<d;j++){
            int a; cin>>a;
            ans[a]=1;
        }
    }
    int cnt=0;
    rep(i,n+1){
        if(ans[i]==0) cnt++;
    }
    cout<<cnt-1<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'a' = 97

int main()
{
    int n;
    cin >> n;

    int ans = 1e9;
    rep(i, 1, n) {
        int j = n - i;
        int sum_i = 0;
        int sum_j = 0;
        int tmp = i;
        while (tmp > 0) {
            sum_i += tmp % 10;
            tmp /= 10;
        }
        while (j > 0) {
            sum_j += j % 10;
            j /= 10;
        }
        ans = min(ans, sum_i + sum_j);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

int main() {
  int n;
  scanf("%d", &n);
  vector<int64> a(n), sum(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
  }
  sort(a.begin(), a.end());
  sum[0] = a[0];
  for (int i = 1; i < n; ++i) {
    sum[i] = sum[i - 1] + a[i];
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    // cout << "i=" << i << endl;
    int64 cur = sum[i];
    int idx;
    while (true) {
      // cout << "cur=" << cur << endl;
      idx = upper_bound(a.begin(), a.end(), cur * 2) - a.begin();
      if (idx == n) break;
      if (cur == sum[idx - 1]) break;
      cur = sum[idx - 1];
    }
    if (idx == n) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 1792
a=int(input())
l=a/100
r=a%100
if 1<=l and l<=12:
    if 1<=r and  r<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1<=r and r<=12:
        print("YYMM")
    else:
        print("NA")

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

struct	UnionFind {
	int		size;
	int		*par;
	int		*rank;
	int		num_set;
	int64_t	*set_size;
	int64_t	inconvenience;
	UnionFind(int size): size(size), par(NULL), rank(NULL),
		num_set(size), set_size(NULL), inconvenience(0) {
		assert(size > 0);
		par = new int[size];
		rank = new int[size];
		set_size = new int64_t[size];
		assert(par != NULL && rank != NULL && set_size != NULL);
		for (int i = 0; i < size; ++i) {
			par[i] = i;
			rank[i] = 0;
			set_size[i] = 1;
		}
		inconvenience = static_cast<int64_t>(size) * (size - 1) / 2;
	}
	~UnionFind() {
		delete [] par;
		delete [] rank;
		delete [] set_size;
		par = NULL;
		rank = NULL;
		set_size = NULL;
	}
	int		find(int idx) {
		if (par[idx] == idx)
			return idx;
		return (par[idx] = find(par[idx]));
	}
	bool	same(int lhs, int rhs) {
		if (find(lhs) == find(rhs))
			return true;
		return false;
	}
	void	unite(int lhs, int rhs) {
		int	par_l = find(lhs), par_r = find(rhs);
		if (par_l == par_r)
			return;
		inconvenience -= set_size[par_l] * set_size[par_r];
		if (rank[par_l] < rank[par_r]) {
			par[par_l] = par_r;
			set_size[par_r] += set_size[par_l];
		} else {
			par[par_r] = par_l;
			set_size[par_l] += set_size[par_r];
			if (rank[par_l] == rank[par_r])
				++rank[par_l];
		}
		--num_set;
	}
};

int	main()
{
	int	N, M;
	cin >> N >> M;
	vector<pair<int, int>>	edge_vec(M);
	int	A, B;
	for (int i = 0; i < M; ++i) {
		cin >> A >> B;
		--A; --B;
		edge_vec.at(i) = {A, B};
	}
	vector<int64_t>	inconv_vec(M, 0);
	UnionFind	uf(N);
	for (int i = M - 1; i >= 0; --i) {
		inconv_vec.at(i) = uf.inconvenience;
		uf.unite(edge_vec.at(i).first, edge_vec.at(i).second);
	}
	for (int i = 0; i < M; ++i)
		cout << inconv_vec.at(i) << endl;
}




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

using namespace std;

using ll = long long;

const int mod = 1000000007;
class modint {
public:
    ll a = 0;
    modint(ll x = 0) {while(x < 0)x += mod;a = x%mod;}
    modint(const modint &r) {a = r.a;}
    modint operator -(){return modint(-a);}
    modint operator +(const modint &r) {return modint(*this)+=r;}
    modint operator -(const modint &r) {return modint(*this)-=r;}
    modint operator *(const modint &r) {return modint(*this)*=r;}
    modint &operator +=(const modint &r){
        a += r.a;
        if(a >= mod) a -= mod;
        return *this;
    }
    modint &operator -=(const modint &r) {
        a -= r.a;
        if(a < 0) a += mod;
        return *this;
    }
    modint &operator *=(const modint &r) {
        a = a * r.a % mod;
        return *this;
    }
    modint pow(ll r) const {
        if (!r) return 1;
        modint x = pow(r >> 1);
        x *= x;
        if (r & 1) x *= *this;
        return x;
    }
    modint inverse() const {
        return pow(mod-2);
    }
    modint& operator/=(const modint r) {
        return (*this) *= r.inverse();
    }
    modint operator/(const modint r) const {
        modint res(*this);
        return res /= r;
    }
};
istream &operator>>(istream &is, modint &x) {
    ll t;
    is >> t;
    x = t;
    return is;
}
ostream &operator<<(ostream &os, const modint& x) {
    return os << x.a;
}
const int MAX = 500000;
modint fac[MAX], inv[MAX], finv[MAX];
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * modint(i);
        inv[i] = - inv[mod%i] * modint(mod/i);
        finv[i] = finv[i-1] * inv[i];
    }
}
modint Com(ll n, ll k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
modint Per(ll n, ll k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k];
}

using Mint = modint;

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n;
   cin >> n;
   vector<Mint> dp(n + 1, 0);
   dp[0] = 1;
   for(int i = 1; i <= n; i++) {
       for(int j = 0; j <= i - 3; j++) {
           dp[i] += dp[j];
       }
   }
   cout << dp[n] << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; ++i)
    cin >> A[i];
  for (int k = 1; k <= M; ++k) {
    for (int i = 1; i <= N - 1; ++i) {
      if (A[i] % k > A[i + 1] % k) {
        int swap = A[i];
        A[i] = A[i + 1], A[i + 1] = swap;
      }
    }
  }
  for (int i = 1; i <= N; ++i)
    cout << A[i] << endl;
}


Measured memory_bytes: 3096
import math

N, D = map(int, input().split())

l = list()
for i in range(N):
    l.append(list(map(int, input().split())))

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ins = 0
        for k in range(D):
            ins += (l[i][k] - l[j][k]) ** 2
        #print(ins, math.sqrt(ins))
        if math.sqrt(ins) == int(math.sqrt(ins)):
            ans += 1
            #print("now")

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		String win = (b - a) % 2 == 0 ? "Alice" : "Borys";
		System.out.println(win);
	}
}


Measured memory_bytes: 21844
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]
Y = sorted([(i, (p, y)) for i, (p, y) in enumerate(L)], key=lambda x: x[1])
result = [""] * M
x = 0
before_p = 0
for i, (p, y) in Y:
    if before_p != p:
        x = 0
        before_p = p
    x += 1
    result[i] = "{:06}{:06}".format(p, x)
for r in result:
    print(r)


Measured memory_bytes: 52592
n = gets.to_i
list = {}
n.times{ |i|
    str = gets.chomp
    list[str] = 1
}
for i in ["S","H","C","D"] do
    for j in 1..13 do
        str =  i + " " + j.to_s
        if  !list.include?(str)
            puts str
        end
    end
end

Measured memory_bytes: 8496
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};

string s,t;
vector<ll> s_co[26];
vector<ll> t_co[26];
int main(){
	cin>>s>>t;
	
	REP(i,s.size()){
		s_co[s[i]-'a'].push_back(i);
	}
	REP(i,t.size()){
		t_co[t[i]-'a'].push_back(i);
	}
	REP(i,26){
		if(t_co[i].size()!=0&&s_co[i].size()==0){
			cout<<-1<<endl;
			return 0;
		}
	}
	ll ans=0;
	ll t1=0;
	for(ll i=0;i<t.size();i++){
		auto itr=lower_bound(s_co[t[i]-'a'].begin(),s_co[t[i]-'a'].end(),t1);
		if(itr!=s_co[t[i]-'a'].end()){
			t1=*itr;
		}else{
			ans++;
			t1=s_co[t[i]-'a'][0];
		}
		t1++;
		if(t1==s.size()){
			ans++;
			t1=0;
		}
		//cout<<i<<" "<<t1<<" "<<ans<<endl;
	}
	cout<<(ans*(ll)s.size())+t1<<endl;
	return 0;
}

Measured memory_bytes: 2872
def check():
    flag=True
    for x,y in a:
        if i[x-1]!=str(y):
            flag=False
    if flag==True:
        print(i)
        exit()
        
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]

for i in range(1000):
    if n==1 and i<10:
        i=str(i)
        check()
    elif n==2 and 10<=i<=99:
        i=str(i)
        check()
    elif n==3 and 100<=i<=999:
        i=str(i)
        check()
print(-1)

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

int main(){
  int n, W;
  std::cin >> n >> W;
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) {
    std::cin >> v[i] >> w[i];
  }
  int dp[n + 1][W + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= W; j++) 
      dp[i][j] = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= W; j++) {
      if(j + w[i] <= W){
        dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
      }
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
  }
  std::cout << dp[n][W] << std::endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector <int> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());

    int ans=1;
    for(int i=0;i<N-1;i++){
        if(vec.at(i)<vec.at(i+1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/* Bismillahir Rahmanir Rahim */

#include <bits/stdc++.h>

#define rep(i, n)	for(int i=0;i<n;i++)
#define repn(i, n)	for(int i=1;i<=n;i++)
#define set(i, n)	memset(i, n, sizeof(i))

#define pb	push_back
#define oo	1e9 

using namespace std;

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

int main(){
	int a, b, x, y;
	cin >> a >> b >> x >> y;
	for(int i=a;i<x;i++) cout << "R";
	for(int i=b;i<y;i++) cout << "U";
	for(int i=a;i<x;i++) cout << "L";
	for(int i=b;i<y;i++) cout << "D";
	cout << "D";
	for(int i=a;i<=x;i++) cout << "R";
	for(int i=b;i<=y;i++) cout << "U";
	cout << "LU";
	for(int i=a;i<=x;i++) cout << "L";
	for(int i=b;i<=y;i++) cout << "D";
	cout << "R";
	cout << endl;
	return 0;
}


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

#define fto(i, x, y) for(auto i = (x); i <= (y); ++i)
#define fdto(i, x, y) for(auto i = (x); i >= (y); --i)
#define ftoa(i, x, y, a) for(auto i = (x); i <= (y); i += a)
#define ftoit(it, var) for (auto it = var.begin(); it != var.end(); ++it)

#define ii pair<int, int>
#define mp make_pair
#define ff first
#define ss second

#define vi vector<int>
#define vii vector<ii>
#define ll long long
#define vll vector<ll>

#define eb emplace_back
#define ef emplace_front
#define lb lower_bound
#define ub upper_bound

#define oo 1000000007
#define OO 1000000000000000007LL

using namespace std;

#define Pro "tmp"
#define maxN 100007

int a[maxN], b[maxN], c[maxN];

int main() {
	int n;
	scanf("%d", &n);

	fto(i, 1, n) scanf("%d", &a[i]);
	fto(i, 1, n) scanf("%d", &b[i]);

	ll sum = 0LL;
	fto(i, 1, n) sum += a[i]-b[i];
	
	if (sum < 0LL) {
		puts("-1");
		return 0;
	}

	int ans = 0;
	fto(i, 1, n) c[i] = a[i]-b[i];

	int j = n+1;
	sort(c+1, c+n+1);

	fto(i, 1, n) {
		if (c[i] >= 0) break;
		++ans;
		while (-c[i] > c[j]) {
			c[i] += c[j];
			c[j] = 0;
			--j;
			++ans;
		}
		c[j] += c[i];
		c[i] = 0;
	}

	printf("%d\n", ans);
	return 0;
}

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i, n) {
        cin >> a[i];
    }

    VI ans(2, 0);
    REP(i, 2) {
        int temp = 0;
        REP(j, n) {
            if (j % 2 == i) {
                if (temp + a[j] <= 0) {
                    ans[i] += 1 - (temp + a[j]);
                    temp = 1;
                } else {
                    temp += a[j];
                }
            } else {
                if (temp + a[j] >= 0) {
                    ans[i] += (temp + a[j]) - (-1);
                    temp = -1;
                } else {
                    temp += a[j];
                }
            }
        }
    }

    cout << *min_element(ALL(ans)) << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int W, H;
char map[25][25];
int sx, sy;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int dfs(int x, int y)
{
  int ret = 1;
  map[x][y] = '#';
  for(int i = 0; i < 4; i++){
    int nx = x + dx[i], ny = y + dy[i];
    if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
    if(map[nx][ny] == '#') continue;
    ret += dfs(nx, ny);
  }
  return ret;
}

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

  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    for(int y = 0; y < H; y++){
      for(int x = 0; x < W; x++){
        cin >> map[x][y];
        if(map[x][y] == '@'){
          sx = x, sy = y;
          map[x][y] = '.';
        }
      }
    }
    cout << dfs(sx, sy) << endl;
  }
  return 0;
}



Measured memory_bytes: 3144
#include <iostream>
using namespace std;
int main(void){
    string a;
    cin>>a;
    if(a[0]=='A'){
        if(a[1]=='A'){
            if(a[2]=='A'){
                cout<<"No";
                return 0;
            }
        }
    }else if(a[0]=='B'){
        if(a[1]=='B'){
            if(a[2]=='B'){
                cout<<"No";
                return 0;
            }
        }
    }
     cout<<"Yes";
     return 0;

    
}


Measured memory_bytes: 256
//****************************//
/**********  main *************/
//****************************//
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(i = 0; i < n; i++)
#define FOR(i, a, b) for(i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())

double pi = 3.141592653589793;

int gcd(int a, int b) {
    if(a % b == 0) {
        return (b);
    } else {
        return (gcd(b, a % b));
    }
}

int main() {

    std::cin.tie(0);

    string s;
    string t;
    int i,res;
    int count = 0;

    cin >> s >> t;

    for(i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            count++;
        }
    }
    
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main() {
    int n;
    cin>>n;
    int kai,nai,ans=0,b;
    b=n;
    for(int i=0;i<=9;i++){
        kai=n%10;
        nai=n/10;
        if(nai==0){
            ans+=kai;
            break;
        }
        ans+=kai;
        n=nai;
    }
    if(b%ans==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 384
# input
c1 = [int(i) for i in input().split()]
c2 = [int(i) for i in input().split()]
c3 = [int(i) for i in input().split()]

#値の異なる行を探す
flag = 0

'''
if c1[0] == c1[1] and c1[0] == c1[2]:
    flag = 1
    
if flag == 0 and c2[0] == c2[1] and c2[0] == c2[2]:
    flag = 2
    
if c3[0] == c3[1] and c3[0] == c3[2]:
    flag = 3
'''
    
for i in range(0,c1[0]+1):
        a1 = c1[0] - i
        a2 = c2[0] - i
        a3 = c3[0] - i
        b2 = c1[1] - a1
        if b2 + a2 == c2[1] and b2 + a3 == c3[1]:
           b3 = c1[2] - a1
           if b3 + a2 == c2[2] and b3 + a3 == c3[2]:
               print('Yes')
               flag = 1
               break
               
if flag == 0:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;

const ll MOD_CONST = 1000000007;



int main()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<ll> s(n+1);
	for (int i = 0; i < n; i++) {
		s[i + 1] = s[i] + a[i];
	}
	vector<ll> x(n + 1);
	x[0] = (1 << 21) - 1;
	for (int i = 0; i < n; i++) {
		x[i + 1] = x[i] ^ a[i];
	}

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		if ((s[n] - s[i]) ==( x[n] ^x[i])) {
			ans += n - i;
		}
		else {
			int l = i+1;
			int r = n;
			int mid = (l + r) / 2;
			while (l != mid) {
				
				if ((s[mid] - s[i]) ==( x[mid] ^x[i])) {
					l = mid;
				}
				else {
					r = mid;
				}
				mid = (l + r) / 2;
			}
			//cout << l -i<< endl;
			ans += l - i;
		}
		//cout << ans << endl;
	}

	cout << ans << endl;
}  



Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
    int a, b, c, d;
    int s1, s2;

    scanf("%d %d %d %d", &a, &b, &c, &d);
    s1 = a * b;
    s2 = c * d;

    printf("%d", s1 >= s2 ? s1 : s2);

    return 0;
}

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

#define Rep(i,n) for(int i=0;i<(n);i++)
#define For(i,n1,n2) for(int i=(n1);i<(n2);i++)
#define REP(i,n) for(ll i=0;i<(n);i++)
#define RREP(i,n) for(ll i=(n-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(n1);i<(n2);i++)
#define put(a) cout<<(a)<<"\n";
#define all(a)  (a).begin(),(a).end();
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n,m;

int main(){
    cin >> n;
    vector<int> d(n);
    REP(i,n){
        cin >> d[i];
    }
    cin >> m;
    vector<int> t(m);
    unordered_map<int, int> mp;
    REP(i,m){
        cin >> t[i];
        mp[t[i]]++;
    }
    REP(i,n){
        auto itr = mp.find(d[i]);
        if(itr!=mp.end()){
            if(mp[d[i]]>0){
                mp[d[i]]--;
            }
            
        }else{
            //mp[d[i]];
        }
    }
    bool flag = true;
    REP(i,m){
        if(mp[t[i]]>0){
            flag = false;
            break;
        }
    }
    if(flag){
        put("YES");
    }else{
        put("NO");
    }
    return 0;
}



Measured memory_bytes: 10056
def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return [ok, ng]

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

a.sort()
print(sum([a[bisect(a, lambda x:x >= i, n, -1)[0]] == i for i in m]))


Measured memory_bytes: 16896
#include<iostream>
using namespace std;
int main(void) {
	while (1) {
		char c;
		int goban[3][3] = { 0 }, result = 0, judge = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> c;
				if (c == '0') return 0;
				if (c == 'b')goban[i][j] = 1;
				else if (c == 'w')goban[i][j] = -1;
				else goban[i][j] = 0;
			}
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				judge += goban[i][j];
			}
			if (judge == 3) result = 1;
			else if (judge == -3) result = -1;

			judge = 0;
		}
		for (int j = 0; j < 3; j++) {
			for (int i = 0; i < 3; i++) {
				judge += goban[i][j];
			}
			if (judge == 3) result = 1;
			else if (judge == -3) result = -1;

			judge = 0;
		}
		for (int i = 0; i < 3; i++) {
			judge += goban[i][i];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;

		for (int i = 0; i < 3; i++) {
			judge += goban[i][2 - i];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;


		if (result == 1) {
			cout << "b" << endl;
		}
		else if (result == -1) {
			cout << "w" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 1136
from collections import deque

def main():
    n,q = map(int, input().split())

    procs = [input().split() for x in range(n)]
    procs = deque([[proc[0], int(proc[1])] for proc in procs])

    finished_procs = []
    t = 0
    
    while len(procs) > 0:
        proc = procs.popleft()

        t += min(q, proc[1])

        if q - proc[1] >= 0:
            finished_procs.append([proc[0], t])
        else:
            proc[1] -= q
            procs.append(proc)

    for proc in finished_procs:
        print(proc[0] + ' ' + str(proc[1]))

if __name__ == "__main__":
    main()



Measured memory_bytes: 21664
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define MAX 393
using namespace std;

/*
n
s1 l1 p1
...
sN lN pN
m
w1
...
wm
 */

int n,m;
int dp[MAX+1][MAX+1];

int main(){
  cin >> n;

  REP(j,MAX+1){
    REP(k,MAX+1){
      dp[0][j] = j==0 ? 0 : -1;
    }    
  }

  REP(i,n){
    int s,l,p;
    cin >> s >> l >> p;
    REP(j,MAX+1){
      int dp1 = -1;
      FOR_IN(w,s,l+1)
        dp1 = j>=w && dp[i+1][j-w]!=-1 ? max(dp1, dp[i+1][j-w] + p) : dp1;
      dp[i+1][j] = max(dp[i][j], dp1);
    }
  }

  cin >> m;
  int w[m];
  bool f=true;
  REP(r,m){
    cin >> w[r];
    f &= dp[n][w[r]] != -1;
  }

  if(!f)
    cout << -1 << endl;
  else
    REP(r,m)
      cout << dp[n][w[r]] << endl;

  return 0;
}


Measured memory_bytes: 3724