akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

int main(){
  ll n;cin >> n;
  ll m,a,r,c,h;
  m=a=r=c=h=0;
  REP(i,n){
    string s;
    cin>>s;
    if(s[0]=='M'){m++;a*=1;}
    else if(s[0]=='A')a++;
    else if(s[0]=='R')r++;
    else if(s[0]=='C')c++;
    else if(s[0]=='H')h++;
  }
  cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h<<endl;
}

Measured memory_bytes: 256
import kotlin.math.*
import java.util.*
import java.io.*
var ans:Int = 0
fun main() {
    val S = readLine()!!
    if(S == "SSS"){
        ans = 0
    }
    else if(S == "SRR" || S == "RRS"){
        ans = 2
    }
    else if(S == "RRR"){
        ans = 3
    }
    else{
        ans = 1
    }
    println(ans)
}

Measured memory_bytes: 34672
H, W, K = map(int, input().split())
c = [input() for _ in range(H)]

# 各行・各列を選ぶか選ばないかで全列挙してbit

ans = 0

for hn in range(2**H):
    hbit = bin(hn)[2:].zfill(H)
    for wn in range(2**W):
        wbit = bin(wn)[2:].zfill(W)
        count = 0
        # hbit[h] == "1" and wbit[w] == "1" の場合は "#" が残ると考える
        for h in range(H):
            for w in range(W):
                if hbit[h] == "1" and wbit[w] == "1" and c[h][w] == "#":
                    count += 1
        if count == K:
            ans += 1

print(ans)



Measured memory_bytes: 9196
(defconstant +color-unknown+ -1)
(defconstant +color-white+ 0)
(defconstant +color-black+ 1)

(defun solve ()
  (let*  ((n (next-int))                 ; 頂点の数
          ;; 根を除いて各頂点にはたった1つの親頂点があるので、辺の数は
          ;; 「頂点の数-1」になる。
          (from (make-array (1- n)))     ; 番号が小さいほうの頂点
          (to (make-array (1- n)))       ; 番号が大きいほうの頂点
          (w (make-array (1- n))))       ; 辺の長さ
    (loop for i below (1- n)
         do
         ;; 0ベース配列の添字にしたいので、各頂点番号をデクリメントしておく。
         (setf (aref from i) (1- (next-int)))
         (setf (aref to i) (1- (next-int)))
         (setf (aref w i) (next-int)))

    (let ((g (pack-wu n from to w))
          (color (make-array n :initial-element +color-unknown+))
          (stack nil)) ; 頂点の色。


      (push (list 0 +color-white+) stack)
      (loop while stack
         do
           (destructuring-bind (now mod) (pop stack)
             (setf (aref color now) mod)
             (loop for edge across (aref g now)
                do
                  (destructuring-bind
                        (next-vertex length) edge
                    (when (= (aref color next-vertex) +color-unknown+)
                      (push (list next-vertex (mod (+ mod length) 2)) stack))))))

      (loop for i below n
           do
           (format t "~A~%" (aref color i))))))

(defun next-int ()
  (read))

;; 各頂点についてその接続情報を収めた表 g を生成して返す。
;; g[頂点番号][各辺] = (list 辺の長さ 接続先の頂点)
(defun pack-wu (n from to w)
  (let ((sup (length from)) ; 辺の数
        (g (make-array n))
        (p (make-array n :initial-element 0))) ; 各頂点の次数(接続している辺の数)

    ;; 各頂点の次数を数える。各辺は、2つの頂点の次数をそれぞれ1つずつ
    ;; 増やす。
    (loop for i below sup
       do
         (incf (aref p (aref from i)))
         (incf (aref p (aref to i))))

    (loop for i below n
       do
       ;; g[i] に頂点 i 接続している辺の情報を収める配列を割り当てる。
         (setf (aref g i) (make-array (aref p i))))

    ;; 各頂点の持つ辺の情報を配列の後ろから格納する。
    (loop for i below sup
       do
         (let ((v (aref from i))
               (u (aref to i))
               (len (aref w i)))

           (decf (aref p v))
           (setf (aref (aref g v) (aref p v)) (list u len))

           (decf (aref p u))
           (setf (aref (aref g u) (aref p u)) (list v len))))

    g))

(solve)


