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

using namespace std;

#define INF 1e9
typedef long long ll;
typedef vector<ll> Vec;
 
struct State{
  Vec v;
  int sp,cost;
  State(Vec v,int sp,int cost) 
    : v(v),sp(sp),cost(cost) {}
  bool operator > (const State &s)const{
    return cost > s.cost;
  }
};
 
int ch,cv;
const int d[4] = {-1,1,-3,3};

ll getVal(Vec &v){
  ll res = 0LL;
  for(int i = 0 ; i < (int)v.size() ; i++){
    res *= 9;
    res += v[i];
  }
  return res;
}

int dijkstra(Vec &st,ll target,int sp){
  priority_queue<State,vector<State>,greater<State> > Q;
  Q.push(State(st,sp,0));
  unordered_map<ll,int> mp;
  mp[getVal(st)] = 0;

  while(!Q.empty()){
    State s = Q.top(); Q.pop();
    ll val = getVal(s.v);
    if(mp.find(val) != mp.end() && mp[val] < s.cost){
      continue;
    }
    if(val == target){ return mp[val]; }
    for(int i = 0 ; i < 2 ; i++){
      int nsp = (s.sp + d[i] + 9) % 9;
      swap(s.v[nsp],s.v[s.sp]);
      ll nval = getVal(s.v);
      if(mp.find(nval) == mp.end()){
        mp[nval] = mp[val] + ch;
        Q.push(State(s.v,nsp,mp[nval]));
      }else{
        if(mp[val] + ch < mp[nval]){
          mp[nval] = mp[val] + ch;
          Q.push(State(s.v,nsp,mp[nval]));
        }
      }
      swap(s.v[nsp],s.v[s.sp]);
    }
    for(int i = 2 ; i < 4 ; i++){
      int nsp = (s.sp + d[i] + 9) % 9;
      swap(s.v[nsp],s.v[s.sp]);
      ll nval = getVal(s.v);
      if(mp.find(nval) == mp.end()){
        mp[nval] = mp[val] + cv;
        Q.push(State(s.v,nsp,mp[nval]));
      }else{
        if(mp[val] + cv < mp[nval]){
          mp[nval] = mp[val] + cv;
          Q.push(State(s.v,nsp,mp[nval]));
        }
      }
      swap(s.v[nsp],s.v[s.sp]);
    }
  }
  return INF;
}

int main(){
  while(cin >> ch >> cv, (ch|cv)){
    int sp;
    Vec s(9),t(9);
    for(int i = 0 ; i < 9 ; i++){
      cin >> s[i];
      if(s[i] == 0){ sp = i; }
    }
    for(int i = 0 ; i < 9 ; i++){
      cin >> t[i];
    }
    cout << dijkstra(s,getVal(t),sp) << endl;
  }
  return 0;
}

Measured memory_bytes: 33952
n,k = map(int,input().split())
i = 1
while 1:
    if n < k:
        print(1)
        break
    if n < k ** i and n > k ** (i - 1):
        print(i)
        break
    if n == k ** i:
        print(i + 1)
        break
    else:
        i = i + 1



Measured memory_bytes: 2940
// ITP1_4_A:   A / B Problem
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
    scanf("%d%d", &a, &b);
    printf("%d %d %lf\n", a/b, a%b, (double)a/b);
    return 0;
}


