akhauriyash/Code-Regression huggingface dataset:
#Bowling
def solve(S):
    ret, i = 0, 0
    for g in xrange(10):
        if S[i] == 10:
            ret += sum(S[i:i + 3])
            i += 1
        elif sum(S[i:i + 2]) == 10:
            ret += sum(S[i:i + 3])
            i += 2
        else:
            ret += sum(S[i:i + 2])
            i += 2
    return ret

while True:
    m = input()
    if m == 0:
        break
    ans = []
    for _ in xrange(m):
        data = map(int, raw_input().split())
        n, s = data[0], data[1:]
        ans += [(solve(s), n)]
    print "\n".join(map(lambda x:"{1} {0}".format(*x), sorted(ans, key = lambda (a, b): (-a, b))))

Measured memory_bytes: 4264
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)

int h,w,s, total;
int u[32][32], sep[32][32][32][32], pow[32][32][32][32];
bool calced[32][32][32][32];
int imos[33][33];

void init(){
    REP(i,h) REP(j,w) REP(k,h) REP(l,w){
        sep[i][j][k][l] = pow[i][j][k][l] = -1;
        calced[i][j][k][l] = false;
    }
    
    REP(i,h) imos[i][0] = 0;
    REP(j,w) imos[0][j] = 0;
    REP(i,h) REP(j,w) imos[i+1][j+1] = u[i][j];
    REP(i,h+1) REP(j,w) imos[i][j+1] += imos[i][j];
    REP(i,h) REP(j,w+1) imos[i+1][j] += imos[i][j];
}

int getsum(int ay, int ax, int by, int bx){
    return imos[ay][ax] +imos[by+1][bx+1] -imos[ay][bx+1] -imos[by+1][ax];
}

void solve(int ay, int ax, int by, int bx){
    if(calced[ay][ax][by][bx]) return;

    pair<int, int> res(1, s -(total -getsum(ay,ax,by,bx)));
    if(res.second < 0){
        calced[ay][ax][by][bx] = true;
        return;
    }
    
    for(int i=ay; i<by; i++){
        solve(ay, ax, i, bx);
        solve(i+1, ax, by, bx);
        int val1 = sep[ay][ax][i][bx], val2 = sep[i+1][ax][by][bx];
        if(val1>=0 && val2>=0 && val1+val2 >= res.first){
            int cap = min(pow[ay][ax][i][bx], pow[i+1][ax][by][bx]);
            if(val1+val2 == res.first){
                res.second = max(res.second, cap);
            }else{
                res.first = val1+val2;
                res.second = cap;
            }
        }
    }
    for(int i=ax; i<bx; i++){
        solve(ay, ax, by, i);
        solve(ay, i+1, by, bx);
        int val1 = sep[ay][ax][by][i], val2 = sep[ay][i+1][by][bx];
        if(val1>=0 && val2>=0 && val1+val2 >= res.first){
            int cap = min(pow[ay][ax][by][i], pow[ay][i+1][by][bx]);
            if(val1+val2 == res.first){
                res.second = max(res.second, cap);
            }else{
                res.first = val1+val2;
                res.second = cap;
            }
        }
    }
    
    calced[ay][ax][by][bx] = true;
    sep[ay][ax][by][bx] = res.first;
    pow[ay][ax][by][bx] = res.second;
}

int main(){
    while(1){
        cin >> h >> w >> s;
        if(h==0) break;

        total=0;
        REP(i, h) REP(j, w){
            cin >> u[i][j];
            total += u[i][j];
        }
        
        init();
        solve(0, 0, h-1, w-1);
        cout << sep[0][0][h-1][w-1] << " " << pow[0][0][h-1][w-1] << endl;
    }
    return 0;
}



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

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;

int n;
int a[100000];