Measured memory_bytes: 62052
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		sc.close();
		int ans = 0;
		for (int i = A; i <= B; i++) {
			String s = String.valueOf(i);
			char[] c = s.toCharArray();
			if (c[0] == c[4] && c[1] == c[3]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 31956
import math
import sys
sys.setrecursionlimit(10 ** 6 + 10)
from collections import defaultdict




def main():
    num = int(input())
    data = [input().split() for i in range(num)]

    for i in range(num):
        data[i][1] = int(data[i][1])
        data[i].append(i + 1)

    data.sort(key=lambda x: (x[0], -x[1]))
    for i in range(num):
        print(data[i][2])




if __name__ == '__main__':
    main()


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


int main() {
  int N;
  cin >> N;
    long int Ans = 0;
  for(int i=1; i<=N; i++){
     Ans = Ans+i;
    
    if(i%3==0||i%5==0){
    Ans = Ans-i;
    }
    
  }
  
  cout << Ans;

}


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

long long num[30] ;

char tmp[200005] ;

int main()
{
    int a , b , c , d , e ;
    scanf("%d %d %d %d %d",&a,&b,&c,&d,&e) ;
    a*= 4 ;
    b*= 2 ;
    int minn = std::min(a,std::min(b,c)) ;
    if(minn*2 <=d){
        printf("%lld\n",(long long)minn*e) ;
    }
    else{
        printf("%lld\n",(long long)e/2*d+e%2*minn) ;
    }
    return 0 ;
}

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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll; 
typedef long double ld; 
typedef vector<int> vi; 
typedef pair<int,int> pii; 
#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }
const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
const int mod=1000*1000*1000+7;  

// ----------------------------------------------------------------------------	-------------- 


const int nax=1e5+5; 
vector<pii> adj[nax];
int deg[nax];

void solve(){
  int n; cin>>n; 
  int mx=-1, node=-1; 
  for(int i=1;i<n;i++){
    int u,v; cin>>u>>v; 
    deg[u]++; 
    deg[v]++; 
    if(deg[u]>mx) { mx=deg[u]; node=u; }
    if(deg[v]>mx) { mx=deg[v]; node=v; }
    adj[u].push_back({v,i}); 
    adj[v].push_back({u,i}); 
  }
  vi ans(n+1);
  queue<pii> q; 
  q.push({node,-1}); 
  vi done(n+1,0); 
  while(!q.empty()){
    auto p=q.front(); q.pop(); int u=p.first, c=p.second; 
    done[u]=1; 
    int prev=0; 
    for(auto pp:adj[u]){
      int v=pp.first; 
      if(done[v]) continue; 
      prev++;  
      if(c==prev) prev++;
      ans[pp.second]=prev; 
      q.push({v,prev}); 
    }
  }
  cout<<mx<<endl; 
  for(int i=1;i<n;i++){
    cout<<ans[i]<<endl; 
  }
}



int main(){
	// clock_t beg=clock(); 
	fast_io; 
  // cout << fixed << setprecision(13); 
  int t; 
  t=1; 
  //cin>>t; 
  while(t--){
	  solve(); 	
  }
	// clock_t end=clock(); 
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}

Measured memory_bytes: 7808
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	char[][] map;
	int max;
	int n;
	int[] dx = {-1,1,0,0,-1,1,-1,1};
	int[] dy = {0,0,-1,1,-1,-1,1,1};
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			n = scan.nextInt();
			if(n == 0){
				break;
			}
			map = new char[n][];
			max = 0;
			for(int i = 0;i < n;i++){
				map[i] = scan.next().toCharArray();
			}
			for(int i = 0;i < n;i++){
				for(int j = 0;j < n;j++){
					if(map[i][j] == '1'){
						for(int k = 0;k < 8;k++){
							if(i+dy[k] >= 0 && i+dy[k] < n && j + dx[k] >= 0 && j +dx[k] < n){
								checkGrid(i,j,k,1);
							}
						}
						map[i][j] = '0';
					}
				}
			}
			System.out.println(max);
		}
	}
	public void checkGrid(int i,int j,int dir,int count){
		if(i+dy[dir] >= 0 && i+dy[dir] < n && j + dx[dir] >= 0 && j +dx[dir] < n
				&& map[i+dy[dir]][j + dx[dir]] != '0'){
			checkGrid(i+dy[dir],j+dx[dir],dir,count+1);
		}
		max = (max > count)?max:count;
		return;
	}
}

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

// 1からpまでp種類の目が当確率で出るサイコロの期待値を返す
// 期待値は初項1公差1総項数pの等差級数わるp
constexpr double expectation_value(int p)
{
    return (1 + p) / 2.0;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];

    vector<double> csexpval(n + 1);
    csexpval[0] = 0;
    for (int i = 0; i < n; i++)
        csexpval[i + 1] = csexpval[i] + expectation_value(p[i]);

    double max_score = 0;
    for (int i = k; i <= n; i++)
    {
        double score = csexpval[i] - csexpval[i - k];
        max_score = max(score, max_score);
    }

    cout << max_score << endl;

}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N, T;
//最後の一個をまだつかていない、すでに使ってい流
long long memo[4000][2];
long long A[4000];
long long B[4000];