Measured memory_bytes: 2728
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main()
{
	int n, k, d, tmp;
	cin >> n >> k;
	vector<int> v(n, 0);
	rep(i, k) {
		cin >> d;
		rep(j, d) {
			cin >> tmp;
			v[tmp - 1]++;
		}
	}
	int ans = 0;
	rep(i, n) {
		if (v[i] == 0)	ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3220
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n_ = 2*10**6 + 5
mod = 10**9+7
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod

def nCr(n,r):
    if r > n:
        return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod

r1,c1,r2,c2 = nm()

def H(k,l):
    return (nCr(k+l+2, k+1)-1)%mod

ans = H(r2,c2) - H(r1-1,c2) - H(r2,c1-1) + H(r1-1,c1-1)
ans %= mod
print(ans)


Measured memory_bytes: 163316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int n,k;
cin >> n >> k;
vi h(n);
rep(i,n) cin >> h[i];

sort(all(h));
int ans = INF;

for(int i = 0;i <= n-k;i++){
    ans = min(ans,h[i+k-1] - h[i]); 
}

cout << ans << endl;

return 0;
}

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

typedef unsigned long long int LL;
const int MAX_N = 10;

// aとbの最大公約数を返す(ユークリッドの互除法)
LL gcd(LL a, LL b){
    return (b == 0)? a : gcd( b , a%b ) ;
}

// aとbの最小公倍数を返す
LL lcm(LL a, LL b){
    return ( a / gcd(a,b) * b );
}

int main(){
	int n;
	while( cin >> n , n ){
		LL d[MAX_N], v[MAX_N];
		for(int i=0 ; i < n ; i++ ){
			cin >> d[i] >> v[i];
			LL a = gcd( d[i] , v[i] );
			d[i] = d[i] / a;
			v[i] = v[i] / a;
		}
		LL b = lcm( d[0] , d[1] );
		for(int i=2 ; i < n ; i++ ){
			b = lcm( b , d[i] );
		}
		LL f[MAX_N] = {0};
		for(int i=0 ; i < n ; i++ ){
			f[i] = v[i] * (b / d[i]);
		}
		LL c = gcd( f[0] , f[1] );
		for(int i=2 ; i < n ; i++ ){
			c = gcd( f[i] , c );
		}
		for(int i=0 ; i < n ; i++ ){
			cout << (f[i] / c) << endl;
		}
	}
}

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

using namespace std;

const int range = 1000005;

int main(){
    int N;

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

    vector<int> M(range);

    for(int x : A){
        if(M[x] != 0){
            M[x] = 2;
            continue;
        }
        
        for(int i = x ; i < range ; i += x){
            M[i]++;
        }
    }

    int ans = 0;
    for(int x : A){
        if(M[x] == 1){
            ans++;
        }
    }

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

Measured memory_bytes: 7532
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int A, B, C, D, E, F;
    cin>> A >> B >> C >> D >> E >> F;
    int w = 0, ans_w = 0;
    int s = 0, ans_s = 0;
    long double max_con = 0;
    int countA, countB, countC, countD;
    countA = countB = countC = countD = 0; 
    while(A * 100 * countA <= F){
        while(A * 100 * countA + B * 100 * countB <= F){
            w = (A * countA + B * countB) * 100;
            while(w + C * countC <= F){
                while(w + C * countC + D * countD <= F){
                    s = C * countC + D * countD; 
                    if(w/100 * E < s) break;
                    long double con = 100 * (long double)s /(long double)(s + w);
                    if(con > max_con){
                        max_con = con;
                        ans_w = w + s;
                        ans_s = s;
                    }
                    countD++;
                }
                countD = 0;
                countC++;
            }
            countC = 0;
            countB++;
        }
        countB = 0;
        countA++;
    }
    if(max_con == 0){
        ans_w = 100* A;
        ans_s = 0;
    }
    cout << ans_w << " " << ans_s << endl;   
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,k;
    cin >> n >> k;
    vl a(n+1,0);
    rep(i,n){
        int t;cin >> t;
        a[i+1] = t + a[i];
    }
    vl b;
    rep(i,n){
        for(int j=i+1;j<=n;j++){
            b.push_back(a[j] - a[i]);
        }
    }
    ll ans = 0;
    sort(b.begin(),b.end(),greater<ll>());
    for(int i=49;i>=0;i--){
        vl d;
        rep(j,b.size()) if(b[j]>>i & 1){
            d.push_back(b[j]);
        }
        if(d.size()>=k){
            b = d;
            ans |= 1LL<<i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6388
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

class factorials:
    '''
    args:
      n : max val when exploring factorials
    '''
    def __init__(self, n):
        self.n = 1
        self.factorials = []
        self.update(n)

    def update(self, n):
        if self.n >= n:
            return None
        for i in range(self.n+1, n+1):
            done = False
            limit = int(i ** 0.5)
            for j in self.factorials:
                if j > limit: break
                if not i % j:
                    done = True
                    break
            if not done:
                self.factorials.append(i)
        self.n = n
        return None

    def lists(self):
        return self.factorials

    def check_fact(self, x):
        if x > self.n**2:
            self.update(int(x ** 0.5)+1)
        for f in self.factorials:
            if not x % f:
                return False
        return True

def prod(lis):
    ret = []
    def f(l, product):
        #print(l)
        if not l:
            ret.append(product)
            return None
        for k in l[0]:
            f(l[1:], product + [k])

    f(lis, [])
    return ret

def run():
    N = int(input())
    ori = N
    FACT = factorials(int(N ** 0.5))
    dissociated = defaultdict(lambda:0)
    for f in FACT.lists():
        while not N % f:
            dissociated[f] += 1
            N = N // f
    if N != 1:
        dissociated[N] += 1

    val_dic = {}
    lis = []
    facts = []
    for key in dissociated.keys():
        facts.append(key)
        lis.append(list(range(dissociated[key]+1)))

    products = prod(lis)
    ans = 1 << 50
    for p in products:
        S = 1
        for i, v in enumerate(p):
            S *= facts[i] ** v
        S = max(ori // S, S)
        ans = min(ans, S)

    print(math.floor(math.log10(ans))+1)
    #print(facts, products)
    #print(dissociated)
    #print(lis)


    #print(factorials)
if __name__ == "__main__":
    run()

Measured memory_bytes: 10352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


ll areaA,areaB,areaC;

int main() {
  ll H,W;
  scanf("%lld%lld", &H,&W);

  ll ans = pow(10,12);
  
  FOR(i,1,H-1){
    areaA = i*W;
    areaB = (H-i)/2 * W;
    areaC = (H-i+1)/2*W;

    ll max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

    areaB = W/2*(H-i);
    areaC = (W+1)/2*(H-i);
    max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

  }

  int change = H;
  H = W;
  W = change;

  FOR(i,1,H-1){
    areaA = i*W;
    areaB = (H-i)/2 * W;
    areaC = (H-i+1)/2*W;

    ll max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

    areaB = W/2*(H-i);
    areaC = (W+1)/2*(H-i);
    max_min = max({areaA,areaB,areaC})-min({areaA,areaB,areaC});
    chmin(ans,max_min);

  }

  cout << ans << endl;

}



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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;

    int MOD = 1000000007;
    int N = 100100;
int fac[100101];
int inv[100101];

ll bitpow(ll x,ll n){
    ll ans = 1;
    while(n > 0){
        if(n%2 == 1) ans = ans * x % MOD;
        x = x * x %MOD;
        n = n >> 1;
    }
    return ans;
}

ll COM(ll n,ll k){
    return fac[n]*inv[k]%MOD*inv[n-k]%MOD;
}

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


    
fac[0] = 1;
inv[0] = 1;
for(int i = 1;i <= N;i++){
    fac[i] = fac[i-1]*i%MOD;
    inv[i] = bitpow(fac[i],MOD-2)%MOD;
}

    vector<int> x;

    for(int i = 2; i*i <= m ;i++){
        if(m%i == 0){
            x.pb(0);
            while(m%i == 0){
                x[x.size()-1]++;
                m /= i;
            }
        }
    }
    if(m != 1){
        x.pb(1);
    }

    //for(int i : x) cout << i << " " ;cout << endl;


    int ans = 1;
    for(int i : x){
        ans *= COM(i + n -1, i);
        ans %= MOD;
    }

    cout << ans << endl;
    
    return 0;
}
//g++ -std=c++14 code1.cpp



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 998244353;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll dp[3003][3003]; // dp[i][j] := i番目まで見て合計値がjとなるような部分集合全てについて
// それを含む数の個数

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=s;j++){
            // a[i]を使わない場合はそれを含む集合に入れる入れないの
            // 2通りあるのでdp[i+1][j]
            dp[i+1][j] += dp[i][j] * 2 % mod;
            if(j-a[i]>=0)dp[i+1][j] += dp[i][j-a[i]];
            dp[i+1][j] %= mod;
        }
    }
    cout << dp[n][s] << endl;
}

Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
cin>>A>>B;
vector<int>H(13);
H={2,3,4,5,6,7,8,9,10,11,12,13,1};
for(int i=0; i<13; i++){
    if(A==H.at(i)){
        A=i;
        break;
    }
}
for(int i=0; i<13; i++){
    if(B==H.at(i)){
        B=i; 
        break;
    }
}
if(A>B){
    cout<<"Alice"<<endl;
}
else if(B>A){
    cout<<"Bob"<<endl;
}
else
{
    cout<<"Draw"<<endl;
}

}


