akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

    
  int main(){
      COMinit();
     lint n,a,b;
     cin>>n>>a>>b;
     lint l=modpow(2,n,MOD);
       lint x=1,y=1;
     for(lint i=n;i>n-a;i--){
         x=(x*i);
         x%=MOD;
         x*=modpow(a-n+i,MOD-2,MOD);
         x%=MOD;
     }
      for(lint i=n;i>n-b;i--){
         y=(y*i);
         y%=MOD;
         y*=modpow(b-n+i,MOD-2,MOD);
         y%=MOD;
     }
    lint ans=l-x-y;
    while(ans<0){
ans+=MOD;
    }
    cout<<--ans;
    }
     
  


Measured memory_bytes: 234624
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>

#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)

int main(){
	int n;
	stack<int> st;

	while(cin >> n){
		if(n == 0){
			cout << st.top() << endl;
			st.pop();
		}else{
			st.push(n);
		}
	}

	return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>

void swap(int* a,int* b);

int main(void) {

  int flag1=1,flag2=0,flag3=0;

  char left,right;

  while(scanf("%c,%c",&left,&right)!=EOF) {

    switch(left) {
      
    case 'A':
      if(right=='B') swap(&flag1,&flag2);

      if(right=='C') swap(&flag1,&flag3);
      
      break;

    case 'B':
      if(right=='A') swap(&flag1,&flag2);

      if(right=='C') swap(&flag2,&flag3);

      break;

    case 'C':
      if(right=='A') swap(&flag1,&flag3);

      if(right=='B') swap(&flag2,&flag3);

      break;

    }

  }

  if(flag1==1) printf("A\n");

  if(flag2==1) printf("B\n");

  if(flag3==1) printf("C\n");

  return 0;

}

void swap(int* a,int* b) {

  *a=*a^*b;
  *b=*a^*b;
  *a=*a^*b;

}

Measured memory_bytes: 0
def main():
    N, K, C = map( int, input().split())
    S = input()
    T = [False]*N
    ANS = [1]*N
    for i in range(N):
        if S[i] == "o":
            T[i] = True
        else:
            ANS[i] = 0
    F = []
    i = 0
    now = 0
    D = [False]*N
    k = 0
    while i < N and k < K:
        if T[i]:
            F.append(i)
            D[i] = True
            i += C+1
            k += 1
        else:
            i += 1
    for i in range(N):
        if not D[i]:
            ANS[i] = 0
    # print(ANS, F)
    end = N-1
    for i in range(N-1,-1,-1):
        if T[i]:
            end = i
            break
    for m in F[::-1]:
        # print(m, end)
        if m < end:
            ANS[m] = 0
        if end == 0:
            break
        for j in range(end-C-1,-1,-1):
            # print(j,T[j])
            if T[j]:
                end = j
                break

    print("\n".join( map( str, [ i+1 for i in range(N) if ANS[i] == 1])))
            
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 36300
H,W=map(int,input().split())

L=[]
l=["." for i in range(W+2)]
L.append(l)
for i in range(H):
    S=["."]+list(input())+["."]
    L.append(S)
L.append(l)
#print(L)
X=[1,-1,0,0]
Y=[0,0,1,-1]
for h in range(1,H+1):
    for w in range(1,W+1):
        if L[h][w]=="#":
            F=0
            for i in range(4):
                if L[h+X[i]][w+Y[i]]=="#":
                    F=1
            if F==0:
                print("No")
                exit()
print("Yes")

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

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}




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;
vector<int> a;
int dp[100010][2];
bool vis[100010][2];

int solve(int pos, int f)
{
    if (vis[pos][f])
        return dp[pos][f];
    vis[pos][f] = true;
    if (pos == n)
        return dp[pos][f] = 0;
    int num = (f == 1 ? -a[pos] : a[pos]);
    if (pos == n - 1)
        return dp[pos][f] = solve(pos + 1, 0) + num;
    return dp[pos][f] = max(solve(pos + 1, 1) - num, solve(pos + 1, 0) + num);
}

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

    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    cout << solve(0, 0) << endl;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int main(){
   string a,b,c;
   cin>>a>>b>>c;
   int x=1,y=0,z=0;
   char check=a[0];
   bool flag=true;
   char ans='f';
   while(flag){
   switch(check){
      case 'a':check=a[x];
      if(x==a.size()) {ans='A';flag=false;break;}
      x++;
      break;
      case 'b':check=b[y];
      if(y==b.size()) {ans='B';flag=false;break;}
      y++;
      break;
      case 'c':check=c[z];      
      if(z==c.size()) {ans='C';flag=false;break;}
      z++;
      break;
   }
   }
   cout<<ans<<endl;
}


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

