akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    VI a(n-1);
    REP(i,n-1){
        if (s[i] == 'A' && s[i + 1] == 'C') a[i] = 1;
    }
    VI sum(n);
    REP(i,n-1) sum[i + 1] = sum[i] + a[i];

    while (q--){
        int l = in() - 1, r = in() - 1;
        int ans = sum[r] - sum[l];
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
using namespace std;
static const int max_n = 20000;
static const int INF = 1e8;
const long mod =1e9 + 7;
static long long x,a,b,V,m,n,h,D=0,amax=1;
typedef pair<long long, long long> p;
static long long s[max_n],t[max_n],u[max_n],v[max_n],w[2*max_n],z[2*max_n];
static long long dp[max_n][max_n];
long long k = 1;
void solve(){
    if(n>a) k = 0;
    long long b = a;
    for(int i=0 ; i<n ; i++){
        k *= b--;
        k %= mod;
    }
    cout << k << endl;
}
int main(){
    cin >> n >> a;
    solve();
    return 0;
}



Measured memory_bytes: 3116
import sys
n , a= map(int,input().split())


for i in range(n+1):
    for j in range(n-i+1):
        if 10**4 * i + 5 * 10 ** 3 * j + 10 ** 3 * (n - i - j) == a:
            print(i,j,n-i-j)
            sys.exit()

print(-1,-1,-1)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
	public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();

	if(a < b && b < c){
		System.out.println("Yes");	
	}
	else{
		System.out.println("No");
	}
	}
}

Measured memory_bytes: 26096
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
ll max[100001], max2[100001];

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> P(N);
	vector<long long> idx(N);
	for(ll i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&P[i]);
		P[i]--;
		idx[P[i]] = i;
	}
	set<ll> s;
	ll res = 0;
	for (ll i=N-1; i>=0; i--) {
		s.insert(idx[i]);
		vector<ll> l(2,-1), r(2,N);
		auto it = s.find(idx[i]);
		rep(j,2) {
			if (it == s.begin()) break;
			it--;
			l[j] = *it;
		}
		it = s.find(idx[i]);
		rep(j,2) {
			it++;
			if (it == s.end()) {
				break;
			}
			r[j] = *it;
		}
		// cout << i << ": " << l[1] << " " << l[0] << " " << idx[i] << " " << r[0] << " " << r[1] << " :" << ((l[0]-l[1])*(r[0]-idx[i])+(idx[i]-l[1])*(r[1]-r[0])) << endl;
		res += (i+1)*((l[0]-l[1])*(r[0]-idx[i])+(idx[i]-l[0])*(r[1]-r[0]));
	}
	cout << res << endl;
	return 0;
}


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

A = 1
B = 1
for _ in range(N):
    x, y = map(int, input().split())
    na = A // x if A % x == 0 else A // x + 1
    nb = B // y if B % y == 0 else B // y + 1
    n = max(na, nb)
    A = n * x
    B = n * y

print(A + B)

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


#define all(x) (x).begin() , (x).end();
#define rall(x) (x).rbegin() , (x).rend();
#define fi first
#define se second
#define pb push_back