int main(){
    cin >> n;
    rep(i,n) cin >> a[i];
    int mm = MOD, ma = -1;
    rep(i,n) {
        mm = min(mm, a[i]);
        ma = max(ma, a[i]);
    }
    if(ma-mm > 1) {
        cout << "No" << endl;
        return 0;
    }
    int cnt = 0;
    int cnt2 = 0;
    rep(i,n) if(a[i] == ma) cnt++;
    rep(i,n) if(a[i] == mm) cnt2++;
    if(ma == mm) {
        if(mm == n-1) cout << "Yes" << endl;
        else if(mm*2 <= n) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    if(cnt == 1) {
        cout << "No" << endl;
        return 0;
    }
    if(ma <= cnt2) {
        cout << "No" << endl;
        return 0;
    }
    if((ma-cnt2) * 2 <= cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
}
































Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
 
int main(){
	int n, m;
	vector<long long> a, b, c, d, e, f, g, h;
	long long xi,yi,zi;
	cin>>n>>m;
	for(int i=0;i<n;i++){
			cin>>xi>>yi>>zi;
			a.push_back(+xi+yi+zi);
			b.push_back(+xi+yi-zi);
			c.push_back(+xi-yi+zi);
			d.push_back(+xi-yi-zi);
			e.push_back(-xi+yi+zi);
			f.push_back(-xi+yi-zi);
			g.push_back(-xi-yi+zi);
			h.push_back(-xi-yi-zi);
	}
	stable_sort(a.begin(),a.end());
	stable_sort(b.begin(),b.end());
	stable_sort(c.begin(),c.end());
	stable_sort(d.begin(),d.end());
	stable_sort(e.begin(),e.end());
	stable_sort(f.begin(),f.end());
	stable_sort(g.begin(),g.end());
	stable_sort(h.begin(),h.end());
	long long aa=0, bb=0, cc=0, dd=0, ee=0, ff=0, gg=0, hh=0;
	for(int i=0;i<m;i++){
		aa+=a[n-i-1];
		bb+=b[n-i-1];
		cc+=c[n-i-1];
		dd+=d[n-i-1];
		ee+=e[n-i-1];
		ff+=f[n-i-1];
		gg+=g[n-i-1];
		hh+=h[n-i-1];
	}
	cout<<(max({aa,bb,cc,dd,ee,ff,gg,hh}))<<endl;
}

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

#define N 200200

int n, up[N], pw[N], ans[N];
const int mod = 998244353;
char s[N];

inline void add(int &x, int y) {
    ((x += y) >= mod) ? x -= mod : 0;
}

vector <int> vec;

int main() {
    pw[0] = 1;
    for (int i = 1; i < N; i ++) pw[i] = (pw[i-1] << 1) % mod;
    scanf("%d %s", &n, s);
    for (int i = 0; i < n; i ++) s[i] -= '0';
    int d;
    for (d = 1; d * d < n; d ++) if (n % d == 0) {
        int dd = n / d;
        if (d & 1) vec.push_back(dd);
        if (dd & 1) vec.push_back(d);
    }
    if (d * d == n && d & 1) vec.push_back(d);
    int mn = n;
    for (auto d : vec) {
        int k;
        for (k = d; k < n; k ++) if (s[k] == s[k-d]) break;
        up[d] = k;
        if (k == n) mn = min(mn, d);
    }
    for (int i = 0; i < n; i ++) {
        if (s[i]) {
            for (auto d : vec) {
                if (d > i) add(ans[d], pw[d-i-1]);
                else if (up[d] == i) add(ans[d], 1);
            }
        }
    }

    int sz = vec.size(); sort(vec.begin(), vec.end());
    for (int i = 0; i < sz; i ++) {
        int dd = vec[i];
        for (int j = i + 1; j < sz; j ++) {
            int d = vec[j];
            if (d % dd == 0 && (d / dd) & 1) add(ans[d], mod - ans[dd]);
        }
    }
    int rlt = mn;
    for (auto d : vec) rlt = (rlt + 1ll * d * ans[d]) % mod;
    rlt <<= 1; if (rlt >= mod) rlt -= mod;
    printf("%d\n", rlt);
}


Measured memory_bytes: 1408
# coding:utf-8

import math
import re

def main(params):
    n = list(params[0])
    f = n[0] + n[1]
    s = n[2] + n[3]

    try:
        if (int(f) >= 1 and int(f) <= 12) and (int(s) == 0 or int(s) > 12):
            print "MMYY"
        elif (int(f) >= 1 and int(f) <= 12) and (int(f) >= 1 and int(f) <= 12):
            print "AMBIGUOUS"
        elif (int(s) >= 1 and int(s) <= 12) and (int(f) == 0 or int(f) > 12):
            print "YYMM"
        else:
            print "NA"
    except:
        print "NA"

if __name__ == "__main__":
    cnt = 1 # TODO: edit here
    params = []
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)



Measured memory_bytes: 2696
n, q = [int(i) for i in input().split()]
queue = []
for ni in range(n):
    name, time = input().split()
    queue.append([name, int(time)])
total_time = 0
while queue != []:
    queue_pop = queue[0]
    if queue_pop[1] <= q:
        print(queue_pop[0],total_time+queue_pop[1])
        total_time += queue_pop[1]
        del queue[0]
    else:
        total_time += q
        del queue[0]
        queue_pop[1] -= q
        queue.append(queue_pop)


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

typedef pair<long, int> pli;

int main(){
	int n, m, t, b;
	long a, v, mm;
	pli p[100010];
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		p[i] = {a, b};
	}
	sort(p, p+n, [](pli& x, pli& y){return x.first < y.first;});
	t = v = 0;
	for (int i = 0; i < n; ++i) {
		a = p[i].first; b = p[i].second;
		mm = min(m-t, b);
		t += mm;
		v += mm*a;
		if (m == t) break;
	}
	cout << v;
}

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

const int maxN=4010;
const int Mod=998244353;

char Input[maxN];
int n;
int Sum[maxN][2];
int F[maxN][maxN];

void Plus(int &x,int y);