int main() {
  int n;
  while(cin >> n && n!=0) {
    int m;
    cin >> m;
    for(int i=0; i<m; i++) {
      int a,b;
      cin >> a >> b;
      n-=b-a;
    }
    if(n>0) cout << n << endl;
    else cout << "OK" << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;


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



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    string s;
    cin >> s;
    int32 ans = 0;
    REP(l1, n - 1){
        FOR(l2, l1+1, n){
            int32 lenMax = min(l2 - l1, n - l2);
            if(lenMax < ans)continue;
            bool match = true;
            REP(i,lenMax){
                if(s[l1+i] != s[l2+i]){
                    ans = max(ans, i);
                    match = false;
                    break;
                }
            }
            if(match)ans = max(ans, lenMax);
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 384
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder();
  let n = o.n();
  let s = o.s();
  if(s.length <= n){
    o.o(s);
  }else{
    o.o(s.slice(0, n) + '...')
  }
}
m();

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> edge_num(n,0);
	for(int i=0;i<m;i++) {
		int a,b;
		cin >> a >> b;
		a--,b--;
		edge_num[a]++;
		edge_num[b]++;
	}
	for(int i=0;i<n;i++) {
		if(edge_num[i]%2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct edge{
	int to, cost;
	edge(){}
	edge(int to_, int cost_){
		to = to_; cost = cost_;
	}
};

vector<edge> G[200];
int V, m, n, k, d, cal[10];

void add_edge(int u, int v, int c){
	G[u].push_back(edge(v, c));
	G[v].push_back(edge(u, c));
}

struct State{
	int cost, v, bits;
	State(){}
	State(int cost_, int v_, int bits_){
		cost = cost_; v = v_; bits = bits_;
	}
};
bool operator<(const State &a, const State &b){
	return a.cost > b.cost;
}

const int INF = 1e+8;
// dp[v][bits] := 頂点vにケーキ屋訪れる状態がbitsのときの最小値
int dp[200][1 << 8];

int solve(){
	for(int i = 0; i < 200; i++){
		for(int j = 0; j < (1 << 8); j++){
			dp[i][j] = INF;
		}
	}
	
	dp[0][0] = 0;
	priority_queue<State> q;
	q.push(State(0, 0, 0));
	
	int res = INF;
	while( !q.empty() ){
		int cost = q.top().cost, v = q.top().v, bits = q.top().bits; q.pop();
		
		// ゴールのとき
		if( v == n + m + 1 ){
			res = min(res, cost);
		}
		if( dp[v][bits] < cost ) continue;
		
		for(int i = 0; i < G[v].size(); i++){
			int next_cost = cost + G[v][i].cost;
			int to = G[v][i].to;
			
			if( 1 <= to && to <= m ){ // ケーキ屋のとき
				if( !(bits & (1 << to)) ){ // まだ訪れていない
					int next_bits = bits | (1 << to);
					next_cost -= cal[to-1];
					if( next_cost < dp[to][next_bits] ){
						//cout << "v:" << v << ", cost:" << cost << ", to:" << to << ", next cost:" << next_cost << endl;
						dp[to][next_bits] = next_cost;
						q.push(State(next_cost, to, next_bits));
					}
				}
			}else{ // それ以外のとき
				if( next_cost < dp[to][bits] ){
					//cout << "v:" << v << ", cost:" << cost << ", to:" << to << ", next cost:" << next_cost << endl;
					dp[to][bits] = next_cost;
					q.push(State(next_cost, to, bits));
				}
			}
		}
	}
	return res;
}

int get(string s){
	if( s[0] == 'H' ) return 0;
	if( s[0] == 'D' ) return n + m + 1;
	if( s[0] == 'L' ) return m + atoi(s.substr(1).c_str());
	if( s[0] == 'C' ) return atoi(s.substr(1).c_str());
}

int main(){
	while( cin >> m >> n >> k >> d , n ){
		// 頂点数
		V = n + m + 2;
		for(int i = 0; i < 200 ; i++) G[i].clear();
		
		for(int i = 0; i < m; i++) cin >> cal[i];
		
		for(int i = 0; i < d; i++){
			string s, t;
			int c;
			cin >> s >> t >> c;
			
			c *= k;
			int u = get(s), v = get(t);
			add_edge(u, v, c);
		}
		int ans = solve();
		cout << ans << endl;
	}
}

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

int main() {
  int a, b;
  int kaunto = 0;
  cin >> a >> b;
  for (int i = 0; i < 10000000; i++) {
    if (a < b) {
      cout << a;
      kaunto++;
      if (kaunto >= b) {
        break;
      }
    }
    if (a > b) {
      cout << b;
      kaunto++;
      if (kaunto >= a) {
        break;
      }
    }
    if (a == b) {
      cout << a;
      kaunto++;
      if (kaunto >= a) {
        break;
      }
    }
  }
}
      

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=4000010;
ll fact[N];
ll m=1e9+7;
ll power(ll a,ll p)
{
    ll res=1;
    ll y=a;
    while(p>0)
    {
        if(p&1)res=(res*y)%m;
        p>>=1;
        y=(y*y)%m;
    }
    return res;
}
int main()
{
    IOS;
    fact[0]=1;
    for(int i=1;i<N;i++)fact[i]=(fact[i-1]*i)%m;
    ll a,b;cin>>a>>b;
    ll x=-1,y=-1;
    if((2*b-a)%3==0)x=(2*b-a)/3;
    if((2*a-b)%3==0)y=(2*a-b)/3;
    if(x<0||y<0)cout<<0<<endl;
    else{
//        cout<<x<<" "<<y<<endl;
//        ll res=(fact[x+y])/(fact[x]*fact[y]);
        ll res=(((fact[x+y]*power(fact[x],m-2))%m)*(power(fact[y],m-2)))%m;
        cout<<res<<endl;
    }
}









Measured memory_bytes: 34896
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> P(m), Y(m);
    rep(i, m) {
        cin >> P[i] >> Y[i];
        --P[i];
    }
    vector<vector<int>> vals(n);
    rep(i, m) { vals[P[i]].push_back(Y[i]); }

    rep(v, n) {
        sort(all(vals[v]));

        vals[v].erase(unique(all(vals[v])), vals[v].end());
    }

    rep(i, m) {
        int v = P[i];
        printf("%06d", v + 1);

        int id = lower_bound(all(vals[v]), Y[i]) - vals[v].begin();
        printf("%06d\n", id + 1);
    }
}

Measured memory_bytes: 7808
#include <iostream>
#include <math.h>
#include <limits>
using namespace std;
int main()
{

long long int n;
cin>>n;
long long int i=sqrt(n+10);
while (i>=1)
{if (n%i==0)
{cout <<i+(n/i)-2;
break;}
else i--;
}
}

Measured memory_bytes: 256
s=str(input())
L=[0]*26
n=len(s)
for i in range(n):
  L[ord(s[i])-97]+=1
num=0
total=n*(n-1)//2 +1
for i in range(26):
  if L[i]>1:
    num+=L[i]*(L[i]-1)//2
print(total-num)

Measured memory_bytes: 3500
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    h = list(map(int, input().split()))
    INF = 10**10
    dp = [INF]*N
    dp[0] = 0

    for i in range(N):
        if (i+1)<N:
            dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]))
        if (i+2)<N:
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]))

    print(dp[N-1])

