akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];

	int hi = arr[N-1] + 1;
	R0F(i, N) {
		--hi;
		if (arr[i] < hi || arr[0] != 0) {
			print(-1); return 0;
		}
		hi = max(hi, arr[i]);
	}

	ll ans = 0;
	ROF(i, 1, N) {
		if ((arr[i] == N-1) || (arr[i] + 1 != arr[i+1]))
			ans += arr[i];
	}
	print(ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,x;
	int ans=0;
	cin >>n>>x;
	vector<int>l(n);
	rep(i,n){
		cin>>l[i];
	}
	int at=0;
	rep(i,n){
		at+=l[i];
		if(at <=x){
			ans++;
		}
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 256
s=input()
n=int(input())
if len(s)==1:print(n//2);exit()
if len(set(s))==1:print(len(s)*n//2);exit()
c=1
l=[]
for x in range(1,len(s)):
    if s[x-1]==s[x]:
        c+=1
        if x==len(s)-1:l.append(c)
    else:l.append(c);c=1

t=0
if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1
print(sum([i//2 for i in l])*n+t)

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

const int base = 1000000007;

int inv(long long p)
{
  int q = base - 2, r = 1;
  while (q)
  {
    if (q & 1) r = r * p % base;
    p = p * p % base;
    q /= 2;
  }
  
  return r;
}

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  
  vector<int> dim(1000001, 0);
  for (int i = 0; i < n; ++i)
  {
    int m = a[i];
    for (int j = 2; j*j <= m; ++j)
    {
      int count = 0;
      while (m % j == 0)
      {
        ++count;
        m /= j;
      }
      
      dim[j] = max(count, dim[j]);
    }
    
    if (m > 1) dim[m] = max(1, dim[m]);
  }
  
  long long lcm = 1;
  for (int i = 2; i < 1000001; ++i)
    if (dim[i])
    {
      int p = i, r = 1;
      while (dim[i])
      {
        if (dim[i] & 1) r *= p;
        p *= p;
        dim[i] /= 2;
      }
      
      lcm = lcm * r % base;
    }
  
  int total = 0;
  for (int i = 0; i < n; ++i)
    total = (total + lcm * inv(a[i])) % base;
  
  cout << total << endl;
}

Measured memory_bytes: 4224
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	A, B, X = map(int, input().split(" "))
	
	if A+B >= X:
		if A <= X:
			print("YES")
		else:
			print("NO")
	else:
		print("NO")
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 22628
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
int main(){
    long long d, g;
    cin >> d >> g;
    vector<long long> p(d), c(d), score(d);
    for(int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
        score[i] = (i + 1) * 100;
    }
    long long ans = INF;
    for(int bit = 0; bit < (1 << d); bit++){
        long long G = g;
        long long res = 0;
        vector<int> flag(d, 1);
        for(int i = 0; i < d; i++){
            if(bit & (1 << i)) {
                G -= p[i]*score[i] + c[i];
                flag[i] = 0;
                res += p[i];
            }
        }
        int t = -1;
        for(int j = 0; j < d; j++){
            if(flag[j] == 1) t = j;
        }
        if(G > 0 && G <= p[t] * score[t] + c[t]){
            res += min(p[t], (G + score[t] - 1) / score[t]);
            ans = min(res, ans);
        }
        else if(G <= 0) ans = min(res, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys

line = sys.stdin.readline()
N = int(line.strip())

F = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(10):
        F[i, j] = xs[j]

f = [sum((1 << j) for j in range(10) if F[i,j]) for i in range(N)]

pt = [sum(((i >> j) & 1) for j in range(10)) for i in range(2**10)]

P = {}
for i in range(N):
    line = sys.stdin.readline().strip()
    xs = [int(x) for x in line.split()]
    for j in range(11):
        P[i, j] = xs[j]


rr = -100000000000000000000

for i in range(1, 2**10):
    r = sum([P[j, pt[f[j] & i]] for j in range(N)])
    if rr < r:
        rr = r

print(rr)


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n,ud=0,cur,prv,ans=0;
	cin>>n;
	cin>>prv;
	for(int i=0;i<n-1;i++){
		cin>>cur;
		if(ud==1){
			if(cur<prv){ans++;ud=0;}
		}
		else if(ud==-1){
			if(cur>prv){ans++;ud=0;}
		}
		else{
			if(cur>prv)ud=1;
			if(cur<prv)ud=-1;
		}
		prv=cur;
	}
	cout<<ans+1<<endl;
	return 0;
}

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

public class Main {
    static final long MOD = 1000000007L;

    Main(){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        init(N);

        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = Long.parseLong(scanner.next());
        }

        Arrays.sort(A);

        long totalMax = 0L, totalMin = 0L;

        for (int i = N-1; i >= K-1; i--) {
            totalMax = ( totalMax + ( A[i] * combination(i, K-1) ) % MOD ) % MOD;
        }

        for (int i = 0; i <= N-K; i++) {
            totalMin = ( totalMin + ( A[i] * combination(N-i-1, K-1) % MOD)) % MOD;
        }

        long R = ( totalMax - totalMin ) % MOD;
        if (R < 0) R += MOD;
        System.out.println(R);
    }

    public static void main(String[] args){
        new Main();
    }

    long[] fac, finv, inv;

    void init(int max){
        max += 1;
        fac  = new long[max];
        finv = new long[max];
        inv  = new long[max];

        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[(int)(MOD%i)] * (MOD/i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }

    long combination(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;
    }

    long modInv(long a){
        return modPow(a, MOD-2);
    }

    long modPow(long a, long b){
        long R = 1L;
        a %= MOD;
        while (b > 0){
            if ( (b&1) == 1){
                R = R * a % MOD;
            }
            a = a * a % MOD;
            b = b >> 1;
        }

        return R;
    }
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        int tmp; cin >> tmp;
        while(!(tmp % 2)) tmp /= 2, cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e17;
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int tab[3][n];
    int maxi[3][n];
    for(int  i =0 ;i < n;i++){
        cin >> tab[0][i] >> tab[1][i] >> tab[2][i];
    }
    maxi[0][0] = tab[0][0];
    maxi[1][0] = tab[1][0];
    maxi[2][0] = tab[2][0];
    for(int i = 1; i < n; i++){
        maxi[0][i] = tab[0][i] +max(maxi[1][i-1], maxi[2][i-1]);
        maxi[1][i] = tab[1][i] +max(maxi[0][i-1], maxi[2][i-1]);
        maxi[2][i] = tab[2][i] +max(maxi[0][i-1], maxi[1][i-1]);
    }
    cout << max(maxi[0][n-1], max(maxi[1][n-1],maxi[2][n-1]));
    return 0;
}



Measured memory_bytes: 2560
#include <vector>
#include <iostream>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int cnt = 0;
    int i = 0;
    while(true) 
    {
        // cout << "i: " << i << endl;
        // cout << "cnt: " << cnt << endl;
        // for (auto c : a) {
        //     cout << c << " ";
        // }
        // cout << endl;
        if (i == 1) {
            break;
        } else if (a[i] != -1) {
            int temp;
            cnt++;
            temp = a[i] - 1;
            a[i] = -1;
            i = temp;
        } else {
            cnt = -1;
            break;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >>n;

    bool can_enter(true);
    rep(i,0,n)
    {
        ll a;
        cin >> a;
        if (a%2==0)
        {
            if ((a%3==0) || (a%5==0)) can_enter=true;
            else can_enter = false;
        }
        if (!can_enter) break;
    }

    if (!can_enter)
        cout << "DENIED" << endl;
    else
        cout << "APPROVED" << endl;
    return 0;
}


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

#define int long long
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
ll ltmp;
int f(string s,int a){
  if(a==0)return -1;
  int res=0,t=1;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    (res+=t*(s[i]=='1'))%=a;
    (t*=2)%=a;
  }
  return res;
}
int p(int a){
  int res=0;
  while(a){
    if(a&1)res++;
    a>>=1;
  }
  return res;
}
int F(int a){
  int res=0;
  while(a){
    res++;
    a%=p(a);
  }
  return res;
}

ll getMod(ll value,ll mod){
    if(value == 0) return 0;
    return (value + mod) % mod;
}

#define base10_6 1000000    //1e6
ll getPower(ll value,ll shisu,ll mod){
    ll ans = 1;
    ll cnt = shisu;
    while(cnt>0){
        if(cnt%2==1){
            ans = ans * value % mod;
        }
        value = value * value % mod;
        cnt = cnt/2;
    }
    return ans;
}
ll bit2[1000010]={};

ll mod_p[base10_6+10]={};
ll mod_m[base10_6+10]={};
ll getIntSubstr(string s,ll start_index,ll length){
    return atoi(s.substr(start_index,length).c_str());
}

signed main(){
    int n;cin>>n;
    string s;cin>>s;
    int sum=0;
    for(char p:s)sum+=p=='1';
  
    ll base_pop = 0;
    string S = s;
    ll N = n;
    rep(ni,N){
        bit2[ni] = getIntSubstr(S,ni,1);
        //bit2[ni] = 1;
        base_pop+=bit2[ni];
    }
    sum = base_pop;

    ll basev= 1;

    basev=1;



    ll base_pop_p;
    ll base_pop_m;
    base_pop_p = base_pop+1;
    base_pop_m = base_pop-1;
    if(base_pop_m==0) base_pop_m=1;

    basev = 1;
    ltmp = 1;
    for( ll keta = 1 ; keta <=base10_6 ; keta++ ){
        mod_p[keta] = basev;
        basev = basev * 2;
        basev = getMod(basev,base_pop_p); 
    }
    basev = 1;
    for( ll keta = 1 ; keta <= base10_6 ; keta++ ){
        mod_m[keta] = basev;
        basev = basev * 2;
        basev = getMod(basev,base_pop_m); 
    }

    ll base_f1_p = 0;
    ll base_f1_m = 0;
    for( ll keta = 1 ; keta <=N ; keta++ ){
        ll ind = N -keta;
        base_f1_p += mod_p[keta] * bit2[ind];
        base_f1_m += mod_m[keta] * bit2[ind];
        base_f1_p = getMod(base_f1_p,base_pop_p );
        base_f1_m = getMod(base_f1_m,base_pop_m );
    }

    int A=base_f1_p;//f(s,sum+1);
    int B=base_f1_m;//f(s,sum-1);


  for(int i=0;i<n;i++){
    if(sum==1&&s[i]=='1'){
      cout<<0<<endl;
      continue;
    }
    if(s[i]=='0'){
      int res=A;
      ll keta = N - i;
      ll value = base_f1_p + mod_p[keta];
      value = getMod(value,base_pop_p);

      //res+=getPower(2,n-i-1,sum+1);res%=sum+1;
      
      res = value;
      cout<<F(res)+1<<endl;
    }
    else{
      int res=B;
      res-=getPower(2,n-i-1,sum-1);
      res+=sum-1;res%=sum-1;
      cout<<F(res)+1<<endl;
    }
  }
}


Measured memory_bytes: 21028
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;

bool check(string s1,string s2,int num){
	for(int i=0;i<num;++i){
		cout<<s1;
	}
	cout<<"\n";
	for(int i=0;i<num;++i){
		cout<<s2;
	}
	cout<<endl;
	fflush(stdout);
	string str;
	cin>>str;
	if(str=="F")return false;
	else return true;
}

int getMaxLength(int N,string s1,string s2){
	int Min=1,Max=N+1,Mid=0;
	while(1){
		Mid=(Max-Min)/2+Min;
		bool ans=check(s1,s2,Mid);
		if(ans){
			if(Min==Mid){
				return Mid;
			}
			Min=Mid;
		}
		else{
			if(Min==Mid){
				if(Min==1)return 0;
				else{
					return Max;
				}
			}
			Max=Mid;
		}
	}
}

bool check1(const deque<pair<char,char>>& deq,string s1,string s2){
	for(const auto& val:deq)
		cout<<val.first;
	cout<<s1;
	cout<<"\n";
	for(const auto& val:deq)
		cout<<val.second;
	cout<<s2;
	cout<<endl;
	fflush(stdout);
	string str;
	cin>>str;
	if(str=="F")return false;
	else return true;
}

bool check2(const deque<pair<char,char>>& deq,string s1,string s2){
	cout<<s1;
	for(const auto& val:deq)
		cout<<val.first;
	cout<<"\n";
	cout<<s2;
	for(const auto& val:deq)
		cout<<val.second;
	cout<<endl;
	fflush(stdout);
	string str;
	cin>>str;
	if(str=="F")return false;
	else return true;
}

int main(){
	int N;
	cin>>N;
	int BB=0,WW=0,WB=0,BW=0;
	BB=getMaxLength(N,"#","#");
	if(BB==N)return 0;
	WW=getMaxLength(N,".",".");
	if(WW==N)return 0;
	WB=getMaxLength(N,".","#");
	if(WB==N)return 0;
	BW=getMaxLength(N,"#",".");
	if(BW==N)return 0;

	array<pair<int,string>,4> a;
	a[0]=make_pair(BB,"##");
	a[1]=make_pair(WW,"..");
	a[2]=make_pair(WB,".#");
	a[3]=make_pair(BW,"#.");
	sort(begin(a),end(a),[](auto x,auto y)->bool{return x.first>y.first;});
	int length=a.front().first;
	deque<pair<char,char>> deq(length,make_pair(a.front().second[0],a.front().second[1]));

	while(length<N){
		if(check1(deq,".",".")){
			++length;
			deq.push_back(make_pair('.','.'));
		}
		else{
			if(check1(deq,"#","#")){
				++length;
				deq.push_back(make_pair('#','#'));
			}
			else{
				if(check1(deq,".","#")){
					++length;
					deq.push_back(make_pair('.','#'));
				}
				else{
					if(check1(deq,"#",".")){
						++length;
						deq.push_back(make_pair('#','.'));
					}
					else{
						break;
					}
				}
			}
		}
	}

	while(length<N){
		if(check2(deq,".",".")){
			++length;
			deq.push_front(make_pair('.','.'));
		}
		else{
			if(check2(deq,"#","#")){
				++length;
				deq.push_front(make_pair('#','#'));
			}
			else{
				if(check2(deq,".","#")){
					++length;
					deq.push_front(make_pair('.','#'));
				}
				else{
					if(check2(deq,"#",".")){
						++length;
						deq.push_front(make_pair('#','.'));
					}
					else{
						break;
					}
				}
			}
		}
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int q1;
	while(~scanf("%d",&q1)){
		if(q1==0) break;
		int b,c1,c2,q2;
		//1:aize chiken 2:normal chiken
		scanf("%d %d %d %d",&b,&c1,&c2,&q2);
		for(int i=q2;i>=1;i--){
			int cost = i*c1;
			if(cost > b) continue;
			int ub = 1000000;
			int lb = 0;

			for(int j=0;j<20;j++){
				int md = (ub+lb)/2;
				if(cost + md*c2 <=b) lb = md;
				else ub = md;
			}

			if(lb+i >= q1 && cost + lb*c2 <=b){
				printf("%d %d\n",i,lb);
				goto next;
			}
		}
		printf("NA\n");
next:;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int getPar(int i) {
  return (i+1)/2-1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> V(N), W(N);
  rep(i, N) cin >> V[i] >> W[i];
  ll Q;
  cin >> Q;
  vector<int> qv(Q);
  vector<ll> qL(Q);
  rep(i, Q) {
    cin >> qv[i] >> qL[i];
    qv[i]--;
  }

  ll MAX = *max_element(all(qL))+1;
  int K = ceil(log2(N))/2;
  vector<vector<ll>> dp(1<<K, vector<ll>(MAX));
  rep(i, 1<<K) {
    if(i >= N) continue;
    int par = getPar(i);
    if(par == -1) {
      dp[i][W[i]] = V[i];
      continue;
    }
    rep(j, MAX) {
      dp[i][j] = max(dp[par][j], dp[i][j]);
      if(j+W[i] < MAX) {
        dp[i][j+W[i]] = max(dp[par][j]+V[i], dp[i][j+W[i]]);
      }
    }
  }
  rep(i, 1<<K) {
    if(i >= N) continue;
    rep(j, MAX) {
      if(j) dp[i][j] = max(dp[i][j-1], dp[i][j]);
    }
  }
  rep(i, Q) {
    int v = qv[i]; ll L = qL[i];
    int tmp = v;
    vector<vector<pair<ll, ll>>> vv(2);
    vv[0].emplace_back(0, 0);
    int flag = 1;
    while(tmp >= 1<<K) {
      vv[flag].clear();
      for(auto& ele: vv[1-flag]) {
        ll w = ele.first;
        ll v = ele.second;
        vv[flag].emplace_back(ele);
        vv[flag].emplace_back(w+W[tmp], v+V[tmp]);
      }
      flag = 1-flag;
      tmp = getPar(tmp);
    }
    ll mx = 0;
    for(auto& ele: vv[1-flag]) {
      ll w = ele.first;
      ll v = ele.second;
      if(L-w < MAX && L-w >= 0) {
        mx = max(v+dp[tmp][L-w], mx);
      }
    }
    cout << mx << endl;
  }
  return 0;
}


Measured memory_bytes: 410924
#include<bits/stdc++.h>
using namespace std;
int n[1000000];
int main(void){
    int a;
    cin >> a;
    long long sum = 0;
     
    for (int i = 0; i < a; i++){
        cin >> n[i];  
         sum += n[i];
    }
     
    int min = n[0];
    int max = n[0];
    
    for (int i = 0; i < a; i++){
        if(max < n[i]){
        max = n[i];
        }
        if(min > n[i]){
        min = n[i];
        }
     }
    
     cout << min << " " << max << " " << sum << endl;    

}


Measured memory_bytes: 3132
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#define RG register
using namespace std;
const int N=1e5+10, M=2e5+10;
const long long mod=15131;
struct dabt{
	int next,to,dis;
}e[M*6],hsh[N*2];
struct node{
	int u,dis;
	bool operator < (const node&x)const{return x.dis<dis;}
};
int n,m,head[N+2*M],k,dist[N+2*M],st[2*M],ed[2*M],cnt,kk;
int kh,h[mod+1];
bool vis[N+2*M];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
inline void add(int from,int to,int d){
	e[++k]=(dabt){head[from],to,d}; head[from]=k;
	e[++k]=(dabt){head[to],from,d}; head[to]=k;
}
inline void adde(int from,int to,int d){hsh[++kh]=(dabt){h[from],to,d}; h[from]=kh;}
/*inline int id(int a,int b){
	int ss=((long long)a*n%mod+b)%mod;
	for(int i=h[ss];i;i=hsh[i].next)
	{
		int v=hsh[i].to;
		if(st[v]==a && ed[v]==b) return hsh[i].dis;
	}
	st[++kk]=a; ed[kk]=b;
	adde(ss,kk,++cnt);
	return cnt;
}*/
map<pair<int,int>,int> P;
int id(int u,int c) {
    if(P.find(make_pair(u,c))!=P.end())
        return P[make_pair(u,c)];
    return P[make_pair(u,c)]=++cnt;
}
inline void dij()
{
	priority_queue<node> pn;
	while(!pn.empty()) pn.pop();
	for(int i=1;i<=n+m*2;i++) dist[i]=2e9;
	pn.push((node){1,0}); dist[1]=0;
	while(!pn.empty())
	{
		node u=pn.top(); pn.pop();
		int x=u.u; vis[x]=1;
		for(int i=head[x];i;i=e[i].next)
		{
			int v=e[i].to;
			if(dist[v]>dist[x]+e[i].dis)
			{
				dist[v]=dist[x]+e[i].dis;
				if(!vis[v]) pn.push((node){v,dist[v]});
			}
		}
	}
}
int main()
{
//	freopen("Snuke's Subway Trip.in","r",stdin);
//	freopen(". out","w",stdout);
	read(n,m); cnt=n;
	for(int i=1,a,b,c;i<=m;i++)
	{
		read(a,b,c);
		int id1=id(a,c), id2=id(b,c);
		add(a,id1,1); add(id1,id2,0); add(id2,b,1);
	}
	dij();
	printf("%d\n",dist[n]==2e9 ? -1 : dist[n]/2);
//	for(int i=1;i<=9;i++) printf("%d\n",dist[i]);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 48892
#include<stdio.h>

int main(void){
	int H,W,a[100000],b,c=0,d=0,e=0;
	for(b=0;;b++){
		scanf("%d %d",&H,&W);
		a[b]=H;
		a[b+1]=W;
		if(a[b]+a[b+1]==0){
			break;
		}
		b++;
	}
	for(b=0;a[b]+a[b+1]!=0;b++){
		for(c=0;c<a[b];c++){
			if(c%2==0){
				for(e=0;e<a[b+1];e++){
					if(e%2==0){
						printf("#");
						if(c>=a[b]){
							printf("\n");
						}
					}else{
						printf(".");
						if(c>=a[b]){
							printf("\n");
						}
					}
				}
			}else{
				for(e=0;e<a[b+1];e++){
					if(e%2==0){
						printf(".");
						if(c>=a[b]){
							printf("\n");
						}
					}else{
						printf("#");
						if(c>=a[b]){
							printf("\n");
						}
					}
				}
			}
			printf("\n");
		}
		printf("\n");
		b++;
	}
		return 0;
}

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

void solve()
{
    int a;
    cin >> a;
    cout << a + pow(a,2) + pow(a,3) << endl;
}

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

Measured memory_bytes: 4148
#include <iostream>

using namespace std;

typedef long long ll;

int n;
int ga, sa, ba;
int gb, sb, bb;

ll da[25252525];
ll db[25252525];

ll uu;

int main() {
    cin >> n;
    cin >> ga >> sa >> ba;
    cin >> gb >> sb >> bb;
    for (int i = 1; i <= n*5000; i++) {
        da[i] = da[i-1]+1;
        db[i] = db[i-1]+1;
        if (i-ga >= 0) da[i] = max(da[i],da[i-ga]+gb);
        if (i-sa >= 0) da[i] = max(da[i],da[i-sa]+sb);
        if (i-ba >= 0) da[i] = max(da[i],da[i-ba]+bb);
        if (i-gb >= 0) db[i] = max(db[i],db[i-gb]+ga);
        if (i-sb >= 0) db[i] = max(db[i],db[i-sb]+sa);
        if (i-bb >= 0) db[i] = max(db[i],db[i-bb]+ba);
    }
    for (int i = 0; i <= n; i++) {
        ll x = da[i]+n-i;
        x = db[x];
        uu = max(uu,x);
    }
    cout << uu << "\n";
}

Measured memory_bytes: 393472
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).OrderBy(x=>x).ToArray();
        var max = 0L;
        var max2 = 0L;
        var currentNum = A[0];
        var currentNumCount = 1;
        for (int i=0;i<N;++i)
        {
            if (A[i] == currentNum)
            {
                currentNumCount++;
                if (2 == currentNumCount)
                {
                    if (max < currentNum)
                    {
                        max2 = max;
                        max = currentNum;
                    }else if (max2<currentNum)
                    {
                        max2 = currentNum;
                    }
                }else if(4 == currentNumCount)
                {
                    if (max < currentNum)
                    {
                        max2 = max;
                        max = currentNum;
                    }
                    if (max2 < currentNum)
                    {
                        max2 = currentNum;
                    }
                }
            }
            else
            {
                currentNum = A[i];
                currentNumCount = 1;
            }
        }
        var ans = max * max2;
        Console.WriteLine(ans);
    }
}

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


int main()
{
    string s;
    cin >> s;
    deque<char> q;
    for (char c : s) q.push_back(c);
    bool flip = false;
    int Q;
    cin >> Q;
    string t;
    rep(qi, Q) {
        int ty;
        cin >> ty;
        if (ty == 1) {
            flip = !flip;
        } else {
            int f; char c;
            cin >> f >> c;
            if (flip) f = 3 - f;
            if (f == 1) {
                q.push_front(c);
            } else {
                q.push_back(c);
            }
        }
    }

    if (flip) reverse(q.begin(), q.end());
    string ans;
    for (char c : q) ans += c;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s, t;
ll dp[3005][3005], bt[3005][3005];
void solve(int i, int j) {
  if (i == 0 || j == 0)
    return;
  if (bt[i][j] == 0) {
    solve(i - 1, j - 1);
    cout << s[i - 1];
  } else if (bt[i][j] == 1)
    solve(i - 1, j);
  else
    solve(i, j - 1);
}
int main() {
  cin >> s >> t;
  for (int i = 1; i <= s.length(); i++) {
    for (int j = 1; j <= t.length(); j++) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 1, bt[i][j] = 0;
      else if (dp[i - 1][j] >= dp[i][j - 1])
        dp[i][j] = dp[i - 1][j], bt[i][j] = 1;
      else
        dp[i][j] = dp[i][j - 1], bt[i][j] = -1;
    }
  }
  solve(s.length(), t.length());
}


Measured memory_bytes: 141312
import math

n=int(input())
xylist=[]
for i in range(n):
    x, y=map(int, input().split())
    xylist.append([x, y])

kyori=0
for i in range(n):
    for j in range(n):
        kyori+=math.sqrt((xylist[i][0]-xylist[j][0])**2+(xylist[i][1]-xylist[j][1])**2)

print(kyori/n)

Measured memory_bytes: 38384
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;

#define f first
#define s second 
#define F0R(i, a) for (int i = 0;i < (a);++i)
#define FOR(i, a, b) for (int i = a; i < (b);++i)
#define FORd(i, a) for (int i = (a)- 1;i >= 0;--i)
#define F0Rd(i, a, b) for (int i = (a)- 1;i >= (a);--i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int N, M;	
	cin>>N>>M;
	map<int, vector<int>> g;
	for (int i = 0;i < M;++i) {
		int x, y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}

	vector<int> d(N+1, MAX);

	auto bfs = [&] (int r) {
		queue<int> q;
		q.push(r);
		vb v(N);
		v[r] = true;
		d[r] = 0;
		while (!q.empty()) {
			int next = q.front();
			q.pop();
			for (auto const& neigh : g[next]) {
				if (!v[neigh]) {
					if (d[neigh] > d[next] + 1) {
						d[neigh] = d[next] + 1;
					}

					q.push(neigh);
				}

				v[neigh] = true;
			}
		}
	};

	bfs(1);
	vi ans;
	for (int i = 2;i <= N;++i) {
		int min_d = MAX;
		int post = -1;
	 	for (auto const& neigh : g[i]) {
			if (d[neigh] < min_d) {
				post = neigh;
				min_d = d[neigh];
			}
		}

		if (min_d == MAX) {
			cout<<"No"<<endl;
			return 0;
		}
		else {
			ans.pb(post);
		}
	}

	cout<<"Yes"<<endl;
	for (auto const& x : ans) {
		cout<<x<<endl;
	}

	return 0;
}


Measured memory_bytes: 16096
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n,m,x[100000],y[100000];
    long long z=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        y[i]=x[i+1]-x[i];
    }
    sort(y,y+m-1);
    for(int i=0;i<m-n;i++){
        z+=y[i];
    }
    cout<<z<<endl;
}


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

using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int INF=1e9+5;
set<int> se;
multiset<int> mse;
int dis[maxn]={0};///到第i位置的最小值
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int h,w;
    cin>>h>>w;
    for(int i=0;i<w;i++)
    {
        se.insert(i);///存目前可以到达的点 （0-w-1）
        mse.insert(0);///存到到达点的距离
    }
    for(int i=0;i<h;i++)
    {
        int l,r;
        cin>>l>>r;
        l--;
        int Min=INF;
        set<int>::iterator it=se.lower_bound(l);
        while(it!=se.end()&&*it<=r)
        {
            int x=*it;
            //cout<<x<<endl;
            Min=min(Min,dis[x]+r-x);
            it=se.erase(it);
            mse.erase(mse.find(dis[x]));
            dis[x]=INF;
        }
        if(r!=w&&Min!=INF)
        {
            dis[r]=Min;
            se.insert(r);
            mse.insert(dis[r]);
        }
        if(!mse.empty())
        {
            cout<<*mse.begin()+i+1<<"\n";
        }
        else
        {
            cout<<"-1"<<"\n";
        }

    }
    return 0;
}


Measured memory_bytes: 23188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

double A, B, C, D, E, F;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    cin >> A >> B >> C >> D >> E >> F;

    double water_total = 0;  
    double sugar_total = 0;  
    double percent = 0;
    int max_v = F;

    for (int a = 0; a <= max_v; a += A * 100) {
        for (int b = 0; b <= max_v; b += B * 100) {
            for (int c = 0; c <= max_v; c += C) {
                for (int d = 0; d <= max_v; d += D) {
                    ll water = a + b;
                    ll sugar = c + d;
                    if (water + sugar > F) continue;

                    double tmp = (double)sugar / (sugar + water);
                    double max_rate = (double)E / (100 + E);
                    if (max_rate < tmp) continue;

                    // cout << sugar << " " << (sugar + water) << endl;
                    // if (percent < tmp) {
                    if (percent <= tmp) {
                        water_total = water;
                        sugar_total = sugar;
                        percent = tmp; 
                    }
                }
            }
        }
    } 

    cout << water_total + sugar_total << " " << sugar_total << endl;
}

Measured memory_bytes: 3776
a,b = map(int, input().split())
if a==1 and b!=1:
  print("Alice")
elif a!=1 and b==1:
  print("Bob")
elif a==1 and b==1:
  print("Draw")
elif a>b:
  print("Alice")
elif a<b:
  print("Bob")
else:
  print("Draw")

Measured memory_bytes: 3060
//41
#include<iostream>
#include<complex>

using namespace std;

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    complex<double> p[2];
    for(int j=0;j<2;j++){
      double x,xx,y,yy;
      cin>>x>>y>>xx>>yy;
      p[j]=complex<double>(x-xx,y-yy);
    }
    cout<<((p[0].real()*p[1].imag()-p[0].imag()*p[1].real())?"NO":"YES")<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N,K,Q = map(int, input().split())
seikaisha = [0 for _ in range(N)]
for _ in range(Q):
  seikaisha[int(input())-1] += 1
sum_seikai = sum(seikaisha)
for seikai in seikaisha:
  shitten = sum_seikai - seikai
  if K - shitten > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 4624
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            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 same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
 
ans = 1
 
uf = UnionFind(n)
for i in range(m):
    friends = list(map(int, input().split()))
    uf.union(friends[0]-1,friends[1]-1)
    if ans < uf.size(friends[1]-1):
        ans = uf.size(friends[1]-1)
print(ans)

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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private struct Item
        {
            public int v;
            public int w;
            public Item(int v, int w)
            {
                this.v = v;
                this.w = w;
            }
        }
        private static void SolveA(string[] args)
        {
            int n = ReadAndParseInt();
            int[] a = new int[n];
            for(int i=0;i<n;++i)
            {
                a[i] = ReadAndParseInt();
            }
            int[] l = new int[n];
            l[0] = a[0];
            int length = 1;
            for(int i=1;i<n;++i)
            {
                if(l[length-1] < a[i])
                {
                    l[length] = a[i];
                    length++;
                }
                else
                {
                    int idx = 0;
                    for(int j=0;j<length;++j)
                    {
                        if(l[j ] >= a[i])
                        {
                            idx = j;
                            break;
                        }
                    }
                    l[idx] = a[i];
                }
            }
            Console.WriteLine(length);
        }
        
    }
}



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

int main(){

  int n, c[501]={0}, s[501]={0}, f[501]={0};

  cin>>n;
  for(int i=1;i<n;i++) cin>>c[i]>>s[i]>>f[i];

  for(int i=1;i<=n;i++){
    int t=0;
    for(int j=i;j<n;j++){
      if(t<=s[j]){
        t+=c[j]+(s[j]-t);
      }else{
        for(int k=1;;k++){
          if((t+k-1)%f[j]==0){
            t+=(k-1)+c[j];
            break;
          }
        }
      }
    }
    cout<<t<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, k;
bool dp[100010][2], vis[100010][2];
vector<int> a;

bool solve(int N, int turn)
{
    if (vis[N][turn])
        return dp[N][turn];
    vis[N][turn] = true;
    bool res = (turn == 0);
    if (turn == 1)
    {
        rep(i, n) if (N >= a[i]) res = res || solve(N - a[i], 0);
    }
    else
    {
        rep(i, n) if (N >= a[i]) res = res && solve(N - a[i], 1);
    }
    return dp[N][turn] = res;
}

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

    cin >> n >> k;
    a.resize(n);
    rep(i, n) cin >> a[i];
    bool ans = solve(k, 1);
    cout << (ans ? "First" : "Second") << endl;
}

Measured memory_bytes: 3712
# coding: utf-8
import time
import re
import math
import fractions

def main():
    global N,A
    N=int(input())
    A=[]
    A.append(list(map(int,input().split())))
    A.append(list(map(int,input().split())))
    print(hoge(0,0,0))
def hoge(x,y,total):
    global N,A
    if (x==N-1 and y==1):return total+A[y][x]
    if(x>=N or y>=2):return -1e9
    total+=A[y][x]
    return max([hoge(x+1,y,total),hoge(x,y+1,total)])
    
    
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



Measured memory_bytes: 5064
#include <stdio.h>
int main (void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0) break;
    
    if(x < y)
    printf("%d %d\n",x,y);
    
    if(y < x)
    printf("%d %d\n",y,x);
    
    if(x == y)
    printf("%d %d\n",x,y);
    }
    
    return 0;
}



Measured memory_bytes: 2028
n = int(input())
a = []
for i in range(n):
	t = []
	for _ in range(int(input())):
		x, y = map(int, input().split())
		t.append((x-1, y))
	a.append(t)

def is_valid(s):
	for i in range(n):
		if s[i] == 0:
			continue
		for x, y in a[i]:
			if s[x] != y:
				return False
	return True

ans = 0
for i in range(1 << n):
	s = [0] * n
	for j in range(n):
		if (i >> j) & 1:
			s[j] = 1
	if is_valid(s):
		ans = max(ans, sum(s))

print(ans)

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

const int MAX = 1000000;
const int MOD = 1000000007;

long long 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;
    }
}