int main(){
	cin >> N >> T;
	rep(i, N) {
		cin >> A[i] >> B[i];
	}
	rep(i, T + 10) {
		memo[i][0] = -1;
		memo[i][1] = -1;
	}

	memo[0][0] = 0;

	long long ans = 0;
	rep(i, N) {
		for(long long t = T - 1; t >= 0; t--){

			if(memo[t][1] >= 0) {
				//すでにラス一を使っているので t より下に治らないとダメ
				if(t + A[i] < T) {
					memo[t + A[i]][1] = max(memo[t + A[i]][1], memo[t][1] + B[i]);
					ans = max(ans, memo[t + A[i]][1]);
				}
			}

			if(memo[t][0] >= 0) {
				//普通に使う
				if(t + A[i] < T) {
					memo[t + A[i]][0] = max(memo[t + A[i]][0], memo[t][0] + B[i]);
					ans = max(ans, memo[t + A[i]][0]);
				}
				//最後に使う
				memo[t][1] = max(memo[t][1], memo[t][0] + B[i]);
				ans = max(ans, memo[t][1]);

			}
		}
	}
	cout << ans << endl;

}


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

int main() {
    int num = 3, x;
    cin >> x;
    vector<int> finded;
    bool ans;
    if(x == 2){
        cout << 2 << endl;
        return 0;
    }
    while(1){
        ans = true;
        for(int i: finded){
            if(num % i == 0){
                ans = false;
                break;
            }
        }
        if(ans){
            finded.push_back(num);
            if(num >= x){
                cout << num << endl;
                return 0;
            }
        }
        num += 2;
    }
}

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

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  
    int n;
    cin >> n;
    vector<int> sub_cnt(n+1);
    for (int i = 2; i <= n; i++) {
        int boss;
        cin >> boss;
        sub_cnt[boss]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << sub_cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3964
#include <stdio.h>

int main(void)
{
	char s[10];
	
	scanf("%s",s);
	
	int year = 1000*(s[0]-48)+100*(s[1]-48)+10*(s[2]-48)+(s[3]-48);
	
	int month = 10*(s[5]-48)+(s[6]-48);
	
	if(year < 2019){
		puts("Heisei");
	}else if(year == 2019 && month <= 4){
		puts("Heisei");
	}else if(year == 2019 && month >= 5){
		puts("TBD");
	}else{
		puts("TBD");
	}
	
	return 0;
}
	
	

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long X = scanner.nextLong();

        long a = X / 500;
        X = X % 500;
        long b = X / 5;
        System.out.println(a * 1000 + b * 5);
    }
}


Measured memory_bytes: 23636
s = input()
ans = float("inf")
for i in range(len(s)):
  ls = [c for c in s]
  k = ls[i]
  if ls.count(k) == len(ls):
    ans = 0
    break
  for l in range(len(s)):
    ls1 =[]
    for j in range(len(ls)-1):
      if (ls[j] == k or ls[j+1] == k):
        ls1.append(k)
      else:
        ls1.append(0)
    ls = ls1
    if ls.count(k) == len(ls):
      ans = min(ans,l+1)
      break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 233
int n;
char s[250005];
map<unsigned long long,int>a;
unsigned long long f[250005],g[250005],inv=1,xx=mod;
int main(){
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=63;i++){
        inv=inv*xx;
        xx=xx*xx;
    }
    f[0]=0;g[0]=1;
    for(int i=1;i<=n;i++) {
        f[i]=f[i-1];g[i]=g[i-1];
        switch (s[i]){
            case '+':f[i]+=g[i];break;
            case '-':f[i]-=g[i];break;
            case '<':g[i]*=inv;break;
            case '>':g[i]*=mod;break;
        }
        a[f[i]]++;
    }
    long long ans=0;
    for(int i=1;i<=n;i++){
        ans+=a[f[n]*g[i-1]+f[i-1]];
        a[f[i]]--;
    }
    printf("%lld",ans);
    return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    if(n<1000) cout << "ABC" << "\n";
    else cout << "ABD" << "\n";

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for (auto x : mp) mx = max(mx, x.second);
  vector<string> ans;
  for (auto x : mp) {
    if (x.second == mx) ans.push_back(x.first);
  }
  sort(ALL(ans));
  rep(i, ans.size()) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 26868
n, m = map(int,input().split())

res = 1
num = int(m ** 0.5) + 1
for i in range(1, num):
    if m % i != 0:continue 
    j = m // i
    if i >= n:
        res = max(j, res)
    if j >= n:
        res = max(i, res)
print(res)