if __name__ == '__main__':
    main()

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

long long getGcd(long long a, long long b){
    if(a < b){
        long long tmp = a;
        a = b;
        b = tmp;
    }
    
    if(b == 0)return a;
    
    return getGcd(b, a%b);
}

int main(){

    int N;
    cin >> N;

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

    long long gcd_s[N];
    gcd_s[0] = a[0];
    for(int i = 1; i < N; i++) {
        gcd_s[i] = getGcd(gcd_s[i-1], a[i]);
    }

    long long gcd_e[N];
    gcd_e[N-1] = a[N-1];
    for(int i = N-2; i >= 0; i--) {
        gcd_e[i] = getGcd(gcd_e[i+1], a[i]);
    }

    long long ans;
    ans = gcd_e[1];
    ans = max(ans, gcd_s[N-2]);
    for(int i = 1; i < N-1; i++) {
        ans = max(ans, getGcd(gcd_s[i-1], gcd_e[i+1]));
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
import math

A, B, H, M = (int(x) for x in input().split())

minuteAngle = math.pi * M / 30

hourAngle = math.pi * (H + M / 60) / 6

angleC = abs(hourAngle - minuteAngle)

print(math.sqrt((A ** 2) + (B ** 2) - (2 * A * B * math.cos(angleC))))


Measured memory_bytes: 9504
#int(input())
#int(x) for x in input().split()
#map(int,input().split())
a,b,c,k=[int(x) for x in input().split()]
ans=0
if k<=a:
	ans+=k
	k=0
elif k>a:
	ans+=a
	k-=a
if k<=b:
	k=0
elif k>b:
	k-=b
if k<=c:
	ans-=k
	k=0
print(ans)



Measured memory_bytes: 61664
import bisect
N=int(input())
A=sorted(list(map(int,input().split())))
B=sorted(list(map(int,input().split())))
C=sorted(list(map(int,input().split())))
print(sum(bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b)) for b in B))

