akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int n;
  while (scanf("%d", &n) == 1) {
    int s = 0;
    while (n) {
      s += n % 10;
      n /= 10;
    }
    if (s == 1) s += 9;
    printf("%d\n", s);
  }

  return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
//#define int long long

const long long infl = 1e18; 
const int N = 1e6 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N], d[N][2];
string s;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	reverse(all(s));
	for (int i = 0; i < N; i++) d[i][0] = d[i][1] = inf;
	for (int i = 0; i <= s.size(); i++){
		if (i == 0){
			int x = s[i] - '0';
			for (int j = 0; j <= 9; j++){
				if (j < x){
					d[i][1] = min(j + (10 + j - x), d[i][1]);
				}
				else{
					d[i][0] = min(j + (j - x), d[i][0]);
				}
			}
		}
		else if (i < s.size()){
			int x = s[i] - '0', val0 = d[i - 1][0], val1 = d[i - 1][1];
			for (int j = 0; j <= 9; j++){
				if (j < x){
					d[i][1] = min(j + (10 + j - x) + val0, d[i][1]);
				}
				else{
					d[i][0] = min(j + (j - x) + val0, d[i][0]);
				}
			}
			x++;
			for (int j = 0; j <= 9; j++){
				if (j < x){
					d[i][1] = min(j + (10 + j - x) + val1, d[i][1]);
				}
				else{
					d[i][0] = min(j + (j - x) + val1, d[i][0]);
				}
			}
		}
		else{
			/*for (int j = 0; j < s.size(); j++){
				cout << d[j][0] << " " << d[j][1] << endl;
			}
			return 0;*/
			int ans = min(d[i - 1][0], d[i - 1][1] + 1);		
			cout << ans;
			return 0;
		}
	}
	return 0;
}












Measured memory_bytes: 9500
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

N, K = map(int, inp().split())
R, S, P = map(int, inp().split())
T = inpS()

d = {"r":P, "s":R, "p":S} # じゃんけんで勝点数
ans = 0
wins = [False]*K
for i in range(len(T)):
  if not wins[i%K] or T[i-K] != T[i]:
    ans += d[T[i]]
    wins[i%K] = True
  else:
    wins[i%K] = False
print(ans)    

Measured memory_bytes: 3892
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

# 値を1増やす、符号反転でXをYにする
X, Y = getNM()

# 符号反転する回数はたかだか１回
opt_plus = abs(Y - X) if Y >= X else abs(Y - X) + 2
opt_minus = abs(Y - (-X)) + 1

print(min(opt_plus, opt_minus))

