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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

#define lpair pair<ll, ll>

int main()
{
  ll n;
  cin >> n;
  vector<ll> data;
  rep(i, n)
  {
    ll tmp;
    cin >> tmp;
    data.push_back(tmp);
  }
  
  sort(data.begin(), data.end());
  ll ans = 0;
  repl(i, data.size())
  repsl(j, i+1, data.size())
  repsl(k, j+1, data.size())
  {
    if(data[i] == data[j] || data[j] == data[k] || data[k] == data[i])
    {
      continue;
    }

    if(data[i] + data[j] > data[k])
    {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
 
int main(void) {
	// your code goes here
	int x,y;
	do{
	scanf("%d\n",&x);
	}while(x>100 || x<1);
 
	y=x*x*x;
 
	printf("%d\n",y);
 
	return 0;
}

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

typedef int64_t i64;
typedef uint64_t ui64;

class graph{
public:
    struct adj{
        int index;
        int start;
        int to;
        i64 cost;
    };
    int nd;
    int eg;
    vector<adj> *node;
    vector<adj> edge;
    graph(int n,int m){
        nd=n;
        eg=m;
        node=new vector<adj>[nd]{};
        edge={};
    }
    void add_dir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        edge.push_back({i,s,t,c});
    }
    void add_undir(int i,int s,int t,i64 c){
        node[s].push_back({i,s,t,c});
        node[t].push_back({i,t,s,c});
        edge.push_back({i,s,t,c});
    }
    void refr(void){
        for(int i=0;i<nd;i++) vector<adj>().swap(node[i]);
        delete[] node;
        vector<adj>().swap(edge);
    }
    bool IsLink(void);
    void DFS(int r,i64 *&p,bool *&vst);
    bool IsPlus(void);
    void BellmanFord(int s,i64 *&d);
    void Dijkstra(int s,i64 *&d);
    void BFS(int s,i64 *&d);
    void WarshallFloyd_dir(i64 **&d);
    void WarshallFloyd_undir(i64 **&d);
    i64 WMST_dir(int r);
    i64 WMST_undir(void);
    void Edmonds(int r,vector<adj> &p);
    void Kruscal(vector<adj> &p);
    void Prim(vector<adj> &p);
    void Artic(vector<int> &p);
    void Artic_sub(int r,int &k,int par,vector<int> &p,int *&ord,int *&low,bool *&vst);
    void Bridge(vector<adj> &p);
    void Bridge_sub(int r,int &k,int par,vector<adj> &p,int *&ord,int *&low,bool *&vst);
    void SCC(int *&c);
    void SCC_sub1(int r,vector<int> &vs,bool *&vst);
    void SCC_sub2(int r,int k,int *&c,bool *&vst,graph &rg);
    bool IsDAG(void);
    bool IsDAG_sub(int r,int &k,int *&l,int *&vst);
    void Cumul(int s,i64 *&d);
};

bool graph::IsDAG(void){
    int *vst=new int[nd]{};
    int *l=new int[nd]{};
    int k=0;
    for(int i=0;i<nd;i++){
        if(vst[i]==0){
            if(!IsDAG_sub(i,k,l,vst)){
                delete[] l;
                delete[] vst;
                return 0;
            }
        }
    }
    delete[] l;
    delete[] vst;
    return 1;
}

bool graph::IsDAG_sub(int r,int &k,int *&l,int *&vst){
    bool f=1;
    if(vst[r]==-1){
        return 0;
    }
    else if(vst[r]==0){
        vst[r]=-1;
        for(const auto &i:node[r]){
            f=(f && IsDAG_sub(i.to,k,l,vst));
        }
        if(!f) return 0;
        vst[r]=1;
        l[k]=r;
        k++;
    }
    return f;
}

int main(void){
    int v,e;
    scanf("%i%i",&v,&e);
    graph g(v,e);
    int s,t;
    for(int i=0;i<e;i++){
        scanf("%i%i",&s,&t);
        g.add_dir(i,s,t,1);
    }
    if(!g.IsDAG()) printf("1\n");
    else printf("0\n");
    return 0;
}



Measured memory_bytes: 3228
//abc120_d.cpp
//Mon Jun  3 21:59:38 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
//Union-Find木
int par[100000]; //親
int treerank[100000]; //木の深さ
ll nodenum[100000];

//n要素で初期化
void init(int n){
	for (int i=0;i<n;i++){
		par[i] = i;
		treerank[i] = 0;
		nodenum[i] = 1;
	}
}

//木の根（親）を見つける
int find (int x){
	if (par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合の併合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	} 

	if (treerank[x] < treerank[y]){
		par[x] = y;
		nodenum[y] += nodenum[x];
		nodenum[x] = 0;
	} else {
		par[y] = x;
		nodenum[x] += nodenum[y];
		nodenum[y] = 0;
		if (treerank[x] == treerank[y]){
			treerank[x]++;
		}
	}
}

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

	P bridge[m];
	for (int i=0;i<m;i++){
		cin >> bridge[i].first >> bridge[i].second;
		bridge[i].first--;
		bridge[i].second--;
	}

	init(n);

	ll ans[m];
	fill(ans,ans+m,0);
	if (n%2==0){
		ans[m-1] = n/2;
		ans[m-1] = ans[m-1]*(n-1);
	}else{
		ans[m-1] = (n-1)/2;
		ans[m-1] = ans[m-1]*n;
	}
	for (int i=m-1;i>=1;i--){
		if (find(bridge[i].first)==find(bridge[i].second)){
			ans[i-1] = ans[i];
		}else{
			ans[i-1] = ans[i]-nodenum[find(bridge[i].first)]*nodenum[find(bridge[i].second)];
			unite(bridge[i].first,bridge[i].second);
		}
//		for (int j=0;j<n;j++){
//			cout << nodenum[j] << " ";
//		}
//		printf("\n");
	}

	for (int i=0;i<m;i++){
		cout << ans[i] << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 4480
import java.util.Scanner;

    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int a = sc.nextInt();
    		String op = sc.next();
    		int b = sc.nextInt();
    		if(op.equals("+")) {
    			System.out.println(a+b);
    		}
    		else{
    			System.out.println(a-b);
    		}
    	}
    }

Measured memory_bytes: 23124
from collections import deque
S = deque(input())
Q = int(input())
reverse = 0
for i in range(Q):
  Query = list(input().split())
  if Query[0] == "1":
    reverse = (reverse + 1) % 2
  if Query[0] == "2":
    f = int(Query[1])
    c = Query[2]
    if (f + reverse) % 2 == 1:
      S.appendleft(c)
    else:
      S.append(c)

S = "".join(list(S))
 
if reverse == 0:
  print(S)
else:
  print(S[::-1])

Measured memory_bytes: 8692
N, K = map(int, input().split())
x = list(map(int, input().split()))

ans = []

for i in range(N-K+1):
    tmp = x[i+K-1] - x[i] + min(abs(x[i]), abs(x[i+K-1]))
    ans.append(tmp)

#print(ans)
ans = min(ans)
print(ans)

Measured memory_bytes: 14224
num = int(input())
if num <= 200:

    num_list = [int(x) for x in input().split()]

    even_flg = True
    count = 0
    while even_flg:
        for i, n in enumerate(num_list):
            if n % 2 == 0:
                count += 1
                num_list[i] = n / 2
            else:
              	even_flg = False
    count = count / len(num_list)
    print(int(count))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector< vector <int> >vee;
typedef vector<pair<int,int> >vepa;
typedef set<char>se;
typedef map<ll,ll> mpp;
const int N=1e5+5;
bool f;
ll dp[10000][10000],n,m;
char grid[1005][1005];
ll solve(int i=0,int j=0)
{
    if(i==n-1&&j==m-1)return 1;
    if(i<0||i==n||j<0||j==m||grid[i][j]=='#')return 0;
    ll &ret=dp[i][j];
    if(~ret) return ret;
    return ret=( solve(i+1,j)+solve(i,j+1) )%((int)1e9+7);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
     memset(dp,-1,sizeof dp);
     cin>>n>>m;
     rep(i,n)
      rep(j,m)
       cin>>grid[i][j];
     cout<<solve();
go;
}



Measured memory_bytes: 782592
import math

a, b, h, m = map(int, input().split())

x = 6 * m
y = 30 * h + 0.5 * m
C = max(x, y) - min(x, y)
C = min(C, 360 - C)

print(math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C))))


