akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<double, double> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

string debug_show(P a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}



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

	int H, W, d;
	cin >> H >> W >> d;

	if (d % 2 != 0) {
		rep(i, H) {
			rep(j, W) {
				if ((i + j) % 2 == 0) {
					cout << 'R';
				}
				else {
					cout << 'B';
				}
			}
			cout << endl;
		}
	}
	else {
		char c[4] = { 'R','G','B','Y' };
		vi num = { 1,d - 1,1,d - 1 };
		int col = 0, scol = 0;
		int asc = 1;

		rep(i, H) {
			int cnt = (num[0] + 1) / 2;
			rep(j, W) {
				cout << c[col];
				cnt--;
				if (cnt == 0) {
					col = (col + 1) % 4;
					cnt = num[col];
				}
			}
			cout << endl;
			if (i % (d / 2) == (d / 2) - 1){
				asc = 0;
			}
			else if ((i%d) / (d / 2) == 0) {
				asc = 1;
			}
			else {
				asc = -1;
			}
			if (asc == 1) {
				num[0]+=2;
				num[1]-=2;
				num[2]+= 2;
				num[3]-= 2;
			}
			else if(asc == -1){
				num[0]-= 2;
				num[1]+= 2;
				num[2]-= 2;
				num[3]+= 2;
			}

			if ((i + 1) % d == 0) {
				swap(c[0], c[2]);
			}
			else if (i % d == d / 2 - 1) {
				swap(c[1], c[3]);
			}
			col = scol;
		}
	}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n,k,a[500];

bool check(int d){
	int b[500];
	rep(i,n) b[i]=a[i]%d;
	sort(b,b+n);

	int sum=accumulate(b,b+n,0);
	return accumulate(b,b+n-sum/d,0)<=k;
}

int main(){
	scanf("%d%d",&n,&k);
	rep(i,n) scanf("%d",&a[i]);

	int ans=0,sum=accumulate(a,a+n,0);
	for(int d=1;d*d<=sum;d++) if(sum%d==0) {
		if(check(  d  )) ans=max(ans,  d  );
		if(check(sum/d)) ans=max(ans,sum/d);
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((int)Math.abs(x - a) < (int)Math.abs(x - b) ? "A" : "B");
		scan.close();

	}

}


Measured memory_bytes: 23892
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int sum=a+b+c;
  int mx = max(a,max(b,c));
  if(sum-mx == mx) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

long long a,b;

int main(){
	cin>>a>>b;
	if(a>b)swap(a,b);
	if((a==0||b==0)||(a<=0&&b>=0)){
	cout<<"Zero"<<endl;
	exit(0);	
	}
	if(a<=0&&b>=0){
		if(abs(a)%2==0){
		cout<<"Positive"<<endl;exit(0);	
		}
		else{
			cout<<"Negative"<<endl;exit(0);	
		}
	}
	if(b<0){
		if(abs(a-b)%2==1){
		cout<<"Positive"<<endl;exit(0);	
		}
		else{
			cout<<"Negative"<<endl;exit(0);	
		}
	}
	if(a>0){
		cout<<"Positive"<<endl;exit(0);	
	}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[1005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }

    ll Q;
    cin >> Q;
    REP(_, Q) {
        ll b, e, t;
        cin >> b >> e >> t;
        REP(i, e - b) {
            swap(A[b + i], A[t + i]);
        }
    }

    REP(i, N) {
        cout << A[i];
        if (i < N - 1)
            cout << " ";
    }
    cout << endl;
    return 0;
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n, k - q);
	for(int i = 0; i < q; i++) {
		int foo;
		cin >> foo;
		foo--;
		a[foo]++;
	}
	for(int i = 0; i < n; i++) {
		cout << (a[i] > 0 ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 3732
def solve(C,K,i,borrow):
	if i == -1:
		return int("".join(map(str,C)))
	if A[i] - borrow >= B[i]:
		C[i] = A[i] - borrow - B[i]
		return solve(C,K,i-1,0)
	else:
		C[i] = A[i] - borrow + 10 - B[i]
		if K > 0:
			return max(solve(C,K-1,i-1,0),solve(C,K,i-1,1))
		else:
			return solve(C,K,i-1,1)

A,B,K = raw_input().split()
A,B,K = [int(i) for i in A],[int(i) for i in B],int(K)
n = len(A)
B = [0] * max(0, n - len(B)) + B
C = [0] * n
print solve(C,K,n-1,0)

Measured memory_bytes: 4260
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

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) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}