Measured memory_bytes: 78056
#include<bits/stdc++.h>
using namespace std;
map<long long,long long>p;
long long n,a[200000+100],sum,ans;
int main()
{
	cin>>n;p[0]=1;
	for (int i=1; i<=n; ++i)
	{
		cin>>a[i];
		sum+=a[i];
		ans+=p[sum];
		p[sum]++;
	}
	cout<<ans;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  int A, B;
  cin >> N >> A >> B;
  int a, b;
  a = A%N;
  b = B%N;
  if (a == 0 || b == 0 || (A/N != B/N)){
    cout << "OK" << endl;
  }
  else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a >> b >> c;
	if (a <= b&&b <= c){
		cout << a <<" "<< b <<" "<< c << endl;
	}
	else if (a <= c&&c <= b){
		cout << a <<" "<< c <<" "<< b <<endl;
	}
	else if (b <= a&&a <= c){
		cout << b <<" "<< a <<" "<<c<< endl;
	}
	else if (b <= c&&c <= a){
		cout << b <<" "<< c <<" "<< a << endl;
	}
	else if (c <= a&&a <= b){
		cout << c <<" "<< a <<" "<< b << endl;
	}
	else if (c <= b&&b <= a){
		cout << c <<" "<< b <<" "<< a << endl;
	}
	return 0;
}

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

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

Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    S = input()
    if len(S)%2!=0:
        return "No"
    for i in range(len(S)//2):
        t = i*2
        if S[t:t+2] != "hi":
            return "No"
    return "Yes"

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

std::vector<std::pair<int, int>> ab;
int main() {
	ll cnt = 0;
	ll pos = -INF;
	in(int, n, m);
	loop(i, m){
		in(int, t1, t2);
		ab.push_back({t1, t2});
	}
	sort(ab.begin(), ab.end(), [](const auto& a, const auto& b){ return a.second < b.second;});
	for(auto p : ab){
		//cout << "p.first = " << p.first << ", p.second= " << p.second << ", pos = " << pos << ", cnt = " << cnt << endl;
		if(p.first > pos){
			pos = p.second-1;
			++cnt;
		}
	}
	out(cnt);
}



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


int main() {
  int b[3][3];
  for(int i=0;i<3;i++){
    for(int k=0;k<3;k++){
      cin >> b[i][k];
    }
  }
  int ans[6];
  memset(ans,0,sizeof(ans));
  int n;
  cin >> n;
  for(int p=0;p<n;p++){
    int a;
    cin >> a;
    for(int i=0;i<3;i++){
      for(int k=0;k<3;k++){
        if(a==b[i][k]){
          b[i][k] = 0;
          ans[i]++;
          ans[k+3]++;
        }
      }
    }
  }
  int naname[2];
  memset(naname,0,sizeof(naname));
  naname[0] = b[0][0]+b[1][1]+b[2][2];
  naname[1] = b[0][2]+b[1][1]+b[2][0];

  for(int i=0;i<6;i++) 
    if(ans[i] == 3 || naname[0]==0||naname[1]==0){
      cout << "Yes" << endl;
      return 0;
    }

  cout << "No" <<endl;
  return 0;

}


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

int main() {
	int k;
	cin >> k;
	queue<ll> q;
	rep(i, 9) q.push(i+1);
	int cnt = 0;
	while(1) {
		ll now = q.front();
		q.pop();
		cnt++;
		if(cnt == k) {
			cout << now << endl;
			break;
		}
		for(int i = -1; i <= 1; i++) {
			int d = now%10 + i;
			if(d >= 0 && d <= 9) q.push(now*10+d);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = 1
i = 0
cnt = 0
while i < n-1:
    if A[i] == A[i+1]:
        ans *= A[i]
        i += 2
        cnt += 1
    else:
        i += 1
    if cnt == 2:
        print(ans)
        exit(0)
print(0)


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

inline std::string to_binString(int val)
{
    if( !val )
        return std::string("0");
    std::string str;
    while( val != 0 ) {
        if( (val & 1) == 0 )  // val は偶数か？
            str.insert(str.begin(), '0');  //  偶数の場合
        else
            str.insert(str.begin(), '1');  //  奇数の場合
        val >>= 1;
    }
    return str;
}

std::vector<std::string> my_split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main() {

    string s;

    cin >> s;

    long long int ans = 0;

    for(int loop=0; loop < (1<<s.size()-1); loop++){

        string split_point = "";

        string bin_str = to_binString(loop);
        
        for(int i=0; i<static_cast<int>(s.size()) -1 - static_cast<int>(bin_str.size()); i++){
            split_point += '0';
        }

        split_point += bin_str;

        string culc = "";

        for(int i=0; i<s.size(); i++){
            culc += s[i];
            if(split_point[i] == '1'){
                culc += '.';
            }
        }

        vector<string> formulas = my_split(culc,'.');

        long long int sum = 0;

        for(int i=0; i<formulas.size(); i++){
            stringstream ss;
            ss << formulas[i];
            long long int tmp = 0;
            ss >> tmp;
            sum += tmp;
        }

        ans += sum;

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
const int MOD=998244353;
int K,w[2][SZ]; ll rv;
inline ll qp(ll a,ll b)
{
    ll ans=1; a%=MOD;
    while(b)
    {
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD; b>>=1;
    }
    return ans;
}
inline void fftinit(int n)
{
    for(K=1;K<n;K<<=1);
    w[0][0]=w[0][K]=1;
    ll g=qp(3,(MOD-1)/K);
    for(int i=1;i<K;i++) w[0][i]=w[0][i-1]*g%MOD;
    for(int i=0;i<=K;i++) w[1][i]=w[0][K-i];
    rv=qp(K,MOD-2);
}
inline void fft(int* x,int v)
{
    for(int i=0;i<K;i++) (x[i]<0)?(x[i]+=MOD):0;
    for(int i=0,j=0;i<K;i++)
    {
        if(i>j) swap(x[i],x[j]);
        for(int l=K>>1;(j^=l)<l;l>>=1);
    }
    for(int i=2;i<=K;i<<=1)
        for(int l=0;l<i>>1;l++)
        {
            register int W=w[v][K/i*l],*p=x+l+(i>>1),*q=x+l,t;
            for(register int j=0;j<K;j+=i)
            {
                p[j]=(q[j]-(t=(ll)p[j]*W%MOD)<0)?(q[j]-t+MOD):(q[j]-t);
                q[j]=(q[j]>=MOD-t)?(q[j]-MOD+t):(q[j]+t);
            }
        }
    if(!v) return;
    for(int i=0;i<K;i++) x[i]=x[i]*rv%MOD;
}
#define SZ 666666
int f[233][8888],a[16388],b[16388];
ll fac[SZ],rfac[SZ];
int main()
{
	fac[0]=1;
	for(int i=1;i<SZ;++i) fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i) rfac[i-1]=rfac[i]*i%MOD;
	fftinit(16000); f[0][0]=1;
	for(int j=1;j<=8003;++j) b[j]=rfac[j+2];
	fft(b,0);
	for(int i=1;i<=200;++i)
	{
		for(int k=0;k<K;++k) a[k]=0;
		for(int k=0;k<=8003;++k)
			a[k]=f[i-1][k]*(ll)rfac[k]%MOD;
		fft(a,0);
		for(int k=0;k<K;++k) a[k]=a[k]*(ll)b[k]%MOD;
		fft(a,1);
		for(int k=0;k<=8003;++k)
			f[i][k]=
			(f[i-1][k]*(ll)(((k+1)*(ll)k/2+1)%MOD)
			+a[k]*(ll)fac[k+2])%MOD;
	}
	int n,m;
	cin>>n>>m;
	ll ans=0;
	for(int i=0;i<=n;++i)
		ans+=f[m][i]*(ll)fac[n]%MOD*rfac[i]%MOD*rfac[n-i]%MOD;
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}


Measured memory_bytes: 22784
IDENTIFICATION DIVISION.
PROGRAM-ID. 161A.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(20).
01 X          PIC 9(3).
01 Y          PIC 9(3).
01 Z          PIC 9(3).
01 I          PIC 9(2).
01 J          PIC 9(2).
01 P          PIC 9(2).
01 ED.
   03 A       PIC ZZ9.
   03 FIILER  PIC X VALUE SPACE.
   03 B       PIC ZZ9.
   03 FIILER  PIC X VALUE SPACE.
   03 C       PIC ZZ9.
   03 FIILER  PIC X VALUE SPACE.
01 OUT        PIC X(12).
*>
PROCEDURE DIVISION.
  ACCEPT INP.
*>
  UNSTRING INP DELIMITED BY ' '
      INTO X Y Z.
  MOVE X TO B.
  MOVE Y TO C.
  MOVE Z TO A.
*>
  MOVE SPACE TO OUT.
  MOVE 1 TO P.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > 3
    PERFORM VARYING P FROM P BY 1 UNTIL ED(P:1) <> ' '
    END-PERFORM
    PERFORM VARYING P FROM P BY 1 UNTIL ED(P:1) = ' '
        ADD 1 TO J 
        MOVE ED(P:1) TO OUT(J:1)
    END-PERFORM
    ADD 1 TO J
    MOVE ' ' TO OUT(J:1)
  END-PERFORM
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.


Measured memory_bytes: 764
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(K: int):
    l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(l[K-1])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main(){
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    vector<bool>dp(k+1,false);
    dp[0]=false;
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i-a[j]>=0) dp[i]=dp[i]||!dp[i-a[j]];
        }
    }
    if(dp[k]) cout << "First" <<endl;
    else cout << "Second" <<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	N, K := nextInt(), nextInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = nextInt()
	}
	sort.Ints(h)
	result := h[N-1]
	for i := 0; i < N-K+1; i++ {
		if result > h[i+K-1]-h[i] {
			result = h[i+K-1] - h[i]
		}
	}
	fmt.Println(result)
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}
int n,tak,aok;
vector<set<int>> v;
vector<int> tak_dis;
vector<int> aok_dis;
vector<int> ans_vec;
void Init(){
  v.resize(n);
  tak_dis.resize(n);
  aok_dis.resize(n);
  ans_vec.resize(n);
}

void Bfs(int s,bool isT){
  bitset<100010> bs;
  queue<P<int,int>> que;
  que.push({s,0});
  while(!que.empty()){
    int now = que.front().first;
    int dis = que.front().second;
    bs[now] = 1;
    if(isT)tak_dis[now] = dis;
    else aok_dis[now] = dis;
    que.pop();
    for(auto&e:v[now]){
      if(bs[e])continue;
      bs[e] = 1;
      que.push({e,dis+1});
    }
  }
}


int Bfs2(int s){
  int ans = 0;
  bitset<100010> bs;
  queue<P<int,int>> que;
  que.push({s,0});
  while(!que.empty()){
    int now = que.front().first;
    int dis = que.front().second;
    ans_vec[now] = dis;
    ChangeMax(ans,aok_dis[now]);
    que.pop();
    debug(now+1);
    debug(dis);
    debug(tak_dis[now]);
    debug(aok_dis[now]);
    bs[now]=1;
    if(tak_dis[now]==aok_dis[now])continue;
    for(auto&e:v[now]){
      if(tak_dis[e]>aok_dis[e])continue;
      if(bs[e])continue;
      bs[e] = 1;
      que.push({e,dis+1});
    }
  }
  return ans;
}


int main(){
  cin >> n >> tak >> aok; tak--; aok--;
  Init();
  for(int i = 1; i < n; ++i){
    int a,b; cin >> a >> b; a--; b--;
    v[a].insert(b);
    v[b].insert(a);
  }
  dline;
  Bfs(tak,true);
  dline;
  Bfs(aok,false);
  dline;
  cout << Bfs2(tak)-1 << endl;
  return 0;
}


Measured memory_bytes: 17664
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void) {
    int i;
    unsigned long sum = 0;
    int k, n;
    int h[200000];

    scanf("%d%d", &n, &k);

    for (i = 0; i < n; i++)
        scanf("%d", &h[i]);

    qsort(h, n, sizeof(int), asc);

    for (i = 0; i < n - k; i++)
        sum += h[i];

    printf("%lu\n", sum);

    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

int main()
{	
    ll n, m, x;
    cin >> n >> m >> x;
    vector<vector<ll>> v(n, vector<ll>(m));
    vector<ll> c(n);
    REP(i, n){
        cin >> c[i];
        REP(j, m){
            cin >> v[i][j];
        }
    }
    ll ans = INF;

    //bit全探索
    for(int bit = 0; bit < (1<<n); bit++){  //ex)n = 8のときは'00000000'から'11111111'まで探索
        vector<ll> sum(m);                  //理解度を合計した値を入れる配列
        ll cost = 0;                        //コストの合計値
        REP(i, n){                          //0からi bitまで
            if(bit & (1<<i)){               //bitが立っているかの判定
                cost += c[i];               //bitが立っていれば買っているのでコストを足す
                REP(j, m){                  
                    sum[j] += v[i][j];      //それぞれの理解度を足す
                }
            }
        }
        bool ok = true;                     //理解度がx以上か判定する用のbool
        REP(i, m){              
            if(sum[i] < x) ok = false;      //それぞれの理解度がx以上かの判定
        }
        if(ok) ans = min(ans, cost);        //x以上ならばコストを更新
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    
    int count = 0;
    for (size_t i = 0; i < s.length(); ++i)
    {
        if (s[i] != t[i]) count++;
    }
    
    cout << count;
    return 0;
}


Measured memory_bytes: 3920
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int x[10];

    for (int i = 0; i < 10; i++)
      cin >> x[i];

    sort(x, x+10);

    for (int i = 0; i < 3; i++)
      cout << x[9-i] << endl;

    return 0;
}

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

using namespace std;

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

    int ans = 0;
    int tmin = 200;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ans += a;
        if (a % 10 != 0) tmin = min(a, tmin);
    }

    if (tmin == 200) tmin = ans;
    if (ans % 10 == 0) ans -= tmin;
    
    cout << ans << endl;
    return 0;
}


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