Measured memory_bytes: 9520
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
int n, m, i, j, k, t, a, b;
char s[80];
int main(){
	cin>>a>>b;
	if(b<=9) n=a*10+b;
	else{
		if(b==100) n=a*1000+b;
		else n=a*100+b;
	}
	t=0;
	for(i=1;i<=1100;i++){
		if(i*i==n) t=1;
	}
	if(t) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
//
//  abc151_e.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll INF = 1000000007;
#define PI 3.14159265

const int MAX = 110000;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; i++) {
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

ll COM(int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k]* finv[n-k] % mod) % mod;
}

ll HCOM(int n, int k) {
    return (n == 0 && k == 0) ? 1 : COM(n+k-1, k);
}


int main() {
  int n, k;
  std::cin >> n >> k;
  vector<ll> a;

  COMinit();

  for (int i = 0; i < n; i++) {
    ll t;
    std::cin >> t;
    a.push_back(t);
  }
  sort(a.begin(), a.end());

  ll smax = 0;
  for (int i = k-1; i < n; i++) {
    smax = (smax + a[i]*COM(i, k-1)) % mod;
  }

  ll smin = 0;
  for (int i = 0; i < n-k+1; i++) {
    smin = (smin + a[i]*COM(n-1-i, k-1)) % mod;
  }

  std::cout << (smax - smin + mod)%mod << std::endl;
  return 0;
}



Measured memory_bytes: 3960
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n){
        vector<long long> A;
        vector<long long> ans;
        rep(i,n){
            int inp;
            cin >> inp;
            A.push_back(inp);
        }
        sort(A.begin(), A.end());
        long long  t, a, l;
        rep(i,5){
            rep(j,5){
                if(i == j) continue;
                t = (int)log10(A[j]);
                a = A[i];
                rep(k,t + 1){
                    a*=10;
                }
                ans.push_back(a + A[j]);
            }
        }
        sort(ans.begin(), ans.end());
        cout << ans[2] << endl;
    }
}

Measured memory_bytes: 1384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, T;
    cin >> N >> T;
    int c[100], t[100], min = 1001, ans = -1;
    for(int i=0;i<N;i++)
        cin >> c[i] >> t[i];
    
    for(int i=0;i<N;i++){
        if(t[i] <= T && c[i] < min){
            ans = c[i];
            min = c[i];
        }
            

    }
    if(ans == -1)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