int main(){
    scanf("%s",Input+1);n=strlen(Input+1);
    for (int i=1;i<=n;i++){
        Sum[i][0]=Sum[i-1][0];Sum[i][1]=Sum[i-1][1];
        if (Input[i]=='0') Sum[i][0]+=2;
        if (Input[i]=='1') Sum[i][0]++,Sum[i][1]++;
        if (Input[i]=='2') Sum[i][1]+=2;
    }
    for (int i=n+1;i<=n+n;i++) Sum[i][0]=Sum[i-1][0],Sum[i][1]=Sum[i-1][1];
    //for (int i=1;i<=n+n;i++) cout<<"("<<Sum[i][0]<<" "<<Sum[i][1]<<") ";cout<<endl;
    F[0][0]=1;
    for (int i=0;i<n+n;i++)
        for (int j=0;j<=min(i,Sum[i][0]);j++){
            if (Sum[i+1][0]>j) Plus(F[i+1][j+1],F[i][j]);//,cout<<"("<<i<<" "<<j<<")->("<<i+1<<","<<j+1<<")"<<endl;
            if (Sum[i+1][1]>i-j) Plus(F[i+1][j],F[i][j]);//,cout<<"("<<i<<" "<<j<<")->("<<i+1<<","<<j<<")"<<endl;
        }
        /*
    for (int i=1;i<=n+n;i++){
        for (int j=0;j<=i;j++) cout<<F[i][j]<<" ";cout<<endl;
    }
    //*/
    int Ans=0;
    for (int i=0;i<=n+n;i++) Plus(Ans,F[n+n][i]);
    printf("%d\n",Ans);return 0;
}
void Plus(int &x,int y){
    x+=y;if (x>=Mod) x-=Mod;return;
}

Measured memory_bytes: 61440
#周期m以下

n,x,m=map(int, input().split())

used = [0]*(m+1)
used_list=[]
pre=x

flag0=False
s=-1;t=-1
for i in range(m+1):
    if pre==0:
        flag0=True
        break
    now=(pre*pre)%m
    if used[pre]:
        s=used[pre]
        break
    used[pre]=i
    used_list.append(pre)
    pre=now
    