// 二項係数計算
long long 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() {
  int X,Y;
  cin>>X>>Y;
  int m,n;
  if((2*X-Y)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  if((2*Y-X)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  m=(2*Y-X)/3;
  n=(2*X-Y)/3;
    // 前処理
    COMinit();

    // 計算例
    //cout<<m<<n<<endl;
    cout << COM(m+n, n) << endl;

}


Measured memory_bytes: 23808
let bin_search x (a : int array) =
  let rec doit l r =
    if l >= r then false
    else
      let m = (l + r) / 2 in
      if x = a.(m) then true
      else if x < a.(m) then doit l m
      else doit (m + 1) r in
  doit 0 (Array.length a)

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let read_seq () = List.map int_of_string (split_on_char ' ' (read_line ())) in
  let _ = read_int () in
  let s = Array.of_list (read_seq ()) in
  let _ = read_int () in
  let t = read_seq () in
  Printf.printf "%d\n" (List.fold_left (fun acc e -> acc + (if bin_search e s then 1 else 0)) 0 t)

Measured memory_bytes: 17024
N = int(input())
alphas = list(map(int, input().split()))

all_xor = alphas[0] ^ alphas[1]
for i in range(2, N):
    all_xor = all_xor ^ alphas[i]
    
ans_list = []
for i in range(N):
    num_i = all_xor ^ alphas[i]
    ans_list.append(str(num_i))
    
ans = " ".join(ans_list)
print(ans)

Measured memory_bytes: 35608
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = True
mod = 10 ** 9 + 7
for i,j in enumerate(a):
  if n % 2:
    if j != ((i+1) // 2) * 2:
      b = False
      break
  else:
    if j != (i // 2) * 2 + 1:
      b = False
      break
if b == True:
  print(pow(2,n//2,mod))
else:
  print(0)


Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll NMAX = 200005;
vector<ll> par(NMAX);
vector<ll> siz(NMAX);
ll n;
void init(){
    for(ll i=0;i<n;i++){
        par.at(i) = i;
        siz.at(i) = 1;
    }
}

ll root(ll x){
    if(par.at(x) == x){
        return x;
    }else{
        return par.at(x) = root(par.at(x));
    }
}

bool same(ll x,ll y){
    return root(x) == root(y);
}

bool unite(ll x,ll y){
    x = root(x);
    y = root(y);
    if(x==y){
        return false;
    }
    if(siz[x]<siz[y]) swap(x, y);
    siz[x] += siz[y];
    par.at(y) = x;
    return true;
}

ll size(ll x){
    return siz.at(root(x));
}

int main(){
    cin >> n;
    ll m;
    cin >> m;
    init();
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
      	--a;
      	--b;
        unite(a,b);
    }
  
  	ll ans=0;
  	for(ll i=0;i<n;i++){
      ans = max(ans,size(i));
    }
  
  cout << ans << endl;
  
    return(0);
}


Measured memory_bytes: 6212
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef long long ll;
//No change above here

const ll maxi = (2 * 1e5 + 3);
ll mod = (1e9 + 7);

//function for power
ll power(ll x, ll n) {
	ll res = 1;
	x %= mod;
	while (n) {
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

ll dir[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };

ll p, q;
bool valid(ll i, ll j) { return i >= 1 && i <= p && j >= 1 && j <= q; }

//declare needed things here
unordered_map<int, int> m;
int main()
{
	IOS;
	int n;
	cin >> n;
	vector<int> v(n);
	int total = 0;

	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
		total ^= v[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cout << (total ^ v[i]) << " ";
	}
	return 0;
}

Measured memory_bytes: 3948
import collections
n, q = map(int, input().split())
Q = [collections.deque() for i in range(n)]
queries = list()
for i in range(q):
    queries.append(list(map(int, input().split())))
for query in queries:
    if query[0] == 0:
        Q[query[1]].append(query[2])
    elif query[0] == 1:
        try:
            print(Q[query[1]][0])
        except:
            pass
    elif query[0] == 2:
        try:
            Q[query[1]].popleft()
        except:
            pass


Measured memory_bytes: 44592
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s; cin >> s;
    int ans = 0;
    FOR(i,1,s.size()) {
        if (s[i-1] != s[i]) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

N = input()
A_ = map(int, raw_input().split())
minA = min(A_)
lst = []
for i in range(N):
    lst.append((A_[i], i))
lst.sort()

A = [0] * N
for i in range(N):
    A[lst[i][1]] = (lst[i][0], i)

flag = [False] * N

def func(pos, lst):
    if flag[pos]:
        return
    lst.append(A[pos][0])
    flag[pos] = True
    func(A[pos][1], lst)

ans = 0
for i in range(N):
    if not flag[i]:
        ret = []
        func(i, ret)
        ans += min(min(ret) * (len(ret) - 2) + sum(ret), sum(ret) + min(ret) + minA * (len(ret) + 1))

print ans


Measured memory_bytes: 5824
#include<bits/stdc++.h>
using namespace std;
#define rep(c) for(int i = 0; i < c; i++)
int D[10] = {};
bool foo(int n){
	string num = to_string(n);
	int size = num.size();
	rep(size) if(D[num[i]-'0'])return false;
	return true;
}
int main(){
	int d, N, K;
	cin>>N>>K;
	rep(K){cin>>d;D[d] = true;}
	while(!foo(N++));
	cout<<N-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
   
int main(void)
{
	
	char ch[10001];
	int i=0,joi,ioi;
	while(scanf("%s",&ch)==1){
		ioi=0;
		joi=0;
		i=0;
		while(ch[i]!='\0'){
			if(ch[i]=='J' && ch[i+1]=='O' && ch[i+2]=='I'){
				joi++;
			}
			if(ch[i]=='I' && ch[i+1]=='O' && ch[i+2]=='I'){
				ioi++;
			}
			i++;
		}
		
		printf("%d\n%d\n",joi,ioi);
	}
	return 0;
}


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

typedef long long ll;

using namespace std;

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

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

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

  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    ans = lcm(ans, t);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(void) {
	int A,B,C;
	cin >> A >> B >> C;
	map<int,bool> memo;
	bool find,ob;
	find = ob = false;
	int num = A;
	while (!find && !ob) {
		int c = num%B;
		if (memo[c]) {
			ob = true;
		}

		if (c == C) {
			find = true;
		}
		else {
			memo[c] = true;
		}
		num += A;
	}

	if (find) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}


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

void leave(string message) {
    cout << message << endl;
    exit(0);
}

int main() {
    lint n, m;
    cin >> n >> m;

    string num = string(n, '?');
    for(lint i=0; i<m; i++) {
        lint s;
        char c;
        cin >> s >> c;
        if(num[s-1] != '?' && num[s-1] != c)  leave("-1");
        num[s-1] = c;
    }

    if(num[0] == '0') {
        if(n == 1)  leave("0");
        leave("-1");
    }

    if(num[0] == '?') {
        if(n == 1)  leave("0");
        num[0] = '1';
    }
    for(lint i=0; i<n; i++) {
        if(num[i] == '?')  num[i] = '0';
    }
    cout << num << endl;
}

Measured memory_bytes: 256