Measured memory_bytes: 3632
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	static boolean dp[] = new boolean[20*2000];	
	static int [] F;
	public static void main(String[] args) {
		int m = sc.nextInt();
		F = new int[50];
		cout(fib(m));
	}
	
	public static int fib(int n){
		if(n==0 || n== 1 ) return F[n] = 1;
		if(F[n]!=0) return F[n];
		return F[n] = fib(n-1) + fib(n-2);
	
	}
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
}

Measured memory_bytes: 26320
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,m;
int v[22][22];
char maze[22][22];
int res=0;
bool check(int x,int y){
	if(maze[x][y]=='.'&&!v[x][y]) return 1;
	return 0;
}
void bfs(int now){
	rb(i,1,n)
		rb(j,1,m) v[i][j]=0;
	queue<mp> q;
	q.push(II(now,0));
	while(!q.empty()){
		int now_=q.front().FIR,step=q.front().SEC;
		q.pop();
		res=max(res,step);
		int x,y;
		x=now_/100,y=now_%100;
		if(v[x][y]) continue;
		v[x][y]=1;
		if(x!=1){
			if(check(x-1,y)){
				q.push(II((x-1)*100+y,step+1));
			}
		}
		if(x!=n){
			if(check(x+1,y)){
					q.push(II((x+1)*100+y,step+1));
			}
		}
		if(y!=1){
			if(check(x,y-1)){
					q.push(II((x)*100+y-1,step+1));
			}
		}
		if(y!=m){
			if(check(x,y+1)){
					q.push(II((x)*100+y+1,step+1));
			}
		} 
	}
}
int main(){
	cin>>n>>m;
	rb(i,1,n)
		rb(j,1,m) cin>>maze[i][j];
	rb(i,1,n)
		rb(j,1,m){
			if(maze[i][j]=='.')
			bfs(i*100+j);
		}
		cout<<res;
	return 0;	
}


Measured memory_bytes: 256
n = int(input())
x = []
y = []
h = []