Measured memory_bytes: 9436
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> xs;
  for (int i = 0; i < N; ++i) {
    int xi;
    cin >> xi;
    xs.push_back(xi);
  }

  int ans = INT_MAX;
  for (int i = 0; i < N - K + 1; ++i) {
    int min_val = xs[i];
    int max_val = xs[i + K - 1];
    if (min_val < 0 && max_val < 0) {
      ans = min(ans, abs(min_val));
    } else if (min_val > 0 && max_val > 0) {
      ans = min(ans, max_val);
    } else {
      if (abs(min_val) < max_val) {
        ans = min(ans, 2 * abs(min_val) + max_val);
      } else {
        ans = min(ans, abs(min_val) + 2 * max_val);
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 892
n,x,y = gets.split.map {|i| i.to_i-1 }
v = Array.new(n+=1) {|i| n-i}
a = Array.new(n) {|i| Array.new(i) {|j| i-j} } << Array.new(n,0)
f = proc {|a,i,d;b| (v[a[i]=d]+=1) && v[b]-=1  if d < b=a[i] }
e = [0,n]
0.upto(n) {|r;j|
  e.reject! {|e|
    next 1  if y!=(j= e>0 ? y+r : y-r) && !f[a[j],x,r+1]
    e = [0,n]
    1.upto(n) {|c|
      e.reject! {|e;i| !f[a[j],(e>0 ? x+c : x-c),r+c+1] }
      break  if !e[0]
    }
  }
  break  if !e[0]
}
f[a[y],x,1]
puts v[1,n]

Measured memory_bytes: 19708
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll N, M;
    cin >> N >> M;

    ll s = 0;
    REP(i, M) {
        ll a; cin >> a;
        s += a;
    }

    if (N < s) print(-1);
    else print(N - s);

    
}


Measured memory_bytes: 3576
#include <iostream>
#include <cmath>

int64_t f(const int64_t b, const int64_t n)
{
    if (n < b)
    {
        return n;
    }
    else
    {
        return f(b, n / b) + (n % b);
    }
}

int main()
{
    int64_t n, s;
    std::cin >> n >> s;

    if (s == n)
    {
        // この場合は自明
        std::cout << n + 1 << std::endl;
        return 0;
    }
    else if (s > n)
    {
        std::cout << -1 << std::endl;
        return 0;
    }

    // bが大きいほうが各桁が大きくなるので、和も大きくなる傾向にある
    // ただし、単調ではないので、全探索になる
    //
    // sqrt(n) < b <= nで2桁のb進数になる
    // p,qを使って、n = p*b + q, s = p + q
    // n = p*b + s - p
    // n - s = p*(b - 1)
    // b = (n - s) / p + 1
    // また、n = p*b + q >= p*b > p^2
    // p < sqrt(n)
    //
    // 同様に3桁の場合も考えられるが、手間なうえに計算量はあまり減らないようなのであまり意味はない
    // よって、sqrt(n)まで全探索し、残りは2桁の場合を考える

    const int64_t sqrt_n = std::sqrt(n);
    for (int64_t b = 2; b <= sqrt_n; ++b)
    {
        if (f(b, n) == s)
        {
            std::cout << b << std::endl;
            return 0;
        }
    }

    for (int64_t p = sqrt_n; p >= 1; --p)
    {
        const int64_t b = (n - s) / p + 1;
        if (b >= 2 && f(b, n) == s)
        {
            std::cout << b << std::endl;
            return 0;
        }
    }

    std::cout << -1 << std::endl;
    return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)


int rui[501][501] = {{0}};
int n,m,q;

int calc(int l, int r){
  return rui[r][r] +rui[l-1][l-1] - rui[l-1][r] - rui[r][l-1];
}

int main(){
  cin >> n >> m >> q;
  REP(i,m){
    int l,r;
    cin >> l >> r;
    rui[l][r]++;
  }
  REP(i,n+1)REP(j,n){
    rui[i][j+1] += rui[i][j];
  }
  REP(i,n+1)REP(j,n){
    rui[j+1][i] += rui[j][i];
  }
  REP(i,q){
    int l,r;
    cin >> l >> r;
    cout << calc(l,r) <<endl;
  }
}


Measured memory_bytes: 1920
import itertools
N=int(input())
A=list(map(int,input().split()))
Asum=list(itertools.accumulate(A))
leftcut=1
rightcut=3
ans=10**9
for i in range(2,N-1):
  Ldiff=abs((Asum[i-1]-Asum[leftcut-1])-Asum[leftcut-1])
  while leftcut+1<i:
    if abs((Asum[i-1]-Asum[leftcut+1-1])-Asum[leftcut+1-1]) < Ldiff:
      Ldiff=abs((Asum[i-1]-Asum[leftcut+1-1])-Asum[leftcut+1-1])
      leftcut+=1
    else:
      break
  Rdiff=abs((Asum[-1]-Asum[rightcut-1])-(Asum[rightcut-1]-Asum[i-1]))
  while rightcut+1<N:
    if abs((Asum[-1]-Asum[rightcut+1-1])-(Asum[rightcut+1-1]-Asum[i-1])) < Rdiff:
      Rdiff=abs((Asum[-1]-Asum[rightcut+1-1])-(Asum[rightcut+1-1]-Asum[i-1]))
      rightcut+=1
    else:
      break
  P=Asum[leftcut-1]
  Q=Asum[i-1]-Asum[leftcut-1]
  R=Asum[rightcut-1]-Asum[i-1]
  S=Asum[-1]-Asum[rightcut-1]
  ans=max(P,Q,R,S)-min(P,Q,R,S) if max(P,Q,R,S)-min(P,Q,R,S)<ans else ans
print(ans)

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

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

    ll X;
    cin >> X;
    ll div, mod;
    div = X / 100;
    mod = X % 100;
    ll ma = div * 5;
    if (mod <= ma)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}

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

//テストケースはあんまり見ないほうが良い。デバッグする能力が必要.
int main()
{
    string s;
    cin >> s; 
    string a = "RUD";
    string b = "LUD";
    int ans =0;
    rep(i,s.size()){
        if(i%2==0){
            rep(j,3){
                if(a[j] == s[i])++ans;
            }
        }else{
            rep(j,3){
                if(b[j] == s[i])++ans;
            }
        }
    }
    if(ans == s.size())cout <<"Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long int lli;

int main(){
	ios_base::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	vector <vector<int>> hob(h);
	vector <vector <int>> wob(w);
	char mat[h][w];
	for(int i=0; i<h; i++)
		cin >> mat[i];

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(mat[i][j] == '#'){
				hob[i].pb(j);
				wob[j].pb(i);
			}
		}
	}

	int res = -INT_MAX;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(mat[i][j] == '#') continue;
			//dbg(i);
			//dbg(j);
			int locres = 0;
			// count vertical
			auto it = lower_bound(ALL(hob[i]), j);
			int l, r;

			if(it != hob[i].begin()){
				auto it2 = it-1;
				l = *it2;
			}
			else{
				l = -1;
			}

			if(it != hob[i].end()){
				r = *it;
			}else{
				r = w;
			}
			locres += r-l-1;
			//dbg(locres);
			it = lower_bound(ALL(wob[j]), i);
			if(it != wob[j].begin()){
				auto it2 = it-1;
				l = *it2;
			}
			else{
				l = -1;
			}

			if(it != wob[j].end()){
				r = *it;
			}else{
				r = h;
			}
			locres += r-l-1;
			res = max(res, locres-1);
		}
	}

	cout << res;
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  map<int, int> m;
  vector<int> a(N);
  for(int i=0;i<N;i++) cin>>a[i];


  for(int i=0;i<N;i++){
    if(a[i]%2==0){
      if(a[i]%3!=0&&a[i]%5!=0){
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }
cout<<"APPROVED"<<endl;

}


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

using namespace std;

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

    set<int> st1, st2;
    while (m--) {
        int a, b;
        cin >> a >> b;
        if (a == 1) st1.insert(b);
        if (b == n) st2.insert(a);
    }

    bool flag = false;
    for (int i = 2; i < n; ++i) {
        if (st1.find(i) != st1.end() and st2.find(i) != st2.end()) {
            flag = true;
            break;
        }
    }

    if (flag) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


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

using namespace std;

#define lli long long
#define ld long double
#define mod 1000000007 
#define set(n) cout << fixed << setprecision(n)    
#define fi first
#define se second
#define mp make_pair
#define pll pair<lli, lli>
#define endl '\n'

const double PI = acos(-1);
const double epsilon = 1e-7;  // floating point precision

signed main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    lli mx = 0ll;
    for(int i = 0; i < s.length(); i++) {
        lli len = 0ll;
        while(i < s.length() and s[i] == 'R') {
            len ++;
            i++;
        }    
        mx = max(mx, len);
    }
    cout << mx << endl;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,m;
  while(1){
    cin >> n >> m;
    if(n==0) return 0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(i!=j){
          if(a[i]+a[j]<=m){
            ans=max(ans,a[i]+a[j]);
          }
        }
      }
    }
    if(ans==0){
      cout << "NONE" << endl;
    }else{
      cout << ans << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmix(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	string t;
	t = s;
	reverse(all(s));

	ll ans = 0;
	rep(i, s.length()){
		if(s[i] != t[i]) ans++;
	}
	co(ans/2);

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

int main()
{
    int R;
    scanf("%d",&R);

    if( R < 1200 ){
        printf("ABC\n");
    }else if( R < 2800 ){
        printf("ARC\n");
    }else{
        printf("AGC\n");
    }

    return 0;
}

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

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

using namespace std;

using ll = long long;

using P = pair<int,int>;



int main() {

  double r ;
cin>> r ;
  double ans= r*6.283 ;
printf("%.5f\n",ans) ;
  return 0;

}

Measured memory_bytes: 3752
#include<stdio.h>

int a[1111], b[1111], c[1111], d[1111], p[333], x, y, z, i, j;

int main(){
  
  while(scanf("%d %d %d", &a[0], &b[0], &c[0])&&(*a+=*b+*c)){
    for(i=332;i;) p[i--] = 2;
    
    scanf("%d", &p[0]);
    for(i=0;i++<*p;) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
    
    for(i=0;i++<*p;){
      for(j=0;j++<*p;){
	if(d[j]) p[a[j]] = p[b[j]] = p[c[j]] = 1;
	else{
	  if((x=p[a[j]]&1)&(y=p[b[j]]&1)) p[c[j]] = 0;
	  else if(x&(z=p[c[j]]&1)) p[b[j]] = 0;
	  else if(y&z) p[a[j]] = 0;
	}
      }
    }
    for(i=0;i<*a;) printf("%d\n", p[++i]);
  }
  return 0;
}

Measured memory_bytes: 616
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b; cin >> a >> b;
    out(LCM(a,b));

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
#define ll long long
using namespace std;
inline ll read(){
	ll x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
ll n,m;
char s[maxn],S[maxn];
int main(){
	n=read();m=read();
	scanf("%s",s);scanf("%s",S);
	ll tmp=__gcd(n,m);ll Ans=n*m/tmp,N=n/tmp,M=m/tmp;
	for(ll i=0;i<tmp;i++)if(s[i*N]!=S[i*M]){Ans=-1;break;}
	printf("%lld\n",Ans);return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int flag=0;
	for(int i=0;i<s.length();i++)
	{
		if(i%2==0)
		{
			if(s[i]!='h')
			{
				flag=1;
				break;
			}
		}
		else
		{
			if(s[i]!='i')
			{
				flag=1;
				break;
			}
		}
	}
  	if(s.length()%2!=0)
    {
      cout<<"No"<<endl;
    }
	else if(flag==1)
	{
		cout<<"No"<<endl;
	}
	else
	{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX   20
#define N 200

int solve(int,int);

int n;
int A[MAX];

int main()
{
  int q,i,res;
  int B[N];

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i = 0; i < q; i++){
    scanf("%d",&B[i]);
  }

  for(i = 0; i < q; i++){
    res = solve(0,B[i]);
    if(res == 1){
      printf("yes\n");
    }
    else if(res == 0){
      printf("no\n");
    }
  }

  return 0;
}

/*1 solve(i, m)
2   if m == 0
3     return true
4   if i >= n
5     return false
6   res = solve(i + 1, m) || solve(i + 1, m - A[i])
7   return res*/

int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  if(solve(i+1,m) == 1 || solve(i+1,m - A[i]) == 1){
    return 1;
  }
  return 0;
}



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

namespace ProCon
{
    class Program
    {
        static void Main(string[] args)
        {
            AC142B();

        }

        private static void AC142B()
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var people = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

            int count = 0;
            foreach(var h in people)
            {
                if(NK[1] <= h)
                {
                    count++;
                }
            }

            Console.WriteLine(count);
            Console.ReadKey();

        }

    }
}


Measured memory_bytes: 19296
#include<bits/stdc++.h>
using namespace std;
int main(){
char a,b;
  cin >> a >> b;
  if(a == 'H' && b == 'H')
    cout << b << endl;
  else if(a == 'H' && b == 'D')
    cout << b << endl;
  else if(a == 'D' && b == 'D')
    cout << 'H' << endl;
  else
    cout << a << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			String s = scanner.next();
			int size = s.length();
			int pos = -1;
			int stock = -1;
			for (int i = 0; i < size; i++) {
				int button = s.charAt(i) - '0';
				if (button == 0) {
					if (stock == -1)
						continue;
					System.out.print(mes[stock].charAt(pos
							% mes[stock].length()));
					stock = -1;
					pos = -1;
				} else {
					stock = button;
					pos++;
				}
			}
			System.out.println();

		}
	}

	String[] mes = { " ", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs",
			"tuv", "wxyz" };
}