class UnionFindTree {
private:
    vector<int> parent;
    vector<int> count;
public:
    UnionFindTree(int n) : parent(n), count(n, 1) {
        // 最初は全てを根として初期化
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int get_root(const int x) {
        // データxが属する木の根を取得する
        if (parent[x] == x) return x;
        // 取得したものは直接木の根をつなぐ(経路圧縮)
        return parent[x] = get_root(parent[x]);
    }

    void unite(const int x, const int y) {
        // xとyの木を併合する
        int rx = get_root(x);
        int ry = get_root(y);
        // 元から同じ木に属している場合は何もしない
        if (rx == ry) return;
        // xの属する木をyの属する木につける
        parent[rx] = ry;
        count[ry] += count[rx];
        count[rx] = 0;
    }

    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }

    int get_size(const int x) {
        return count[get_root(x)];
    }

    void print() {
        for(auto elm : parent) cout << elm << " ";
        cout << endl;
        for(auto elm : count) cout << elm << " ";
        cout << endl;
    }
};

int main(){
    int n, k, l;
    cin >> n >> k >> l;

    UnionFindTree road_tree(n), rail_tree(n);
    for (auto i = 0; i < k; i++) {
        int p, q; cin >> p >> q; p--; q--;
        road_tree.unite(p, q);
    }
    for (auto i = 0; i < l; i++) {
        int r, s; cin >> r >> s; r--; s--;
        rail_tree.unite(r, s);
    }

//    road_tree.print();
//    rail_tree.print();

    map<int, map<int, int>> root;
    for (auto i = 0; i < n; i++) {
        root[road_tree.get_root(i)][rail_tree.get_root(i)]++;
//        cout << road_tree.get_root(i) << " " << rail_tree.get_root(i) << endl;
    }

    for (auto i = 0; i < n; i++)
        cout << root[road_tree.get_root(i)][rail_tree.get_root(i)] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 31916
h,w,k = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = []
n = 1
cnt = 0
for i in range(h):
    if "#" in S[i]:
        ans = []
        for j in range(w):
            if S[i][j] == "#":
                for _ in range(j+1-len(ans)):
                    ans.append(str(n))
                n += 1
        if len(ans) < w:
            x = ans[-1]
            for _ in range(w-len(ans)):
                ans.append(x)
    if ans:
        for _ in range(i+1-cnt):
            print(" ".join(ans))
            cnt += 1

Measured memory_bytes: 4340
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
int main()
{   long long i,n,cnt=0,ans=0;
    char s[200002];
    scanf("%s",s);
    int a[200002];
    n=strlen(s);
    for(i=0;i<n;i++){
        if(s[i]=='B'){
            a[i]=0;
            cnt++;
        }else{
            a[i]=1;
            ans+=cnt;
        }
    }
    printf("%lld",ans);

    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
#define N 100050
ll ans;
int l[N],r[N],n;
int main() {
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) scanf("%d%d",&l[i],&r[i]);
	sort(l,l+n+1); sort(r,r+n+1);
	for(i=0;i<=n;i++) {
		if(l[n-i]<=r[i]) break;
		ans+=l[n-i]-r[i];
	}
	printf("%lld\n",ans<<1);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
int main()
{
    ll n,m ,sum;
    ll a[10000] ;
    cin>>n>>m;
    sum=0;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i] ;
        sum+=a[i] ;
    }
    if(n>sum)
    {
        cout<<n-sum<<endl;
    }
    else if(n==sum)
        {
        cout<<"0"<<endl;
    }
    else if(sum>n)
          {
        cout<<"-1"<<endl;
    }
    return 0;

}