Measured memory_bytes: 107108
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef pair<int, int> P;
//typedef pair<int, pair<int, int> > PP;
const int MOD=1e9+7;

ll dp[2005][2005];

int main(){
	int N,M;
	cin>>N>>M;
	vi S(N), T(M);
	rep(i,N)cin>>S[i];
	rep(j,M)cin>>T[j];
	
	//dp[i][j]は[0,i), [0,j)での個数
	dp[0][0]=1;
  	rep1(i,N)dp[i][0]=1;
  	rep1(j,M)dp[0][j]=1;
	rep1(i,N)rep1(j,M){
		if(S[i-1]==T[j-1])dp[i][j]=(dp[i][j-1]+dp[i-1][j])%MOD;
		else dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+MOD)%MOD;
	}
	cout<<dp[N][M]<<endl;
}

Measured memory_bytes: 31616
// https://atcoder.jp/contests/caddi2018/tasks/caddi2018_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        n: usize, a: [i64; n]
    };

    let lose = a.into_iter().filter(|w| w % 2 == 0).collect::<Vec<_>>().len() == n;
    println!("{}", ifv!(lose, "second", "first"));
}


Measured memory_bytes: 8444
#include <stdio.h>
#include <string.h>
typedef long long ll;

int len;
char str[200005];