void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<" ";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    long long n ; cin>>n;
    long long happy = (n / 500) * 1000 + ((n % 500)/5) * 5;
    cout<<happy<<endl;

    
    //int t; cin>>t;for(;t--;)done();
}

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right) {
	llint middle;
	if (right < left) {
		return -(INF64);
	} else {
		middle = left + (right - left) / 2;
		if (ary[middle] > key) {
			return my_binary_search(ary, key, left, middle - 1);
		} else if (ary[middle] < key) {
			return my_binary_search(ary, key, middle + 1, right);
		} else {
			return middle;
		}
	}
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	
	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}
	
	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}
	
	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}
	
	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main (void)
{
	//INPUT
	llint A,B,K;
	cin >> A >> B >> K;
	
	//SOLVE
	if (A>=K) {
		A-=K;
	} else {
		K = K-A;
		A = 0;
		if (B>=K) {
			B-=K;
		} else {
			B = 0;
		}
	}
	
	//OUTPUT
	cout << A << " " << B << endl;
	
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;


int main(){
	long long a,b,x;
	cin>>a>>b>>x;
	long long ans=0;
	if (a!=0) ans=(b/x)-((a-1)/x);
	else ans=(b/x)+1;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> vd[1000010];
int main()
{
	int n;
    cin>>n;
    int cnt[1000010]={};
    for(int i=0; i<n; i++){
        int a; cin>>a;
        cnt[a]++;
    }
    for(int i=1; i<=1000000; i++){
        for(int j=i*2; j<=1000000; j+=i){
            if(cnt[j]==1) vd[j].push_back(i);
        }
    }
    int ans=0;
    for(int i=1; i<=1000000; i++){
        if(cnt[i]!=1) continue;
        bool dame=0;
        for(auto d:vd[i]){
            if(cnt[d]){
                dame=1; break;
            }
        }
        if(!dame) ans+=cnt[i];
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 49860
import numpy as np
from collections import Counter

N = int(input())
As = list(map(int, input().split()))
As.insert(0, 0)

sum_list = np.cumsum(As)

c = Counter(sum_list)
ans = 0

for v in c.values():
  ans += v * (v-1) // 2
  
print(ans)

Measured memory_bytes: 45924
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
      //整数の入力
      Scanner sc = new Scanner(System.in);
      int A = Integer.parseInt(sc.next());
      int B = Integer.parseInt(sc.next());
      int C = Integer.parseInt(sc.next());
      int D = Integer.parseInt(sc.next());
      
      boolean takasugiWin = false;
      while(A > 0){
        C -= B;
        if(C <= 0){
          takasugiWin = true;
          break;
        }
        A -= D;
      }
      String kotae = takasugiWin ? "Yes" : "No";

      System.out.println(kotae);
    }  
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

string s;
int c1,c2;
int main(void){
    cin>>s;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i]=='0')c1++;
            else c2++;
        }
        else{
            if(s[i]=='1')c1++;
            else c2++;
        }
    }
    d(c1); d(c2);
    p(min(c1,c2));
    return 0;
}



Measured memory_bytes: 512
import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String l = in.readLine();
        int N = Integer.parseInt(l);//5
        int candy = 0;
    for (int i=0; i-1<N; i++){
         candy = candy +i ;
        
   }
      System.out.println(candy); 
   }
   
  }

Measured memory_bytes: 8148
s = gets.chomp.split(' ').map(&:to_i)[0]
a = [s]
1000000.times do |i|
  am = a.last.even? ? a.last / 2 : 3 * a.last + 1
  if a.include?(am)
    puts i + 2
    exit
  else
    a << am
  end
end

Measured memory_bytes: 1788
import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;
  
public class Main{
    public static void main(final String[] args){
       
        final Scanner sc = new Scanner(System.in);

        ArrayList<String>  allmen =new ArrayList <String>(){{}};
        String abc = "abcdefghijklmnopqrstuvwxyz";
        int bigNum =11;
        Long alf = 26l;
        Long N = sc.nextLong();
        String ans = "";
        
        for(int i=bigNum;N>0;i--){
            Long targetNum = N-1;
            int targetStr = (int)(targetNum%alf);
            ans = abc.substring(targetStr,targetStr+1)+ans;
            N =  targetNum/alf;
        }


        System.out.println(ans);

    }
}
    


    

Measured memory_bytes: 39300
import sys
input = sys.stdin.readline
from collections import *

def dfs(x, y):
    if x==0 and y==0:
        t[x][y] = False
        return False
    
    if x>=1:
        t[x][y] |= not dfs(x-1, y)
        
    if y>=1:
        t[x][y] |= not dfs(x, y-1)
        
    if min(x, y)>=1:
        t[x][y] |= not dfs(x-1, y-1)
   
    return t[x][y]
    
t = [[False]*7 for _ in range(7)]

for i in range(7):
    for j in range(7):
        dfs(i, j)

"""
for ti in t:
    print(*ti)
"""

