akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <deque>
using namespace std;

int sum[200010][26], dijk[200010], n[200010];

int main() {
	string S;
	cin >> S;
	for(int i=0; i<26; ++i){
		sum[0][i]=0;
		for(int j=0; j<S.size(); ++j){
			sum[j+1][i]=sum[j][i];
			if(S[j]-'a'==i) sum[j+1][i]=1-sum[j+1][i];
		}
	}
	unordered_map<int, vector<int>> ump;
	for(int i=0; i<=S.size(); ++i){
		n[i]=0;
		for(int j=0; j<26; ++j){
			n[i] += ((sum[i][j])<<j);
		}
		if(i==S.size()){
			ump[n[i]].clear();
		}
		ump[n[i]].emplace_back(i);
	}
	for(int i=1; i<=S.size(); ++i) dijk[i]=1e6;
	deque<int> dq{0};
	while(dq.front()<S.size()){
		int t=dq.front();
		dq.pop_front();
		for(int i=-1; i<26; ++i){
			int u=n[t];
			if(i>=0) u ^= (1<<i);
			auto itr=upper_bound(ump[u].begin(), ump[u].end(), t);
			if(itr!=ump[u].end()){
				int nx=*itr;
				if(dijk[nx]>dijk[t]+1){
					dijk[nx]=dijk[t]+1;
					dq.push_back(nx);
				}
			}
		}
	}
	cout << dijk[S.size()] << endl;
	return 0;
}

Measured memory_bytes: 209756
N,K=map(int,input().split())
A=list(map(int,input().split()))

for i in range(1,N):
    A[i]+=A[i-1]

A.append(0)
A.sort()

A=[((A[i]-i)%K,i) for i in range(0,N+1)]
A.sort()
count=0
s=0
t=1
while N>=t and N>=s:
    if A[t][0]==A[s][0] and K>A[t][1]-A[s][1]:
        t+=1
        if t==N+1:
            count+=((t-s)*(t-s-1))//2
    else:
        count+=t-s-1
        s+=1
        if s==t:
            t+=1

print(count)

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

int main(){
  string n;
  cin >> n;
  if(stoi(n)%10==0) {
    cout<<10<<endl;
    return 0;
  }
  int cnt=0;
  string k="";
  for(int i=0;i<n.length();i++){
    k=n.at(i);
    cnt+=stoi(k);
  }
  cout<< cnt <<endl;
  return 0;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())

def solve(n):
    if n == 0:
        return 0
    else:
        temp = n % 10
        return temp + solve(n // 10)

ans = 0
for i in range(1, N+1):
    if A <= solve(i) <= B:
        ans += i
print(ans)

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

using namespace std;

#define ll long long int
#define MOD 1000000007
#define mt make_tuple
#define eb emplace_back
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}