l=len(used_list[s:])
try:
    ans=sum(used_list[:s])+sum(used_list[s:])*((n-s)//l)+sum(used_list[s:s+(n-s)%l])
    if not flag0:
        print(ans)
    else:
        print(sum(used_list))
except:
    print(sum(used_list))

Measured memory_bytes: 69632
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int arr[300005];
int32_t main()
{
    IOS;
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}

Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
using namespace std;
int n;
inline int read()
{
	int ret=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') ret=(ret<<1)+(ret<<3)+(ch^48),ch=getchar();
	return ret;
}
int main()
{
	n=read();
	if (n/100==n%10) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
OK=[True]*N
for m in range(M):
    a,b=map(int, input().split())
    if H[a-1] <= H[b-1]: OK[a-1] = False
    if H[b-1] <= H[a-1]: OK[b-1] = False
print(OK.count(True))

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

int main(){
  string S;
  int Q;
  cin>>S>>Q;
  
  int T,F;
  string C;
  bool rev = false;
  
  rep(i,Q){
    cin>>T;
    if(T==1){
      rev = !rev;
    }
    else{
      cin>>F>>C;
      if((F==1&&!rev)||(F==2&&rev))
        S.insert(0,C);
      else{
        char D = C.at(0);
        S.push_back(D);
      }
    }
  }
  
  if(rev)
  reverse(S.begin(), S.end());
  
  cout << S <<endl;
}
    


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            var x = new int[N];
            var y = new int[N];
            for (int i = 0; i < N; i++)
            {
                var ss = Console.ReadLine().Split();
                x[i] = int.Parse(ss[0]);
                y[i] = int.Parse(ss[1]);
            }

            if (N == 1)
            {
                Console.WriteLine(1);
                return;
            }

            var map = new Dictionary<Tuple<int, int>, int>();

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (i == j) continue;

                    var tuple = Tuple.Create(x[j] - x[i], y[j] - y[i]);
                    if (!map.ContainsKey(tuple))
                        map.Add(tuple, 1);
                    else
                        map[tuple]++;
                }
            }

            Console.WriteLine(N - map.Values.Max());
        }
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
multiset<ll>se;
ll get()
{
	multiset<ll>::iterator it = se.begin();
	ll a = *it;
	it = se.end();
	it--;
	return (*it) - a;
}
int main()
{
	int num;
	scanf("%d", &num);
	ll min1 = 1000000000, max1 = 0, min2 = 1000000000, max2 = 0;
	ll mini = 1000000001, maxi = -1;
	int r1, r2;
	vector<pii>zv;
	for (int i = 0; i < num; i++)
	{
		ll za, zb;
		scanf("%lld%lld", &za, &zb);
		if (za > zb)swap(za, zb);
		min1 = min(min1, za), max1 = max(max1, za);
		min2 = min(min2, zb), max2 = max(max2, zb);
		if (mini > za)mini = za, r1 = i;
		if (maxi < zb)maxi = zb, r2 = i;
		zv.push_back(make_pair(za, zb));
	}
	ll ans = (max2 - min2)*(max1 - min1);
	if (r1 != r2)
	{
		vector<pii>v;
		for (int i = 0; i < num; i++)if (i != r1&&i != r2)v.push_back(zv[i]);
		se.insert(zv[r1].second);
		se.insert(zv[r2].first);
		sort(v.begin(), v.end());
		for (int i = 0; i < v.size(); i++)se.insert(v[i].first);
		ll t = get();
		for (int i = 0; i < v.size(); i++)
		{
			multiset<ll>::iterator it = se.find(v[i].first);
			se.erase(it);
			se.insert(v[i].second);
			t = min(t, get());
		}
		ans = min(ans, t*(maxi - mini));
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 17772
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<sstream>
#include<cmath>
#include<climits>
#include<algorithm>
#include<bitset>
#include<set>
#include<stack>
#include<queue>
#include<iomanip>
#include<memory.h>
#include<complex>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tuple<int,int> tii;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV int(1e9+7)
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
 
/* Coding Space*/

bool check(string s){
  rep(i,s.size()/2){
    if(s[i] != s[s.size()-1-i])
      return false;
  }
  return true;
}

int main(){
  string s; cin >> s;
  string con = s;
  int x_cnt = 0;
  int cnt = 0;
  rep(i,con.size())
    if(con[i] == 'x'){
      con.erase(i,1),i--;
      x_cnt++;
    }else{
      cnt++;
    }
  if(check(con)){
    int ans = 0;
    int a = 0,b = 0;
    int r = s.size()-1;
    int l = 0;
    while(r > l){
      if(s[r] == s[l]){
        r--;l++;
      }else if(s[r] == 'x'){
        r--; ans++;
      }else{
        l++; ans++;
      }
    }
    cout << ans << endl;
  }else
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int AS = 1 << 17;
ll dat[2 * AS];
const ll are = 1 << 30;
void modify(int p) {
	for (dat[p += AS] -= are; p > 1; p >>= 1) dat[p >> 1] = max(dat[p], dat[p ^ 1]);
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = ' ';
}

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


	int N;
	cin >> N;
	int A[100000];
	rep(i, N) {
		cin >> A[i];
		A[i]--;
		dat[AS + A[i]]++;
	}
	rep(i, N) dat[AS + i] = (dat[AS + i] << 30) + i;
	for (int i = AS - 1; i > 0; i--) dat[i] = max(dat[i << 1], dat[i << 1 | 1]);

	if (N == 2) {
		co(-1);
		return 0;
	}

	int dame = -1;
	int j = 0;
	const int m = (1 << 30) - 1;
	bool used[100000] = {};
	rep(i, N - 3) {
		int kotae;
		ll tmp = dat[1];
		if (N - i - 1 == tmp >> 30) kotae = tmp & m;
		else {
			int k = j;
			while (used[k] || k == dame) k++;
			kotae = k;
		}
		modify(A[kotae]);
		putint(kotae + 1);
		used[kotae] = 1;
		dame = A[kotae];
		while (used[j]) j++;
	}

	int kouho[3];
	int k = 0;
	for (int i = j; i < N; i++) {
		if (!used[i]) kouho[k++] = i;
	}
	while (1) {
		if (dame != kouho[0] && A[kouho[0]] != kouho[1] && A[kouho[1]] != kouho[2]) break;
		next_permutation(kouho, kouho + 3);
	}
	putint(kouho[0] + 1);
	putint(kouho[1] + 1);
	putint(kouho[2] + 1);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

void dijkstra(vector<vector<int>> &edge, vector<int> &dist){
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));

    while((int)que.size()>0){
        int cost=que.front().first;
        int x=que.front().second;
        que.pop();
        if(dist[x]>cost){
            dist[x]=cost;
        }else{
            continue;
        }

        for(const auto &e:edge[x]){
            que.push(make_pair(cost+1,e));
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int>> edge(N,vector<int>(0));
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vector<int> dist(N,MOD);
    dijkstra(edge,dist);

    vector<int> guide(N,0);
    for(int i=1; i<N; i++){
        for(const auto &e:edge[i]){
            if(dist[i]==dist[e]+1){
                guide[i]=e;
                continue;
            }
        }
    }

    cout << "Yes\n";
    for(int i=1; i<N; i++){
        cout << guide[i]+1 << '\n';
    }
}

Measured memory_bytes: 12132
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N, K, ans=0;

    cin >> N >> K;

    vector<int> h(N);

    rep(i, N) {
        cin >> h[i];
        if(h[i]>=K) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 640
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("sumsqr.in");ofstream out("sumsqr.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll k,l,r; cin>>k>>l>>r;
    ll fl = 0;
    for(; l<=r; l++) fl |= l%k==0;
    cout<<(fl ? "OK" : "NG");
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {
	 public static void main(String args[]){
	Scanner scanner = new Scanner(System.in);
	// "abc"という文字列
	String a=scanner.next();
	    if(a.equals("ABC")){
	    	System.out.println("ARC");
	}
	    else {
	    	System.out.println("ABC");
	    }
	    }
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(void){
    int K,sum=0;
    cin >> K;
    for (int i = 1; i <= K; i++){
        for (int j = 1; j <= K; j++){
            for (int l = 1; l <= K; l++){
                sum += gcd(gcd(i,j),l);
            }
            
        }
        
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 3636
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io

	ll n,h,w;
	cin>>n>>h>>w;
	ll cnt=0;
	rep(i,0,n)
	{
		ll x,y;
		cin>>x>>y;
		if(x>=h && y>=w)
		{
			cnt++;
		}
	}
	cout<<cnt;


}

Measured memory_bytes: 256
import sys

# import numpy as np
import math
from fractions import gcd
from collections import deque
import bisect

sys.setrecursionlimit(1000000)


def main():
    # map(int, input().split())
    # l = list(map(int, input().split()))

    N = int(input())
    A = list(map(int, input().split()))
    combi = list(zip(range(1, N+1), A))
    combi.sort(key=lambda x: x[1])
    for key in combi:
        print(key[0], end=' ')
    print('')


if __name__ == "__main__":
    main()


Measured memory_bytes: 21968
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer[] abc = new Integer[3];
		abc[0] = sc.nextInt();
		abc[1] = sc.nextInt();
		abc[2] = sc.nextInt();
		Arrays.sort(abc, Collections.reverseOrder());
		System.out.println(((abc[0] * 10) + abc[1]) + abc[2]);
	}
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i, h) cin >> c[i];

    rep(i, h)
    {
        rep(j, 2)
        {
            cout << c[i] << '\n';
        }
    }
    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 77;

ll nCr[MAX_N + 1][MAX_N + 1];

void getnCr(ll n) {
  // nCnとnC0を1で初期化
  REP(i, n + 1) {
    nCr[i][0] = nCr[i][i] = 1ll;
  }

  // nCr = n-1Cr-1 + n-1Cr
  REP(i, n + 1) {
    REP(j, i) {
      nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
    }
  }
}

int main()
{

  ll N, A, B;
  cin >> N >> A >> B;
  vector< ll > v(N);
  map< ll, ll > mp;
  REP(i, N) {
    cin >> v[i];
    mp[v[i]]++;
  }

  // 降順にソート
  sort(ALL(v));
  reverse(ALL(v));
  
  long double ans = 0.0;
  REP(i, A) {
    ans += v[i];
    // debug(ans);
  }
  // debug(ans);
  ans /= (long double)A;

  // debug(ans);
  printf("%.10Lf\n", ans);
  // cout << ans << endl;

  ll r = 0ll;
  REP(i, A) {
    if (v[i] == v[A - 1]) r++;
  }
  
  
  getnCr(MAX_N);
  // debug(n);
  // debug(r);
  ll ans2 = 0ll;

  if (r == A) {
    // 全部同じ
    FOR (i, A, B + 1) {
      ans2 += nCr[mp[v[A - 1]]][i];
    }
  } else {
    //FOR(i, 1, A - r + 1) {
      // debug(mp[v[A - 1]]);
      // debug(i);
      ans2 += nCr[mp[v[A - 1]]][r];
      //}
  }
  cout << ans2 << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	double a_d,b_d;
	scanf("%d %d",&a,&b);
	a_d = static_cast<double>(a);
	b_d = static_cast<double>(b);
	printf("%d %d %.5f\n",a/b,a%b,a_d/b_d);
}


Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
typedef struct data {
    ll x,y;
    bool operator<(const data& a) const
    {
        return x < a.x;
    }
} stu;
 
 
 
ll n,m ;
int arr[600000];
ll memo[600000];
 
ll rec(int i){
    if(i>=n-1)return 0 ;
    if(memo[i]!=-1)return memo[i];
    ll m1,m2;
    if(i==n-2){
    m1= rec(i+1)+abs(arr[i]-arr[i+1]);
    m2= 1000000;
    memo[i]=min(m1,m2);
    return min(m1,m2);
    }
    m1= rec(i+1)+abs(arr[i]-arr[i+1]);
    m2= rec(i+2)+abs(arr[i]-arr[i+2]);
    memo[i]=min(m1,m2);
    return min(m1,m2);
 
}
 
void solve(){
    memset(memo,-1,sizeof memo);
    cin >> n ;
    for (int i = 0; i < n; ++i)
    {   
        cin >> arr[i];    
    }
    cout <<  rec(0) <<endl;
 
 
 
 
 
 
}
 
 
 
 
int main() {
 
   
 
        //clock_t startTime = clock();
 
    solve();
    //cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<<  endl;    
    return 0;
}


Measured memory_bytes: 9472
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}
 
fn main() {
  let _: f64 = read();
  let xs: Vec<f64> = read_vec();
  let max = &xs.iter().fold(0.0, |m, &v| v.max(m));
  let min = &xs.iter().fold(std::f64::MAX, |m, &v| v.min(m));
  println!("{}", (max - min) as u32);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[100];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n-1-i;i++) swap(a[i],a[n-1-i]);
    for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<a[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int [n - 1];
        for (int i = 0; i < b.length; i++) {
            b[i] = sc.nextInt();
        }
        int ans = b[0];
        for (int i = 0; i < b.length; i++) {
            if(i == b.length - 1) {
                //System.out.println(b[i]);
                ans += b[i];
            } else {
                int min = Math.min(b[i], b[i + 1]);
                //System.out.print(min + " ");
                ans += min;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 36088
//all possible//
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c,d=0,e,f,i;
	vector<long long > v;
	cin>>a>>b;
	for(i=0;i<a;i++)
	{
		cin>>c;
		v.push_back(c);
	}
	sort(v.begin(),v.end());
	if(a==b)
	{
		for(i=0;i<v.size();i++)
		{
			d+=v[i];
		}
		cout<<d;
		
	}
	else
	{
		for(i=v.size()-1;i>=a-b;i--)
		d+=v[i];
		cout<<d;
	}

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll X;
    cin >> X;
    ll count = 100;
    ll res = 0;
    while(X > count){
        count = ((double) count * (double)1.01);
        //cout << count << endl;
        res++;
    }
    cout << res << endl;

}


Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc138/tasks/abc138_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll a; string s; cin>>a>>s;
    if (a>=3200) {
        cout<<s<<endl;
    } else {
        cout<<"red"<<endl;
    }
    return 0;
}

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

int main() {
	int N;
    cin >> N;
     	
  for (int i = 0; i < N; i++) {
    char S;
    cin >> S;
    
    if( S == 'Y') {
      cout << "Four" << endl;
      return 0;
  }
  }
	cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class A{
  public static void Main(){
    var s = Console.ReadLine();
    if(s == "25") Console.WriteLine("Christmas");
    if(s == "24") Console.WriteLine("Christmas Eve");
    if(s == "23") Console.WriteLine("Christmas Eve Eve");
    if(s == "22") Console.WriteLine("Christmas Eve Eve Eve");
  }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  cout << (int)abs(*max_element(a, a + N) - *min_element(a, a + N)) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sn = new Scanner(System.in);
        int a = sn.nextInt();
        int b = sn.nextInt();
        int c = sn.nextInt();
        
        int d = b / a;
        if(d > c){
            System.out.println(c);
        } else {
            System.out.println(d);
        }
        
        
    }
}

Measured memory_bytes: 21844
import math

N = int(input())
A = sorted(list(map(int,input().split())))
d = [0]*(10**6+2)
d[1] = 1
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

f = 1
for e in A:
    for y in make_divisors(e):
        if y == 1:
            continue
        if d[y] != 0:
            f = 0
            break
        else:
            d[y] = 1
    if f == 0:
        break
if f == 1:
    print("pairwise coprime")
    exit(0)

t = A[0]
for e in A:
    t = math.gcd(e,t)

if t == 1:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 197096
//そうか…bitsetか…
#include <iostream>
#include <bitset>
using namespace std;

bitset<4000001> dp;
int n;
int a[2000];
int s;

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) { cin >> a[i]; s += a[i]; }
	
	dp.set(0);
	for (i = 0; i < n; i++) {
		dp |= dp << a[i];
	}
	
	for (i = (s + 1) / 2; i <= s; i++) {
		if (dp[i]) break;
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 1664
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())

	fmt.Println(int(math.Pow(float64(x), 3)))
}



Measured memory_bytes: 1092
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int list[] = new int[100000];
    int list2[] = new int[100000];
    int check = 1;

    for(int i = 0; i < n ; i++){
        list[i] = sc.nextInt();
    }

    for(int i = 0 ; i < n ; i++){
        list2[list[i]-1] = check;
        check++;
    }

    for(int i = 0; i < n ; i++){
        System.out.print(list2[i] + " ");
    }

   
    
    


    
    


    


    
    


    
	}
}

Measured memory_bytes: 63512
(let ((s (read-line))
    (ans 0)
    (num 0))
    (loop for i below (length s) do
        (if (or (string= (char s i) "A") (string= (char s i) "C") (string= (char s i) "G") (string= (char s i) "T"))
            (incf num)
            (progn
                (if (> num ans)
                    (setq ans num)
                )
                (setq num 0)
            )
        )
    )
    (if (> num ans)
        (setq ans num)
    )

    (princ ans)

)

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

typedef long long LL;

int a,b,c,d,e;

int main(){
  scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
  printf("%d\n",max(c*60+d-a*60-b-e,0));
  return 0;
}

Measured memory_bytes: 3868
import java.util.Scanner;


public class Main {

    public static String Y = "Yes";
    public static String N = "No";
    public static String I = "IMPOSSIBLE";
    public static String B = "Bad";
    public static String G = "Good";
    public static long MOD = (long) (Math.pow(10, 9) + 7);
    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        // abc132_b

        int n = ni();

        int tmp_iBef1 = 0;
        int tmp_iBef2 = 0;
        int ans = 0;

        int[] list = new int[n];

        for (int i = 0; i < n; i++) {
            list[i] = ni();
        }

        for (int i = 1; i <= n - 2; i++) {
            int now = list[i];
            int bef = list[i - 1];
            int af = list[i + 1];
            if (!(max(max(bef, af), now) == now) && !(min(min(bef, af), now) == now)) {
                ans++;
            }
        }
        out(ans);
    }

    /*
     * 以下メソッド集
     */
    static int ni() {

        return sc.nextInt();
    }

    static long nl() {

        return sc.nextLong();
    }

    static String n() {

        return sc.next();
    }

    static char[] nc() {

        return sc.next().toCharArray();
    }

    static int kaijo(int n) {

        if (n == 0 || n == 1) {
            return 1;
        } else {
            return n * kaijo(n - 1);
        }
    }

    static int fib(int n) {

        return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
    }

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

    static void out(char info) {

        System.out.println(info);
    }

    static void outn(String info) {

        System.out.print(info);
    }

    static void outn(int info) {

        System.out.print(info);
    }

    static void outn(double info) {

        System.out.print(info);
    }

    static void outn(long info) {

        System.out.print(info);
    }

    static void outn(char info) {

        System.out.print(info);
    }

    static int max(int a, int b) {

        return Math.max(a, b);
    }

    static long max(long a, long b) {

        return Math.max(a, b);
    }

    static int min(int a, int b) {

        return Math.min(a, b);
    }

    static long min(long a, long b) {

        return Math.min(a, b);
    }
}