for i in range(n):
	xtemp, ytemp, htemp = map(int, input().split())
	x.append(xtemp)
	y.append(ytemp)
	h.append(htemp)
H = 1000000000

for i in range(0, 101):
	for j in range(0, 101):
		for k in range(n):
			if h[k] != 0:
				H = h[k] + abs(i - x[k]) + abs(j - y[k])
				break
		count = 0
		for k in range(n):
			if h[k] == max(H - abs(i - x[k]) - abs(j - y[k]), 0):
				count += 1
			else:
				break
		if count == n:
			print(i, j, H)
			exit()


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

int main () {

    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;

    int white = H * W;
    white -= h * W;
    white -= (H - h) * w;

    cout << white << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.pop();
    let ans = solve(s);
    println!("{}", ans);
}

fn solve(s: String) -> u32 {
    s.chars().filter(|c| *c == '1').count() as u32
}


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

using namespace std;

int main()
{
	string s, t;
	char c;
	
	while (getline(cin, s))
	{
		for (string::reverse_iterator it = s.rbegin(); it < s.rend(); it++)
		{
			t.push_back(*it);
		}
		
		printf("%s\n", t.c_str());
	}
	
	return 0;
}

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

typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)


int main()
{
    optimize();
   // tt
    {
        int n, m;
        cin>> n>> m;

        int f[m]={}, k, r, c=0;

        for(int i= 0; i<n; i++)
        {
            cin>> k;
            for(int p=0; p<k; p++)
            {
                cin>> r;
                f[r-1]++;
            }

        }

        for(int i=0; i<m; i++)
        {
            if(f[i]== n)
                c++;
        }

        cout<< c;
        nl;
    }

    return 0;
}



Measured memory_bytes: 3664
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

s = list(ns())
ans = ''
from collections import deque
d=[]

for i in s:
    if i == '0':
        d.append('0')
    elif i == '1':
        d.append('1')
    elif i == 'B' and len(d) > 0:
        d.pop()

print(''.join(d))

Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
string s;
  cin>>s;
  long long int sum=0,i=0;
  while(i<s.length())
  {
  if(s[i]=='1')sum+=1;
   if(s[i]=='2')sum+=2;
   if(s[i]=='3')sum+=3;
   if(s[i]=='4')sum+=4;
   if(s[i]=='5')sum+=5;
     if(s[i]=='6')sum+=6;
     if(s[i]=='7')sum+=7;
     if(s[i]=='8')sum+=8;
     if(s[i]=='9')sum+=9;
    
  i++;}
if(sum%9==0)cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


Measured memory_bytes: 3720
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN=110000;
int n, a[MAXN];
bool check(int k)
{
	long long s=0;
	for (int i=1; i<=k; i++) s+=a[i];
	for (int i=k+1; i<=n; i++)
	{
		if (2*s<a[i]) return 0;
		s+=a[i];
	}
	return 1;
}
int main()
{
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	sort(a+1, a+n+1);
	int l=1, r=n;
	while (l<r)
	{
		int mid=l+r>>1;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n", n-l+1);
	return 0;
}

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

using namespace std;
typedef long long int ll;

ll N,A,B,C,D;
int main() {

  cin>>N>>A>>B>>C>>D;

  bool success = 0;
  for( ll i=0;i<N-1;i++){
    if(A+i*D-(N-1-i)*C >= B && A+i*C-(N-1-i)*D<=B){
      success = 1;
      break;
    }
  }
  if(success)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
    
  
  

  return 0;
}


Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
MOD = 10**9+7

def mint():
    return map(int,input().split())
def lint():
    return map(int,input().split())
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

N = int(input())
x0,y0,t0 = 0,0,0
ans = True
for _ in range(N):
    t,x,y = mint()
    tmp = (t-t0)-(abs(x-x0)+abs(y-y0))
    if not (tmp>=0 and tmp%2==0):
        ans = False
        break
    x0,y0,t0 = x,y,t
judge(ans)

Measured memory_bytes: 74624
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// UnionFind高速
type UnionFind struct {
	d []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.d = make([]int, N)
	for i := 0; i < N; i++ {
		u.d[i] = -1
	}
	return u
}

func (p *UnionFind) root(x int) int {
	if p.d[x] < 0 {
		return x
	}
	p.d[x] = p.root(p.d[x])
	return p.d[x]
}

func (p *UnionFind) unite(x, y int) bool {
	x = p.root(x)
	y = p.root(y)
	if x == y {
		return false
	}
	if p.d[x] > p.d[y] {
		x, y = y, x
	}
	p.d[x] += p.d[y]
	p.d[y] = x
	return true
}

func (p *UnionFind) same(x, y int) bool {
	return p.root(x) == p.root(y)
}

func (p *UnionFind) size(x int) int {
	return -p.d[p.root(x)]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, M := getInt(), getInt()
	u := newUnionFind(N)
	for i := 0; i < M; i++ {
		a, b := getInt()-1, getInt()-1
		u.unite(a, b)
	}
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		x := u.root(i)
		m[x]++
	}
	ans := 0
	for _, e := range m {
		ans = max(ans, e)
	}
	out(ans)
}


Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int x,y;
  cin >> x >> y;
  if(y-2*x>=0 && (y-2*x)%2==0 && 4*x-y>=0 && (4*x-y)%2==0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3636
// Problem : B - 81
// Contest : AtCoder - AtCoder Beginner Contest 144
// URL : https://atcoder.jp/contests/abc144/tasks/abc144_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli t,n,a=0,i;
	cin>>n;
	for(i=1;i<10;i++){
		for(lli j=1;j<10;j++){
			if(i*j==n)
			{
				a=1;
				break;
			}
		}
	}
	if(a==0)
	cout<<"No";
	else
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)
#define FastIO() ios::sync_with_stdio(false), cin.tie(0);
#define IO() freopen("palindrome.in","rw",stdin)
#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long LL;
const int N = 1e4+9, M = 1e2+9, OO = 0x3f3f3f3f,MOD = 1e9 + 7;
int n,d;
char a[N];
LL memo[N][M][2];
LL solve(int i,int sum,bool last)
{
  
  if(i==n) return (sum==0);

  LL &ret = memo[i][sum][last];
  if(~ret) return ret;

  ret = 0;
  int limit=-1;

  if(!last) limit = 9;
  else limit = (a[i]-'0');

  for(int j=0;j<=limit;++j) ret += solve(i+1,(sum+j)%d, last && (j==limit))%MOD;
  

  return ret%MOD;
}
int main()
{
  memset(memo,-1,sizeof memo);
  scanf("%s",a);
  scanf("%d",&d);
  
  n=strlen(a);

  printf("%lld",(solve(0,0,1)-1 + MOD)%MOD ); 

  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}