#define ALL(a) (a).begin(), (a).end()

int main() {
    int N;
    cin >> N;
    string S, ans = "";
    cin >> S;

    int score = 0;
    for (char ch : S) {
        if (ch == '(') {
            if (score < 0) score = 0;
            score++;
        } else {
            score--;
        }
        if (score < 0) {
            ans.push_back('(');
        }
    }
    score = ans.size();
    for (char ch : S) {
        if (ch == '(') {
            score++;
        } else {
            score--;
        }
        ans.push_back(ch);
    }
    for (int i = 0; i < score; i++) {
        ans.push_back(')');
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
const ll INF = 1e18;
const int MX=3e5+1;
int N, M, k;
int co[11][11];
multiset<pair<int, int> > ms;
int dd[11];
void dfs(int x)
{
    ms.clear();
    for(int i=0; i<10; i++) dd[i]=1e8;
    ms.insert(mp(0, x));
    dd[x]=0;
    while(ms.size())
    {
        pair<int, int> p=*ms.begin();
        int node=p.S, w=p.F;
        ms.erase(ms.begin());
        if(w > dd[node]) continue;
        for(int i=0; i<10; i++)
        {
            int ch=i;
            if(dd[ch] > dd[node]+co[node][ch])
            {
                dd[ch]=dd[node]+co[node][ch];
                ms.insert({dd[ch], ch});
            }
        }
    }
}
int main()
{
    cin>>N>>M;
    for(int i=0; i<=9; i++)
        for(int j=0; j<=9; j++)
            cin>>co[i][j];
    ll ans=0;
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<M; j++)
        {
            int x;
            scanf("%d",&x);
            if(x != -1)
            {
                dfs(x);
                ans+=dd[1];
            }
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int r, g, b;
    cin >> r >> g >> b;
    if ((100 * r + 10 * g + b) % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

int main(){
  int n;
  int cards[4][13];
  string picture;
  //char picture;
  int num;

  scanf("%d", &n);

  //initialize array
  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      cards[i][j]=0;
    }
  }

  for(int i=0; i<n; i++){
    cin>>picture>>num;
    //scanf("%s %d", &picture, &num);
    if(picture=="S"){
      cards[0][num-1]=1;
    }else if(picture=="H"){
      cards[1][num-1]=1;
    }else if(picture=="C"){
      cards[2][num-1]=1;
    }else if(picture=="D"){
      cards[3][num-1]=1;
    }else{
      printf("Invalid character\n");
    }
  }

  for(int i=0; i<4; i++){
    for(int j=0; j<13; j++){
      if(cards[i][j]==0){
        if(i==0){
          printf("S %d\n", j+1);
        }else if(i==1){
          printf("H %d\n", j+1);
        }else if (i==2){
          printf("C %d\n", j+1);
        }else if(i==3){
          printf("D %d\n", j+1);
        }
      }
    }
  }

  return 0;

}

Measured memory_bytes: 3272
function Main(input) {
            var patternOne = "5 7 5";
            var patternTwo = "5 5 7";
            var patternThree = "7 5 5";
            input = input.split(" ");
            var fiveNum = 0;
            var sevenNum = 0;
            for (var i = 0; i < input.length; i++) {
                if (Number(input[i]) === 5) {
                    fiveNum++;
                } else if (Number(input[i]) === 7) {
                    sevenNum++;
                }
            }
            if (fiveNum === 2 && sevenNum === 1) {
                console.log("YES");
            } else {
                console.log("NO")
            }
        }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 6904
#include <stdio.h>

int main()
{
	int i, j, k, t, T, N, d, base[60], p[60];
	long long A[201], bit[60];
	char S[202];
	scanf("%d", &T);
	for (i = 1, bit[0] = 1; i < 60; i++) bit[i] = bit[i-1] << 1;
	
	for (t = 1; t <= T; t++) {
		scanf("%d", &N);
		for (i = 1; i <= N; i++) scanf("%lld\n", &(A[i]));
		scanf("%s", &(S[1]));
		
		for (i = N, d = 0; i >= 1; i--) {
			for (j = 0; j < d; j++) if ((A[i] | bit[p[j]]) == A[i]) A[i] ^= A[base[j]];
			if (A[i] != 0) {
				if (S[i] == '1') break;
				base[d] = i;
				for (j = 0; j < 60; j++) if ((A[i] | bit[j]) == A[i]) break;
				p[d++] = j;
			}
		}
		
		if (i == 0) printf("0\n");
		else printf("1\n");
	}

	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1592
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
string s="",d="",f="";
std::cin >> s;
s[5]=' ';
s[13]=' ';
std::cout << s << '\n';
}



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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int mod=1000000007;
template<class T,class U>
void add(T& a,U b){
	a=((ll)a+b)%mod;
}

template<class T,class U>
void sub(T& a,U b){
	a=((ll)a-b%mod+mod)%mod;
}

template<class T,class U>
void mult(T& a,U b){
	a=((ll)a*b)%mod;
}

ll modPow(ll a,ll p){
	ll s=1;
	REP(i,30){
		if((p>>i)&1)
			mult(s,a);
		mult(a,a);
	}
	return s;
}

ll modInv(ll a){
	return modPow(a,mod-2);
}

signed main(){
	int n=read(),m=n,k=read();
	vi pri;
	for(int i=2;i*i<=n;i++)
		if(n%i==0){
			pri.PB(i);
			while(n%i==0)n/=i;
		}
	if(n>1)pri.PB(n);
	vi p,q;
	REP(bits,1<<pri.size()){
		int x=1,y=1;
		REP(i,pri.size())
			if((bits>>i)&1){
				x*=pri[i];
				y*=-1;
			}
		p.PB(x);
		q.PB(y);
	}
	int ans=0;
	const auto f=[&](int d){
		return modPow(k,(d+1)/2);
	};
	const auto g=[&](int d){
		int res=0;
		REP(i,p.size())
			if(d%p[i]==0){
				if(q[i]==1)
					add(res,f(d/p[i]));
				else
					sub(res,f(d/p[i]));
			}
		return res;
	};
	const auto h=[&](int d){
		return (d&1)?d:d/2;
	};
	for(int i=1;i*i<=m;i++)
		if(m%i==0){
			add(ans,h(i)*g(i));
			if(i<m/i)
				add(ans,h(m/i)*g(m/i));
		}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
constexpr ll mod = 1000000007;

ull pow2(ull n) {
    ull r = 1;
    for (ull i = 0; i < n; i++) r *= 2;
    return r;
}

int main() {
    ull m, k;
    cin >> m >> k;
    if (k >= pow2(m)) goto no_ans;
    if (m == 0) {
        if (k == 0) {
            cout << "0 0" << endl;
            return 0;
        }
        goto no_ans;
    }
    if (m == 1) {
        if (k == 0) {
            cout << "0 1 1 0" << endl;
            return 0;
        }
        goto no_ans;
    }
    for (ull i = 0; i < pow2(m); i++) if (i != k) cout << i << " ";
    cout << k << " ";
    for (ull i = pow2(m); i > 0; i--) if (i - 1 != k) cout << i - 1 << " ";
    cout << k << endl;
    return 0;
    no_ans:
    cout << -1 << endl;
}

Measured memory_bytes: 1792
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);
	long long A1,A2,B1,B2;
	scanf("%lld%lld%lld%lld",&A1,&A2,&B1,&B2);
	long long C1=a*A1+b*A2;
	long long C2=a*B1+b*B2;
	if(C1==C2){
		printf("infinity\n");return 0;
	}
	if(C1<C2){
		swap(C1,C2);
		swap(A1,B1);
		swap(A2,B2);
	}
	long long ret=0;
	long long D1=a*(B1-A1);
	long long L=0;
	long long R=0;
	if(D1>0){
		L=D1/(C1-C2);
	}
	R=L;
	ret=L+R+1;
	if(D1<0)ret=0;
	if(D1>0&&D1%(C1-C2)==0)ret--;
	printf("%lld\n",ret);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;double s,t,h,a,gap=1000.000;cin>>n>>t>>a;
  for(int i=0;i<n;i++){
    cin>>h;
    s=t-0.006*h;//各地点における気温
    if(abs(a-s)<gap){
      gap=abs(a-s);
      ans =i+1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
 
const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
 
/////////////////////////////////////////////////////////
class UnionFind {
 public:
  static const int MAX_N_LIB = (int)(2e5 + 100);
 
  int uf_par[MAX_N_LIB];
  int uf_rank[MAX_N_LIB];
  int uf_size[MAX_N_LIB];
 
  UnionFind(int n) { init(n); }
 
  void init(int n) {
    for (int i = 0; i < n; ++i) {
      uf_par[i] = i;
      uf_rank[i] = 0;
      uf_size[i] = 1;
    }
  }
 
  int find(int x) {
    if (uf_par[x] == x)
      return x;
    else {
      return uf_par[x] = find(uf_par[x]);
    }
  }
 
  void unite(int leaf_x, int leaf_y) {
    int x = find(leaf_x);
    int y = find(leaf_y);
 
    if (x == y) return;
 
    if (uf_rank[x] < uf_rank[y]) {
      uf_par[x] = y;
      uf_size[y] += uf_size[x];
    } else if (uf_rank[x] > uf_rank[y]) {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
    } else {
      uf_par[y] = x;
      uf_size[x] += uf_size[y];
      uf_rank[x] += 1;
    }
  }
 
  bool same(int x, int y) { return find(x) == find(y); }
 
  int size(int x) { return uf_size[find(x)]; }
};
/////////////////////////////////////////////////////////
 
const int MAX_N = (int)(1e5 + 5);
 
int n, m;
vector<pair<int, int>> edge;
 
int out[MAX_N];
vector<int> graph[MAX_N];
 
UnionFind uf(MAX_N);
 
vector<pair<int, int>> ans;
 
void routine(int cur, int parent) {
  if (out[cur] % 2 == 1) {
    ans.push_back(make_pair(cur, parent));
    out[cur] += 1;
  } else {
    ans.push_back(make_pair(parent, cur));
    out[parent] += 1;
  }
  return;
}
 
void dfs(int cur, int parent) {
  if (graph[cur].size() > 1) {
    for (auto &e : graph[cur]) {
      if (e == parent) continue;
      dfs(e, cur);
    }
  }
 
  routine(cur, parent);
  return;
}
 
int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);
 
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
 
    edge.push_back(make_pair(a, b));
  }
 
  if (m % 2 == 1) {
    printf("%d\n", -1);
    return 0;
  }
 
  for (int i = 1; i <= n; ++i) {
    out[i] = 0;
  }
 
  for (auto &e : edge) {
    if (uf.same(e.first, e.second)) {
      int inkey = min(e.first, e.second);
      int outkey = max(e.first, e.second);
      ans.push_back(make_pair(outkey, inkey));
      out[outkey] += 1;
    } else {
      graph[e.first].push_back(e.second);
      graph[e.second].push_back(e.first);
      uf.unite(e.first, e.second);
    }
  }
 
  for (auto &e : graph[1]) {
    dfs(e, 1);
  }
 
  for (auto &e : ans) {
    printf("%d %d\n", e.first, e.second);
  }
 
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  for(int i=0; i > -1; i++){
    S.pop_back();
    string x = S.substr(0,S.size()/2);
    string y = S.substr(S.size()/2,S.size()-1);
    if(x == y){
      cout << S.size() << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3624
import sys


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


i = 1
while 1:
    x = I()
    if x == 0:
        break
    print('Case '+str(i)+': '+str(x))
    i += 1



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

int main() {
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if(c - a > b || c - a < 0) {
        cout << "NO" << endl; 
    }
    else {
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    char c = s[0];
    REP(i, s.size()) {
        if (k == 0) break;
        if (s[i] == c) {
            continue;
        }
        else {
            k--;
            while (i < s.size() && s[i] != c) {
                s[i] = c;
                i++;
            }
            i--;
        }
    }
    int ans = 0;
    REP(i, s.size()-1) {
        if (s[i] == s[i + 1]) {
            ans++;
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 512
n = int(input())
x = list(map(int, input().split()))
minx = min(x)
maxx = max(x)
list = []
for i in range(minx,maxx+1):
  klist = []
  for j in x:
    k = (j-i)*(j-i)
    klist.append(k)
  #print(klist)
  list.append(sum(klist))
print(min(list))

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int s = 3*c;
  cout << a << " " << b << " " << s - a - b << endl; 
  cout << 2*s - 2*a - b - 2*c << " " << c << " " << 2*a + b + c - s << endl; 
  cout << a + b + 2*c - s << " " << s - b - c << " " << s - a - c << endl; 
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 100005
#define M 51
#define INF 500
#define MOD 924844033
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

int a[N],b[N];
ll sa[N];
int n,m;
const int cmp(const int x,const int y)
{
    return x>y;
}
int bs(int x)
{
    int l = 0,r = n+1;
    while(l<r-1)
    {
        int mid = (l+r)>>1;
        if(a[mid]>=x)l = mid;
        else r = mid;
    }
    return l;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin>>n>>m)
    {
        sa[0] = 0;
        FOR(i,1,n)cin>>a[i];
        FOR(i,1,m)cin>>b[i];
        sort(a+1,a+n+1,cmp);
        FOR(i,1,n)sa[i] = sa[i-1]+a[i];
        a[0] = INF;
        ll ans = 0;
        FOR(i,1,m)
        {
            int p = bs(b[i]);
            ans+=sa[n]-sa[p]+(ll)(p+1)*(ll)b[i];
            //cout<<i<<" "<<p<<" "<<ans<<endl;
        }
        ans+=sa[n];
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int len = s.length();
    string ts;
    REP(i,len){
        if(s[i] != 'x') {
            ts += s[i];
        }
    }
    string us = ts;
    reverse(us.begin(),us.end());
    if(us != ts){
        cout << -1 << endl;
        return 0;
    }
    VI cnt;
    int suc = 0;
    REP(i,len){
        if(s[i] == 'x'){
            suc++;
        }
        else{
            cnt.eb(suc);
            suc = 0;
        }
    }
    cnt.eb(suc);

    for(auto p : cnt){
        dump(p)
    }
    int csize = SZ(cnt);
    LL ans = 0;
    REP(i,(csize+1)/2){
        ans += abs(cnt[i] - (cnt[(csize-1-i)]));
    }
    cout << ans << endl;

}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
int ans=0;
int n;
vector<int> v(100);
void solve(int idx,int tot){
	if(idx==n+1) {
		ans=max(ans,tot);
		return;
	}
	solve(idx+1,tot+v[idx]);
	solve(idx+1,tot);
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	cin>>n;

	for(int i=1; i<=n; i++) {
		cin>>v[i];
	}
	for(int i=1; i<=n; i++) {
		int a; cin>>a;
		v[i]-=a;
	}
	solve(1,0);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#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;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
void solve(){

}

int main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int n;
    cin>>n;
    n%=10;
    if(n==3) cout<<"bon"<<endl;
    else if(n==0 or n==1 or n==6 or n==8) cout<<"pon"<<endl;
    else cout<<"hon"<<endl;

     return 0;

}
///Alhamdulillah



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

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

  string S;
  cin >> S;

  int cnt_black = 0, cnt_wite = 0, cnt_even = 0, cnt_odd = 0;
  for(int i = 0; i < S.size(); i++) {
    if(i % 2 == 0) {
      cnt_even++;
      if(S[i] == '0') cnt_black++;
    }
    else {
      cnt_odd++;
      if(S[i] == '1') cnt_wite++;
    }
  }

  cout << min((cnt_black + cnt_wite), ((cnt_even - cnt_black) + (cnt_odd - cnt_wite))) << endl;
  return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b))puts("A");
	else puts("B");
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
s = a.inject(:+)
res = Array.new(n, 0)
res[0] = s

(n / 2).times do |i|
  res[0] -= 2 * a[2 * i + 1]
end

(n - 1).times do |i|
  res[i + 1] = 2 * a[i] - res[i]
end
puts res.join(" ")

Measured memory_bytes: 24568
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]


    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))
    U = UnionFind(N)
    for _ in range(M):
        x, y = map(int, input().split())
        U.union(x - 1, y - 1)
    Q = {p: i for i, p in enumerate(P)}
    r = 0
    for i in range(N):
        if U.find(Q[i + 1]) == U.find(i):
            r += 1
    return r

print(main())


Measured memory_bytes: 22624
S=input()
T=input()

LS=len(S)
LT=len(T)

ans=[]
for i in range(LS-LT+1):
    F=True
    for t in range(LT):
        if T[t]==S[i+t] or S[i+t]=="?":continue
        else:
            F=False
            break
    if F:
        temp=""
        for j in range(LS):
            if j<i and S[j]=="?":
                temp+="a"
            elif i<=j<i+LT:
                temp+=T[j-i]
            elif j>=i+LT and S[j]=="?":
                temp+="a"
            else:
                temp+=S[j]
        ans.append(temp)

if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])


Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <iomanip>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll K;
    vector<ll> lengthes = {
        1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
    };
    cin >> K;
    cout << lengthes[K - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

const long long DIV = 1e9+7;
const int NMAX = 1e5;
long long dp[NMAX] = {};

int main(){

    int n, m;
    cin >> n >> m;

    int a[m];
    int c[n] = {};

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


    int i=0;
    for(int j=0; j<n; j++){
        if(j == a[i]){
            c[j] = 1;
            i++;
            if(i == m){
                break;
            }
        }
    }

    dp[0] = 1;
    dp[1] = 1;

    bool isNG = false;
    for(int i=2; i<n+1; i++){

        if(c[i] == 1 && c[i-1] == 1){
            isNG = true;
            break;
        } 

        if(c[i-1] == 1){
            dp[i] = dp[i-2];
            // cout << i << ":(1) " << dp[i] << endl;
        }
        else if(c[i-2] == 1){
            dp[i] = dp[i-1];
            // cout << i << ":(2) " << dp[i] << endl;
        }
        else{
            dp[i] = (dp[i-1] + dp[i-2]) % DIV;
            // cout << i << ":(3) " << dp[i] << endl;
        }
    }

    // cout << endl;
    // for(int i=0; i<n+1; i++){
    //     cout << dp[i] << endl;
    // }
    // cout << endl;
    
    if(isNG){
        cout << 0 << endl;
    }
    else{
        cout << dp[n] << endl;
    }




    return 0;
}

Measured memory_bytes: 1664
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
int n;

bool dfs(queue<int> S,int l,int r){
  if(S.empty())
    return true;
  int x = S.front();
  S.pop();

  if(x < l&& x <r)
    return false;
  else if(x < l)
    return dfs(S,l,x);
  else if(x <r)
    return dfs(S,x,r);
  else 
    return dfs(S,x,r)||dfs(S,l,x);
}

int main()
{
  cin>>n;
  for(int i = 0;i < n;i++){
    queue<int> S1;
    for(int j = 0;j < 10;j++){
      int ball;
      cin >>ball;
      S1.push(ball);
    }
    if(dfs(S1,0,0)){
      cout <<"YES"<<endl;
      }else
      cout <<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
def gcd(x,y):
    while(y): 
        x, y = y, x % y 
    return x
    
MOD = 10 ** 9 + 7

out = 0
N, K = map(int, input().split())

val = [i for i in range(K+1)]
for i in range(2,K+1):
    if val[i] == i:
        for j in range(i, K + 1, i):
            val[j] //= i
            val[j] *= (i - 1)

for i in range(1, K + 1):
    count = K//i
    out += val[i] * pow(count, N, MOD)
    out %= MOD
print(out)


Measured memory_bytes: 73448
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll H, W, A, B;
combination comb( 1000010 );
mint ans = 0;

int main()
{
  std::cin >> H >> W >> A >> B;

  rep( h, H-A )
    ans += comb( B-1+h, h )*comb( W-B-1+H-h-1, W-B-1 );
  
  std::cout << ans.x << std::endl;

  return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,kaisu=0;
    cin>>N;
    vector<ll> A(N),B(N);
    rep(i,N) cin>>A.at(i);
    rep(i,N) cin>>B.at(i);
    rep(i,N) kaisu+=B.at(i)-A.at(i);
        
    ll needa=0,needb=0;
    rep(i,N){
        if(A.at(i)>B.at(i)) needb+=A.at(i)-B.at(i);
        else if(A.at(i)<B.at(i)) needa+=(B.at(i)-A.at(i)+1)/2;
    }
    if(needa<=kaisu && needb<=kaisu) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<bitset>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<sstream>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int q,n,s,d;
    cin>>q>>n>>s>>d;
    q*=2;
    n=min(n,q);
    n*=2;
    s=min(s,n);
    cin>>n;
    long long ans=0;
    if (n%2==1) ans+=s;
    s*=2;
    d=min(d,s);
    ans+=(n/2)*(long long)d;
    cout<<ans<<endl;
    return 0;
} 


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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;
    int xi = x2;
    int yi = y2;
    rep(i, 2){
        int _dx = -dy;
        int _dy = dx;
        dx = _dx;
        dy = _dy;
        xi = xi + dx;
        yi = yi + dy;
        cout << xi << " " << yi;
        if (i == 0) cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;
constexpr ll MOD = 1000000007;

ll fact[1000001];
ll factinv[1000001];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll comb(ll n,ll k) {
  ll tmp = fact[n] * factinv[k] % MOD;
  return tmp * factinv[n-k] % MOD;
}

int main()
{
  fact[0] = factinv[0] = 1;
  for (int i:irange(0,1000000)) {
    fact[i+1] = fact[i] * (i+1);
    fact[i+1] %= MOD;
    factinv[i+1] = inv(fact[i+1], MOD);
  }
  ll x,y;
  cin>>x>>y;
  ll p3 = 2*y-x;
  ll q3 = 2*x-y;
  if ((p3%3) != 0 || p3 < 0 || (q3%3) != 0 || q3 < 0) {
    cout<<0<<endl;
    return 0;
  }
  ll p=p3/3;
  ll q=q3/3;
  ll n=p+q;
  cout<<comb(n,p)<<endl;
  return 0;
}


Measured memory_bytes: 15872
<?php
fscanf(STDIN,'%d',$N);
$A=[];
$judge=0;
for ($i=0; $i <$N ; $i++) { 
    # code...
    fscanf(STDIN,'%s',$K);
    if(in_array($K,$A)){
        $judge=1;
        break;
    }
    $A[]=$K;
    if($i>=1){
      if($A[$i-1][strlen($A[$i-1])-1]!=$A[$i][0]){
          $judge=1;
          break;
      }
     
    }
}
if($judge==1){
    echo "No\n";
}else{
    echo "Yes\n";
}




?>

Measured memory_bytes: 3576
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define SORT(v) sort(v.begin(),v.end(),greater<lli>())

/*0～numまでのbit番目がONになっている数を数え上げる*/
lli bitNum(lli num,lli bit){
	lli targetNum = (1LL<<bit+1);
	lli rtn = 0;
	/*割った余り*/
	rtn += max(0LL, num%targetNum - (targetNum/2 -1 ));

	/*割って以上であれば全部足す*/
	rtn += num/targetNum * (targetNum/2);

	return rtn;
}

signed main(){

	lli a,b;
	cin>>a>>b;
	if(a==0)a=1;

	lli ans=0;
	for(lli i=0;i<55;i++){
		lli bitA = bitNum(a-1,i);
		lli bitB = bitNum(b,i);
		lli bit = bitB-bitA;
		if(bit%2)ans |= (1LL<<i);
	}
	cout<<ans<<endl;
}

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

using namespace std;

int N;
int k;
int ssum[2002][2002];
int mmap[2001][2001];

inline int co(int x1, int y1, int x2, int y2) {
	return ssum[x2+1][y2+1] - ssum[x1][y2+1] - ssum[x2+1][y1] + ssum[x1][y1];
}

int main()
{
	cin >> N >> k;
	for (int i = 0; i < N; i++) {
		int a, b;
		char c;
		cin >> a >> b >> c;
		if (c == 'W') {
			a += k;
		}
		a = a % (2 * k);
		b = b % (2 * k);
		mmap[a][b]++;
	}
	for (int i = 1; i < 2 * k + 2; i++) {
		for (int j = 1; j < 2 * k + 2; j++) {
			ssum[i][j] = mmap[i-1][j-1] + ssum[i-1][j] + ssum[i][j-1] - ssum[i-1][j-1];
		}
	}
	int ma = 0;
	int mi = N;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			int t = 0;
			int x1 = i;
			int y1 = j;
			int x2 = min((i + k - 1), 2 * k);
			int y2 = min((j + k - 1), 2 * k);
			t += co(x1, y1, x2, y2);
			if (i - 1 >= 0 && j - 1 >= 0) {
				x1 = max(0, i - k);
				y1 = max(0, j - k);
				x2 = i - 1;
				y2 = j - 1;
				t += co(x1, y1, x2, y2);
			}
			if (i - 1 >= 0) {
				x1 = max(0, i - k);
				y1 = min(2 * k, j + k);
				x2 = i - 1;
				y2 = min(2 * k, j + 2 * k - 1);
				t += co(x1, y1, x2, y2);
			}
			if (j - 1 >= 0) {
				x1 = min(2 * k, i + k);
				y1 = max(0, j - k);
				x2 = min(2 * k, i + 2 * k - 1);
				y2 = j - 1;
				t += co(x1, y1, x2, y2);
			}
			x1 = min(2 * k, i + k);
			y1 = min(2 * k, j + k);
			x2 = min(2 * k, i + 2 * k - 1);
			y2 = min(2 * k, j + 2 * k - 1);
			t += co(x1, y1, x2, y2);
			ma = max(ma, t);
			mi = min(mi, t);
		}
	}
	ma = max(ma, N-mi);
	cout << ma << endl;
}


Measured memory_bytes: 31488
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
#include <bits/stdc++.h>
#define maxn 400010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int c[maxn], pre[maxn], pos[maxn], n;
ll f[maxn];
const ll p = 1e9 + 7;
template <class T> void read (T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(c[i]);
  }
  for (int i = 1; i <= n; i++) {
    pre[i] = pos[c[i]], pos[c[i]] = i;
  }
  f[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (pre[i] == i - 1)
      f[i] = f[i - 1];
    else
      f[i] = (f[i - 1] + f[pre[i]]) % p;
  }
  printf("%lld\n", f[n]);
  return 0;
}

Measured memory_bytes: 6656
#include <cstdio>
#include <string>

using namespace std;

int main() {
    string X[3];
    for (int i=0; i<3; ++i) {
        char buf[128];
        scanf("%s", buf);
        X[i] = buf;
    }

    size_t x[3]={};
    int next=0;
    while (true) {
        if (X[next].length() == x[next])
            return !printf("%c\n", next+'A');

        ++x[next];
        next = X[next][x[next]-1]-'a';
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int quick(int a[],int left,int right);
int swap(int* ,int* );

int main(void){
	int N,i,tmp,sum;
	scanf("%d",&N);
	
	int p[N];
	for(i=0;i<N;++i){
	scanf("%d",&p[i]);
	}		
	
	quick(p,0,N);
	
	p[0]=p[0]/2;
	sum=0;
	for(i=0;i<N;i++){
		sum+=p[i];
	}
	printf("%d\n",sum);
	return 0;
}
	
int quick(int a[],int left, int right){	//クイックソート関数
	if(right-left<=1) return 0;
	
	int j,pivot,pivot_index;
	
	pivot_index=(left+right)/2;
	pivot=a[pivot_index];
	swap(&a[pivot_index],&a[right-1]);		
	
	
	int i=left; 
	for(j=left;j<right-1;++j){
		if (a[j]>pivot){
			swap(&a[j],&a[i++]);
				
		}
	}
			swap(&a[i],&a[right-1]);
	
	    quick(a,left,i);
		quick(a,i+1,right);
		
	return 0;
	
}

int swap(int *a,int *b){
	int tmp;
	tmp=*a;
	*a=*b;
	*b=tmp;
	return 0;
}
	
	
	
	

	

Measured memory_bytes: 128