program different_strokes
  implicit none
  integer :: n, a, b, s(100000), i
  integer(8) :: m
  s = 0
  m = 0_8
  read(*,*) n
  do i = 1, n
    read(*,*) a, b
    s(i) = a+b
    m = m-int(b,8)
  end do
  call bitonic_sort(s(1:n),.false.)
  m = m+sum(int(s(1:n:2),8))
  write(*,'(i0)') m
  stop
contains
  recursive subroutine bitonic_sort(a,ascend)
    implicit none
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n
    n = size(a)
    if (n.eq.1) return
    call bitonic_sort(a(1:n/2),.not.ascend)
    call bitonic_sort(a(n/2+1:n),ascend)
    call bitonic_merge(a,ascend)
    return
  end subroutine bitonic_sort
  recursive subroutine bitonic_merge(a,ascend)
    implicit none
    integer, intent(inout) :: a(:)
    logical, intent(in) :: ascend
    integer :: n, m, i, b
    n = size(a)
    if (n.eq.1) return
    m = 1
    do while (2*m.lt.n)
      m = 2*m
    end do
    do i = 1, n-m
      if ((a(i).gt.a(i+m)).eqv.ascend) then
        b = a(i)
        a(i) = a(i+m)
        a(i+m) = b
      end if
    end do
    call bitonic_merge(a(1:m),ascend)
    call bitonic_merge(a(m+1:n),ascend)
    return
  end subroutine bitonic_merge
end program different_strokes

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] cnt = new int[13];
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();

			cnt[a / 400]++;
		}

		int min = 0;
		for (int i = 0; i <= 7; i++) {
			if (cnt[i] > 0) {
				min++;
			}
		}

		int max = 0;
		for (int i = 8; i < 13; i++) {
			max += cnt[i];
		}

		pr.printf("%d %d\n", Math.max(1, min), min + max);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23764
s=list(input())
w=0
c=0
if s[0]!='A':
    w=1
if s[1].isupper():
    w=1
for i in range(2,len(s)-1):
    if s[i]!='C' and s[i].isupper():
        w=1
    elif s[i]=='C':
        c+=1
if s[-1].isupper():
    w=1
if w==0 and c==1:
    print('AC')
else:
    print('WA')


Measured memory_bytes: 3060
#include <cstdio>

int f[8010][8010],a[200001],b[200001],_mul[100001],invmul[100001],n;
const int P=1000000007;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
inline int add(int a,const int &b){a+=b;return(a>=P)?a-P:a;}
inline int sub(int a,const int &b){a-=b;return (a<0)?a+P:a;}
int C(int n,int m){return mul(mul(_mul[n],invmul[m]),invmul[n-m]);}
int main(){
	scanf("%d",&n);
	_mul[0]=_mul[1]=invmul[0]=invmul[1]=1;
	for(int i=2;i<=8000;i++)_mul[i]=mul(_mul[i-1],i);
	for(int i=2;i<=8000;i++)invmul[i]=mul(P-P/i,invmul[P%i]);
	for(int i=2;i<=8000;i++)invmul[i]=mul(invmul[i-1],invmul[i]);
	for(int i=1;i<=n;i++)scanf("%d%d",a+i,b+i),++f[a[i]+2000][b[i]+2000];
	for(int i=4000;~i;--i)
		for(int j=4000;~j;--j)
			f[i][j]=add(add(f[i][j],f[i+1][j]),f[i][j+1]);
	int ans=0;
	for(int i=1;i<=n;i++)ans=add(ans,sub(f[2000-a[i]][2000-b[i]],C((a[i]+b[i])<<1,a[i]<<1)));
	printf("%d\n",mul(ans,(P+1)>>1));
}