N = int(input())
flag = True

for _ in range(N):
    a = int(input())
    
    if a%2==1:
        flag = False
        
if flag:
    print('second')
else:
    print('first')

Measured memory_bytes: 49496
#include<iostream>
using namespace std;
int main(void) {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x <= 0 || y <= 0) {
        cout << "No" << endl;
        return 0;
    }
    if(w < (x + r)){
        cout << "No" << endl;
        return 0;
    }
    if(h < (y + r)){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3100
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc166/tasks/abc166_f

//ポイント：全体の和で場合分けするという考え方

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL stone[3];
string S[100000];

string ans = "No";
vector<char> method;

void solve(){
	LL sum = stone[0]+stone[1]+stone[2];
	if(sum==0) return;
	if(sum==1){
		for(int i=0;i<N;i++){
			if(stone[S[i][0]-'A']==1 || stone[S[i][1]-'A']==1){
				if(stone[S[i][0]-'A']>stone[S[i][1]-'A']){
					stone[S[i][0]-'A']--;
					stone[S[i][1]-'A']++;
					method.push_back(S[i][1]);
				}else{
					stone[S[i][0]-'A']++;
					stone[S[i][1]-'A']--;
					method.push_back(S[i][0]);
				}
			}else return;
		}
	}
	if(sum==2){
		for(int i=0;i<=N-2;i++){
			if(stone[S[i][0]-'A']==0 && stone[S[i][1]-'A']==0) return;
			if(stone[S[i][0]-'A']==1 && stone[S[i][1]-'A']==1){
				if(S[i+1][0]==S[i][0] || S[i+1][1]==S[i][0]){
					stone[S[i][0]-'A']++;
					stone[S[i][1]-'A']--;
					method.push_back(S[i][0]);
				}else if(S[i+1][0]==S[i][1] || S[i+1][1]==S[i][1]){
					stone[S[i][0]-'A']--;
					stone[S[i][1]-'A']++;
					method.push_back(S[i][1]);
				}
			}
			else{
				if(stone[S[i][0]-'A']>stone[S[i][1]-'A']){
					stone[S[i][0]-'A']--;
					stone[S[i][1]-'A']++;
					method.push_back(S[i][1]);
				}else{
					stone[S[i][0]-'A']++;
					stone[S[i][1]-'A']--;
					method.push_back(S[i][0]);
				}
			}
		}

		if(stone[S[N-1][0]-'A']==0 && stone[S[N-1][1]-'A']==0) return;
		if(stone[S[N-1][0]-'A']>stone[S[N-1][1]-'A']){
			stone[S[N-1][0]-'A']--;
			stone[S[N-1][1]-'A']++;
			method.push_back(S[N-1][1]);
		}else{
			stone[S[N-1][0]-'A']++;
			stone[S[N-1][1]-'A']--;
			method.push_back(S[N-1][0]);
		}
	}
	if(sum>=3){
		if(stone[S[0][0]-'A']>=1 || stone[S[0][1]-'A']>=1){
			if(stone[S[0][0]-'A']>stone[S[0][1]-'A']){
				stone[S[0][0]-'A']--;
				stone[S[0][1]-'A']++;
				method.push_back(S[0][1]);
			}else{
				stone[S[0][0]-'A']++;
				stone[S[0][1]-'A']--;
				method.push_back(S[0][0]);
			}
		}else return;
		for(int i=1;i<N;i++){
			if(stone[S[i][0]-'A']>stone[S[i][1]-'A']){
				stone[S[i][0]-'A']--;
				stone[S[i][1]-'A']++;
				method.push_back(S[i][1]);
			}else{
				stone[S[i][0]-'A']++;
				stone[S[i][1]-'A']--;
				method.push_back(S[i][0]);
			}
		}
	}
	ans = "Yes";
}

int main(){
    cin >> N >> stone[0] >> stone[1] >> stone[2];
    for(int i=0;i<N;i++) cin >> S[i];

    solve();

    cout << ans << endl;
    if(ans=="No") return 0;
    for(int i=0;i<method.size();i++) cout << method[i] << endl;
    return 0;
}

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

const int MX = 100001;

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

  int ans = 0;

  rep(i,a+1) rep(j,b+1) rep(k,c+1){
        if(i*500+j*100+k*50==x) ans++;
  }

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

Measured memory_bytes: 3608
from collections import Counter,defaultdict
t=int(raw_input())
f=defaultdict(int)
while(t!=0):
    t=t-1
    s=(raw_input())
    s=sorted(list(s))
    f["".join(s)]+=1
ans=0
for i in f:
    p=f[i]
    ans+=((p)*(p-1))/2
print ans    

Measured memory_bytes: 16176
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
#define rep(i,n) for (int i=1;i<=n;i++)
//#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin>>N;
    vector<long int> f(N,0);
    rep(i,100){
        rep(j,100){
            rep(k,100){
                if (i*i+j*j+k*k+i*j+j*k+k*i<=N) f[i*i+j*j+k*k+i*j+j*k+k*i-1]++;
            }
        }
    }
    for(int i=0;i<N;i++) cout<<f[i]<<endl;
    return 0;
}