Measured memory_bytes: 18048
k,a,b=map(int,input().split())
if a+2>=b:print(k+1)
elif a>=k:print(k+1)
else:
    k-=(a-1)
    ans=a+(b-a)*(k//2)
    if k%2==1:print(ans+1)
    elif k%2==0:print(ans)


Measured memory_bytes: 2940
n, m = map(int, input().split())
ps = [input().split() for _ in range(m)]
res = [[0,0] for _ in range(n)]
for p,s in ps:
    if s =="WA":
        if res[int(p)-1][0] != int(1):
            res[int(p)-1][1] += 1
    else:
        res[int(p)-1][0] = 1
ans = 0
pen = 0
for f,w in res:
    if f==1:
        ans+=1
        pen += w
print(str(ans) +" "+str(pen))

Measured memory_bytes: 81880
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, m, k = ns()

    for i in range(m + 1):
        for j in range(n + 1):
            if (m-i)*j+(n-j)*i==k:
                print("Yes")
                exit(0)

    print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5332
# include <bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# pragma GCC target("avx2")
# pragma GCC optimize("O3")
# pragma GCC optimize("unroll-loops")
# define int long long

using namespace std;

const int N = 3e3 + 7;
const int mod = 1e7;

int dp[N][N];
string s, t;

void rec( int n, int m ) {
    if ( n == 0 || m == 0 ) {
        return;
    }
    if ( dp[n][m] != -1 ) {
        return;
    }
    if ( s[n - 1] == t[m - 1] ) {
        rec( n - 1, m - 1 );
        dp[n][m] = max( dp[n][m], dp[n - 1][m - 1] + 1 );
    }
    rec( n - 1, m );
    rec( n, m - 1 );
    rec( n - 1, m - 1 );
    dp[n][m] = max( { dp[n][m], dp[n - 1][m], dp[n][m - 1], dp[n - 1][m - 1] } );
}

int32_t main() {
    speed;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    for ( int i = 0; i <= n; i++ ) {
        for ( int j = 0; j <= m; j++ ) {
            dp[i][j] = -1;
        }
    }
    for ( int i = 0; i <= m; i++ ) {
        dp[0][i] = 0;
    }
    for ( int j = 0; j <= n; j++ ) {
        dp[j][0] = 0;
    }
    rec( n, m );
    string ans;
    while ( n > 0 && m > 0 ) {
        if ( s[n - 1] == t[m - 1] ) {
            ans += s[n - 1];
            n--;
            m--;
        }
        else {
            if ( dp[n - 1][m] >= dp[n][m - 1] ) {
                n--;
            }
            else {
                m--;
            }
        }
    }
    reverse( ans.begin(), ans.end() );
    cout << ans;
}


Measured memory_bytes: 74636
#include <iostream>
typedef long long ll;
using namespace std;

int main()
{
  int N;

  cin >> N;

  string S[N];

  for (int i = 0; i < N; i++)
    cin >> S[i];

  int ans[4] = {0, 0, 0, 0};
  string res[4] = {"AC", "WA", "TLE", "RE"};
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 4; j++)
      if (S[i].compare(res[j]) == 0)
      {
        ans[j]++;
        break;
      }
  }

  cout << "AC x " << ans[0] << endl;
  cout << "WA x " << ans[1] << endl;
  cout << "TLE x " << ans[2] << endl;
  cout << "RE x " << ans[3] << endl;
}