Measured memory_bytes: 128512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] table = new int[r + 1][c + 1];
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				table[i][j] = sc.nextInt();
			}
		}
		for (int i = 0; i < r; i++) {
			int sum = 0;
			for (int j = 0; j < c; j++) {
				sum += table[i][j];
			}
			table[i][c] = sum;
		}
		for (int i = 0; i < c + 1; i++) {
			int sum = 0;
			for (int j = 0; j < r; j++) {
				sum += table[j][i];
			}
			table[r][i] = sum;
		}
		for (int i = 0; i <= r; i++) {
			for (int j = 0; j <= c; j++) {
				if (j == 0) {
					System.out.print(table[i][j]);
				}else {
					System.out.print(" " + table[i][j]);
				}
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 42640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int minPrice(int* menu, int length) {
    int mPrice = 0;
    for (int i = 0; i < length; i++) {
        if (mPrice == 0 || mPrice > menu[i])
            mPrice = menu[i];
    }
 
    return mPrice;
}
 
int main(void){
    int pasta[3], juice[2];
    for (int i = 0; i < 3; i++) {
        cin >> pasta[i];
    }
    for (int i = 0; i < 2; i++) {
        cin >> juice[i];
    }
 
    int minSetPrice = minPrice(pasta, 3) + minPrice(juice, 2) - 50;
    cout << minSetPrice << endl;
}

Measured memory_bytes: 3092
import numpy as np
import functools
import math
import collections
import scipy
import fractions
import itertools

def rle(l):
    hoge = list(set(l))
    huga = []
    for i in hoge:
        huga.append(l.count(i))
    huga.sort()
    return huga

def solve():
    s = list(input())
    t = list(input())
    if rle(s) == rle(t):
        print("Yes")
    else:
        print("No")
    return 0

if __name__ == "__main__":
    solve()


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

int main(){
  double pb[100][5001];
  int x,y,z,n,m,l,ub;
  int v[4],e[51],a[51];

  while(cin >> x >> y >> z && (x||y||z)){

    for(int i=0;i<x;i++)cin >> v[i];
    for(int i=0;i<=y;i++)e[i] = a[i] = 0;
    ub = 0;
    for(int i=0;i<z;i++){
      cin >> n >> m >> l;
      e[n] = m; a[n] = l;
      if(m==2)ub += a[n];
    }

    for(int i=0;i<=y;i++)
      for(int j=0;j<=ub;j++)pb[i][j] = 0.0;
    pb[0][0] = 1.0;

    for(int i=0;i<y;i++)
      for(int j=0;j<=ub;j++){
	if(pb[i][j] == 0.0)continue;
	for(int k=0;k<x;k++){
	  int next = min(y,i+v[k]),value = j;
	  if(e[next] == 1)next = min(y,next+a[next]);
	  else if(e[next] == 2)value = j + a[next];
	  else if(e[next] == 3)value = max(0,j-a[next]);
	  pb[next][value] += pb[i][j]/x;
	}
      }
    

    double ans = 0.0;
    for(int i=0;i<=ub;i++)ans += pb[y][i] * i;
    cout << (int)(ans) << endl;
  }
}

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

int main(){
  int n,k;
  cin >> n >> k ;
  int i;
  vector<int> h(n);
  for(i=0; i<n; i++) cin >> h[i];
  int ans=0;
  for(i=0; i<n; i++){
    if(h[i]>=k) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

ll b[55], p[55], l[55];

int main(int argc, char const *argv[])
{
	int n; ll x; cin >> n >> x;
	b[0] = 0; p[0] = 1; l[0] = 1;
	rep(i, n) {
		b[i + 1] = 2 * b[i] + 2;
		p[i + 1] = 2 * p[i] + 1;
		l[i + 1] = b[i + 1] + p[i + 1];
	}

	ll sum = 0, sump = 0;
	for (int i = n; i >= 1; --i) {
		rep(j, 5) {
			if (j == 0) {
				if (sum + 1 > x) {
					break;
				}
				sum++;
			} else if (j == 1) {
				if (sum + l[i - 1] > x) {
					break;
				}
				sum += l[i - 1];
				sump += p[i - 1];
			} else if (j == 2) {
				if (sum + 1 > x) {
					break;
				}
				sum++; sump++;
			} else if (j == 3) {
				if (sum + l[i - 1] > x) {
					break;
				}
				sum += l[i - 1];
				sump += p[i - 1];
			} else {
				if (sum + 1 > x) {
					break;
				}
				sum++;
			}
		}
		if (sum == x) break;
	}

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

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  int A[N+1],B[N];
  for(int i=0;i<=N;i++){
    scanf("%d",&A[i]);
  }
  for(int i=0;i<N;i++){
    scanf("%d",&B[i]);
  }
  long long a=0;
  for(int i=0;i<N;i++){
    if(B[i]>=A[i]+A[i+1]){
      a=a+A[i]+A[i+1];
      A[i]=0;
      A[i+1]=0;
    }
    else if(B[i]>=A[i]){
      A[i+1]=A[i+1]-B[i]+A[i];
      a=a+B[i];
      A[i]=0;
    }
    else{
      A[i]=A[i]-B[i];
      a=a+B[i];
    }
  }
  printf("%lld\n",a);
  return 0;
}


Measured memory_bytes: 896
# your code goes here
from math import floor
N, X = [int(x) for x in input().split()]

y = N-X
x = X
L = X
while x > 0:
#	k = 2*floor(y/x)
	k, z = divmod(y, x)
#	dL = x*(2*k-1)+y
	L += x*(2*k-1)+y
#	print(x, y, k, dL)
	y, x = (x, z)

#L += y
print(L)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N, K;
    cin >> N >> K;
    
    vector<int> h(N);
    REP(i, N) cin >> h[i];
    
    sort(ALL(h));

    int diff = 0;
    int ans = inf;

    diff = h[K-1] - h[0];
    ans = diff;
    // cout << ans << endl;
    
    for(int i = K; i < N; i++) {
        diff = h[i] - h[i-K+1];
        ans = min(ans, diff);
        // cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
// <head>
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
// </head>

// <library>
    
// </library>

struct Edge{
    ll to, a, b;
    Edge(ll to, ll a, ll b): to(to),a(a),b(b){}
};
const ll MAXV = 50;
const ll MAXS = MAXV * 50 + 5;
vector<Edge> g[MAXV];
ll dp[MAXV][MAXS+5];

struct Data{
    ll s,v,t;
    Data(ll v, ll s, ll t) : v(v),s(s),t(t) {}
    bool operator<(const Data& a) const {
        return t> a.t;
    }
};
int main(){
    ll n,m,s;
    cin >> n >> m >> s;

    for (int i = 0; i < m; i++){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].emplace_back(v,a,b);
        g[v].emplace_back(u,a,b);
    }
    vector<ll> c(n), d(n);
    for (int i = 0; i < n; i++){
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i < MAXV; i++){
        for (int j = 0; j < MAXS; j++){
            dp[i][j] = LINF;
        }
    }
    s = min(s, MAXS);

    priority_queue<Data> q;
    dp[0][s]= 0;
    q.emplace(0,s,0);
    while(!q.empty()){
        Data dt = q.top(); q.pop();
        if(dp[dt.v][dt.s]<dt.t) continue;
        if(dt.s<0) continue;

        // exchange
        ll ns = min(MAXS, dt.s+c[dt.v]);
        if (dp[dt.v][ns] > dt.t+d[dt.v]){
            dp[dt.v][ns] = dt.t+d[dt.v];
            q.emplace(dt.v, ns, dt.t+d[dt.v]);
        }

        // move to other station
        for (Edge e : g[dt.v]){
            if (dt.s-e.a >=0 && dp[e.to][dt.s-e.a] > dp[dt.v][dt.s] + e.b){
                dp[e.to][dt.s-e.a] = dp[dt.v][dt.s] + e.b;
                q.emplace(e.to,dt.s-e.a,dp[e.to][dt.s-e.a]);
            }
        }
    }
    for (int i = 1; i < n; i++){
        ll ans = LINF;
        for (int j = 0; j < MAXS; j++){
            ans = min(ans, dp[i][j]);
            
        }
        cout << ans << '\n';
        
    }
    
    
}

Measured memory_bytes: 7284
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int maxn = 1e5 + 5;
LL a[maxn], d[maxn];
const int inf = 1e9 + 7; 
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n, k;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		d[i] = inf;
	}
	d[0] = 0;
	for(int i = 1; i < n; ++i){
		for(int j = 1; j <= k && i >= j; ++j){
			d[i] = min(d[i], d[i - j] + abs(a[i - j] - a[i]));
		}
	}
	cout << d[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
from collections import deque
H, W = map(int, input().split(' '))
maze = [[ch for ch in input()] for _ in range(H)]
max_ans = -1
'''
幅優先探索 実装
'''
def bfs(sx, sy):
    queue = deque()
    queue.append([sx, sy])
    cost_map = [[None if maze[i][j] == '.' else -1 for j in range(W)] for i in range(H)]
    cost_map[sy][sx] = 0
    while queue:
        x, y = queue.popleft()
        for next_x, next_y in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if (-1 < next_x < W) and (-1 < next_y < H) and (cost_map[next_y][next_x] is None):
                queue.append([next_x, next_y])
                cost_map[next_y][next_x] = cost_map[y][x] + 1
    return max([max(x) for x in cost_map])

for i in range(W):
    for j in range(H):
        if maze[j][i] != '#':
            ans = bfs(i, j)
            if max_ans < ans:
                max_ans = ans
print(max_ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define P 998244353
#define ll long long
using namespace std;
map<vector<int>,int>mp,pm;
int Get(vector<int> S);
int G(vector<int>S)
{
	int n=S.size();
	if (n==1) return S[0]?2:1;
	if (mp[S]) return mp[S];
	int sum=0;
	for (int i=2;i<=n;i++)
	if (n%i==0)
	{
		vector<int>tmp;tmp.clear();
		for (int j=1;j<=n/i;j++)
			tmp.push_back(1);
		for (int j=0;j<n;j++)
			tmp[j%(n/i)]&=S[j];
		//cout<<tmp[0]<<' '<<S[0]<<endl;
		sum=(sum+Get(tmp))%P;
	}
//	cout<<"#";for (int i:S)cout<<i<<' ';cout<<sum<<endl;

	return mp[S]=sum;
}
int Get(vector<int> S)
{
	if (pm[S]) return pm[S];
	int n=S.size(),sum=G(S);
	vector<int>T;T.clear();
	for (int i=1;i<n;i++)
	{
		T.push_back(S[i-1]);
		vector<int> tmp;tmp.clear();
		for (int j=i;j<n;j++)tmp.push_back(S[j]);

		sum=(sum+(ll)G(T)*Get(tmp))%P;
	}
//	for (int i:S)cout<<i<<' ';cout<<sum<<endl;
	return pm[S]=sum;
}
int main()
{
	int n;char s[1005];
	scanf("%s",s+1);n=strlen(s+1);
	vector<int>S;
	for (int i=1;i<=n;i++)
		S.push_back(s[i]-'0');
	printf("%d\n",Get(S));
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;

    int total = 0;
    for (int i = 1; i <= n; i++) {
        int subtotal = 0;
        int tmp = i;
        while (tmp > 0) {
            subtotal += tmp % 10;
            tmp = tmp / 10;
        }

        if (a <= subtotal && subtotal <= b) {
            total += i;
        }
    }

    cout << total << endl;
}


Measured memory_bytes: 256
#include <cstdio>
char str[1001];
int main() {
	scanf("%s",str);
	for(int i=0;str[i];i++) {
		if(str[i]>='D') {
			putchar(str[i]-3);
		}else {
			putchar('Z'+(str[i]-'C'));
		}
	}
	putchar('\n');
}

Measured memory_bytes: 932
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll a,b,c,d; cin>>a>>b>>c>>d;
  vector<ll> vv{ a*c, a*d, b*c, b*d };
  ll mx = a*c;
  for( ll i=0; i<4; i++ ){
    mx = max(vv[i],mx);
  }
  cout<<mx<<endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<numeric>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  long long a,b,c;
  cin>>a>>b>>c;
  long long ans=min(b+c,a+2*b+1);
  cout<<ans<<endl;
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    ll res = 0;
    rep(i, n + 1)
    {
        if (i % 3 != 0 && i % 5 != 0)
        {
            res += i;
        }
    }
    c(res);
}


Measured memory_bytes: 3564
def solve():
    n = int(input())
    s=input()
    s=[1 if i=='o' else -1 for i in s]
    ans=[0]*n
    ini=[(1, 1), (1, -1), (-1, 1), (-1, -1)]
    for i in ini:
        ans[0]=i[0]
        ans[1]=i[1]
        for j in range(2, n):
            ans[j]=ans[j-1]*ans[j-2]*s[j-1]
        if ans[n-1]*ans[0]*s[0]==ans[1] and ans[n-1]*ans[n-2]*s[n-1]==ans[0]:
            ans=['S' if i==1 else 'W' for i in ans]
            return ''.join(ans)
    return -1
print(solve())

Measured memory_bytes: 48692
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <limits>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, start, end) for(ll i_=(ll)start; i_<(ll)end; i_++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");

ll gcd(ll a, ll b){
	if(b == 0)
		return a;
	else return gcd(b,a%b);
}

int main(){
  ll a, b, ans=1, last=0, i=2;
  cin >> a >> b;
  ll x = gcd(a, b);
  ll t = x;
  
  while (i * i <= t){
    if (x % i == 0){
      while (x % i == 0){
        x /= i;
      }
      ans++;
    }
    i++;
  }
  if (x != 1) ans++;
  print(ans);
  
  return 0;
}

Measured memory_bytes: 256
//21
#include<iostream>
#include<stack>
#include<string>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<iomanip>

using namespace std;

int main(){
  for(string s;getline(cin,s);){
    stringstream ss(s);
    stack<double> stk;
    for(string t;ss>>t;){
      if(t.size()>1||isdigit(t.c_str()[0])){
	stk.push(atof(t.c_str()));
      }else{
	double a,b;
	a=stk.top();
	stk.pop();
	b=stk.top();
	stk.pop();
	switch(t.c_str()[0]){
	case '+':
	  stk.push(b+a);
	  break;
	case '-':
	  stk.push(b-a);
	  break;
	case '*':
	  stk.push(b*a);
	  break;
	case '/':
	  stk.push(b/a);
	  break;
	}
      }
    }
    if(!stk.empty()){
      cout<<fixed<<setprecision(5)<<stk.top()<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ll long long
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  int ans = 0;
  REP(i, n){
    cin >> v[i];
    ans += v[i] - 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int64_t facc(int64_t k){
    int64_t sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
      sum %= 1000000007;
    }
    return sum;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long faccinv(int64_t k){
  if(k==0){
    return 1LL;
  }
  long long sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum *= modinv(i, 1000000007);
      sum %= 1000000007;
    }
    return sum % 1000000007;
}

int main(){
  int64_t X, Y;
  cin >> X >> Y;
  if((X+Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  int64_t c = (X+Y)/3;
  int64_t cnt = 0;
  int64_t res = 0;
  rep(i, c+1){
    if(X==(i+2*(c-i)) && Y==(2*i + (c-i))){
      res = facc(c)*faccinv(i);
      res %= 1000000007;
      res *= faccinv(c-i);
      res %= 1000000007;
      cnt += res;
//      cout << facc(c) << " " << faccinv(i) << " " << faccinv(c-i) << endl;
//      cout << i << " " << cnt << endl;
    }
  }
  cout << cnt % 1000000007 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ABC152E
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            BigInteger[] A = ReadLong();

            BigInteger mod = 1000000007;
            BigInteger lcm = 1;
            lcm = (A.Aggregate(Calc.Lcm) % mod);
            //for (int i = 0; i < N; i++)
            //{
            //    lcm = Calc.Lcm(A[i], lcm) % mod;
            //}

            BigInteger sum = 0;
            for (int i = 0; i < N; i++)
            {
                sum += (lcm * Calc.ModPow(A[i], mod - 2, mod)) % mod;
                sum %= mod;
            }

            Console.WriteLine(sum);
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static BigInteger[] ReadLong()
        {
            BigInteger[] ret = Console.ReadLine().Split().Select(BigInteger.Parse).ToArray();
            return ret;
        }
    }

    class Calc
    {
        // 最小公倍数
        public static BigInteger Lcm(BigInteger a, BigInteger b)
        {
            //return a / Gcd(a, b) * b;
            return a / (BigInteger)BigInteger.GreatestCommonDivisor(a, b) * b;
        }

        // ユークリッドの互除法 
        public static BigInteger Gcd(BigInteger a, BigInteger b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

        /// <summary>
        /// a^n (mod p)
        /// nが非常に大きい時に有効
        /// </summary>
        /// <param name="a"></param>
        /// <param name="n"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static BigInteger ModPow(BigInteger a, BigInteger n, BigInteger p)
        {
            if (n == 1) return a % p;
            if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p;

            BigInteger t = ModPow(a, n / 2, p);
            return (t * t) % p;
        }

        /// <summary>
        /// 組み合わせ個数
        /// </summary>
        /// <param name="n"></param>
        /// <param name="k"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static BigInteger nCk(BigInteger n, BigInteger k, BigInteger p)
        {
            BigInteger ans = 1;
            for (BigInteger i = n; i > n - k; i--)
            {
                ans = (ans * i) % p;
            }

            for (BigInteger i = 1; i <= k; i++)
            {
                ans = (ans * ModPow(i, p - 2, p)) % p;
            }

            return ans;
        }
    }
}


Measured memory_bytes: 41512
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;
LL N, K;
std::vector<LL>a(N);
std::vector<std::vector<LL>>memo;

// dp(i, j) = dp(i - 1, j) + dp(i - 1, j - 1) + ... + dp(i - 1, j - a[i])
// dp(i, j) = dp(i - 1, j) + dp(i, j - 1) - dp(i - 1, j - a[i] - 1)
LL dp(LL i, LL j)
{
	if (j == 0) return 1;
	if (j < 0) return 0;
	if (i == -1) return 0;
	if (memo[i][j] != -1) return memo[i][j];
	return memo[i][j] = ((dp(i - 1, j) + dp(i, j - 1)) % mod - dp(i - 1, j - a[i] - 1) + mod) % mod;
}

int main()
{
	in >> N >> K;
	a.resize(N);
	rep(i, N) in >> a[i];

	memo.resize(N);
	rep(i, memo.size()) memo[i].resize(K + 1, -1);
	out << dp(N - 1, K) << std::endl;
}


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

int main() {
  long long k,n,ans=2000000;
  cin>>k>>n;
  long long a[500000];
  for(int i=0;i<n;i++){
    int l;
    cin>>l;
    a[i]=l;
  }
  for(int i=0;i<n;i++){
    a[i+n]=a[i]+k;
  }
  for(int i=0;i<n;i++){
    ans=min(ans,a[i+n-1]-a[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  vector<int> a(M);
  for(int i=0;i<M;i++){
    cin>>a[i];
    N=N-a[i];
  }
  if(N<0){
    cout<<-1<<endl;
  }
  else{
    cout<<N<<endl;
  }
  
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=998244353,MAX=100001;
const ll INF=1LL<<50;

ll rui(ll a,ll b){
    if(b==1) return a%mod;
    else if(b<=0) return 1;
    else if(b%2==0) return (rui(a,b/2)*rui(a,b/2))%mod;
    else return (rui(a,b-1)*a)%mod;
}

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    int sum=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    
    int dp[N+1][sum+1],dp2[N+1][sum+1];
    
    for(int i=0;i<N+1;i++){
        for(int j=0;j<sum+1;j++){
            dp[i][j]=0;
            dp2[i][j]=0;
        }
    }
    
    dp[0][0]=1;
    dp2[0][0]=1;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=sum-A[i];j++){
            dp[i+1][j]+=(2*dp[i][j])%mod;
            dp2[i+1][j]+=dp2[i][j];
            if(dp[i+1][j]>=mod) dp[i+1][j]%=mod;
            if(dp2[i+1][j]>=mod) dp2[i+1][j]%=mod;
            
            dp[i+1][j+A[i]]+=dp[i][j];
            dp2[i+1][j+A[i]]+=dp2[i][j];
            if(dp[i+1][j+A[i]]>=mod) dp[i+1][j+A[i]]%=mod;
            if(dp2[i+1][j+A[i]]>=mod) dp2[i+1][j+A[i]]%=mod;
        }
    }
    
    ll ans=0;
    
    for(int i=(sum+1)/2;i<=sum;i++){
        ans+=dp[N][i];
        ans=ans%mod;
    }
    
    if(sum%2==0){
        ans+=mod-dp2[N][sum/2];
        ans=ans%mod;
    }
    
    cout<<(rui(3,N)+3*mod-ans*3)%mod<<endl;
}


Measured memory_bytes: 211200
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int s, t;
  s = A * B;
  t = C * D;
  if(s >= t){
    cout << s;
  } else {
    cout << t;
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = 0

l = [0]*(n+1)
l[-1] = a[-1]
for i in range(n-1,-1,-1):
    l[i] += l[i+1]+a[i]

if a[0] == 1:
    if n > 0:
        print(-1)
        exit()
    else:
        print(1)
        exit()
b = 1
ans = 0
for i in range(n+1):
    if b < a[i]:
        print(-1)
        exit()
    else: 
        b = min(b,l[i])
        ans += b
        b = (b-a[i])*2   
print(ans)



Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll N, x;
  cin >> N >> x;

  if (x == 1 || x == 2 * N - 1)
    FINALANS("No");

  vector<ll> ans(2 * N - 1);
  ans.at(N - 1) = x;
  ll y = (x <= N) ? (x - 1) : (x + 1);
  ans.at(N - 2) = y;
  for (ll i = 0, cnt = 1; i < 2 * N - 1; i++)
  {
    if (i == N - 1 || i == N - 2)
      continue;
    if (cnt == x || cnt == y)
      cnt++;
    if (cnt == x || cnt == y)
      cnt++;
    
    ans.at(i) = cnt;
    cnt++;
  }

  cout << "Yes" << endl;
  for (ll i = 0; i < 2 * N - 1; i++)
  {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main(void){
    int H, W;
    int i, j, k;

    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0) break;

        for(i = 1; i <= H; i++){
            if(i == 1){
                for(j = 1; j <= W; j++)
                    cout << "#";
                cout << endl;
            }
        
            else if(i == H){
                for(j = 1; j <= W; j++)
                    cout << "#";
                cout << endl;
                break;
            }

            else{
                cout << "#";
                for(k = 1; k <= W - 2; k++)
                    cout << ".";
                cout << "#" << endl;
            }
        }
    cout << endl;
    }
}


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

namespace AtCoder {
	class Program {
		static void Main(string[] args) {
			var input = Console.ReadLine();
			var times = input.Split(' ').Select(item => Convert.ToInt32(item)).ToArray();

			Console.WriteLine((times[0] + times[1]) % 24);
		}
	}
}


Measured memory_bytes: 11348
/*
        ####   ####
     ###    ###    ###
   ###    Bravery    ###
  ###  Determination  ###
   ##  Perseverance   ##
    ##   Integrity   ##
     ##  Patience   ##
      ## Kindness  ##
        ##Justice##
         ##     ##
           ## ##
             #
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int n,q,l[100005],r[100005],p[100005];
string str;
int main(){
	cin>>n>>q;
	cin>>str;
	for (int i=1;i<n;i++){
		p[i]=p[i-1];
		if (str[i-1]=='A' && str[i]=='C') p[i]++;
	}
	for (int i=0;i<q;i++){
		cin>>l[i]>>r[i];
		cout<<p[r[i]-1]-p[l[i]-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 2176
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc144
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc144A();
        }

        public static void solve_abc144C()
        {
        }

        public static void solve_abc144B()
        {
        }

        public static void solve_abc144A()
        {
            int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int a = ab[0];
            int b = ab[1];

            Console.WriteLine(a < 10 && b < 10 ? a * b : -1);
        }

        /*
            BinarySearchIterativeLeft
         */
        public static int binarySearchIterativeLeft(long[] haystack, long needle)
        {
            int left = -1;
            int right = haystack.Length;
            while (left < right - 1)
            {
                int middle = left + (right - left) / 2;
 
                if (haystack[middle] < needle)
                {
                    left = middle;
                }
                else
                {
                    right = middle;
                }
            }
 
            return right;
        }
        
        public static int binSearch(int[] haystack, int needle)
        {
            int l = -1;
            int r = haystack.Length;
            while(l < r - 1)
            {
                int mid = (r + l) / 2;
                if (haystack[mid] <= needle)
                {
                    l = mid;
                }
                else 
                {
                    r = mid;
                }
            }
 
            return r;
        }                        
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
unsigned long long ans;
char c[100010][13];
vector<string>v;
int main()
{
	int n;
	string tmp;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
		sort(c[i],c[i]+10);
		for(int j=0;j<10;j++)
		{
			tmp.append(1,c[i][j]);
		}
//		cout<<tmp<<endl;
		v.push_back(tmp);
		tmp="";
	}
	unsigned long long t=1;
	sort(v.begin(),v.end());
//	for(int i=0;i<n;i++)
//		cout<<v[i]<<endl;
	for(int i=1;i<n;i++)
	{
		if(v[i]==v[i-1])
		{
			t++;
		}
		else
		{
			ans+=(t*(t-1))/2;
			t=1;
		}
	}
	ans+=((t*(t-1))/2);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 8564
#include<iostream>
using namespace std;
void p(int x,int y){
 
  cout<<x;
  for(int i=x+1;i<=y;i++){
    cout<<' '<<i;
  }
  
}
void pb(int x,int y){
  cout<<x;
  for(int i=x-1;i>=y;i--){
    cout<<' '<<i;
  }

}
int main(){
  int n,a,b;
  cin>>n;
  while(n--){
    cin>>a>>b;
    if(a<=5&&b<=5){
      if(a<b)p(a,b);
      else {
	
	pb(a,b);
      }
      cout<<endl;
    }else if(a<=5&&b>=6){

      if(a<=4){p(a,4);cout<<' ';}
      p(5,b);
      cout<<endl;

    }else if(a>=6&&b<=5){

      p(a,9);cout<<' ';
      pb(5,b);cout<<endl;

    }else{
      
      if(a<=b){
	p(a,b);cout<<endl;
      }else{
	p(a,9);cout<<' ';
	pb(5,0);cout<<' ';
	p(1,4);cout<<' ';
	p(5,b);cout<<endl;
      }

    }
  }
  
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef unsigned long long int ll;
using namespace std;

int main(){
    int n, seq = 0;
    double s;
    int x[65], y[65];
    while (cin >> n, seq++, n){
        for (int i = 0; i < 66; ++i)    x[i] = y[i] = 0;
        for (int i = 1; i <= n; ++i)    cin >> x[i] >> y[i];
        x[n+1] = x[1];
        y[n+1] = y[1];

        s = 0;
        for (int i = 1; i <= n+1; ++i)  s += (x[i] * y[i+1]) - (x[i+1] * y[i]);
        s /= 2;
        if (s<= 0)  s *= -1;

        printf("%d %.1lf\n", seq, s);
    }
    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define N 205
using namespace std;
int n;
int in[N];
void solve(){
	scanf("%d",&n);
	double res=0;
	for(int a,i=1;i<=n;i++)
		scanf("%d",&in[i]);
	sort(in+1,in+n+1);
	res=in[1];
	for(int i=2;i<=n;i++){
		res=(res+in[i])/2;
	}
	printf("%.6f\n",res);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 256