Measured memory_bytes: 3548
#include<stdio.h>
#define exchange(a,b) {typeof(a) _tmp=a; a=b; b=_tmp;}

char A[100001];
int B[100001];

int Partition(int A[], int p, int r){
    int i,j;
    int x;
    x = A[r];
    i = p-1;
    for(j=p; j<r; ++j){
        if(B[A[j]] <= B[x]){
            i += 1;
            exchange(A[i],A[j]);
        }
    }
    exchange(A[i+1],A[r]);
    return i+1;
}

void Quicksort(int A[], int p, int r){
    int q;
    if(p < r){
        q = Partition(A,p,r);
        Quicksort(A,p,q-1);
        Quicksort(A,q+1,r);
    }
}

int isStable(int A[], int n){
    int i;
    for(i=2; i<=n; ++i){
        if(B[A[i-1]] == B[A[i]] && A[i-1] > A[i])return 0;
    }
    return 1;
}

int main(){
    int i;
    int n;
    int C[100001];
    scanf("%d",&n);
    for(i=1; i<=n; ++i){
        scanf(" %c %d", A+i,B+i);
        C[i] = i;
    }
    Quicksort(C,1,n);
    if(isStable(C,n)) printf("Stable\n");
    else printf("Not stable\n");
    for(i=1; i<=n; ++i){
        printf("%c %d\n",A[C[i]], B[C[i]]);
    }
    return 0;
}


Measured memory_bytes: 2580
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c,e,d;cin>>a>>b>>c>>d>>e;
  if(a==0)cout<<1;
  if(b==0)cout<<2;
  if(c==0)cout<<3;
  if(d==0)cout<<4;
  if(e==0)cout<<5;
}


Measured memory_bytes: 27060
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

const int MAX = 1e7;
const int MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[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] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for (int i = 1; i <= h - a; i++) {
        ans += COM(i - 1 + b - 1, b - 1) * COM(h - i + 1 - 1 + w - b - 1, w - b - 1);
        ans %= MOD;
    }
    OUT(ans);
}

Measured memory_bytes: 234624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll W_I_MAX = 1000000000;

class Edge{
public:
	ll to;
	ll distance;
	Edge (ll to, ll distance) : to(to), distance(distance){}
};

vector<int> seen;
vector<vector<Edge>> g;
ll N;


void input() {
	scanf("%lld", &N);
	g=vector<vector<Edge>>(N);
	rep(i, N-1) {
		ll t1,t2,t3;
		scanf("%lld%lld%lld", &t1,&t2,&t3);
		t1--;t2--;
		Edge e1(t2,t3);
		g[t1].push_back(e1);
		Edge e2(t1,t3);
		g[t2].push_back(e2);
	}
	seen.assign(N,-1);
}