int main()
{
    ll ans = 0;
    ll dist = 0;
        
    scanf("%s", str);
    len = strlen(str);

    for (int i = 0; i < len; i++) {
        if (str[i] == 'W') {
            ans += dist;
        }
        else {
            dist++;
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    
    String n = sc.nextLine();
    
    int sum = 0;
    for(String s:n.split("")){
      sum += Integer.parseInt(s);
    }
    
    if(sum%9 == 0)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
}


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

def main():
    lst=[int(input()) for a in range(5)]
    index=0
    mx=0
    total=0
    for a in range(len(lst)):
        if math.ceil(lst[a]/10)*10-lst[a]>mx:
            mx=math.ceil(lst[a]/10)*10-lst[a]
            index=a
    #print(index)
    for a in range(len(lst)):
        if a==index:
            total+=lst[a]
        else:
            total+=math.ceil(lst[a]/10)*10
    print(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: 5060
#include<iostream>
#include<vector>
using namespace std;
int ans;
int main(){
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin >> v[i];
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans += v[i]*v[j];
    }
  }
  cout << ans << endl;
  return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
string strd(int n){
    string x;
    while(n){
        int d=n%10;
        x+=(d+'0');
        n/=10;
    }
    reverse(x.begin(),x.end());
    return x;
}
void digit()
{
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        char a=(char)s[i];
        int d=(int) a-'0';
        sum+=d;
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
    digit();
}


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

using namespace std;

int main()
{
	int r;
	cin >> r;
	
	if(r < 1200) cout << "ABC" << endl;
	else if(r < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	return 0;
}


Measured memory_bytes: 256
A=[]
fp =0
bp =0
n=int(raw_input())
while n: 
    cmd = raw_input()
    if cmd[0] == 'i':
        A.append(int(cmd[7:]))
        fp += 1
    elif cmd[6] == ' ':
        try:
            i = A[::-1].index(int(cmd[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif cmd[6] == 'F':
        A.pop()
        fp -=1
    elif cmd[6] == 'L':
        bp +=1
    n -=1
 
for k in A[bp:fp+1][::-1]:
    print int(k),

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    long double a, b, c;
    cin >> a >> b >> c;
    long double d = a + b + (2.0 * sqrt(a) * sqrt(b));
    if(d < c) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int a[1000];
		rep(i,n) scanf("%d",a+i);

		bool ok;
		int b[1012];
		rep(S,1<<m){
			int sum=0;
			rep(i,m) sum+=b[i]=S>>i&1;
			rep(i,n-1) b[m+i]=a[i+1]-a[i]+b[i];

			ok=(sum==a[0]);
			rep(i,n+m-1) if(b[i]!=0 && b[i]!=1) ok=false;
			if(ok) break;
		}

		if(ok){ rep(i,n+m-1) printf("%d",b[i]); puts(""); } else puts("Goofy");
	}

	return 0;
}

Measured memory_bytes: 1048
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int ans = 0;
  rep(k,1000) {
    string a = to_string(k);
    if(sz(a) == 2) {
      a = "0" + a; 
    } else if(sz(a) == 1) {
      a = "00" + a;
    }
    int x = 0;
    int i = 0;
    while(x < 3 && i < N) {
      if(s[i] == a[x]) {
        i++;
        x++;
      } else {
        i++;
      }
    }
    if(x == 3) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# https://beta.atcoder.jp/contests/agc029/tasks/agc029_a


def main():
    S = list(input())
    count = 0
    w_offset = 0
    for i in range(len(S)):
        if S[i] == "W":
            count += i - w_offset
            w_offset += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define INFLL 0x3fffffffffffffffLL
#define INF 0x3f3fffff
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define exist(s,e) (s.find(e)!=s.end())
#define ff first
#define ss second
#define EPS 1e-8
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
const ll MOD=1000000007;
/////////////////// DEBUG MODE ///////////////////////////////////
#define D(x) cerr<<"DEBUG: "<<#x<<" is: "<<x<<'\n'
#define error(args...) {string _s=#args; replace(all(_s),',',' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
void err(istream_iterator<string>) { cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/////////////////// GLOBAL VARIABLES /////////////////////////////
vector<vector<int>> adj; vector<bool> vis;
/////////////////// FUNCTIONS ////////////////////////////////////
ll mexp(ll x, ll n, ll m){
  ll res=1;  while(n){if(n&1) res=(res*x)%m;n>>=1; x=((x%m)*(x%m))%m;}
  return res;
}
bool ispow2(ll x){ return x && (!(x&(x-1)));}
/////////////////// MAIN STARTS //////////////////////////////////
int main(){
  ios::sync_with_stdio(0);  cin.tie(0); cout<<fixed;   cerr<<fixed;
  cout<<setprecision(14); cerr<<setprecision(3);
  #ifdef DEBUG
  freopen("ip.txt","r",stdin); //freopen("op.txt","w",stdout);
  clock_t tStart = clock();
  #endif

	int h,w; cin>>h>>w;
	char mat[h][w]; bool v[h][w]; memset(v, false, sizeof(v));
	for(int i=0;i<h;++i) for(int j=0;j<w;++j) cin>>mat[i][j];
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(mat[i][j]=='#'){
				if(j<w-1 && mat[i][j+1]=='#')	{v[i][j]=v[i][j+1]=true;}
				if(i<h-1 && mat[i+1][j]=='#') {v[i][j]=v[i+1][j]=true; continue;}
				if(v[i][j]==false){ error(i,j);cout<<"No\n"; return 0;}
			}
			//for(int a=0;a<h;++a,cout<<endl) for(int b=0;b<w;++b) cout<<v[a][b];
		}
	}
	cout<<"Yes\n";

	#ifdef DEBUG
	cerr<<"\nExecution time: "<<(((double)clock() - tStart)/CLOCKS_PER_SEC)*1e3<<"ms.\n";
	#endif
  return 0;
}


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

using namespace std;

int a, b, k[1005][1005], c, l[5], m[505][505], ans = 0;

int main() {
	cin >> a >> b;
	for (int i = 0; i < b; ++i) {
		char str[1234];
		scanf("%s", str);
		for (int j = 0; j < b; ++j) {
			if (str[j] == '1') k[i][j] = 1;
			if (str[j] == '0') k[i][j] = 0;
		}
	}

	for (int i = 0; i < b / 2; ++i) {
		for (int j = 0; j < b / 2; ++j) {
			int count = 0;
			if (k[i][j] == 1) count++;
			if (k[i][b - j - 1] == 1) count++;
			if (k[b - i - 1][b - j - 1] == 1) count++;
			if (k[b - i - 1][j] == 1) count++;
			m[i][j] = count;
		}
	}
	bool flag = true;
	for (int i = 0; i < b / 2; ++i) {
		for (int j = 0; j < b / 2; ++j) {
			if (m[i][j] != 0 && m[i][j] != 4) {
				flag = false;
				goto syamu;
			}
		}
	}
syamu:
	if (flag) ans++;

	while (max(0, a - 1)) {
		flag = true;
		cin >> c;
		for (int i = 0; i < c; ++i) {
			cin >> l[0] >> l[1];
			l[0]--; l[1]--;
			if (k[l[0]][l[1]] == 1) {
				k[l[0]][l[1]] = 0;
				m[min(l[0], b - l[0] - 1)][min(l[1], b - l[1] - 1)]--;
			}
			else if (k[l[0]][l[1]] == 0) {
				k[l[0]][l[1]] = 1;
				m[min(l[0], b - l[0] - 1)][min(l[1], b - l[1] - 1)]++;
			}
		}
		for (int i = 0; i < (b / 2); ++i) {
			for (int j = 0; j < (b / 2); ++j) {
				if (m[i][j] != 0 && m[i][j] != 4) {
					flag = false;
					goto aa;
				}
			}
		}
	aa:
		if (flag) ans++;
		a--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 8068
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int gcd(int x, int y){
  if(x==0) return y;
  else return gcd(y%x,x);
}
int main(){
  int N;
  cin>>N;
  int A[1000000];
  int M=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    M=max(M,A[i]);
  }
  int judge[1000001];
  for(int i=1;i<=M;i++) judge[i]=0;
  for(int i=2;i<=M;i++){
    if(judge[i]==0){
      for(int j=i;j<=M;j+=i){
        if(judge[j]==0) judge[j]=i;
      }
    }
  }
  int set=0;
  int pnum[1000001];
  for(int i=1;i<=M;i++) pnum[i]=0;
  for(int i=0;i<N;i++){
    int a=A[i];
    while(a!=1){
      int n=judge[a];
      while(a%n==0) a/=n;
      pnum[n]++;
    }
  }
  for(int i=1;i<=M;i++){
    if(pnum[i]>1){
      set=1; break;
    }
  }
  if(set==0) cout<<"pairwise coprime"<<endl;
  else{
    int g=A[0];
    for(int i=1;i<N;i++){
      g=gcd(g,A[i]);
    }
    if(g==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 14820
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <queue>

using namespace std;
typedef  long long LL;
const int N = 1e5+5;
int eee[N],add[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; ++i)
    {
        eee[i]=1;
        add[i]=eee[i]-1;
    }
    add[1]=1;
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(add[x])
        {
            if(eee[x]==1)
                add[x]=0;
            add[y]=1;
        }
        eee[x]--;
        eee[y]++;
    }
    int ans=0;
    for(int i=1; i<=n; ++i)
        if(add[i])
        ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1024
info_A = input().split()
info_B = input().split()
T = int(input())
win = ''

A = int(info_A[0]) #A（鬼）の開始位置
V = int(info_A[1]) #A（鬼）の速度
B = int(info_B[0]) #B（逃げる側）の開始位置
W = int(info_B[1]) #B（逃げる側）の速度

# 逃げる側の速度が同じか速ければ追いつけない
if W >= V:
    win = 'B'

else:
# T秒後までに同じ座標にいればAが勝つ
    k = (B-A)/(V-W)
    if A>B:
        k = -k
    
    if k <= T and 0 < k:
        win = 'A'
    else:
        win = 'B'


if win == 'A':
    print('YES')
else:
    print('NO')

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

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

    int dmin = 100000;
    int sum = 0;

    for(int i = 1; i <= N / 2; i++)
    {
        int A,B;
        A = i;
        B = N - i;

        while(A > 0)
        {
            sum += A % 10;
            A /= 10;
        }

        while(B > 0)
        {
            sum += B % 10;
            B /= 10;
        }
        dmin = min(dmin,sum);
        sum = 0;
    }

    cout << dmin << endl;
    return 0;
}

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int cnt[4];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	int a, b;
	for(int i=0;i<3;i++) {
		cin>>a>>b;
		if(++cnt[--a]==3 || ++cnt[--b]==3) {
			cout<<"NO\n";
			return 0;
		}
	}
	cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#define INF 9999999
using namespace std;
int n,m,t[100][100],a,b,c,d,flg[10],sum,mini,miniNo;
void prim(){
	int visited[100],mini,miniNo;
	int cost[100],pi[100];
	for(int i=0;i<n;i++){
		visited[i]=0;
		cost[i]=INF;
	}
	cost[0]=0;
	pi[0]=-1;
	while(1){
		mini=INF;
		for(int i=0;i<n;i++){
			if(mini>cost[i]&&visited[i]==0){
				miniNo=i;
				mini=cost[i];
			}
		}
		if(mini==INF)break;
		visited[miniNo]=1;
		for(int i=0;i<n;i++){
			if(t[miniNo][i]!=INF&&visited[i]==0){
				if(t[miniNo][i]<cost[i]){
					cost[i]=t[miniNo][i];
					pi[i]=miniNo;
				}
			}
		}
	}
	int total=0;
	for(int i=0;i<n;i++){
		if(pi[i]==-1)continue;
		total+=t[i][pi[i]];
	}
	cout<<total<<endl;
}
int main(){
	while(1){
		for(int i=0;i<100;i++){
			for(int j=0;j<100;j++){
				t[i][j]=INF;
			}
		}
		cin>>n>>m;
		if(n==0&&m==0)break;
		for(int i=0;i<m;i++){
			cin>>a>>b>>c;
			t[a][b]=t[b][a]=c;
		}
		prim();
	}
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

#define MAX 10000
#define NIL -1

struct Node {int p,l,r;};
struct Node A[MAX];
int n;

void preparse(int);
void inparse(int);
void postparse(int);

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    A[i].p=NIL;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    A[v].l=l;
    A[v].r=r;
    if(l!=NIL)
      A[l].p=v;
    if(r!=NIL)
      A[r].p=v;
	}
  for(i=0;i<n;i++)
    if(A[i].p==NIL)root=i;

  printf("Preorder\n");
  preparse(root);
  printf("\n");

  printf("Inorder\n");
  inparse(root);
  printf("\n");

  printf("Postorder\n");
  postparse(root);
  printf("\n");

  return 0;
}
void preparse(int a){
  if(a==NIL)return;
  printf(" %d",a);
  preparse(A[a].l);
  preparse(A[a].r);
}
void inparse(int a){
  if(a==NIL)return;
  inparse(A[a].l);
  printf(" %d",a);
  inparse(A[a].r);
}
void postparse(int a){
   if(a==NIL)return;
   postparse(A[a].l);
   postparse(A[a].r);
   printf(" %d",a);

}



Measured memory_bytes: 2752
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <regex>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	string S; cin >> S;
	string patterns[] = {
		"keyence.*",
		"keyenc.*e" ,
		"keyen.*ce" ,
		"keye.*nce" ,
		"key.*ence" ,
		"ke.*yence" ,
		"k.*eyence" ,
		".*keyence" };

	for (const string & p : patterns) {
		if (regex_match(S, regex(p))) {
			print("YES");
			return 0;
		}
	}
	print("NO");
	return 0;
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  if(n == 1){
    cout << "Yes";
    return 0;
  }
  vector<long long> h(n);
  for(int i = 0; i < n; i++)
    cin >> h.at(i);
  for(int i = 0; i < n -1; i++){
    if(h.at(i) <= h.at(i +1)) continue;
    else if(h.at(i) == h.at(i + 1) + 1){
      h.at(i + 1)++;
      continue;
    }
    else{
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
    long A,B; cin>>A>>B;
    long AA = A,BB = B;
    long ex = 1;
    long i = 2;
    while(1){
        while(1){
            if(A%i==0&&B%i==0){
                A /= i;
                B /= i;
                ex *= i;
                break;
            }
            if(i>=AA/2||i>=BB/2)break;
            i++;
        }
        if(i>=AA/2||i>=BB/2)break;
    }
    
    long ans = ex*A;
    ans *= B;
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

const int MOD = 1e9 + 7;
const int INF = 0x3F3F3F3F;
const ll INFLL = 0x3F3F3F3F3F3F3F3FLL;

int n, w;
int val[112];
int pes[112];
ll dp[112][112345];

ll solve(int pos, int total){
	
	if(total > w) return -INF;
	if(pos == n || total == w) return 0;
	if(dp[pos][total] != -1) return dp[pos][total];
	
	return dp[pos][total] = max(
		solve(pos + 1, total), 
		solve(pos + 1, total + pes[pos]) + val[pos]
	);
}

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> w;
	
	for(int i = 0 ; i < n ; i ++)
		cin >> pes[i] >> val[i];
	
	memset(dp, -1, sizeof dp);
	
	cout << solve(0,0) << "\n";
	
	return 0;
}

Measured memory_bytes: 101952
import collections
S = input()
Q = int(input())
q = collections.deque()
q.append(S)
inversion = True
for i in range(Q):
    Query = list(map(str, input().split()))
    if Query[0] == "1":
        inversion = not(inversion)
    elif Query[1] == "1":
        if inversion:
            q.appendleft(Query[2])
        else:
            q.append(Query[2])
    else:
        if inversion:
            q.append(Query[2])
        else:
            q.appendleft(Query[2])

if inversion:
    print("".join(q))
else:
    print("".join(q)[::-1])


Measured memory_bytes: 7156
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  std::string S, T, U;
  long long int A, B;

  std::cin >> S >> T;
  scanf("%lld%lld", &A, &B);
  std::cin >> U;
  
  std::cerr << "Answer: " << std::endl;
  if(S==U){
    std::cout << A-1 << " " << B << std::endl;
  }
  else{
    std::cout << A << " " << B-1 << std::endl;
  }

  return 0;
  
}


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

using namespace std;

int main() {
	
	int N, Y;
	int XX, YY, ZZ;
	int count = 0;

	cin >> N >> Y;

	for (int x = 0;x <= N;x++) {
		for (int y = 0;y <= N;y++) {
			int z = N - x - y;
			if (0 <= z and z <= N) {
				if ((10000 * x + 5000 * y + 1000 * z) == Y) {
					XX = x;
					YY = y;
					ZZ = z;
					count++;
				}
			}

		}
	}

	if (count == 0)
		cout << -1 << " " << -1 << " " << -1 << endl;
	else
		cout << XX << " " << YY << " " << ZZ << endl;

}

Measured memory_bytes: 3556
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*


fun gcd(a:Long, b:Long):Long {
    val c = a % b
    if (c == 0L) return b
    return gcd(b, c)
}

fun lcm(a:Long, b:Long):Long {
    return a / gcd(a, b) * b
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    val b = a.map { it / 2 }.toTypedArray()
    val count = Array(n) { 0 }
    for (i in 0 until n) {
        var x = b[i]
        while (x % 2 == 0) {
            x /= 2
            count[i]++
        }
    }
    if (count.distinct().count() != 1) {
        println(0)
        return
    }
    var lcm = b[0].toLong()
    for (i in 1 until n) {
        lcm = lcm(lcm, b[i].toLong())
        if (lcm > m) {
            println(0)
            return
        }
    }
    println((m - lcm) / (2 * lcm) + 1)
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

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

	vector<int> vec(n);
	int sum = 0;
	for (auto& e : vec) {
		cin >> e;
		sum += e;
	}
	
	int avg = round(sum / static_cast<double>(n));
	int ans = 0;

	for (int i = 0; i < n; i++) {
		ans += pow(vec[i] - avg, 2);
	}

	cout << ans << endl;
}

Measured memory_bytes: 3724
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let (mut s, mut c): (i64, i64) = read();
    let mut ans = 0;

    let mk = min(s, c / 2);
    s -= mk;
    c -= mk * 2;
    ans += mk;
    ans += c / 4;

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;
int gcd(int a, int b)
{
    
    if (a < b)
    {
        int d = a;
        a = b;
        b = d;
    }
    while(b > 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    return a;
}
int main()
{
    int a, b;
    cin >> a >> b;
    
    cout << gcd(a, b) << endl;
    
    return 0;
}


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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);

typedef long long int lli;

int calculate(int n)
{
	int ans=0;
	while(n%2==0)
	{
		n/=2;
		ans++;
	}
	return ans;
}

int main()
{
	fio;
	int n;
	cin>>n;
	lli count=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		count+=calculate(x);
	}
	cout<<count<<endl;
	cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
	return 0;
}

Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(i=a;i<b;i++)
    #define rfo(i,b,a) for(i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
   
    int dp[MAX];
    void solve()
    {
        cin>>n>>k;
         vector<int> v(n);
        fo(i,0,n)
        cin>>v[i];
    	
    	fo(i,0,k+1)
        {
            for(auto x:v)
        	{
        	    if(i>=x && dp[i-x]==0)
        	    dp[i]=1;
        	}
        }
        
        if(dp[k])
        cout<<"First"<<endl;
        else
        cout<<"Second"<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 1024