Measured memory_bytes: 21204
def main():
    s = input()
    
    A = []
    for i in range(len(s)):
        if s[i] == "S":
            A.append("S")
        else:
            if len(A) > 0 and A[-1] == "S":
                A.pop()
            else:
                A.append("T")
    print(len(A))


if __name__ == "__main__":
    main()

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

string calc(string S, int L){
    int a, b;
    a = stoi(S,nullptr,10);
    reverse(S.begin(), S.end());
    b = stoi(S,nullptr,10);
    string res = to_string(b-a);
    while(res.length() < L) res = '0' + res;
    return res;
}

int main(void){
    while(true){
        vector<string> temp;
        string S; int B; cin >> S >> B;
        if(B == 0) break;
        while(S.length() < B) S = '0' + S;
        temp.push_back(S);
        sort(S.begin(), S.end());

        bool cont = true;
        while(cont){
            string nx = calc(S, B);
            //cout << nx << endl;
            rep(i, temp.size()){
                if(temp[i] == nx){
                    cout << i << " " << stoi(nx) << " " << temp.size()-i << endl;
                    cont = false;
                    break;
                }
            }
            temp.push_back(nx);
            S = nx;
            sort(S.begin(), S.end());
        }
    }
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <climits>
#define INF (1<<25)
#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))

using namespace std;

int main()
{
    int n,m,s,g1,g2;
    int b1,b2,c;
    int edge[100][100];
    int mn;
    while(cin >> n >> m >> s >> g1 >> g2 &&n&&m&&s)
    {
        --s;--g1;--g2;
        rep(i,n) rep(j,n) edge[i][j] = (i==j)?0:INF;
        rep(i,m)
        {
            cin >> b1 >> b2 >> c;
            --b1;--b2;
            edge[b1][b2] = c;
        }
        rep(k,n) rep(i,n) rep(j,n) edge[i][j] = min(edge[i][j], edge[i][k]+edge[k][j]);
        mn = INF;
        rep(i,n) mn = min(mn, edge[s][i]+edge[i][g1]+edge[i][g2]);
        cout << mn << endl;
    }
}

Measured memory_bytes: 1200
N = int( input())
V = [0]*(N+1)
L = 0
R = N
print(0)
s = input()
if s == "Vacant":
    pass
else:
    V[0] = V[N]= s
    for i in range(19):
        M = (L+R)//2
        print(M)
        s = input()
        if s == "Vacant":
            break
        else:
            V[M] = s
            if V[L] == V[M]:
                if (M-L)%2 == 1:
                    R = M
                else:
                    L = M
            else:
                if (M-L)%2 == 0:
                    R = M
                else:
                    L = M

Measured memory_bytes: 4424
/* 
 * Project: AtCoder Beginners Contest 158 B - Count Balls
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/03/11
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
long n;
long a, b;
 
void solve() {

    long pack_num = 0;
    pack_num =  n / (a + b);
    long remainder = 0;
    remainder = n % (a + b);
    long sum_a = 0;
    // A+Bパックの余りがAより小さいとき, 余りを追加.
    sum_a = pack_num*a + min(remainder, a);

    cout << sum_a << endl;

}
 
int main() {
 
    cin >> n;
    cin >> a >> b;
 
    solve();
 
}

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

using namespace std;

const int N = 1e6 + 6;

int l[N * 4], r[N * 4];

long long f(long long x) {
  return x & -x;
}

char s[N];

long long dfs(int v, long long d) {
  if (!l[v] && !r[v]) return 0;
  long long ret = 0;
  if (l[v])
    ret ^= dfs(l[v], d-1);
  else
    ret ^= f(d);
  if (r[v])
    ret ^= dfs(r[v], d-1);
  else
    ret ^= f(d);
  return ret;
}

int main() {
  memset(l, 0, sizeof l);
  memset(r, 0, sizeof r);
  int nodes = 1;
  int root = 1;
  int n;
  long long x;
  scanf("%d %lld", &n, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    int len = strlen(s);
    int now = root;
    for (int j = 0; j < len; ++j) {
      if (s[j] == '0') {
        if (!l[now])
          l[now] = ++nodes;
        now = l[now];
      }
      else {
        if (!r[now])
          r[now] = ++nodes;
        now = r[now];
      }
    }
  }
  puts(dfs(root, x) ? "Alice" : "Bob"); 
  return 0;
}

Measured memory_bytes: 36224
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int N; cin >> N;
	vector<string> S(N); rep(i, N) cin >> S[i];
	
	sort(S.begin(), S.end());
	vector<int> cnt(N,1);
	int MAX = 1;
	for (int i = 1; i < N; i++) {
		if (S[i] == S[i - 1]) cnt[i] += cnt[i - 1];
		MAX = max(MAX, cnt[i]);
	}
	
	rep(i, N) {
		if (cnt[i] == MAX) cout << S[i] << endl;
	}
	return 0;
}


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

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 main(){

  string s;
  cin >> s;

  cout << s.substr(0,3) << endl;

  return 0;
} 

Measured memory_bytes: 3628
package  main
import (
  "fmt"
)

func main() {
  var (
    n	int
    count int
  )
  fmt.Scan(&n)
  nums := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&nums[i])
  }
  
  flag := true
  for flag {
    for i := 0; i < n; i++ {
      if nums[i]%2 == 0 {
        nums[i] /= 2
      } else {
        flag = false
      }
    }
    if flag {
      count++
    }
  }
  fmt.Println(count)
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main{
  static int INF = 100000001;

  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int half = n / 2;
    int[] t = new int[n + 2];
    int[][][] dp = new int[2][n + 2][2];

    for(int i = 0; i < n - 1; i++){
      t[i] = Integer.parseInt(br.readLine());
      for(int j = 0; j < 2; j++){
        Arrays.fill(dp[j][i], INF);
      }
    }

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

    for(int I = 0; I < n - 1; I++){
      int i = I % 2;
      int ni = (i + 1) % 2;

      for(int j = 0; j <= half; j++){
        dp[ni][j + 1][0] = Math.min(dp[i][j][0], dp[i][j][1] + t[I]);
        dp[ni][j    ][1] = Math.min(dp[i][j][1], dp[i][j][0] + t[I]);
        Arrays.fill(dp[i][j], INF);
      }
    }

    System.out.println(Math.min(dp[1][half - 1][0], dp[1][half - 1][1]));
  }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  vector<ll> ret;

  for (ll i = 1; i * i <= n; ++i)
    if (n % i == 0) ret.push_back(i);

  ll retb = n / ret.back();
  cout << ret.back() + retb - 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }

int N;
int M;

struct edge{
  i64 to;
  i64 cost;
};

vector<vector<edge>> edges;

vector<i64> dist;

int main(){
  i64 P;
  cin >> N >> M >> P;

  edges.resize(N);
  dist.resize(N,1e12);
  rep(i,0,M - 1){
    i64 a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    edges[a].push_back({b,P-c});
  }

  dist[0] = 0;

  rep(i,0,N){
    rep(v,0,N - 1){
      for(auto & e : edges[v]){
        if(dist[v] == 1e12) continue;
        dist[e.to] = min(dist[e.to] , dist[v] + e.cost);
      }
    }
  }

  vector<bool> ne(N,false);

  rep(i,0,N){
    rep(v,0,N - 1){
      for(auto & e : edges[v]){
        if(dist[v] == 1e12) continue;
        if(dist[e.to] > dist[v] + e.cost){
          dist[e.to] = dist[v] + e.cost;
          ne[e.to] = true;
        }
        ne[e.to] = ne[e.to] || ne[v];
      }
    }
  }

  if(ne[N - 1]){
    cout << -1 << endl;
  }
  else{
    cout << max(0ll, dist[N - 1] * -1) << endl;
  }

}




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

int main(){

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

    int ok = *max_element(A.begin(),A.end());
    int ng = 0;

    while(ok - ng > 1){
        int mid = (ok + ng) / 2;
        int rest = K;
        bool flag = true;

        for(int i=0;i<N;i++){
            rest -= (ceil(double(A[i]) / mid) - 1);
            if(rest < 0){
                flag = false;
                break;
            }
        }

        if(flag)
            ok = mid;
        else
            ng = mid;
    }

    cout << ok;
    return 0;
}

Measured memory_bytes: 3960