int main()
{
	ll t,i,j,k,l,n,m;
	cin>>n;
	ll A[n];
	for(i=0;i<n;++i)
        cin>>A[i];
        ll ans=0;
    for(i=0;i<n;++i){
        l=1;
        while(i+1<n&&A[i]==A[i+1]){
            l++;i++;
        }
        ans += (l/2);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i=0; i<=a; i++) {
        for (int j=0; j<=b; j++) {
            int k = (x - 500*i - 100*j) / 50;  
            if (k < 0 || c < k) continue;
            if (500*i + 100*j + 50*k == x) ans++;
        }
    }
    cout << ans << endl;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		String SW = "SW";
		for(int a=0;a<2;a++){
			for(int b=0;b<2;b++){
				List<char> L = new List<char>();
				L.Add(SW[a]);
				L.Add(SW[b]);
				for(int i=1;i<N;i++){
					if(S[i] == 'o'){
						if(L[i] == 'S'){
							L.Add(L[i-1]);
						}else{
							L.Add(L[i-1] == 'S' ? 'W' : 'S');
						}
					}else{
						if(L[i] == 'S'){
							L.Add(L[i-1] == 'S' ? 'W' : 'S');
						}else{
							L.Add(L[i-1]);
						}
					}
				}
//Console.WriteLine(new String(L.ToArray()));
				if(L[L.Count-1] != L[0]) continue;
				L.RemoveAt(L.Count-1);
				if(S[0] == 'o'){
					if(L[0] == 'S'){
						if(L[L.Count-1] != L[1]) continue; 
					}else{
						if(L[L.Count-1] == L[1]) continue; 
					}
				}else{
					if(L[0] == 'S'){
						if(L[L.Count-1] == L[1]) continue; 
					}else{
						if(L[L.Count-1] != L[1]) continue; 
					}
				}
				Console.WriteLine(new String(L.ToArray()));
				return;
			}
		}
		Console.WriteLine(-1);
		
	}
	int N;
	String S;
	public Sol(){
		N = ri();
		S = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

string komekome(int N,string S,int K){
    //cout << &S << endl;
    char a = S[K-1];
    for(int i=0;i<N;i++){
        if(S[i]!=a){
          S[i]='*';
        }
    }
    return S;
}
int main(){
    int N,K;
    string S;
    cin >> N >> S >> K;
    //cout << &S << endl;
    cout << komekome(N,S,K) << endl;
    return 0;
}

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

using namespace std;

#define ll long long 

int main()
{
    ll a ,b;
    cin >> a >> b;
    ll mid = (a+b) / 2;
    ll ans1 = abs(a-mid);
    ll ans2 = abs(b-mid);
    if(ans1 == ans2) cout << mid << endl;
    else cout << "IMPOSSIBLE\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int m = n * a;
  if(m < b){
    cout << m << endl;
  }else if(m > b){
    cout << b << endl;
  }else{
    cout << b << endl;
  }
}

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

typedef struct{
 int x;
 int y;
}P;//表示坐?

char graph[1000][1000];
P aim[10];
P s,g;//s起点，g?点
int N,W,H;
int vis[1000][1000]; //用来存?距?
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int bfs(P s,P g);

int main(){
    int i,j,t,step=0;
    cin>>H>>W>>N;
    
    for(i=0;i<H;i++)
    for(j=0;j<W;j++){
        cin>>graph[i][j];
      if(graph[i][j]<='9'&&graph[i][j]>='1'){ 
         t=graph[i][j]-'0';
         aim[t].x=i;
         aim[t].y=j;
      } //把1-N的坐?保存在 aim数?中 
      else if(graph[i][j]=='S'){
          s.x=i;
          s.y=j;
          graph[i][j]='.';
      }//得到最初的起点 
    }
    
    for(i=1;i<=N;i++){
       g.x=aim[i].x;
       g.y=aim[i].y;//1-N ，从小到大，?次把一个 作??点 
       step+=bfs(s,g);
       s.x=g.x;
       s.y=g.y;//到??个?点后??点?起点 
       graph[g.x][g.y]='.';
    }
   
    cout<<step<<endl;
}

int bfs(P s,P g){
    queue<P> que;
      P n;
    
    for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
     vis[i][j]=-1;
     
     que.push(s);
     vis[s.x][s.y]=0;
     
     while(que.size()){
         
       P p=que.front();
         que.pop();
       if(p.x==g.x&&p.y==g.y)
       break;
       
       for(int i=0;i<4;i++){
           n.x=p.x+dx[i];
           n.y=p.y+dy[i];//向四方漫射 
        if(0<=n.x&&n.x<H&&0<=n.y&&n.y<W&&graph[n.x][n.y]!='X'&&vis[n.x][n.y]==-1){
               que.push(n);
               vis[n.x][n.y]=vis[p.x][p.y]+1;
           }
       }
   }
     return vis[g.x][g.y];
}

Measured memory_bytes: 7948
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <climits>
#include <vector>
#include <string>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>

using namespace std;

const long long len = 100010;
long long n,a[len],s[len],p;
const long long mo = 1e9+7;
long long mi[len];

void extend_gcd(long long a, long long b, long long &x, long long &y) {
    if (!b) {
        x = 1, y = 0;
        return;
    }
    extend_gcd(b, a % b, y, x);
    y -= a / b * x;
}
/*
long long c(long long x,long long y) {
	if (y<x) return 0;
	long long m,n;
	extend_gcd(mi[y-x]*mi[x], mo, n, m);
    return (mi[y]*n%mo+mo)%mo;
}*/

int inv[len];
long long c(int n, int m) {
	if(m < n) return 0;
	return mi[m] * inv[n]% mo * inv[m - n] %mo;
}
int Pow(int a, int b) {
	int ret = 1;
	while(b) {
		if(b & 1) ret = 1LL * ret * a % mo;
		a = 1LL * a * a % mo;
		b >>= 1;
	}
	return ret;
}
int main()
{
	
    //freopen("test.in","r",stdin);
    //freopen("test.out","w",stdout);
    mi[0] = 1;
    mi[1] = 1;
    memset(s,0,sizeof(s));
    for (int i=2;i<=len;i++) {
    	mi[i] = mi[i-1]*i%mo;
    }
    for (int i = 0; i <= len; i++) {
		inv[i] = Pow(mi[i], mo-2);
	}
//	printf("%d %d %d \n", c(2,3), c(2,4), c(1, 2));
    cin >> n;
    for (int i=1;i<=n+1;i++) {
    	cin >> a[i];
    }
    for (int i=1;i<=n+1;i++) {
    	s[a[i]]++;
    	if (s[a[i]] == 2) {p = a[i];break;}
    }
    long long l[2];
    long long k = 0;
    for (int i=1;i<=n+1;i++) {
    	if (a[i] == p) {
    		l[k] = i;k++;
    	}
    }
    long long m = n+1-(l[1]-l[0]+1);
    for (int i=1;i<=n+1;i++) {
    	if (i == 1) cout << n << endl;
    	 else {
    	 if (i == n+1) cout << 1 << endl;
    	 else {
    	 	long long ans = ((c(i-1, n-1)  ) % mo + mo ) % mo;
    	 	ans = ans * 2 % mo -  c(i - 1, m);
    	 	ans = ans % mo + mo;
    	 	ans %= mo;
    	 	ans = (ans + c(i, n - 1)) % mo;
    	 	ans = (ans + c(i-2, n-1)) % mo;
    	 	printf("%lld\n",ans);
    	   }
    	 }
    }
    return 0;  
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

const ll M = 998244353;

ll n, a, b, k;
ll l;
ll fac[300005];
ll fiv[300005];
ll ans;

int main()
{
    scanf("%lld%lld%lld%lld", &n, &a, &b, &k);
    fac[0] = 1;
    for(ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % M;
    fiv[n] = 1;
    ll x = fac[n];
    for(ll i = 0; (1 << i) <= M; i++)
    {
        if((1 << i) & (M - 2)) fiv[n] *= x, fiv[n] %= M;
        x *= x;
        x %= M;
    }
    for(ll i = n - 1; i >= 0; i--) fiv[i] = fiv[i + 1] * (i + 1) % M;
    for(ll i = 0; i <= n; i++)
    {
        if(k < i * a) break;
        if((k - i * a) % b != 0) continue;
        ll j = (k - i * a) / b;
        if(j > n) continue;
        ans += fac[n] % M * fiv[n - i] % M * fiv[i] % M * fac[n] % M * fiv[j] % M * fiv[n - j] % M;
        ans %= M;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	ll a, b;
	cin >> a >> b;
	int i = 1;
	ll ans = a;
	for (int i = 1; i <= b; i++) {
		if (a * i % b == 0) {
			ans = a * i;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <map>

using namespace std;

typedef unsigned long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000

// ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;

int main(int argc, char const *argv[])
{
	ll n, k, a, b, x;
	map<ll, ll> m;
	map<ll, ll>::iterator it;
	scanf("%lld %lld", &n, &k);

	for(int i=0; i<n; i++)
	{
		scanf("%lld %lld", &a, &b);
		if((it = m.find(a)) != m.end())
		{
			x = (*it).second;
			m.erase(it);
			m.insert(make_pair(a, b+x));
		}
		else m.insert(make_pair(a, b));
	}

	ll l=0, ans;
	it = m.begin();
	while(l<k)
	{
		ans = (*it).first;
		l += (*it).second;
		it++;
	}
	printf("%lld\n", ans);

	return 0;
}


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

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()

ans = float('inf')
a, b, c, d = 0, 0, 0, 0

if H % 2 == 0:
    c, d = H / 2, H / 2
else:
    c, d = H // 2, H // 2 + 1

for i in range(-2, 3):
    a = W // 3 + i
    b = W - a
    if a > 0 and b > 0:
        pqr = [a * H, b * c, b * d]
        ans = min(ans, max(pqr) - min(pqr))
ans = min(ans, H)
H, W = W, H

if H % 2 == 0:
    c, d = H / 2, H / 2
else:
    c, d = H // 2, H // 2 + 1

for i in range(-2, 3):
    a = W // 3 + i
    b = W - a
    if a > 0 and b > 0:
        pqr = [a * H, b * c, b * d]
        ans = min(ans, max(pqr) - min(pqr))
ans = min(ans, H)
print(int(ans))


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
std::vector<std::vector<int> > hen;
std::vector<int> ord, cnter;
int cnt = 0;
std::vector<bool> used;
void dfs(int i) {
	for (auto j : hen[i]) {
		if (!used[j]) {
			used[j] = true;
			dfs(j);
		}
	}
	ord.push_back(i);
	cnter[i] = cnt++;
}
int main() {
	int n = ri(), m = ri();
	hen.resize(n);
	for (int i = 0; i < m; i++) {
		int a = ri() - 1, b = ri() - 1;
		hen[a].push_back(b);
	}
	cnter.resize(n);
	used.resize(n, false);
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			used[i] = true;
			dfs(i);
		}
	}
	std::reverse(ord.begin(), ord.end());
	for (auto &i : cnter) i = n - 1 - i;
	std::vector<int> dp(n);
	for (int i = 0; i < n; i++) {
		for (auto j : hen[ord[i]]) {
			dp[cnter[j]] = std::max(dp[cnter[j]], dp[i] + 1);
		}
	}
	std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;
	return 0;
}


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define int long long
#include <numeric>
using namespace std;

signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ans = 0;
  int x = 0;
  for( int i = 0; i < N; i++ ){
    if( S.at(i) == 'I' ){
      x++;
      if( ans < x ) ans = x;
    }else{
      x--;
      if( ans < x ) ans = x;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 256
def common_str(n,listt):
    ans_list = []
    flag = True

    while flag:
        com = set(listt[0])
        for i in range(1,n):
            com &= set(listt[i])
        a = list(com)
        if len(a) != 0:
            for i in range(len(com)):
                ans_list.append(list(com)[i])
                for j in range(n):
                    listt[j].remove(list(com)[i])
        else:
            flag = False

    return ans_list

if __name__ == '__main__':
    n = int(input())
    listt = []
    for i in range(n):
        x = list(input())
        listt.append(x)

    tmp = common_str(n,listt)
    tmp.sort()
    print(''.join(tmp))


Measured memory_bytes: 9208
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    char A;
    cin >> A;

    if(A >= 'A' && A <= 'Z')
        cout << "A" << endl;
    else
        cout << "a" << endl;

    return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long v = B1 * 100 + B2;
		//Console.WriteLine("{0} {1}",A, v );
		v *= A;
		Console.WriteLine(v / 100);
		
		
	}
	long A;
	long B1,B2;
	public Sol(){
		var ss = rsa();
		A = long.Parse(ss[0]);
		ss = ss[1].Split('.');
		B1 = long.Parse(ss[0]);
		B2 = long.Parse(ss[1]);
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 17872
#include <bits/stdc++.h>
#define N 50
using namespace std;
int ans,n,a[N|1],cnt[N|1],tot,pick[N|1],k,num[N|1],tmp[N|1];
void dfs(int d) {
	if(d>k) {
		for(int i=1;i<=tot;i++)
			tmp[i]=pick[i];
		int mn=abs(tmp[1]-tmp[2]);
		for(int i=1;i<=tot;i++)
			for(int j=1;j<i;j++)
				mn=min(mn,min(abs(tmp[i]-tmp[j]),24-abs(tmp[i]-tmp[j])));
		ans=max(ans,mn);
		return;
	}
	pick[++tot]=num[d];
	dfs(d+1);
	if(num[d])
		pick[tot]=24-num[d];
	dfs(d+1);
	tot--;
}
int main() {
	scanf("%d",&n);
	cnt[0]=1;
	for(int i=1;i<=n;i++) {
		scanf("%d",a+i);
		cnt[a[i]]++;
	}
	for(int i=0;i<=12;i++) {
		if(cnt[i]>=3||(cnt[i]==2&&(i==0||i==12))) {
			puts("0");
			return 0;
		} else if(cnt[i]==2) {
			pick[++tot]=i;
			pick[++tot]=24-i;
		} else if(cnt[i]==1&&(i==0||i==12)) {
			pick[++tot]=i;
		} else if(cnt[i]==1) {
			num[++k]=i;
		}
	}
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
l=list(map(int,input().split()))
#(ng,ok]type
#if k==0:print(max(l));exit()
#(ng,ok]type
ok,ng=10**9+1,0
def enough(x):
    return sum( (i//x) for i in l if i>x)<=k
# [ok,ng)type->eraseng,ok=ok,ng
eps=10**(-3)
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if enough(mid):ok=mid
    else:ng=mid
print(ok)


Measured memory_bytes: 94632
#include <bits/stdc++.h>
using namespace std;
long long a,b,k;
int main() 
{
	cin>>a>>b>>k;
	long long takahashi,aoki;
	if(k<=a) 
	{
		takahashi=a-k;
		aoki=b;
	}
	else 
		if(k<=a+b)
		{
			takahashi = 0;
			aoki=b-(k-a);
		}
		else
		{
			takahashi=0;
			aoki=0;
		}
	cout<<takahashi<<" "<<aoki;
}

Measured memory_bytes: 3588
// ConsoleApplication11.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
	int n,t,a,d;
	cin >> n >> t >> a;
	double b[1200],c=100000000;
	for (int i=0; i < n; i++) {
		cin >> b[i];
		if (t - b[i] * 0.006 < a) {
			if (a+b[i] * 0.006 - t < c) {
				c = a+b[i] * 0.006 - t;
				d = i;
			}
		}
		else { 
			if (t - b[i] * 0.006-a < c) { 
				c = t - b[i] * 0.006-a;
		        d = i;
		     }
		}
	}
	cout << d+1<< endl;
	
    return 0;
}



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

int main()
{
	int N, T;
	cin >> N >> T;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}
	vector<vector<int>> ldp(N + 1, vector<int>(T));
	for (int i = 0; i < N; i++) {
		ldp[i + 1] = ldp[i];
		for (int j = 0; j + A[i] < T; j++) {
			ldp[i + 1][j + A[i]] = max(ldp[i + 1][j + A[i]], ldp[i][j] + B[i]);
		}
		for (int j = 1; j < T; j++) {
			ldp[i + 1][j] = max(ldp[i + 1][j], ldp[i][j]);
		}
	}
	vector<vector<int>> rdp(N + 1, vector<int>(T));
	for (int i = N - 1; i >= 0; i--) {
		rdp[i] = rdp[i + 1];
		for (int j = 0; j + A[i] < T; j++) {
			rdp[i][j + A[i]] = max(rdp[i][j + A[i]], rdp[i + 1][j] + B[i]);
		}
		for (int j = 1; j < T; j++) {
			rdp[i][j] = max(rdp[i][j], rdp[i + 1][j]);
		}
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < T; j++) {
			res = max(res, ldp[i][j] + rdp[i + 1][T - 1 - j] + B[i]);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 70912
#include <map>
#include <utility>
#include <vector>
#include <string>
#include <iterator>
#include <algorithm>
#include <iostream>

int main() {
    int N;

    std::cin >> N;

    std::vector<std::string> S(N);
    std::map<std::string, int> S_map;

    // // O(n*log(n))
    // for (int i = 0; i < N; ++i) {
    //     std::string s;
    //     std::cin >> s;
    //     if (S_map.find(s) != std::end(S_map)) {
    //         S_map[s] += 1;
    //     } else {
    //         S_map[s] = 1;
    //     }
    // }

    // O(n)
    for (int i = 0; i < N; ++i) {
        std::string s;
        std::cin >> s;

        S.at(i) = s;
        S_map[s] = 0;
    }

    // O(n)
    for (auto& s : S) {
        S_map[s] += 1;
    }

    // O(n)
    int max_count = 0;
    for (auto itr = std::begin(S_map); itr != std::end(S_map); ++itr) {
        max_count = itr->second > max_count ? itr->second : max_count;
    }
    
    // O(n)
    std::vector<std::string> S_max_counted;
    for (auto itr = std::begin(S_map); itr != std::end(S_map); ++itr) {
        if (itr->second == max_count) {
            S_max_counted.emplace_back(itr->first);
        }
    }

    std::sort(std::begin(S_max_counted), std::end(S_max_counted));

    for (auto& s : S_max_counted) {
        std::cout << s << std::endl;
    }

    return 0;
}

Measured memory_bytes: 28404
#!python3

# input
N = int(input())


def prime_factor(x):
    m = {}
    i = 2
    while i ** 2 <= x:
        while x % i == 0:
            if i in m:
                m[i] += 1
            else:
                m[i] = 1
            x //= i
        i += 1
    if x != 1:
        m[x] = 1
    return m


def len_divisor(x):
    m = prime_factor(x)
    ans = 1
    for n in m.values():
        ans *= n + 1
    return ans        


def main():
    ans = 0
    for i in range(1, N + 1, 2):
        if len_divisor(i) == 8:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll n, arr[100005], suf[100005], nonleaf, ans;

void fail() {
	cout << -1;
	exit(0);
}

int main() {
	fastio; cin >> n;
	FOR(i, 0, n) cin >> arr[i];
	if (n == 0) {
		if (arr[0] == 1) cout << 1;
		else fail();
		return 0;
	}
	suf[n] = arr[n];
	DEC(i, n-1, 0) suf[i] = arr[i] + suf[i+1];
	if (arr[0] != 0) fail();
	nonleaf = 1; ans = 1;
	FOR(i, 0, n-1) { //currently at stage i, going to stage i+1
		nonleaf = min(nonleaf*2, suf[i+1]);
		ans += nonleaf;
		nonleaf -= arr[i+1];
		if (i != n-1 and nonleaf <= 0) fail();
		if (i == n-1 and nonleaf != 0) fail();
	}
	cout << ans;
}


Measured memory_bytes: 5200
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;

int k, n, a[N], ps[N];

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= min(100, k); i++){
		memset(ps, 0, sizeof ps);
		for (int j = 1; j <= n; j++){
//			cout << j - a[i] << '\n';
			ps[max(0, j - a[j])]++;
			ps[min(n + 1, j + a[j]+ 1)]--;
		}
		for (int j = 1; j <= n; j++) ps[j] += ps[j - 1];
		for (int j = 1; j <= n; j++) a[j] = ps[j];
	}
	for (int i = 1; i <= n; i++) cout << a[i] << ' ';











	return 0;
}


Measured memory_bytes: 5216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace practice01
{
    class Program
    {
        static void Main(string[] args)
        {

            char[] inputArray = (Console.ReadLine()).ToCharArray();

            string ans = "No";
            if(inputArray[0] == inputArray[2])
            {
                ans = "Yes";
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
A = [0] + list(map(int, input().split())) + [0]
diff = [abs(A[i]-A[i+1]) for i in range(n+1)]

#普通に総和を出す
sum = sum(diff)
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= diff[i-1]
  nowsum -= diff[i]
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)


Measured memory_bytes: 14048
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define endl '\n'
typedef long long ll;

int gcd(int a,int b){
    if(a < b){
        int tmp=a;
        a=b;
        b=tmp;
    }
    int r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    cout<<gcd(a,b)<<endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MAX = 1000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
//setprecision(15)

int main() {
	string s; cin >> s;
	if (s == "AAA" || s == "BBB") {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    ll dp[100001]={};
    dp[0]=1;
    ll X;
    cin >> X;
    for(int i=100; i<=100000; i++){
        if(dp[i-100]==1){
            dp[i]=1;
        }
    }
    for(int i=101; i<=100000; i++){
        if(dp[i-101]==1){
            dp[i]=1;
        }
    }
    for(int i=102; i<=100000; i++){
        if(dp[i-102]==1){
            dp[i]=1;
        }
    }
    for(int i=103; i<=100000; i++){
        if(dp[i-103]==1){
            dp[i]=1;
        }
    }
    for(int i=104; i<=100000; i++){
        if(dp[i-104]==1){
            dp[i]=1;
        }
    }
    for(int i=105; i<=100000; i++){
        if(dp[i-105]==1){
            dp[i]=1;
        }
    }
    
    cout<<dp[X]<<endl;
    return 0;
    
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	int N,M,Q;
	cin >> N >> M >> Q;
	vector<int> L(M), R(M);
	for(int i=0;i<M;i++) cin >> L[i] >> R[i];
	
	vector<int> p(Q), q(Q);
	for(int i=0;i<Q;i++) cin >> p[i] >> q[i];
	
	int mp[520][520];
	for(int i=0;i<520;i++) for(int j=0;j<520;j++) mp[i][j] = 0;
	
	for(int i=0;i<M;i++){
		int l = L[i];
		int r = R[i];
		int a = 0, b = r, c = l + 1, d = N + 1;
		mp[a][b]++;
		mp[a][d]--;
		mp[c][b]--;
		mp[c][d]++;
	}
	for(int i=0;i<520;i++){
		for(int j=1;j<520;j++){
			mp[i][j] += mp[i][j-1];
		}
	}
	for(int i=1;i<520;i++){
		for(int j=0;j<520;j++){
			mp[i][j] += mp[i-1][j];
		}
	}
	
	for(int i=0;i<Q;i++){
		printf("%d\n", mp[p[i]][q[i]]);
	}
	
    return 0;
}

Measured memory_bytes: 4352
#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
    return is >> v.first >> v.second;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (T& i: v) is >> i;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    int n = (int) v.size();
    for (int i = 0; i < n; ++i) os << v[i] << (i == n - 1 ? "" : " ");
    return os;
}

template <typename T>
void in(T& x) {
    std::cin >> x;
}

template <typename T1, typename... T2>
void in(const T1 H, const T2... T) {
    std::cin >> (H); in(T...);
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"
#define err(args...)      eout(#args, args)

#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 1000*1000*1000 + 7;

int solve();
int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0);
    //std::cout.tie(0);

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int solve() {
    int n; in(n);
    vi v(n); in(v);
    std::sort(all(v));

    double s = v[0];
    repr(i, 1, n) s = (s + v[i])/2.0;
    out(s);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string s;
    rep(i,3){
        cin>>s;
        cout<<char(s[0]-32);
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
import math

n = int(input())
if n == 1:
    print(1)
    exit()
if n == 2:
    print(1)
    exit()
if n == 3:
    print(1)
    exit()
for i in range(int(math.sqrt(n)),1, -1):
    print(i**2)
    exit()

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

typedef long long ll;

int main()
{
    string S;
    cin >> S;
    if (S == "RRR")
    {
        cout << 3 << endl;
    }
    else if (S == "RRS" || S == "SRR")
    {
        cout << 2 << endl;
    }
    else if (S == "SSS")
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<int> v;

  v.push_back(0);
  if (s[0] == '0') v.push_back(0);

  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) v.push_back(i + 1);
  }

  if (s[n - 1] == '0') v.push_back(n);
  v.push_back(n);

  int ans = 0;
  int m = v.size();
  for (int i = 0; i < m; i += 2) {
    int idx = min(i + 2 * k + 1, m - 1);
    int tmp = v[idx] - v[i];
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

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

using namespace std;

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

    int c0 = 0, c1 = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '0') c0++;
        else c1++;
    }

    cout << 2 * min(c0, c1) << endl;
}

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

struct laden{
	string stadt;
	int punkt;
	int nummer;
};

int main(){
	int n; cin >> n;
	vector<laden> liste;
	for( int i = 1; i <= n; ++i ){
		laden tmp;
		tmp.nummer = i;
		cin >> tmp.stadt >> tmp.punkt;
		liste.push_back(tmp);
	}
	sort(
		liste.begin(), liste.end(),
		[]( const laden& x, const laden& y ){
			return ( x.stadt == y.stadt ) ? ( x.punkt > y.punkt ) : ( x.stadt < y.stadt );
		}
	);
	for( auto l : liste ){
		cout << l.nummer << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

signed main() {
  ll N;
  cin >> N;

  vector<ll> A;
  A.pb(0);
  rep(i, N) {
    ll a;
    cin >> a;
    A.pb(a);
  }

  vector<ll> ans(N + 1);
  repr(i, N) {
    ll sum = 0;
    // debug(i);
    if (i == 0) {
      continue;
    }
    rep(j, N / i) {
      // debug(j);
      ll index = j + 1;
      if (j == 0) {
        sum += A[i];
      } else {
        sum += ans[i * index];
      }
    }
    // debug(sum);

    ans[i] = sum % 2;
  }

  ll count = 0;
  vector<ll> outputs;
  rep(i, N + 1) {
    if (i == 0) {
      continue;
    }
    if (ans[i] == 1) {
      count++;
      outputs.pb(i);
    }
  }

  COUT(count);
  rep(i, outputs.size()) {
    if (i == 0) {
      cout << outputs[i];
    } else {
      cout << " " << outputs[i];
    }
  }
  if (count != 0) {
    ENDL;
  }
  return 0;
}

Measured memory_bytes: 5872
import java.io.*;

public class Main {
	public static void main (String[] args) throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
		
		String numStr = input.readLine();
		
		int num = Integer.parseInt(numStr);
		
		System.out.println(num * num * num);
	}
}



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

using namespace std;

// FFT code from https://cp-algorithms.com/algebra/fft.html
const double PI = acos(-1);
void fft(vector<complex<double> > & a, bool invert) {
    int n = a.size();
    if (n == 1)
        return;

    vector<complex<double> > a0(n / 2), a1(n / 2);
    for (int i = 0; 2 * i < n; i++) {
        a0[i] = a[2*i];
        a1[i] = a[2*i+1];
    }
    fft(a0, invert);
    fft(a1, invert);

    double ang = 2 * PI / n * (invert ? -1 : 1);
    complex<double> w(1), wn(cos(ang), sin(ang));
    for (int i = 0; 2 * i < n; i++) {
        a[i] = a0[i] + w * a1[i];
        a[i + n/2] = a0[i] - w * a1[i];
        if (invert) {
            a[i] /= 2;
            a[i + n/2] /= 2;
        }
        w *= wn;
    }
}
vector<long long> multiply(vector<long long> const& a, vector<long long> const& b) {
    vector<complex<double> > fa(a.begin(), a.end()), fb(b.begin(), b.end());
    int n = 1;
    while (n < a.size() + b.size()) 
        n <<= 1;
    fa.resize(n);
    fb.resize(n);

    fft(fa, false);
    fft(fb, false);
    for (int i = 0; i < n; i++)
        fa[i] *= fb[i];
    fft(fa, true);

    vector<long long> result(n);
    for (int i = 0; i < n; i++)
        result[i] = round(fa[i].real());
    return result;
}

int n;
long long a[200000];;
long long int duapangkat[200004];;
long long int generator[200003];

int main() {
        long long dua = 1;
        duapangkat[0] = 1;
        for (int i = 1; i < 200003; i++) {
                dua = (dua << 1) % 200003;
                generator[dua] = i;
                // printf("generator %d = %d\n", dua, i);
                duapangkat[i] = dua;
        }
        duapangkat[200003] = 2;

        scanf("%d", &n);
        for (int i = 0; i < n; i++) scanf("%lld", a + i);

        vector<long long> power_of_twos;
        for (int i = 0; i < n; i++)
                if (a[i] != 0) {
                        // printf("a[i]=%d generator[a[i]]=%d\n", a[i], generator[a[i]]);
                        power_of_twos.push_back(generator[a[i]]);
                }

        // printf("%d\n", power_of_twos.size());
        // for (int v : power_of_twos) printf("%d\n", v);

        map<long long,long long> count;
        for (long long power: power_of_twos) count[power]++;
        vector<long long> polynomial;
        vector<long long> polynomial2;
        for (long long i = 0; i < 200003; i++)
                polynomial.push_back(count[i]);
        polynomial2 = polynomial;
        vector<long long> result = multiply(polynomial, polynomial2);

        for (long long i = 0; i < power_of_twos.size(); i++)
                result[power_of_twos[i]*2]--;

        long long ans = 0;
        for (long long i = 0; i < (int) result.size(); i++)
                if (result[i] > 0) {
                        // printf("result %d %d %d\n", i, result[i], duapangkat[i%200002]);
                        ans += duapangkat[i%200002] * result[i];
                }
        printf("%lld\n", ans/2);

        return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(m);
	for (int i = 0; i < m; i++)
		cin >> x[i];
	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(), x.end());
	priority_queue<int> d;
	for (int i = 0; i < m - 1; i++)
		d.push(abs(x[i + 1] - x[i]));
	for (int i = 0; i < n - 1; i++)
		d.pop();
	int ans = 0;
	while (!d.empty()) {
		ans += d.top();
		d.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1276
import math

n,h = map(int,input().split())
ab = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append([a,b,False])

ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
amax = ab[0][0]
bmax = ab[0][1]
ab[0][2] = True
ab.sort(key=lambda x:x[1],reverse=True)
cnt = 0
for i in range(n):
    if ab[i][1] > amax:
        h -= ab[i][1]
    else:
        h -= amax
    cnt+=1
    if h<=0:
        break
else:#forloopで終わんなかったら
    cnt += math.ceil(h/amax)

print(cnt)


Measured memory_bytes: 21192
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    /*ll N;
     cin>>N;
     
     vll A(N+1);
     for(ll i=0;i<=N;i++)cin>>A[i];
     if(N==0){
     if(A[0]==1){
     cout<<1<<endl;
     return 0;
     }else {
     cout<<-1<<endl;
     return 0;
     }
     }
     if(A[0]!=0){
     cout<<-1<<endl;
     return 0;
     }
     
     
     vll B(N+1);
     for(ll i=0;i<=N;i++){
     if(i==0){
     B[0]=1;
     }else{
     B[i]=(B[i-1]-A[i-1])*2;
     if(B[i]<A[i]){
     cout<<-1<<endl;
     return 0;
     }
     }
     }
     
     vll C(N+1);
     for(ll i=N;i>=0;i--){
     if(i==N){
     C[i]=A[i];
     }else{
     C[i]=C[i+1]+A[i];
     }
     }
     
     ll ans=0;
     for(ll i=0;i<=N;i++){ans+=min(B[i],C[i]);
     }
     cout<<ans<<endl;
     
     return 0;
     }
     
     int main() {*/
    //ll n,a[100005]={0},b[100005],c[100005],pv,ans=0;
    ll n,pv;
    
    //vll a(100005),b(100005),c(100005);
    bool ok=false;
    cin >> n;
    vll a(n+2),b(n+2),c(n+2);
    for(ll i=0;i<=n;i++){
        cin >> a[i];
    }
    for(ll i=0;i<=n;i++){
        if(i==0){
            if(a[i]>1){
                cout << -1 << endl;
                return 0;
            }
            b[0]=1;
        } else {
            if(ok) b[i]=1e17;
            else b[i]=(b[i-1]-a[i-1])*2;
            if(b[i]>=1e17) ok=true;
            if(a[i]>b[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    
    b[n+1]=1;
    for(ll i=n;i>=0;i--){
        if(i==n){
            c[i]=a[i];
        } else {
            c[i]=c[i+1]+a[i];
        }
    }
    c[n+1]=0;
    for(ll i=0;i<=n+1;i++){
        if(b[i]>c[i]){
            pv=i;
            break;
        }
    }
    ll ans=0;
    for(ll i=0;i<=n;i++){
        if(i<pv){
            ans+=b[i];
        } else {
            ans+=c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5440
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
//https://tradingeconomics.com/forecast/stock-market

signed main() {

	fastio();
	//#define LOCAL_DEFINE	
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,a,b;
	cin>>n>>a>>b;
	int res=(n/(a+b));
	
		cout<<a*res+(((n-res*(a+b))>a)?a:((n-res*(a+b))));
	return 0;
}

// https://github.com/FatihSevbanUyanik/Caltech-UCSD-Birds-PyTorch
// https://github.com/zctpig/Caltech-UCSD-Birds-200-2011/blob/master/%E2%80%9C%E2%80%9Cpytorch_caltech_birds_classification_ipynb%E2%80%9D%E7%9A%84%E5%89%AF%E6%9C%AC%E2%80%9D%E7%9A%84%E5%89%AF%E6%9C%AC.ipynb
// https://github.com/vinodjatav/Bird-Identification-using-ResNet50/blob/master/Bird_Identification_ResNet50_final_correct_model.ipynb
// https://github.com/AdrienBenamira/bird_classification_MVAchallenge
// https://www.kaggle.com/c/mva-recvis-2018/leaderboard
// https://github.com/Louis-Verret/mva-pixel2mesh
// https://github.com/bdvllrs/bird-classification-recvis



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long d = 100000;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		d *= 1.05;
		if(d%1000 > 0){
			d += 1000;
		}

		d /= 1000;
		d *= 1000;
	}
	cout<<d<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
N = int(input())
D  = [list(map(int,input().split())) for i in range(N)]
count = 0 
k = 0 
while count < 3 and k <= N-1:
        if D[k][0] == D[k][1]:
            count += 1
        else:
            count = 0 
        k+=1
        
if count == 3:
    print('Yes')
else:
    print("No")                

Measured memory_bytes: 9176
#include <stdio.h>

int main(void)
{
    char ti[1000];
    int buf;
    int h,m,s;

    fgets(ti,sizeof(ti),stdin);
    sscanf(ti,"%d",&buf);
    
    s = buf;
    h = s / 3600;
    m = s % 3600 / 60;
    s = s % 60;
    
    // printf("%d",buf);
    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num = s.nextInt();
		int ans = 1;

		for (int a = 2; a < 32; a++) {

			for (int b = 2; b < 9; b++) {
				if ((int) Math.pow(a, b) <=num) {
					ans = Math.max(ans, (int) Math.pow(a, b));
				}
			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    x /= 50;
    int ans = 0;
    rep(i, a+1) rep(j, b+1) rep(k, c+1) {
        int sum = 10*i + 2*j + k;
        if (sum==x) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  
  char x = 'A';
  char y = b.at(0);
  char z = 'C';
  
  cout << x ;
  cout << y ;
  cout << z << endl;
  
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n, m;
	cin >> n >> m;
	vector<P> ab(n);
	vector<P> cd(m);
	rep(i, n){
		int a, b;
		cin >> a >> b;
		ab[i] = P(a, b);
	}
	rep(i, m){
		int c, d;
		cin >> c >> d;
		cd[i] = P(c, d);
	}
	
	rep(i, n){
		int dist = INF;
		int point = 0;
		rep(j, m){
			int x = abs(ab[i].first - cd[j].first);
			int y = abs(ab[i].second - cd[j].second);
			if(x + y < dist){
				dist = x + y;
				point = j;
			}
		}
		cout << point+1 << endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
l, r = map(int, input().split(' '))

for i in range(l, r + 1):
    if divmod(i, 2019)[1] == 0:
        print(0)
        exit()

tmp = set()
for i in range(l, r):
    for j in range(l + 1, r + 1):
        tmp.add(divmod(i * j, 2019)[1])

print(min(tmp))


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	string s, t;
	cin >> s >> t;
	string tmp = t.substr(0, t.size() - 1);
	if (s == tmp)	cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 3600
# C - Peaks

n, m = map(int, input().split())
h = list(map(int, input().split()))
assert len(h) == n

# 良くない展望台
bad = set()
for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] <= h[b-1]:
        bad.add(a)
    if h[b-1] <= h[a-1]:
        bad.add(b)

print(n - len(bad))


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

int main(){
    string s;
    cin >> s;
    int x = 0, y = 0;
    for(int i=0; i<s.size(); i++) {
        if(s[i] == '0') x++;
        else y++;
    }
    cout << 2*min(x, y) << endl;
    return 0;
}

Measured memory_bytes: 512