void dfs(vector<vector<Edge>> &g, ll v,ll dis) {
	seen[v]=dis%2 ? 0 : 1;

	for(Edge nextv : g[v]){
		if(seen[nextv.to]!=-1)continue;
		dfs(g,nextv.to,dis+nextv.distance);
	}

}

signed main() {
	input();
	dfs(g,0,0);
	rep(i,N){
		printf("%d\n",seen[i]);
	}
	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    if(N == 1){
        Out(1);
        Out("0");
    }else if(N == 2){
        Out(2);
        Out("0");
        Out("11");
    }else{
        Out(N - 1);
        FOR(i, 2, N + 1){
            string ans(i, '0');
            ans[0] = '1';
            ans[i - 1] = '1';
            Out(ans);
        }
    }

    return 0;
}



Measured memory_bytes: 3236
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	int i;
	for (i = 0; i < n; i++)
	{
		cout << s.at(i) << t.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

int modpow(int a, int n, int mod) {
    int res=1;
    while(n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,b; cin>>n>>b; int r=n-b;

    for(int k=1; k<=b; k++){
        int res=1;
        for(int i=r+1; i>r+1-k; i--){
            res*=i; res%=MOD;
        }
        for(int i=1; i<=k; i++){
            res*=modpow(i,MOD-2,MOD); res%=MOD;
        }
        for(int i=b-1-k+1+1; i<=b-1; i++){
            res*=i; res%=MOD;
        }
        for(int i=1; i<=k-1; i++){
            res*=modpow(i,MOD-2,MOD); res%=MOD;
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,count=0;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];
    for(i=0; i<n; i+=2)
    {
        if(a[i]%2!=0)
            count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3620
require 'prime'
N,M = gets.split.map(&:to_i)
DS = M.prime_division

def r(x,i, &f)
  if i == DS.size
    return f.call(x)
  end
  a,b = DS[i]
  (0..b).each{ |j|
    r(x*(a**j), i+1, &f)
  }
end

$ans = 1

r(1,0) { |x|
  #p x
  if M/x >= N
    $ans = [$ans, x].max
  end
}
p $ans

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int res = 0;
    for (int i = 0; i < n - 1; i++) res += (i + 1);
    for (int i = 0; i < m - 1; i++) res += (i + 1);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <queue>

using namespace std;

#define int long long

signed main(void) {
	int H, W; cin >> H >> W;
	int N; cin >> N;
	vector<int> A(N); for (auto &a : A) cin >> a;
	queue<int> que;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < A[i]; ++j) que.push(i);
	}

	vector<vector<int> > res(H, vector<int>(W));
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			res[i][j] = que.front(); que.pop();
		}
	}
	for (int i = 0; i*2 < res.size(); ++i) {
		std::reverse(res[i * 2].begin(), res[i * 2].end());
	}

	for (auto &a : res) {
		for (auto &aa : a) {
			cout << aa+1 << " ";
		}
		cout << endl;
	}
}


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

int main() {
  string o,e;
  cin >> o >> e;
  for(int i = 0; i < o.size() + e.size(); i++){
    if(i % 2 == 0){
      cout << o.at(i / 2);
    }else{
      cout << e.at(i / 2);
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	map<string,int>in;
	string s;
	int ma=0;
	string mas="";
	while(cin>>s){
		if(s.size()>ma){ma=s.size();mas=s;}
		in[s]++;
	}
	int ma1=-1;string mas1="";
	for(map<string,int>::iterator it=in.begin();it!=in.end();it++){
		string d=it->first;
		if(ma1<in[d]){
			ma1=in[d];
			mas1=d;
		}
	}
	cout<<mas1<<" "<<mas<<endl;
}

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


int main() {
  int w , h , x , y , r ;
  cin >> w >> h >> x >> y >> r ;
  
  if(0<=x-r&&x+r<=w&&y-r>=0&&y+r<=h){
    cout <<"Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long

const ll mod=1e9+7;

int main()
{
    fast;

	int n;
	cin>>n;

	double p[n+1];
	f(i,1,n+1)
		cin>>p[i];

	double dp[n+1][n+1];

	memset(dp,0,sizeof(dp));

	dp[0][0]=1;

	f(i,1,n+1)
		dp[0][i]=dp[0][i-1]*(1-p[i]);

	f(i,1,n+1)
	{
		f(j,1,n+1)
		{
			dp[i][j]=(dp[i][j-1]*(1-p[j]))+(dp[i-1][j-1]*p[j]);
		}
	}

	double ans=0;

	for(int i=n;i>=0;i--)
	{
		if(i>(n/2))
			ans=ans+dp[i][n];
		else
			break;
	}

	cout << std::setprecision (10) <<ans;
}

Measured memory_bytes: 74112
#include<bits/stdc++.h>
using namespace std;
int b[105];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int k;scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			int x;scanf("%d",&x);
			b[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++)
		if(b[i]==n)ans++;
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    string s;
    cin>>s;
    size_t size=s.length();
    int cnt=0;
    
    rep(i,size/2){
        if(s[i]!=s[size-1-i]) cnt++;
    }
    
    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n, k) for (int i = n; i < k; i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v)                      \
    for (int i = 0; i < v.size(); i++) \
        P(v[i]);
#define printt(a, b) cout << a << " " << b << endl;
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int MOD = 1e9 + 7;
 
void solve()
{
    string s;
    cin >> s;
    vi v(s.length() + 1, 0);
    rep(i, s.length())
    {
        if (s[i] == '<')
        {
            v[i + 1] = max(v[i + 1], v[i] + 1);
        }
    }
    for (int i = s.length() - 1; i >= 0; i--)
    {
        if (s[i] == '>')
        {
            v[i] = max(v[i], v[i + 1] + 1);
        }
    }
    ll sum = 0;
    rep(i, v.size())
    {
        sum += v[i];
    }
    P(sum);
}
 
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 2820
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
#define a_macro(args...) sum(args)
#define mp make_pair
#define eb emplace_back
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

typedef long long ll;
const ll mod = 1e9+7;

typedef tuple<int,int,int> State; // operator< defined
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef double ld;
const int N = 55;
struct matrix {
  // N is the size of the matrix
  int m[N][N];
  matrix()
  {
     memset(m,0,sizeof(m));
  }
  matrix operator * (matrix b)
  {
     matrix c = matrix();
     for (int i = 0; i < N; ++i)
       for (int j = 0; j < N; ++j)
         for (int k = 0; k < N; ++k) 
           c.m[i][j] = (c.m[i][j] + 1LL * m[i][k] * b.m[k][j]) % mod;
     return c;
  }
};
matrix unit = matrix();

matrix modPow(matrix m,ll n){
  if ( n == 0 )
    return unit;
  matrix half = modPow(m,n/2);
  matrix out = half * half;
  if ( n % 2 )
    out = out * m;
  return out; 
}
int sum() { return 0; }

template<typename T, typename... Args>
auto sum(T a, Args... args) { return a + sum(args...); }
template<class T> bool uin(T &a,T b) {return a > b ? (a == b, true) : false; }
template<class T> bool uax(T &a,T b) {return a < b ? (a == b, true) : false; }

int main(int argc, const char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n,i,j;
	for(i=0;i<N;++i)
		unit.m[i][i] = 1;

	ll k;
	cin>>n>>k;
	matrix g = matrix();
	for(i=0;i<n;++i)
		for(j=0;j<n;++j)
			cin>>g.m[i][j];
	matrix ans = modPow(g,k);
	int res = 0;
	for(i=0;i<n;++i)
		for(j=0;j<n;++j)
			res  = (res + ans.m[i][j])%mod;

	cout<<res<<"\n";

    
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: "<< 1e1 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL_DEFINE
    return 0;
}

Measured memory_bytes: 4480
function toNum (str) {
	return parseInt(str, 10);
}

// inputに入力データ全体が入る
function Main(input) {
	var N = toNum(input.split('\n')[0]);
	var A = toNum(input.split('\n')[1]);
	var B = toNum(input.split('\n')[2]);
	if ( N === 1 ) {
		console.log('Hello World');
	} else if ( N === 2 ) {
		console.log('%d', A+B);
	}
}

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


Measured memory_bytes: 21192
n,d=map(int,input().split())
a=[list(map(int,input().split())) for j in range(n)]
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    dis=0
    for k in range(d):
      dis+=(a[i][k]-a[j][k])**2
    dis=dis**(0.5)
    if dis==int(dis):
      ans+=1
print(ans)




Measured memory_bytes: 3188
import java.util.Scanner;
import java.util.regex.Pattern;
public class Main {
	public static boolean hantei(String str) {
        return Pattern.matches("^[A-Z]+$", str);
    }
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n;
		String a;
		String[] b;
		do {
			n = stdIn.nextInt();
			a = stdIn.next();
			b = a.split("",0);
		}while(n<3||n>50||n != a.length()||hantei(a)==false);
		int c=0;
		
			
		for(int i=0 ; i<b.length-2 ;i++) {
			if(b[i].equals("A")&&b[i+1].equals("B")&&b[i+2].equals("C")) {
			c++;
			}
		}
		System.out.println(c);
	}
	
	}


Measured memory_bytes: 23764
def fun(n):
    ops = 0
    while n:
        pc = format(n, 'b').count('1')
        n %= pc
        ops += 1
    return ops

n = int(input())
xs = input()

sm = int(xs, 2)
pc = xs.count('1')

mp = sm % (pc + 1)
mm = sm % (pc - 1) if pc > 1 else 0

for i, x in enumerate(xs, 1):
    df = 1 if x == '0' else -1
    pci = pc + df
    if pci == 0:
        print(0)
        continue

    rest = pow(2, n - i, pci)

    if x == '0':
        smi = (mp + rest) % pci
        print(1 + fun(smi))
    else:
        smi = (mm - rest) % pci
        print(1 + fun(smi))


Measured memory_bytes: 9484
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = str(input())
    pointer = 0
    need_left = 0

    for i in range(N):
        if S[i] == '(':
            pointer += 1
        else:
            if pointer == 0:
                need_left += 1
            else:
                pointer -= 1

    need_right = pointer
    print('('*need_left+S+')'*need_right)

resolve()

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt();
        int result = x + y + 2;
        double equation;

        for(double i = 0.0; i <= x; i++) {
            equation = i * y / x;
            if(equation == Math.floor(equation)) result--;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 26224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define i64 unsigned long long
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}


int pow(ll x, ll y, ll mod){
    ll ret=1;
    for(;y;y>>=1,x=1ll*x*x%mod){
        if(y&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
void kill()
{
    cout << -1 << endl;
    exit(0);
}

int main() {
    sonic();
    map<char, ll> mp;
    string s;
    R s;
    ll ans=s.length()*(s.length()-1)/2+1;
    rep(i, s.length()) {
        mp[s[i]] += 1;
    }
    for(const auto& [k, v]:mp)ans-=v*(v-1)/2;
    co(ans);
}


Measured memory_bytes: 3748
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin>>a[i];
  int ans = 1001001001;
  for(int i = -100; i <= 100; ++i){
    int cnt = 0;
    for(int j = 0; j < n; ++j){
      cnt += (i - a[j]) * (i - a[j]);
    }
    ans = min(ans, cnt);
  }
  cout << ans <<endl;
}

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

#define S_MAX 100
#define N_MAX 100000
#define M_MAX 200000
#define INF 10000000
#define MOD 1000000007
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;
typedef   signed long long dll;

int n, m;
int h, w;
int i, j, k;
int a, b;

int arr[N_MAX * 2];

typedef struct {
	int in;
	int out;
} twoway;

void deb(){
	for (i = b; i < w; i++) {
		printf("[%d] %llu\n", i - b, arr[i - b]);
	}
	return;
}

ull bitpow(ull x, ull p){
	ull result = 1;
	while (p) {
		if (p & 1) {
			result *= x;
			result %= MOD;
		}
		p = (p >> 1);
		x *= x;
		x %= MOD;
	}
	return result;
}

ull dividual(ull b){
	return bitpow(b, MOD - 2);
}

ull frac(ull n){
	static ull dp[N_MAX * 2] = {1};
	if (dp[n]) return dp[n];
	return dp[n] = (frac(n - 1) * n) % MOD;
}

void solve(){
	ull result = 0;
	ull prev;
	
	for (i = b; i < w; i++) {
		prev = 1;
		prev *= frac(h - a - 1 + i);
		prev %= MOD;
		prev *= dividual(frac(h - a - 1));
		prev %= MOD;
		prev *= dividual(frac(i));
		prev %= MOD;
		prev *= frac(a - 1 + w - i - 1);
		prev %= MOD;
		prev *= dividual(frac(a - 1));
		prev %= MOD;
		prev *= dividual(frac(w - i - 1));
		prev %= MOD;

		arr[i - b] = prev;
	}

	for (i = b; i < w; i++) {
		result += arr[i - b];
		result %= MOD;
	}

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

	return;
}

int main (void) {
	scanf("%d%d%d%d", &h, &w, &a, &b);

	for (i = 0; i < N_MAX; i += 1000) frac(i);

	solve();
	return 0;
}




Measured memory_bytes: 2688
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=500010, inf=1e9;
int n;
char s[maxn];
int sume[maxn], sumw[maxn], hsume[maxn], hsumw[maxn];

template<typename T>
inline void read(T &k)
{
	int f=1; k=0; char c=getchar();
	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
	k*=f;	
}
 
int main()
{
	read(n);
	scanf("%s", s+1);
	for(int i=1;i<=n;i++)
	sume[i]+=sume[i-1]+(s[i]=='E'), sumw[i]=sumw[i-1]+(s[i]=='W');
	for(int i=n;i;i--)
	hsume[i]+=hsume[i+1]+(s[i]=='E'), hsumw[i]+=hsumw[i+1]+(s[i]=='W');
	int ans=inf;
	for(int i=1;i<=n;i++)
	{
		ans=min(ans, sumw[i-1]+hsume[i+1]);
//		printf("%d %d\n", i, ans);
	}
	printf("%d\n", ans);
}

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

int main() {
  string n;
  cin >> n;
  if(n[0] == n[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int no_of_moves, no_of_stones;
    cin >> no_of_moves >> no_of_stones;

    vector <int> move(no_of_moves + 1);
    for(int i = 1; i <= no_of_moves; i++)
        cin >> move[i];

    vector <int> winner(no_of_stones + 1, 2);
    for(int i = 1; i <= no_of_stones; i++)
    {
        for(int j = 1; j <= no_of_moves; j++)
        {
            if(move[j] > i) continue;

            if(winner[i - move[j]] == 2)
                winner[i] = 1;
        }
    }

    cout << (winner[no_of_stones] == 1 ? "First\n" : "Second\n");
    return 0;
}

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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  vector<vector<bool>> b(3, vector<bool>(3));
  for (auto& v : a) {
    for (auto& e : v) cin >> e;
  }
  int n;
  cin >> n;
  while (n--) {
    int e;
    cin >> e;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (a[i][j] == e) b[i][j] = true;
      }
    }
  }
  bool r = false;
  for (int i = 0; i < 3; i++) {
    r = r || (b[i][0] && b[i][1] && b[i][2]);
    r = r || (b[0][i] && b[1][i] && b[2][i]);
  }
  r = r || (b[0][0] && b[1][1] && b[2][2]);
  r = r || (b[0][2] && b[1][1] && b[2][0]);
  cout << (r ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
int dp[11000];
int h,n;
const int INF = 1001001001;
int main()
{
    cin >> h >> n;
    rep(j,h+1)dp[j] = INF;
    dp[0] = 0;
    rep(i,n){
        int a,b;
        cin >>a >> b;
        rep(j,h+1){
            dp[min(j+a,h)] = min(dp[min(j+a,h)],dp[j] + b);


        }
        

        
    }
    cout << dp[h] << endl;
    return 0;
}


Measured memory_bytes: 384