akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);

  vector<ll> c(3);
  rep(i, 3) {
    cin >> c.at(i);
  }
  sort(all(c));
  c.erase(unique(all(c)), c.end());
  cout << c.size() << endl;

  return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

HW = [[0 for w in range(W)]for h in range(H)]
C = []

count = 1
for a in A:
    for i in range(a):
        C.append(count)
    count += 1

count = 0
for h in range(H):
    if h % 2 == 0:
        for w in range(W):
            HW[h][w] = C[count]
            count += 1
    else:
        for w in range(W):
            HW[h][W-w-1] = C[count]
            count += 1

for hw in HW:
    for s in hw:
        print(s, end=" ")
    print()

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define LLINF LLONG_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

#define MAX_N 110000

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input values
    // dp table
    // init dp table
    // init condition
    // loop

    ll N;
    cin >> N;

    vector<ll> dp(MAX_N, -1);
    dp[0] = 0;

    queue<ll> que;
    que.push(0);

    while (!que.empty()) {
        ll v = que.front();
        que.pop();

        for (ll pow6 = 1; v+pow6 <= N; pow6 *= 6) {
            if (dp[v+pow6] == -1) {
                dp[v+pow6] = dp[v] + 1;
                que.push(v+pow6);
            }
        }
        for (ll pow9 = 1; v+pow9 <= N; pow9 *= 9) {
            if (dp[v+pow9] == -1) {
                dp[v+pow9] = dp[v] + 1;
                que.push(v+pow9);
            }
        }
    }

    cout << dp[N] << endl;
    return 0;
}

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

template <typename T>
vector<T> readList(int len){
    vector<T> res(len);
    for(int i=0; i < len; i++){
        T temp;
        cin >> temp;
        res[i] = temp;
    }
    return res;
}

int n;
vector<int> h;
vector<long> dp;

// return the min cost from start to N
long dfs(int start){
    // treat the end
    if(start == n - 1){
        return 0;
    }
    // treat the OB: give the bad value
    if(start >= n){
        return 11234567890;
    }
    // calc the children
    long res1 = dfs(start + 1) + abs(h[start + 1] - h[start]);
    long res2 = dfs(start + 2) + abs(h[start + 2] - h[start]);
    return min(res1, res2);
}



int main(){
    cin >> n;
    h = readList<int>(n);
    dp = vector<long>(n);

    // fill the end
    dp[n - 1] = 0;  
    dp[n - 2] = abs(h[n - 1] - h[n - 2]);
    for(int i=n-3; i >= 0; i--){
        long res1 = dp[i + 1] + abs(h[i + 1] - h[i]);
        long res2 = dp[i + 2] + abs(h[i + 2] - h[i]);
        dp[i] = min(res1, res2);
    }



    cout << dp[0] << endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int max = 0;
		int min = 0;
		int prospectMin = 0;
		int beforeN = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(br.readLine());
			if (i == 0) {
				min = a;
				prospectMin = a;
				continue;
			}
			if (i == 1) {
				max = a;
				beforeN = a;
				if (a < min) {
					prospectMin = a;
				}
				continue;
			}
			if (beforeN <= a && max - min < a - prospectMin) {
				max = a;
				if (min > prospectMin) {
					min = prospectMin;
				}
			}
			if (a < prospectMin) {
				prospectMin = a;
			}
			beforeN = a;
		}
		System.out.println(max - min);
	}
}

Measured memory_bytes: 42400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
//		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(br.readLine());
//		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);


		String[] tmpArray = br.readLine().split(" ");
		int[] input = new int[n];
		for(int i = 0; i < n; i++){
			input[n - i - 1] = Integer.parseInt(tmpArray[i]);
		}
		
		System.out.print(input[0]);
		for(int i = 1 ; i < n; i++){
			System.out.print(" "+ input[i]);
		}
		System.out.println();
//		
//		Arrays.sort(input);
//		System.out.printf("%d %d %d\n", input[0], input[input.length - 1], sum);
//		
//		while(true){
//			String[] tmpArray = br.readLine().split(" ");
//			int a = Integer.parseInt(tmpArray[0]);
//			int b = Integer.parseInt(tmpArray[1]);
//			if(a == 0 && b == 0){
//				break;
//			}
//			
//			for(int i = 0; i < a; i++){
//				for(int j = 0; j < b; j++){
//					if((i + j)%2 == 1){
//						System.out.print(".");
//					}
//					else{
//						System.out.print("#");
//					}
//				}
//				System.out.println();
//			}
//			System.out.println();
//		}

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 24248
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		cin >> com;
		if(com == "insert"){
			scanf("%d",&x);
			insert(x);
		}else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