Measured memory_bytes: 3648
use proconio::input;
use proconio::marker::Chars;
fn main() {
    input!{
        n: usize, s: Chars
    };
    let s:Vec<u8>  = s.iter().map(|&x| (x as u8) - 0x30).collect();
    let mut ans = 0;
    for i in 0..10 {
        for j in 0..10 {
            for k in 0..10 {
                let mut t = 0;
                for &c in &s {
                    if c == match t {
                        0 => i,
                        1 => j,
                        2 => k,
                        _ => 10
                    } {
                        t += 1;
                    }
                    if t == 3 {
                        ans += 1;
                        break;
                    }
                }
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2352
from collections import Counter
n = int(input())
l = [input() for _ in range(n)]

m = int(input())
l2 = [input() for _ in range(m)]

c = Counter(l)
c2 = Counter(l2)


ans = [0]

for k,v in c.items():
    ans.append(v-c2[k])
    
print(max(ans))


Measured memory_bytes: 3316
program main
    integer five,seven
    integer::temp(3)
    five = 0
    seven = 0
    read *,temp
    do i=1,3
        if( temp(i) == 5) then
            five = five + 1
        else if(temp(i) == 7) then
            seven = seven + 1
        end if
    end do
    if ( five == 2 .and. seven == 1) then
        print *,"YES"
    else
        print *,"NO"
    end if
end program main


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

using namespace std;

#define MAX 100000

int main() {
    int n;
    cin >> n;
    int a[MAX];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == i + 1) {
            ++ans;
            if (i < n - 1 && a[i + 1] != i + 1) {
                    int temp;
                    temp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = temp;
            }
            else {
                int temp;
                temp = a[i];
                a[i] = a[i + 1];
                a[i + 1] = temp;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <iostream>
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
ll dp[41][1<<18];
int main()
{
    int n, x, y, z;
    scanf("%d%d%d%d", &n, &x, &y, &z);
    int l = x+y+z-1;
    int mask = (1<<l)-1;
    int limit = (1<<l);
    int ok = (1 << (x+y+z-1)) | (1 << (y+z-1)) | (1 << (z-1));
    dp[0][0] = 1;
    for(int i = 0; i < n; ++i)
    {
        for(int s = 0; s < limit; ++s)
        {
            for(int a = 1; a < 11; ++a)
            {
                int t = (s << a) | (1 << (a-1));
                if ((ok&t) == ok) continue;
                (dp[i+1][t & mask] += dp[i][s]) %= mod;
            }
        }
    }
    ll ans = 1;
    for(int i = 0; i < n; ++i)
        ans = ans * 10 % mod;
    for(int s = 0; s < limit; ++s)
        ans -= dp[n][s];

    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

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

    lint cnt = 0;
    rep(i, N) {
        lint x, y;
        cin >> x >> y;
        if (x * x + y * y <= D * D) cnt++;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3604
program ABC_056_C_GoHome
   implicit none
   integer(8) X, i ,S
   read(*, *) X
   do i = 1, 100000
      S = i * (i + 1) / 2
	  if(S >= X) then
	      write(*, *) i
		  exit
	  end if
   end do
end program ABC_056_C_GoHome

Measured memory_bytes: 256
def tosec(t):
    return int(t[:2])*60*60 + int(t[3:5])*60 + int(t[6:])

while True:
    n = int(input())
    if n == 0: break
    time = [0] * (60*60*24 + 1)

    for _ in range(n):
        s, f = input().split()
        time[tosec(s)] += 1
        time[tosec(f)] -= 1

    ans = time[0]
    for i in range(60*60*24):
        time[i+1] += time[i]
        ans = max(ans, time[i+1])

    print(ans)

Measured memory_bytes: 10804
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def func(N, mod):
    F = [1]
    for i in range(1, N + 1):
        F.append(F[-1] * i % mod)
    return F


INV = {}


def inv(a, mod):
    if a in INV:
        return INV[a]
    r = pow(a, mod - 2, mod)
    INV[a] = r
    return r


def C(F, a, b, mod):
    return F[a] * inv(F[b], mod) * inv(F[a - b], mod) % mod


class UF:
    def __init__(self, N):
        self.parent = [i for i in range(N)]

    def get_parent(self, a):
        p = self.parent[a]
        if a == p:
            return a

        q = self.get_parent(p)
        self.parent[a] = q
        return q

    def make_pare(self, a, b):
        pa = self.get_parent(a)
        pb = self.get_parent(b)
        if pa != pb:
            self.parent[pa] = pb
            self.parent[a] = pb

    def is_pare(self, a, b):
        return self.get_parent(a) == self.get_parent(b)


def main():
    N, M = read_values()
    P = read_list()
    F = [0] * N

    W = [tuple(read_values()) for _ in range(M)]
    U = UF(N)
    for a, b in W:
        a -= 1
        b -= 1
        U.make_pare(a, b)

    res = 0
    for p in P:
        p -= 1
        if U.is_pare(p, P[p] - 1):
            res += 1
    print(res)


if __name__ == "__main__":
    main()



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

if H == 1 or W == 1:
    print(1)
    exit()

if H % 2 == 0:
    ans = (H * W // 2)
else:
    if W % 2 == 0:
        _H = (H + 1) // 2
        ans = (2 * _H - 1) * (W // 2)
    else:
        _H = (H + 1) // 2
        ans = (2 * _H - 1) * (W // 2) + _H
print(ans)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 

 class Main{
             
    static boolean[] notPrime=new boolean[51000];
    static int[] primes=new int[50000];
    static int primeNum=0;
    
    static void setP(){notPrime[0]=true;notPrime[1]=true;
        int count=0;
        for(int i=2;i<51000;i++){
            if(!notPrime[i]){primes[count]=i;count++;}
            for(int j=2;j*i<51000;j++){
                notPrime[i*j]=true;
            }
        }primeNum=count;
    }
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             setP();
             while((line=br.readLine())!= null){if(line.isEmpty())break;
                String[] spl=line.split(" ");
                int a=Integer.parseInt(spl[0]);
                if(a==0)break;
                // System.out.println(a);
                int cnt=0;
                for(int i=0;primes[i]<a;i++){
                    if(primes[i]>a/2)break;
                    if(!notPrime[a-primes[i]])cnt++;
                }
                 System.out.println(cnt);
                
             }br.close();
             
         }catch(Exception e){e.printStackTrace();}         
     }
   
 }

Measured memory_bytes: 32796
n = int(input())

s = []
for i in range(n):
    word = input()
    s_li = []
    for j in word:
        s_li.append(j)
    s_li.sort()
    s.append(s_li)
s.sort()

ans = 0
memo = 0
for i in range(n-1):
    if s[i] == s[i+1]:
        ans += 1+memo
        memo +=1
    else:
        memo = 0
    
print(ans)
    


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

using namespace std;
typedef long long ll;

int main() {
    ll X;
    cin >> X;
    ll ans = 2;

    int i, j, k;
    int flag = 0;

    if (X != 2) {
        for (i = 3; i <= 100003; i += 2) {
            k = 0;
            for (j = 3; j <= sqrt(i); j += 2) {
                if (i % j == 0) {
                    k = 1;
                    break;
                }
            }

            if (k == 0) {
                if (X <= i) {
                    ans = i;
                    flag = 1;
                }
            }
            if(flag==1){
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N, T;
    scanf("%d %d", &N, &T);
    int c[N], t[N];
    int ans = 2000;
    for (int i =0; i<N;i++){
        scanf("%d %d",&c[i], &t[i]);
        if(t[i] <= T){
            if(c[i] < ans){
                ans = c[i];
            }
        }
    }
    if(ans == 2000){
        printf("TLE");
    } else {
        printf("%d", ans);
    }
    return 0;
}


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

int main() {
    int H, W;
    char pixcels[100][100];

    cin >> H >> W;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            cin >> pixcels[y][x];
        }
    }

    for (int y = 0; y < H*2; y++) {
        for (int x = 0; x < W; x++) {
            cout << pixcels[y/2][x];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
#include <chrono>
#include<unordered_map>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e5 + 10;

pair<LL,LL> dp[MR];

int main()
{
	int N;
	scanf("%d", &N);
	vector<int> A(N + 1, 0);
	REP(i, N + 1)
		scanf("%d", &A[i]);

	int sz = A.size();
	while (sz > 0)
	{
		dp[sz - 1].first = dp[sz].first / 2 + dp[sz].first % 2 + A[sz - 1];
		dp[sz - 1].second = dp[sz].second + A[sz - 1];

		if (sz < 30)
		{
			dp[sz - 1].second = min(dp[sz - 1].second, 1LL << (sz - 1));
			if (dp[sz - 1].second < dp[sz - 1].first)
			{
				printf("-1\n");
				return 0;
			}
		}

		sz--;
	}

	LL res = 0;
	REP(i, N + 1)
	{
		if (dp[i].second < A[i])
		{
			printf("-1\n");
			return 0;
		}
		res += dp[i].second;
		dp[i + 1].second = min(dp[i + 1].second, (dp[i].second - A[i]) * 2);
	}

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

	return 0;
}

// FOR GNU C++ use the following pattern:
// Uncomment the code below and change your main into main2
// It does not build in MS C++
// But it does increase the stack size from 256 MB on CF and uses GNU C++

//#include <Processthreadsapi.h>
//#include <iostream>
//#include <Synchapi.h>
//#include <windows.h>
//#include <process.h>
//
//DWORD WINAPI MyThreadFunction(LPVOID lpParam) {
//    main2(nullptr);
//    return 0;
//}
//int main() {
//    auto h = CreateThread(nullptr, 1024 << 20, MyThreadFunction, nullptr, STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr);
//    WaitForSingleObject(h, INFINITE);
//}

Measured memory_bytes: 4788
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<Long, Long> map = new HashMap<>();

        for(int i = 0;i < n;i++) {
            long ai = sc.nextLong();
            Optional<Long> value = Optional.ofNullable(map.get(ai));
            if(value.isPresent()) map.put(ai, value.get() + 1);
            else map.put(ai, 1L);
        }

        
        System.out.println(map.keySet().stream().mapToLong(map::get).filter(e -> e % 2 == 1).count());
    }

}


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

    class Program
    {
        static void Main(string[] args)
        {
            var line = System.Console.ReadLine();
            var data = line.Split(new char[] { ' ' });
            int H = Convert.ToInt32(data[0]);
            int N = Convert.ToInt32(data[1]);

            line = Console.ReadLine();
            data = line.Split(new char[] { ' ' });
            int[] Skills = data.Select(i => Convert.ToInt32(i)).ToArray();

            for (int i = 0; i < N; i++)
            {
                H -= Skills[i];
            }

            if (H <= 0)
            {
                Console.WriteLine("Yes"); 
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }

Measured memory_bytes: 18144
#include <cstdio>

int main(void)
{
    int c4=0,c1=0;
    int N,x,i;
    scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        scanf("%d",&x);
        if(x%2==0)
        {
            if(x%4==0)
                c4++;
        }
        else
            c1++;
    }
    if(N%2==0)
    {
        if(c4>=c1)
            printf("Yes\n");
        else
            printf("No\n");
    }
    else
    {
        if(c4+1>=c1)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 128
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int i, n;
	short a[101];

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	if (n >= 1) printf("%d", a[n - 1]);
	for (i = n - 2; i >= 0; i--) printf(" %d", a[i]);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>
int main()
{
	int n,k,m[100],i,j,t,s=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
	scanf("%d",&m[i]);
	for(i=2;i<=n;i++)
	{
		for(j=1;j<i;j++)
		{
			if(m[i]>m[j])
			{
				t=m[j];
				m[j]=m[i];
				m[i]=t;
			}
		}
	}
	for(i=1;i<=k;i++)
	s=s+m[i];
	printf("%d",s);
	
}

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

vector<string> MakeHyojunkei(int K) {
	if (K == 1) return { "a" };
	else {
		vector<string> buf = MakeHyojunkei(K - 1);
		vector<string> ans;
		for (string s : buf) {
			char maxc = 'a';
			for (char c : s) maxc = max(c, maxc);
			for (char c = 'a'; c <= maxc + 1; c++) {
				ans.push_back(s + c);
			}
		}
		return ans;
	}
}

int main() {
	int N;
	cin >> N;
	vector<string> ans = MakeHyojunkei(N);
	for (string s : ans) cout << s << endl;
}



Measured memory_bytes: 10956
import sys

n, x, *a = map(int, sys.stdin.read().split())

def main():
    cnt = 0
    lim = x
    for c in a:
        if c > lim:
            cnt += c - lim
            lim = x - lim
        else:
            lim = x - c
            
    return cnt

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 14092
k = 2 *10**5
mod = 10**9+7

n, a, b = map(int,input().split())

modinv_table = [-1]*(k+1)
for i in range(1,k+1):
    modinv_table[i] = pow(i,-1,mod)

def binomial_coefficients(n,k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table[i+1]
        ans %= mod
    return ans
print((pow(2,n,mod)-binomial_coefficients(n,a)-binomial_coefficients(n,b)-1)%mod)

Measured memory_bytes: 16812
#include <iostream>
#include <algorithm>

using namespace std;

int n, a, b, c;
int data[101];

main(){
  cin >> n;
  cin >> a >> b >> c;
  for(int i=0;i<n;i++){
    cin >> data[i];
  }
  sort(data, data+n);
  reverse(data, data+n);
  int ans = c/a;
  int sum = c;
  for(int i=1;i<=n;i++){
    sum += data[i-1];
    if(ans < sum / (a+b*i)){
      ans = sum / (a+b*i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int h, w, n;
int sx, sy;
char S[200020], T[200020];
vector <pii> v[2];

int main() {
	scanf("%d%d%d", &h, &w, &n);
	scanf("%d%d", &sx, &sy);
	scanf("%s", S+1);
	scanf("%s", T+1);
	for(int i=1;i<=n;i++) {
		rep(u, 2) {
			char c = (u == 0 ? S[i] : T[i]);
			int dir = (c == 'R' || c == 'L') ? 1 : 0;
			int val = (c == 'R' || c == 'D') ? 1 : -1;
			v[dir].pb(pii(val, u));
		}
	}
	rep(dir, 2) {
		int lv = 1, rv = (dir == 0 ? h : w);
		int lm = rv;
		reverse(all(v[dir]));
		int ok = 1;
		for(pii e : v[dir]) {
			int val = e.Fi;
			int cmd = e.Se;
			if(cmd == 0) {
				if(val == 1) --rv;
				else ++lv;
			}
			else {
				if(val == 1) --lv;
				else ++rv;
			}
			if(lv < 1) lv = 1;
			if(rv > lm) rv = lm;
			if(lv > rv) ok = 0;
		}
		int vv = (dir == 0 ? sx : sy);
		if(lv <= vv && vv <= rv);
		else ok = 0;
		if(ok == 0) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;

vvi G;
vi V;

bool dfs1(int x) {
  for (auto y : G[x]) {
    if (V[y] == 0) {
      V[y] = -V[x];
      if (!dfs1(y)) return false;
    }
    else if (V[y] == V[x]) return false;
  }
  return true;
}

int bfs(int s) {
  queue<int> Q;
  int res = 0;
  V[s] = 0;
  Q.push(s);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (auto y : G[x]) {
      if (V[y] == -1) {
        V[y] = V[x] + 1;
        res = max(V[y], res);
        Q.push(y);
      }
    }
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  G = vvi(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      char x;
      cin >> x;
      if (x == '1') G[i].push_back(j);
    }
  }
  V = vi(n, 0);
  V[0] = 1;
  if (!dfs1(0)) {
    cout << -1 << '\n';
    return 0;
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    V = vi(n,-1);
    res = max(res, bfs(i)+1);
  }
  cout << res <<'\n';
}


Measured memory_bytes: 512