Measured memory_bytes: 5556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int min = 1000000,max = -1000000;
		long total = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n ; i++) {
			int x = sc.nextInt();
			if(x < min)min = x;
			if(max < x)max = x;
			total = total + x;
		}
		System.out.println(String.format("%d %d %d",min,max,total));
	}
}


Measured memory_bytes: 42340
#include<cstdio>
#include<algorithm>
#define rg register
#define N 200010
using namespace std;
int n,m,ans[N];
struct rec{
	int pos,val;
}a[N];
inline int read(){
	int k=0,f=1; char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
inline bool cmp(rec a,rec b){
	return a.val<b.val;
}
int main(){
	n=read();
	for(rg int i=1;i<=n;i++) a[i].val=read(),a[i].pos=i;
	sort(a+1,a+1+n,cmp);
	for(rg int i=1;i<=n/2;i++) ans[a[i].pos]=a[n/2+1].val;
	for(rg int i=n/2+1;i<=n;i++) ans[a[i].pos]=a[n/2].val;
	for(rg int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0; 
} 

Measured memory_bytes: 4480
# coding: utf-8
# Your code here!

N = input()
L = input().split(' ')

l = len(L)
L = [int(s) for s in L]
L.sort()
  
a = 0
for i in range(l - 2):
    for j in range(i + 1, l - 1):
        for k in range(j + 1, l):
            if (L[i] + L[j]) > L[k]:
                if (L[i] != L[j]) and (L[k] != L[j]) and (L[i] != L[k]):
                    a += 1
print(int(a))

Measured memory_bytes: 9208
// ------!!! I AM A PROFESSIONAL!! !!!------ //
#include <bits/stdc++.h>
using namespace std;
int N, Q, a, b, x, dp[5009][5009];
int main() {
	scanf("%d%d", &N, &Q);
	while(Q--) {
		scanf("%d%d%d", &a, &b, &x); a--, b--, x++;
		dp[a][b] = max(dp[a][b], x);
	}
	int ret = dp[0][0] ? 1 : 0;
	for(int i = 1; i < N; i++) {
		for(int j = 0; j <= i; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
			if(j) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] - 1);
			if(dp[i][j]) ret++;
		}
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 69928
#include <iostream>
#include <iomanip>

int main() {
    
    int a,b,d,r;
    double f;
    
    std::cin >> a >> b;
    d = a / b;
    r = a % b;
    f =  static_cast<double>(a) / static_cast<double>(b);
    
    std::cout << std::fixed;
    std::cout << std::setprecision(6) << d << " " << r << " " << f << "\n";
    
    return 0;
}


Measured memory_bytes: 3292
(stdin => {
  // Define Function
  const hour = v => Math.floor(v / (60 * 60))
  const minute = v => Math.floor((v % (60 * 60)) / 60)
  const Second = v => v % 60

  // Declare Variable
  const inputs = stdin.toString().trim().split('\n')
  const time = parseInt(inputs[0], 10)

  console.log([hour(time), minute(time), Second(time)].join(':'))
})(require('fs').readFileSync('/dev/stdin', 'utf8'))



Measured memory_bytes: 15356
num = []
A = 0
B = 0
count = int(input())
list = input().split()
for i in range(count):
    num.append(int(list[i]))
num = sorted(num, reverse = True)

while num != []:
    A += num.pop(0)
    if num != []:
        B += num.pop(0)

print(A - B)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
//setprecision(12)
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> v(n);
    map<int, int> m;
    int fir = 0;
    rep(i, n) {
        cin >> v[i];
        m[v[i]]++;
        if(v[i]==1) fir++;
    }
    int ans = 0;
    if(fir==1) ans++;
    rep(k, n) {
        int tmp = pow(v[k], 0.5) + 1;
        bool flag = true;
        for (int i = 1; i < tmp; i++) {
            if (v[k] % i == 0) {
                if (m[i] > 0) flag = false;
                if (i != v[k] / i) {
                    if (i == 1) {
                        if (m[v[k] / i] > 1) flag = false;
                    }
                    else {
                        if (m[v[k] / i] > 0) flag = false;
                    }
                }
            }
        }
        if (flag) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 33576
#include <iostream>

using namespace std;

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

int main() {
  int N, X;
  cin >> N >> X;
  int D[100100];
  cout << endl;
  // cout << "-------" << endl;
  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    D[i] = abs(X-num);
    // cout << D[i] << endl;
  }
  // cout << "-------" << endl;
  int ans = D[0];
  for (int i = 1; i < N; i++) {
    // cout << "D[i] " << D[i] << " D[i+1] " << D[i+1] << endl;
    ans = gcd(ans, D[i]);
  }
  cout << ans << endl;
}


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

int main() {
  int x;
  cin >> x;
  if(x==2){
    cout << 2 << endl;
    return 0;
  }
  vector<int> p={2};
  for(int i=3;i<x;i++){
    int cou=0;
    for(int j=0;j<p.size();j++){
      if(i%p.at(j)!=0)
        cou++;
    }
    if(cou==p.size())
      p.push_back(i);
  }
  for(int i=x;i<2*x;i++){
    int cou=0;
    for(int j=0;j<p.size();j++){
      if(i%p.at(j)!=0)
        cou++;
    }
    if(cou==p.size()){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

bool chk(int l,int a[],int n,int k)
{
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=((a[i]-1)/l);
    }
    if(sum<=k)
        return true;
    else
        return false;
}

void solve()
{
    int n,k;cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    int l=1,u=*max_element(a,a+n);
    int ans=u;
    while(l<=u)
    {
        int mid=(l+u)/2;
        if(chk(mid,a,n,k))
        {
            ans=mid;
            u=mid-1;
        }
        else
            l=mid+1;
    }
    cout<<ans<<nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if(d > 0 && d * d > 4 * a * b){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  
  vector<int> vec(n + 1);
  for(int i = 0;i < n + 1;i ++){
    vec.at(i) = 1;
  }
  
  for(int i = 0;i < m;i ++){
    int kari;
    cin >> kari;
    vec.at(kari) = 2;
  }
  
  int zerocount = 0;
  
  for(int i = 0;i < x;i ++){
    if(vec.at(i) == 2)zerocount ++;
  }
  
  int saigocount = 0;
  
  for(int i = x + 1;i < n + 1;i ++){
    if(vec.at(i) == 2)saigocount ++;
  }
  
  cout << min(zerocount,saigocount) << endl;
}

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

using namespace std;



int main()
{
	string s;
	cin >> s;

	int n;
	n = s.size();

	for (int i = 0;i < n;i++)
	{
		if ((i + 1) % 2 != 0)
		{
			cout << s[i];
		}
	}

	cout << endl;
	return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            long n = long.Parse(Console.ReadLine());
            long[] a = new long[5];
            long aMin = (long)Math.Pow(10, 15) + 1;
            for (int i=0; i<5; i++)
            {
                a[i] = long.Parse(Console.ReadLine());
                aMin = Math.Min(aMin, a[i]);
            }
            Console.WriteLine((n - 1) / aMin + 5);
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 11092
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())
    
import collections
c = collections.Counter(A)
startsum = sum(A)
for i in range(Q):
    Bcount = c[B[i]]
    c[B[i]] = 0
    Ccount = c[C[i]]
    c[C[i]] += Bcount
    startsum += (C[i]-B[i])*Bcount
    print(startsum)

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

const int INF = 1001001001;
//const ll INF = 1000000000000000000;

ll a, b, v, w, t;

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

	int ans = a + a*a + a*a*a;
	cout << ans << endl;
	return 0;
}


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

int main(){
 string a,b;
  cin>>a>>b;
  int c,d;
  c=a.size();
  d=b.size();
  for(int i=0;i<d;i++){
    cout<<a[i]<<b[i];
  }
  if(c!=d){
    cout<<a[d];
  }
       cout<<endl;
}


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

int main() {
  int x;
  cin >> x;
  if(x == 1){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }

  return(0);
}

Measured memory_bytes: 3592
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {
	static int id;
	static String S;
	static int V;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			S = sc.next();
			if(S.equals("#")) break;
			boolean ans = true;
			for(V = 0; V < (1 << 12); V++) {
				id = 0;
				ans &= equation();
				if(!ans) break;
			}
			System.out.println(ans?"YES":"NO");
		}
	}
	static boolean equation() {
		boolean a = formula();
		id++;
		boolean b = formula();
		return a == b;
	}
	static boolean formula() {
		if(S.charAt(id) == 'T') {
			id++;
			return true;
		}
		if(S.charAt(id) == 'F') {
			id++;
			return false;
		}
		for(int i = 0; i < 12; i++) {
			
			if(S.charAt(id) == (char)('a' + i)) {
				id++;
				return (V & (1 << i)) != 0;
			}
			
		}
		if(S.charAt(id) == '-') {
			id++;
			return !formula();
		}
		if(S.charAt(id) == '(') {
			id++;
			boolean A = formula();
			char B = S.charAt(id);
			if(B == '-') {
				id++;
			}
			id++;
			boolean C = formula();
			id++;
			if(B == '-') {
				if(A && !C) return false;
				return true;
			}
			if(B == '+') {
				return A | C;
			}
			if(B == '*') {
				return A & C;
			}
		}
		return true;
		
		
	}
 }

Measured memory_bytes: 33056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(k <= a) cout << k << endl;
	else if(k<= a+b)cout << a << endl;
	else cout << a-(k-a-b) << endl;

	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<algorithm>
using std::max;
inline void umx(int &a,int b){a=max(a,b);}
using std::min;
inline void umn(int &a,int b){a=min(a,b);}
const int MAXN=2e5+5,MAXS=3e5+5;

int n,V,K,v[MAXN];int na[MAXN];
int L[MAXN][20],R[MAXN][20];
int f[MAXS],g[MAXS];
int seq[MAXN];

int main()
{
	int i,k,x;scanf("%d%d",&n,&V);
	for(i=1;i<=n;i++) scanf("%d",na+i);

	v[0]=V;while(v[K]) v[++K]=v[K-1]>>1;

	for(k=0;k<=K;k++)
	{
		for(i=x=1;i<=n;i++)
			L[i][k]=x=(i>1&&na[i]-na[i-1]>v[k])?i:x;
		for(i=x=n;i;i--)
			R[i][k]=x=(i<n&&na[i+1]-na[i]>v[k])?i:x;
		R[n+1][k]=n+1;
	}

	std::fill(g,g+(1<<K),n+1);
	for(int S=1;S<1<<K;S++)
		for(i=1;i<=K;i++)
			if((S>>i-1)&1)
				umx(f[S],R[f[S^(1<<i-1)]+1][i]),
				umn(g[S],L[g[S^(1<<i-1)]-1][i]);

	for(int S=0,msk=(1<<K)-1;S<1<<K;S++)
	{
		int l=L[g[S]-1][0],r=R[f[msk^S]+1][0];
		if(l<=r) seq[l]++,seq[r+1]--;
	}

	for(i=1;i<=n;i++) seq[i]+=seq[i-1];
	for(i=1;i<=n;i++) puts(seq[i]?"Possible":"Impossible");
	return 0;
}


Measured memory_bytes: 37376
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>
#include <bitset>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct S {
    int l,r,pos;
};

// 1-indexed
template <typename T=int>
struct BIT {
    const int n;
    vector<T> v;

    BIT(int n): n(n), v(n+1,0) {}

    void add(int i, int x) {
        ++i;
        while (i <= n) {
            v[i] += x;
            i += i & -i;
        }
    }
    T sum(int i) {
        ++i;
        T ret = 0;
        while (i > 0) {
            ret += v[i];
            i -= i & -i;
        }
        return ret;
    }
    T sum(int l, int r) {
        return sum(r) - sum(l-1);
    }
};

void solve() {
    int n,q,l,r;
    cin >> n >> q;
    VI c(n);
    REP(i,0,n) cin >> c[i];
    REP(i,0,n) --c[i];
    vector<S> qs(q);
    REP(i,0,q) {
        cin >> l >> r;
        qs[i].l = --l;
        qs[i].r = --r;
        qs[i].pos = i;
    }
    sort(all(qs),[](auto &l, auto &r) {
        if (l.r == r.r) return l.l < r.l;
        return l.r < r.r;
    });

    VI gs(n,-1);
    VI ans(q);
    BIT<> bit(n);
    int idx = 0;
    REP(p,0,q) {
        while (idx <= qs[p].r) {
            if (gs[c[idx]] != -1) {
                bit.add(gs[c[idx]], -1);
            }
            gs[c[idx]] = idx;
            bit.add(idx,1);
            ++idx;
        }
        ans[qs[p].pos] = bit.sum(qs[p].l, qs[p].r);
    }

    REP(i,0,q) {
        cout << ans[i] << endl;
    }
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 17376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  set<string> se;
  for(int i = 0;i < n;i++){
    string s;
    cin >> s;
    se.insert(s);
  }
  cout << se.size() << endl;
  return 0;
}





Measured memory_bytes: 19204
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>

#define ll long long
#define pll pair<ll, ll>

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

const int INF = 1111111111;
const double EPS = 1e-9;

using namespace std;

void init()
{
}

void solve()
{
	rep(i, 5)
	{
		int a;
		cin >> a;
		if (a == 0)
		{
			cout << i + 1 << endl;
		}
	}
}

int main()
{
	init();
	solve();
}


Measured memory_bytes: 3156
import math
def gcd(a,b): 
    if(b==0): 
        return a 
    else: 
        return gcd(b,a%b) 

    
n = int(input())
d = {'AC':0, 'WA': 0, 'TLE': 0, 'RE': 0 }
for i in range(n):
    s = str(input())
    d[s]+=1
print('AC x', d['AC'])
print('WA x', d['WA'])
print('TLE x', d['TLE'])
print('RE x', d['RE'])


Measured memory_bytes: 74808
h, w = [int(i) for i in input().split()]
while h or w:
    for i in range(h):
        li = ["." if i % 2 else "#"]
        for _ in range(w - 1):
            li.append("#" if li[-1] == "." else ".")
        print("".join(li))
    print()
    h, w = [int(i) for i in input().split()]



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

int main(){

  string a,b,c;
  cin >> a >> b >> c;
  
  if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
  	cout << "YES";
  }else{
  	cout << "NO";
  }
  return 0;
}


Measured memory_bytes: 256