Measured memory_bytes: 26772
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//#include <ext/pb_ds/detail/standard_policies.hpp>
#include<set>
#include<map>
#include <unordered_map>
#include <unordered_set>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<math.h>
#include <strings.h>



#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 2000000000000000000ll
#define mod1 100050001
#define mod2 100030001
#define base1 37
#define base2 31


using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;


const int N = 200002 , LN = 30;


int n,a[N],b[N],c[N];



int main() {
    
    scanf("%d",&n);
    
    lp(i, 1, n) scanf("%d",&a[i]);
    lp(i, 1, n) scanf("%d",&b[i]);
    
    
    ll ans = 0;
    lp(k, 0, LN) {
        ll T = 1<<k, count = 0;
        
        lp(i, 1, n) c[i] = b[i] % (2*T);
        
        sort(c+1, c+n+1);
        
        lp(i, 1, n) {
            ll x = a[i]%(2*T);
            count += lower_bound(c+1, c+n+1, 2*T-x) - lower_bound(c+1, c+n+1, T-x) +
                    lower_bound(c+1, c+n+1, 4*T-x) - lower_bound(c+1, c+n+1, 3*T-x);
        }
        
        ans |= (count&1ll) << k;
    }
    
    printf("%lld\n",ans);
    return 0;
}






/*
 2 3 2
 0 0
 100 0
 0 100
 50 -1 48 3
 49 49 51 52
 4 4 4
 -100 0
 0 100
 0 -100
 100 0
 3 3 -2 -2
 -101 50 101 50
 -101 -101 101 -101
 -49 -50 49 -50
 5 6 4
 40 40
 60 10
 70 30
 60 80
 30 81
 20 40
 0 10 40 50
 10 61 30 61
 -100 90 200 90
 50 20 50 50

 */
//freopen("output.txt","w",stdout);
//freopen("input.txt","r",stdin);
//ios::sync_with_stdio(0);cin.tie(0);

Measured memory_bytes: 2560
#include <stdio.h>
#define N 100000
int main(void){
    int i,j,num1,math1[N],num2,math2[N],h[N],count=0;
    scanf("%d",&num1);
    for(i=0;i<num1;i++){
        scanf("%d",&math1[i]);
    } 
    scanf("%d",&num2);
    for(i=0;i<num2;i++){
        scanf("%d",&math2[i]);
    } 
    
    for(i=0;i<num1;i++){
        for(j=0;j<num2;j++){
            if(math1[i]==math2[j] && h[j]!=1){
                count++;
                h[j]=1;
            }
        }
    }
    printf("%d\n",count);
    
    return 0;
}



Measured memory_bytes: 2052
import std.stdio, std.string, std.conv;