Measured memory_bytes: 21736
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll i = (s); i < (x); i++)
#define MREP(i, s, x) for(ll i = (s); i >= (x); i--)
#define REP(i, x) PREP(i, 0, x)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// variable -------------------------------------------

constexpr ll INF = (1ll << 60);
constexpr ll MOD = 1000000007ll;

// struct ---------------------------------------------

// function -------------------------------------------

// main -----------------------------------------------

int main() {
    string t;
    cin >> t;
    ll n = t.length();
    ll ans = 0;
    REP(i, n){
        if(t[i] == '?'){
            t[i] = 'D';
        }
        if(t[i] == 'D'){
            ans ++;
        }
    }
    REP(i, n-1){
        if(t[i] == 'P' && t[i+1] == 'D'){
            ans ++;
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 3724
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
		String n = sc.next();
      	char[] ary = new char[n.length()];
      	
      	for(int i = 0; i < n.length(); i++) {
         	ary[i] = n.charAt(i); 
          	
          	if(ary[i] == '1') {
	            ary[i] = '9';
            } else if(ary[i] == '9') {
            	ary[i] = '1';
            }
        	System.out.print(ary[i]);
        }
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define for(in1,in2,in3) for (int in1 = in2; in1 < in3; in1++)
#define inf 1e9
#define mp make_pair
#define pb push_back
#define f first
#define s second
using namespace std;

int mx,x,y,z,t,u,v,ans,n,m,o;
string s1,s2,ans1;

int main() {
	cin >> x >> y >> z;
	for(a,0,y) {
		cin >> t;
		if (t > z) n++; else m++;
	}
	cout << min(n,m) << "\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
ABs = [tuple(map(int, input().split())) for _ in range(N)]

ABs.sort(key=lambda x: x[1])

accA = 0
for A, B in ABs:
    accA += A
    if accA > B:
        print('No')
        break
else:
    print('Yes')



Measured memory_bytes: 31840
package main

import "fmt"

const NUM_SIZE = 210

var N int
var A [NUM_SIZE]int

func main() {
	fmt.Scan(&N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}

	count := 0
	for {
		if division() == false {
			break
		}
		count++
	}
	fmt.Println(count)
}

func division() bool {
	for i := 0; i < N; i++ {
		mod := A[i] % 2
		if mod == 1 {
			return false
		}
		A[i] = A[i] / 2
	}
	return true
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    vector<int> position(n);
    for(int i = 0; i < n; i++){
        int in;
        cin >> in;
        position[in - 1] = i;
    }
    vector<int> ans(n);
    ans[n - 1] = 1;
    for(int i = n - 2; i >= 0; i--){
        if(position[i] < position[i + 1]){
            ans[i] = ans[i + 1] + 1;
        } else {
            ans[i] = 1;
        }
    }
    sort(ans.begin(), ans.end());
    cout << n - ans[ans.size() - 1] << endl;
    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  cout << min({(a - a / 2 - a / 2) * b * c, (b - b / 2 - b / 2) * a * c,
               (c - c / 2 - c / 2) * a * b})
       << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin >> N;
  vector<ll> a(N + 1); rep(i,N + 1) cin >> a[i];
  vector<ll> sum(N + 5);
  for(ll i = N + 1 ; i > 0 ; i --){
    sum[i - 1] = sum[i] + a[i - 1];
  }
  // 1こ上の深さでの葉でない頂点の個数の2倍
  vector<ll> v(N + 5 , 1e18); v[0] = 1;
  if(a[0] > 1){
    cout << -1 << endl;
    return 0;
  }
  rep(i,N){
    v[i + 1] = 2 * (v[i] - a[i]);
    if(v[i + 1] > 1e16) break;
    if( ( i + 1 < N - 1 and v[i + 1] < 1 ) or v[i + 1] < a[i + 1] ){
      cout << -1 << endl;
      return 0;
    }
  }

  ll ans = 0;
  rep(i,N + 1){
    ans += min(v[i] , sum[i]);
    // cout << i << " " << min(v[i]  , sum[i]) << " " << a[i] << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int min=scanner.nextInt();
		int midium=scanner.nextInt();
		int max=scanner.nextInt();
		if(min<midium&&midium<max){
			System.out.println("Yes");
		}else
		{
			System.out.println("No");
		}
		
		scanner.close();
	}

}

Measured memory_bytes: 17204
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class L { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	private long N;
	private long[] a;
	private bool[,] flag;
	private long[,] memo;

	public void Solve()
	{
		N = GetLong();
		a = GetLongs(N);

		flag = new bool[N, N];
		memo = new long[N, N];
		WriteLine(rec(0, N - 1));
	}

	private long rec(long l, long r)
	{
		if(flag[l, r])
			return memo[l, r];

		flag[l, r] = true;

		long t = (N - (r - l + 1)) % 2;
		if(l == r)
			return (memo[l, r] = (t == 0) ? a[l] : -a[l]);

		if(t == 0)
			return (memo[l, r] = Max(rec(l + 1, r) + a[l], rec(l, r - 1) + a[r]));
		else
			return (memo[l, r] = Min(rec(l + 1, r) - a[l], rec(l, r - 1) - a[r]));
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 84224
# 共通系になりそう
from math import factorial
import sys, math
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 1000000007

def combination(n, r):
    r = min(r, n - r)
    num = 1
    den = 1
    for i in range(1, r + 1):
        num = (num * (n + 1 - i)) % MOD
        den = (den * i) % MOD
    return num * pow(den, MOD - 2, MOD) % MOD

N, A, B = map(int, input().split())

result_ = pow(2, N) - 1 - combination(N, A) - combination(N, B)
print(result_ % MOD)

# powはn剰の時早い

Measured memory_bytes: 280884
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));
        String s1 = br.readLine();
        String answer = "";
        for (int c : s1.toCharArray()) {
            c = c >= 65 && c <= 90 ? c + 32 : c >= 97 && c <= 122 ? c - 32 : c;
            answer += (char) c;
        }
        System.out.println(answer);
    }
}

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

typedef double D;
typedef complex<D> P;

const D eps=1e-8;

struct C{
  P p; D r;
  C(const P& p,D r):p(p),r(r){}
};

enum RELATION{SAME=1,CONTAINED=2,OVER=4,NO_CROSS=8,ONE_CROSS=16,ONE_CONTAINED_CROSS=32,ONE_OVER_CROSS=64,TWO_CROSS=128};
int cRel(C c1, C c2) {
  D d=abs(c1.p-c2.p);
  D dr1=c1.r-c2.r,dr2=c2.r-c1.r;
  D ar=c1.r+c2.r;
  if(d<eps&&c1.r==c2.r)return SAME;
  if(d<dr1)return OVER;
  if(d<dr2)return CONTAINED;
  if(d==dr1)return ONE_OVER_CROSS;
  if(d==dr2)return ONE_CONTAINED_CROSS;
  if(d==ar)return ONE_CROSS;
  if(d>ar)return NO_CROSS;
  return TWO_CROSS;
}

bool sorter(const C& a,const C& b){
  if(cRel(a,b)==CONTAINED)return true;
  else return a.r < b.r;
}

int main(){
  while(1){
    int N;
    D sx,sy,tx,ty;
    vector<C> cs1,cs2;
    cin>>N;
    if(N==0)break;
    cin>>sx>>sy>>tx>>ty;
    rep(i,N){
      D x,y,r;
      cin>>x>>y>>r;
      int f=0;
      {
        D dx=sx-x;
        D dy=sy-y;
        if(dx*dx+dy*dy<r*r)f|=1;
      }
      {
        D dx=tx-x;
        D dy=ty-y;
        if(dx*dx+dy*dy<r*r)f|=2;
      }
      if(f==1){
        cs1.push_back(C(P(x,y),r));
      }else if(f==2){
        cs2.push_back(C(P(x,y),r));
      }
    }

    sort(all(cs1),sorter); sort(all(cs2),sorter);

    int n1=cs1.size();
    int n2=cs2.size();
    vector<vector<int> > dp1(n1+1,vector<int>(n1+1,-INF));
    vector<vector<int> > dp2(n2+1,vector<int>(n2+1,-INF));

    {
      dp1[0][0]=0;
      rep(i,n1){
        rep(j,n1+1){
          if(dp1[i][j]==-INF)continue;
          if(j==0){
            maxch(dp1[i+1][i+1],dp1[i][j]+1);
            maxch(dp1[i+1][j],dp1[i][j]);
          }else{
            int nj=j-1;
            if(cRel(cs1[nj],cs1[i])==CONTAINED)maxch(dp1[i+1][i+1],dp1[i][j]+1);
            maxch(dp1[i+1][j],dp1[i][j]);
          }
        }
      }
    }
    {
      dp2[0][0]=0;
      rep(i,n2){
        rep(j,n2+1){
          if(dp2[i][j]==-INF)continue;
          if(j==0){
            maxch(dp2[i+1][i+1],dp2[i][j]+1);
            maxch(dp2[i+1][j],dp2[i][j]);
          }else{
            int nj=j-1;
            if(cRel(cs2[nj],cs2[i])==CONTAINED)maxch(dp2[i+1][i+1],dp2[i][j]+1);
            maxch(dp2[i+1][j],dp2[i][j]);
          }
        }
      }
    }

    int res=0;
    rep(i,n1+1){
      rep(j,n2+1){
        if(i==0||j==0||cRel(cs1[i-1],cs2[j-1])==NO_CROSS)maxch(res,dp1[n1][i]+dp2[n2][j]);
      }
    }

    cout<<res<<endl;

  }
  return 0;
}



Measured memory_bytes: 6908
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N, K = map(int, raw_input().split())

ls = []
for i in range(N):
    a, b = map(int, raw_input().split())
    ls.append((a, b))

ls.sort()

for a, b in ls:
    K -= b
    if K <= 0:
        print a
        exit()

Measured memory_bytes: 18680
h,w = map(int,input().split())
H = []
l = []
for i in range(h):
  k = list(input())
  if len(set(k)) == 1 and k[0] == '.':
    H.append(i)
  l.append(k)
W = []
for j in range(w):
  flag = True
  x = l[0][j]
  if x == '.':
    for k in l:
      if k[j] != x:
        flag = False
    if flag:
      W.append(j)
for i in H: 
  for j in range(w):
    l[i][j] = ''
for j in W:
  for i in range(h):
    l[i][j] = ''
for k in l:
  if ''.join(k) != '':
    print(''.join(k))

Measured memory_bytes: 3188