void main() {
	auto input = getStdin!(string[])()[0];
	auto sides = input.split(" ").to!(int[]);
	writefln("%d %d", sides[0] * sides[1], 2 * (sides[0] + sides[1]));
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

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

a = [None]
for i in range(H):
    a.append([None] + list(map(int, input().split())))


def is_odd(i, j):
    return a[i][j] % 2 == 1


def next_cell(i, j):
    if i % 2 == 1:
        if j < W:
            return i, j + 1
    else:
        if 1 < j:
            return i, j - 1
    if i < H:
        return i + 1, j
    return None, None


def move(i, j):
    ni, nj = next_cell(i, j)
    if ni is None:
        return None
    a[i][j] -= 1
    a[ni][nj] += 1
    return "{} {} {} {}".format(i, j, ni, nj)


ans = []
i, j = 1, 1
while True:
    if is_odd(i, j):
        res = move(i, j)
        if res is not None:
            ans.append(res)
    i, j = next_cell(i, j)
    if i is None:
        break

print(len(ans))
for line in ans:
    print(line)


Measured memory_bytes: 15980
#include<iostream>
#define mod 1000000007
using namespace std;
long long gcd(long long a,long long b)
{
	if (b==0)
		return a;
	return gcd(b,a%b);
}
long long fast_pow(long long a,long long b)
{
	if (b==0)
		return 1;
	if (b&1)
		return fast_pow(a*a%mod,b/2)*a%mod;
	else
		return fast_pow(a*a%mod,b/2);
}
int main()
{
	long long n,m,t,n1,n2,m1,m2;
	cin>>n>>m>>t;
	n1=gcd(n,t);
	m1=gcd(m,t);
	n2=n/n1;
	m2=m/m1;
	cout<<fast_pow(fast_pow(2,n2)+fast_pow(2,m2)+fast_pow(2,gcd(n2,m2))-3,n1*m1%(mod-1))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int a[26],b[26];
int main(){
    char s[100];
    char p[100];
    scanf("%s",s);
    scanf("%s",p);
    for(int i=0;i<strlen(s);i++){
        char f[100]={'\0'};
        for(int j=0;j<strlen(p);j++){
            if(i+j>=strlen(s)){
                f[j]=s[i+j-strlen(s)];
            }
            else f[j]=s[i+j];
        }
        if(strcmp(f,p)==0) {printf("Yes\n"); return 0;}
    }
    printf("No\n");
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(void)
{
    ll N, K;
	cin >> N >> K;
    vector<ll> h(N);
    vector<ll> dp(N);
    rep(i, N) cin >> h[i];
    rep(i, N) dp[i] = INF;
    dp[0] = 0;

    rep(i, N)
    {
        rep(j, K)
        {
            if(i+j+1>=N) break;
            chmin(dp[i+j+1], dp[i] + abs(h[i] - h[i+j+1]));
        }
    }
	cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
N = int(input())
a = [int(i) for i in input().split()]

a = sorted(a, reverse=True)
scr_a = 0
scr_b = 0

for i in range(len(a)):
    if i % 2 == 0:
        scr_a += a[i]
    else:
        scr_b += a[i]

print(scr_a - scr_b)

Measured memory_bytes: 3064
import java.util.*;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		
		int count = 0;
		
		for(int i = 0; i < s.length(); i++)
		{
			if(s.charAt(i) == '1')
			{
				count++;
			}
		}

		System.out.println(count);
		scan.close();
	}
}


Measured memory_bytes: 22740
#include <stdio.h>

int main(int argc, char *argv[]){
  int ary[]={0,0,2,0,1,0,1,0,0,1,0,1,0};
  
  int x, y;
  scanf("%d %d", &x, &y);
  
  printf("%s", ary[x]==ary[y]?"Yes":"No");
  
  return 0;
}

Measured memory_bytes: 128
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
x,y,a, = ips()
print(min(x*y,a))

Measured memory_bytes: 13652
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

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

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

int main() {
	/*ll n;
	cin >> n;
	vector<ll> a(n);

	rep(i, n) cin >> a[i];
	sort(all(a));

	ll b = a[n - 1] / 2, ans;
	auto r = lower_bound(all(a), b);
	auto rp = r - 1;
	if (abs(b - *r) == abs(b - *rp)) {
		ans = *r;
	} else if (abs(b - *r) == 0) {
		ans = *r;
	} else if (min(abs(b - *r), abs(b - *rp))== abs(b - *r) == abs(b - *r)){
		ans = *r;
	} else {
		ans = *rp;
	}
	if (ans == a[n - 1])ans = a[0];
	cout << a[n-1] << " " << ans << endl;*/

	ll n;
	cin >> n;
	vector<ll> a(n);

	rep(i, n) cin >> a[i];
	sort(all(a));

	ll b = a[n - 1] / 2, ans;
	auto r = lower_bound(all(a), b);
	auto rp = r - 1;
	if (abs(b - *r) == 0) {
		ans = *r;
	} else if (abs(b - *r)>abs(b-*rp)) {
		ans = *rp;
	} else {
		ans = *r;
	}
	if (ans == a[n - 1])ans = a[0];
	cout << a[n - 1] << " " << ans << endl;
}



Measured memory_bytes: 1024
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-02 08:23:29
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=22,M=(1<<20)|10;
int f[N][M],F[N][M],S[N][M],n,m0[N][M],m1[N][M],m,Ans,ans;
char s[M];
int main()
{
	n=read(); m=read();
	fr(i,0,n)
	{
		scanf("%s",s);
		fr(j,0,(1<<i)-1) f[i][j]=(s[j]=='1');
	}
	fr(i,0,n) fr(j,0,(1<<i)-1)
	{
		m0[i][j]=m1[i][j]=-1;
		fr(k,0,i-1)
			if((j>>k)&1) m1[i][j]=k;
			else m0[i][j]=k;
	}
	fr(i,0,n)
	{
		fr(j,0,n-i) fr(k,0,(1<<(i+j))-1){ F[j][k]=f[j][k]; f[j][k]=0; }
/*		fr(j,0,n-i) fr(k,0,(1<<(i+j))-1) if(F[j][k])
		{
			printf("%d\n ",F[j][k]);
			fd(l,i-1,0) putchar(((k>>(l+j))&1)+48); putchar('|');
			fd(l,j-1,0) putchar(((k>>l)&1)+48); putchar(10);
		}
		putchar(10);*/
		fr(j,0,n-i) fr(k,0,(1<<(i+j))-1)
		{
			S[i][k>>j]+=F[j][k];
			int p=m0[j][k&((1<<j)-1)];
			if(p!=-1) f[p][((k>>j)<<(p+1))|(k&((1<<(p+1))-1))]+=F[j][k];
			p=m1[j][k&((1<<j)-1)];
			if(p!=-1) f[p][((k>>j)<<(p+1))|(k&((1<<(p+1))-1))]+=F[j][k];
		}
	}
	fr(i,1,n) fd(j,(1<<i)-1,0) if(S[i][j]>=m){ Ans=i; ans=j; }
//	fr(i,1,n) fd(j,(1<<i)-1,0) printf("%d %d  %d\n",i,j,S[i][j]);
	fd(i,Ans-1,0) putchar(((ans>>i)&1)+'0');
	putchar(10);
	return 0;
}

Measured memory_bytes: 328960
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/*Atcoder用
 * 		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int a = Integer.parseInt(tmp[0]);
		int b = Integer.parseInt(tmp[1]);
		int c = Integer.parseInt(tmp[2]);


		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String get = br.readLine();
		char[] s = get.toCharArray();
		for(char c:s)System.out.println(c);

		List<Integer> ls = new ArrayList<Integer>();
		String[] tmp = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(tmp[n]));
		}
 */

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int N = Integer.parseInt(tmp[0]);

		List<Integer> ls = new ArrayList<Integer>();
		String[] foo = br.readLine().split(" ");
		for (int n = 0; n < N; n++) {
			ls.add(Integer.parseInt(foo[n]));
		}

		int count = 0;

		for(int i = 0;i<ls.size();i++){
			while(true){
				if(ls.get(i) % 2 == 0){
					count++;
					ls.set(i, ls.get(i)/2);
				}else break;
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 29240
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int x = cin.nextInt();
        int [] m = new int[n];
        for (int i = 0; i < n; i++) {
            m[i] = cin.nextInt();
        }
        int remain = x - Arrays.stream(m).sum();
        int minCount = remain / Arrays.stream(m).min().orElse(remain);
        System.out.println(n + minCount);

    }
}


Measured memory_bytes: 27348
#include <stdio.h>
int main(void){
	int n, f, s, t;
	scanf("%d",&n);
	if(n%10 == 1){
		f = 9;
	}else{
		f = 1;
	}
	n /= 10;
	if(n%10 == 1){
		s = 9;
	}else{
		s = 1;
	}
	n /= 10;
	if(n%10 == 1){
		t = 9;
	}else{
		t = 1;
	}
	printf("%d\n",t*100 + s*10 + f);
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
import itertools


def solve(N: int, d: "List[int]"):
    result = 0
    for pair in itertools.combinations(d, 2):
        result += pair[0] * pair[1]
    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)


if __name__ == "__main__":
    main()


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

int main(void){
    int n,ans=0 ;
    cin >> n ;
    int a[n],b[n],c[n-1];
    for (int i=0; i<n; i++){
        cin >> a[i] ;
    }
    for (int i=0; i<n; i++){
        cin >> b[i] ;
    }
    for (int i=0; i<n; i++){
        cin >> c[i] ;
    }
    for (int i=0; i<n; i++){
        ans+=b[a[i]-1];
        if (a[i]==a[i-1]+1){
            ans+=c[a[i-1]-1] ;
        }
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int[] aa = {scanner.nextInt(),scanner.nextInt(),scanner.nextInt()};
        
        Arrays.sort(aa);
        System.out.print((aa[2] - aa[1]) + (aa[1] - aa[0]));
    }
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            if (A <= 8 && B <= 8)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#define MAX 100005
#define NIL -1

typedef struct{
  int parent, left, right;
}Node;

Node Tree[MAX];
int Depth[MAX];
int Height[MAX];
int degree[MAX];
int h;

int getDepth(int);
int getHeight(int);
void print(int);


int main(void){
  int i, n;
  int vertex;
  int child[2];


  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &vertex, &child[0], &child[1]);

    //子どもがいない場合はdegreeは0である。
    if(child[0] == NIL && child[1] == NIL)
      degree[vertex] = 0;

    //子どもがどちらかにいればdegreeは1である。
    else if(child[0] == NIL && child[1] != NIL){
      degree[vertex] = 1;
      Tree[child[1]].parent = vertex;
      Tree[vertex].right = child[1];
    }
    
    else if(child[0] != NIL && child[1] == NIL){
      degree[vertex] = 1;
      Tree[child[0]].parent = vertex;
      Tree[vertex].left = child[0];
    }


    //子どもが両方存在するという事はdegreeは2という事
    else{
      degree[vertex] = 2;
      Tree[child[0]].parent = vertex;
      Tree[child[1]].parent = vertex;
      
      Tree[vertex].left = child[0];
      Tree[vertex].right = child[1];
    }
  }

  for(i = 0;i < n; i++){
    Height[i] = getHeight(i);
  }

  for ( i = 0; i < n; i++ )
    Depth[i] = getDepth(i);
  
  for ( i = 0; i < n; i++ )
    print(i);
  
  return 0;
}

int getHeight(int u){
  int l = Tree[u].left;
  int r = Tree[u].right;
  int heightL = 0;
  int heightR = 0;

  if(l == NIL && r == NIL){
    return 0;
  }

  if(l != NIL){
    heightL = getHeight(l) + 1;
  }

  if (r != NIL){
    heightR = getHeight(r) + 1;
  }

  if(heightL < heightR){
    return heightR;
  }
  else{
    return heightL;
  }
}


int getDepth(int u){
  int d = 0;

  while(Tree[u].parent >= 0){
    u = Tree[u].parent;
    d++;
  }

  return d;
}

void print(int u){
  int index = Tree[u].parent;

  printf("node %d: parent = %d, ",u, Tree[u].parent);
  if(index == NIL){
    printf("sibling = %d, ",NIL);
  }
  else if(Tree[index].right != u){
    printf("sibling = %d, ",Tree[index].right);
  }
  else if(Tree[index].left != u){
    printf("sibling = %d, ",Tree[index].left);
  }
    
  printf("degree = %d, depth = %d, height = %d, ",degree[u], Depth[u], Height[u]);

  if(Tree[u].parent == NIL)
    printf("root\n");

  else if(degree[u] == 0)
    printf("leaf\n");


  else if(2 >= degree[u] && degree[u] >= 1)
    printf("internal node\n");

  
}

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

typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = ll(1e9+7);


int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> a(X), b(Y), c(Z), tmp, ans;
    for(int i=0;i<X;i++) cin >> a[i];
    for(int i=0;i<Y;i++) cin >> b[i];
    for(int i=0;i<Z;i++) cin >> c[i];
    
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            tmp.push_back(a[i]+b[j]);
        }
    }
    sort(tmp.rbegin(), tmp.rend());
    if(tmp.size() > K) tmp.erase(tmp.begin()+K, tmp.end());
    for(int i=0;i<int(tmp.size());i++){
        for(int j=0;j<Z;j++){
            ans.push_back(tmp[i]+c[j]);
        }
    }
    sort(ans.rbegin(),ans.rend());
    for(int i=0;i<K;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 43368
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
        
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
p = [0] + [int(_) for _ in input().split()]
pair = [[int(_) for _ in input().split()] for _ in range(M)]
uf = UnionFind(N+1)
ans = 0

for i in pair:
    uf.union(i[0], i[1])

for i in range(1, N+1):
    if uf.find(i) == uf.find(p[i]):
        ans += 1

print(ans)

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


int main(){
  
  int N;
  cin >> N;
  
  if(N % 3 == 0){
    cout << N / 3 << endl;
  }
  else if(N % 3 != 3 && N < 3){
    cout << "0" << endl;
  }
  else{
    cout << N / 3 << endl;
  }
  
}


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

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  string S;
  cin >> S;
  int n, w, s, e;
  n = w = s = e = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N') n++;
    if (S[i] == 'W') w++;
    if (S[i] == 'S') s++;
    if (S[i] == 'E') e++;
  }

  if (n > 0 || s > 0) {
    if (n * s == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  if (w > 0 || e > 0) {
    if (w * e == 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

const int inf = 1e9+5;
int main(void)
{
	int n,k;
	scanf("%d %d",&n,&k);
	vector<int> h(n);
	for(int& x : h)
		scanf("%d",&x);
	vector<int> dp(n,inf);
	dp[0] = 0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<=i+k;j++)
			if(j < n)
				dp[j] = min(dp[j],dp[i] + abs(h[i]-h[j]));

	printf("%d\n",dp[n-1]);
	return 0;
}

Measured memory_bytes: 1024
A, B = [int(i) for i in input().split()]
socket_count = A
result = 1

if B == 1:
    print(0)
else:
    while socket_count <= B:
        if socket_count == B:
            break
        else:
            socket_count += (A - 1)
            result += 1
    print(result)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);
 
int main() {
    optimizar_io

    int n, h[100010], right[100010];

    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    right[n - 1] = 0;
    for (int i = n - 2; i >= 0; i--) {
        if (h[i] >= h[i + 1])
            right[i] = right[i + 1] + 1;
        else
            right[i] = 0;
    }
    int ans = n - 1;
    for (int i = 0; i < n; i++) {
        if (right[i] > right[ans])
            ans = i;
    }
    cout << right[ans] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  string s;
  cin >> n;
  cout << 0 << endl;
  cin >> s;
  if(s == "Vacant") return 0;
  ll l = 0, r = n / 2 + 1;
  while(l + 1 < r) {
    ll x = (l + r) / 2 * 2;
    string t;
    cout << x << endl;
    cin >> t;
    if(t == "Vacant") return 0;
    if(t == s)
      l = x / 2;
    else
      r = x / 2;
  }
  string t;
  cout << l * 2 + 1 << endl;
  cin >> t;
  return 0;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define pb push_back
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mod(x) (x % 1000)
#define deb(x) cout << #x << " " << x << endl;
#define yes cout << "yes" << endl;
#define LONG_LONG_MAX 9223372036854775807
#define LONG_LONG_MIN -9223372036854775808
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

const int MOD = 1e9 + 7;
const int maxn = 1e5 + 10;
string s;
int dp[maxn][15];


int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    int len = s.size();
    dp[0][0] = 1;
    for (int i = 0; i < len; ++i) {
        int c;
        if (s[i] == '?') c = -1;
        else c = s[i] - '0';
        for (int j = 0; j < 10; ++j) {
            if (c != -1 && c != j) continue;
            for (int k = 0; k < 13; ++k) {
//                cout << i << " " << k << " " << dp[i][k] << endl;
                dp[i+1][((k * 10) + j) % 13] += dp[i][k];
                dp[i+1][((k * 10) + j) % 13] %= MOD;
            }
        }
    }
//    for (int i = 0; i <= len; ++i) {
//        for (int j = 0; j < 13; ++j) {
//            cout << dp[i][j] << " ";
//        }cout << endl;
//    }
    cout << dp[len][5] << endl;
    return 0;
}


Measured memory_bytes: 6352
#include <bits/stdc++.h>
using namespace std;
char S[500050]; int a[500050],n,m,s;
int main(){
	scanf("%s",S+1); n=strlen(S+1);
	for (int i=1;i<=n;++i) a[n-i]=S[i]-'0';
	for (int i=0;i<n;++i) a[i]*=9;
	for (int i=0;i<n;++i) a[i+1]+=a[i]/10,a[i]%=10;
	m=n*9; if (a[n]) ++n;
	for (int i=0;i<n;++i) s+=a[i];
	for (int i=1;i<=m;++i){
		s-=a[0]; ++a[0];
		for (int j=0;j<n;++j)
		if (a[j]==10) a[j]=0,s-=a[j+1],++a[j+1];
			else {s+=a[j]; break;}
		if (a[n]) ++n,++s;
		if (s<=i) {printf("%d\n",i/9+(i%9>0)); return 0;}
	}
	return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[105][100005];
ll a[100005];
int main(){
	ll n, W;
	cin >> n >> W;
	ll w[105], v[105];
	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 0; i <= W; i++) {
		dp[0][i] = 0;
		
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= W; j++) {
			if (w[i] <= j) {
				dp[i + 1][j] = max(v[i] + dp[i][j - w[i]], dp[i][j]);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 79360
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
char a[MAXN],b[MAXN],c[MAXN];
int ab[MAXN],bc[MAXN],ac[MAXN];
int o=1e4;
int check(char x,char y){
    return x=='?'||y=='?'||x==y;
}
int main(){
    cin>>a+1>>b+1>>c+1;
    int la=strlen(a+1),lb=strlen(b+1),lc=strlen(c+1);
    REP(i,-4000,4000)ab[i+o]=ac[i+o]=bc[i+o]=1;
    REP(i,1,la)REP(j,1,lb){
        if(!check(a[i],b[j]))ab[i-j+o]=0;
    }
    REP(i,1,la)REP(j,1,lc){
        if(!check(a[i],c[j]))ac[i-j+o]=0;
    }
    REP(i,1,lb)REP(j,1,lc){
        if(!check(b[i],c[j]))bc[i-j+o]=0;
    }
    int ans=la+lb+lc;
    REP(i,-4000,4000)REP(j,-4000,4000){
        if(ab[i+o]&&ac[j+o]&&bc[j-i+o]){
            ans=min(ans,max(la,max(i+lb,j+lc))-min(1,min(1+i,1+j))+1);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 8576
N, M = map(int, raw_input().split())
neighbor_graph = [[False] * N for _ in range(N)]
for _ in range(M):
  a, b = map(int, raw_input().split())
  neighbor_graph[a - 1][b - 1] = True
  neighbor_graph[b - 1][a - 1] = True

def find(now, checked):
  if len(checked) == N:
    return 1
  res = 0
  for i in set(range(N)) - checked:
    if neighbor_graph[now][i]:
      res += find(i, checked | {i})
  return res

print find(0, {0})

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int d,g; cin >> d >> g;
	vector<int> p(d),c(d);
	for(int i=0;i<d;i++){
		cin >> p[i] >> c[i];
	}
	int ans=1e9;
	for(int i=0;i<(1<<d);i++){
		int last=-1;
		int sum=0; int ad=0;
		for(int j=0;j<d;j++){
			if((i>>j)&1){
				sum+=(c[j]+(p[j]*(1+j)*100));
				ad+=p[j];
			}
			else last=j;
		}
		if(sum>=g){
			ans=min(ans,ad);
		}
		else if(p[last]*(last+1)*100+sum<g)continue;
		else{
			sum-=g;
			sum*=(-1);
			ad+=(sum+(last+1)*100-1)/((last+1)*100);
			ans=min(ans,ad);
		}
	}
	cout << ans << endl;
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int n; cin >> n;
  vector<ll> a(n+1);
  rep(i, n+1) cin >> a[i];
  if(n == 0) {
    if(a[0] == 1) cout << 1 << endl;
    else cout << -1 << endl;

    return 0;
  }
  if(a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  rep(i, n) a[i+1] += a[i];
  vector<ll> node(n+1, 0);
  node[0] = 1;
  for(int i = 1; i <= n; ++i) {
    ll this_leaf = a[i]-a[i-1];
    if(node[i-1]*2-this_leaf < 0) {
      cout << -1 << endl;
      return 0;
    }
    node[i] = min(node[i-1]*2-this_leaf, a[n]-a[i]);
  }
  ll ans = a[n] + accumulate(ALL(node), 0ll);
  cout << ans << endl;
}


Measured memory_bytes: 4772
// 2015/05/13 Tazoe

#include <iostream>
using namespace std;

const int NOT_FOUND = -1;

int binarySearch(int key, int A[], int n)
{
	int left = 0;
	int right = n;

	while(left<right){
		int mid = (left+right)/2;

		if(A[mid]==key){
			return mid;
		}
		else if(key<A[mid]){
			right = mid;
		}
		else{
			left = mid+1;
		}
	}

	return NOT_FOUND;
}

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

	int S[100000];
	for(int i=0; i<n; i++){
		cin >> S[i];
	}

	int q;
	cin >> q;

	int T[50000];
	for(int i=0; i<q; i++){
		cin >> T[i];
	}

	int C = 0;

	for(int i=0; i<q; i++){
		if(binarySearch(T[i], S, n)!=NOT_FOUND){
			C++;
		}
	}

	cout << C << endl;

	return 0;
}

Measured memory_bytes: 1744
import java.util.Scanner;

class Main {
    private static void solve() {
        final Scanner scanner = new Scanner(System.in);
        for (char c: scanner.nextLine().toCharArray()) {
            if (Character.isLowerCase(c)) {
                System.out.print(Character.toUpperCase(c));
            } else {
                System.out.print(c);
            }
        }
        System.out.println();
    }

    public static void main(String... args) {
        solve();
    }
}

Measured memory_bytes: 11000
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

string S;
vector<string> G;
vector<string> ans;
map<string, int>M;
int main()
{
	int N, m = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		if (M[S] == 0) {
			G.push_back(S);
		}
		M[S]++;
		m = max(m, M[S]);
	}
	for (int i = 0; i < G.size(); i++) {
		if (M[G[i]] == m) {
			ans.push_back(G[i]);
		}
	}
	sort(ans.begin(), ans.end());
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 28400
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main (){

	int N;
	cin >> N;

	int a[100010];
	int i, cnt2 = 0, cnt4 = 0;

	for(i = 0; i < N; i++){
		cin >> a[i];

		if(a[i] % 4 == 0){
			cnt4 = cnt4 + 1;
		}else if(a[i] % 2 == 0){
			cnt2 = cnt2 + 1;
		}
	}
	
	
	
	if(N % 2 == 0){

		if( cnt4 >= N / 2 ){
			cout << "Yes\n";
			return 0;
		}else{
			if(cnt2 >= N - cnt4 * 2){
				cout << "Yes\n";
				return 0;
			}else{
				cout << "No\n";
				return 0;
			}
		}

	}else if(N == 3){
	
		if(cnt4 >= 1){
			cout << "Yes\n";
			return 0;
		}else{
			if(cnt2 == 3){
				cout << "Yes\n";
				return 0;
			}else{
				cout << "No\n";
				return 0;
			}			
		}

	}else{
	
		if(cnt4 >= N / 2){
			cout << "Yes\n";
			return 0;
		}else{
			if(cnt2 >= N - cnt4 * 2){
				cout << "Yes\n";
				return 0;
			}else{
				cout << "No\n";
				return 0;
			}

		}
			
	}

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(a) a.begin(),a.end()
struct Point{int x,y,id;};
bool linkx(Point &p1,Point &p2){ return p1.y==p2.y ? p1.x<p2.x : p1.y<p2.y; }
bool linky(Point &p1,Point &p2){ return p1.x==p2.x ? p1.y<p2.y : p1.x<p2.x; }
int xid(Point &p){return p.id*2;}
int yid(Point &p){return p.id*2+1;}

#define MAX_V 400010
#define INF 1e18
typedef long long ll;
struct edge{ll cost; int to;};
typedef pair<ll,int> P;//dp[v],v

vector<Point> vp;
vector<edge> G[MAX_V]; 
ll dp[MAX_V];
int M,N,K,X,Y;

ll dijkstra(){
	fill(dp,dp+MAX_V,INF);
	priority_queue<P,vector<P>,greater<P>> qu;
	if(vp[0].x==1){
		dp[yid(vp[0])]=vp[0].y-1;
		qu.push({dp[yid(vp[0])],yid(vp[0])});
	}
	while(qu.size()){
		P pr=qu.top(); qu.pop();
		int v=pr.second;
		if(v>=2*K)return pr.first;
		if(dp[v] < pr.first)continue;
		for(edge e:G[v]){
			if( dp[e.to] > dp[v]+e.cost){
				dp[e.to] = dp[v]+e.cost;
				qu.push({dp[e.to],e.to});
			}
		}
	}
	return -1;
}


int main(void){
	cin>>M>>N>>K;
	rep(i,K){
		cin>>X>>Y;
		vp.push_back({X,Y,i});
	}
	vp.push_back({M,N,K});

	//switch
	rep(i,K){
		G[xid(vp[i])].push_back({1,yid(vp[i])});
		G[yid(vp[i])].push_back({1,xid(vp[i])});
	}

	//linkx
	sort(all(vp),linkx);
	rep(i,K){
		if(vp[i].y==vp[i+1].y){
			Point p1=vp[i],p2=vp[i+1];
			int cost=abs(p1.x-p2.x);
			G[xid(p1)].push_back({cost,xid(p2)});
			G[xid(p2)].push_back({cost,xid(p1)});
		}
	}

	//linky
	sort(all(vp),linky);
	rep(i,K){
		if(vp[i].x==vp[i+1].x){
			Point p1=vp[i],p2=vp[i+1];
			int cost=abs(p1.y-p2.y);
			G[yid(p1)].push_back({cost,yid(p2)});
			G[yid(p2)].push_back({cost,yid(p1)});
		}
	}
	cout<<dijkstra()<<endl;
	return 0;
}

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

const int MOD = 1e9+7;
const int MAX = 2e6+10;

typedef long long ll;

ll f[MAX];
ll invf[MAX];

ll bigmod(ll a, ll b, ll m){
	a%=m;
	ll res = 1;
	while(b > 0){
		if(b&1)	res=(res*a)%m;
		a = (a*a)%m;
		b >>= 1;
	}
	return res;
}

void precompute(){
	f[0] = 1;
	for (int i = 1; i < MAX; ++i){
		f[i] = f[i-1]*i%MOD;
	}
	invf[MAX-1] = bigmod(f[MAX-1], MOD-2, MOD);
	for (int i = MAX-2; i > 0; --i){
		invf[i] = invf[i+1]*(i+1)%MOD;
	}
	invf[0] = 1;
}

ll nCr(ll n, ll r){
	return f[n]*invf[n-r]%MOD*invf[r]%MOD;
}

int main(){
	precompute();
	ll r1, c1;	cin >> r1 >> c1;
	ll r2, c2;	cin >> r2 >> c2;
	ll ans = 0;
	for (ll i = r1; i <= r2; ++i){
		ans += nCr(i+c2+1, i+1) - nCr(i+c1, i+1) % MOD;
		ans %= MOD;
	}
	cout << (ans+MOD)%MOD << endl;
	return 0;
}


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

using namespace std;

#define LL long long
#define reg register
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)

inline int Read() {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a,T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a,T const&b) {
	return a<b?a=b,1:0;
}

const int N=1e5+5;

int n,flag=1,cnt,tot[N];

char S[5];

int main() {
	scanf("%s",S+1);
	rep(i,1,4)tot[S[i]-'A']++;
	rep(i,0,25)if(tot[i]&&tot[i]!=2)return !puts("No");
	puts("Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    string s;
    cin >> s;
    vector<ll> a(4, 0);
    for(ll i = 0; i < s.length(); i++){
        if(s[i]=='S') a[0]++;
        if(s[i]=='E') a[1]++;
        if(s[i]=='N') a[2]++;
        if(s[i]=='W') a[3]++;
    }
    bool check = true;
    if(a[0]>0 && a[2]==0 || a[2]>0 && a[0]==0)
        check = false;
    if(a[1]>0 && a[3]==0 || a[3]>0 && a[1]==0)
        check = false;
    if(check == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char* argv[])
{
    long n, h, w;
    scanf("%ld %ld %ld",&n, &h, &w);

    long count = 0;
    long i=0;
    for(i=0; i<n; i++) {
        long a, b;
        scanf("%ld %ld",&a, &b);
        if(a>=h && b>=w) {
            count++;
        }
    }
    printf("%d\n", count);

	return 0;
}



Measured memory_bytes: 128