akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <sstream>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define clr(a) memset(a, 0, sizeof(a))
#define set(a) memset(a, -1, sizeof(a))
#define pb push_back
#define sz(a) ((ll)a.size())
#define all(a) a.begin(), a.end()
#define mp make_pair
#define rep(i, a, y) for (ll i = a; i <= y; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(x) scanf("%d", &x)
#define pcl(x) printf("%d", x)
#define FastRead                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
/*
 
     ██╗██╗   ██╗██╗  ██╗ █████╗ ███╗   ██╗
     ██║██║   ██║██║  ██║██╔══██╗████╗  ██║
     ██║██║   ██║███████║███████║██╔██╗ ██║
██   ██║██║   ██║██╔══██║██╔══██║██║╚██╗██║
╚█████╔╝╚██████╔╝██║  ██║██║  ██║██║ ╚████║
 ╚════╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝
 
*/
//map<char, ll> p;
//map<char, ll>::iterator it;
// bool solve(string ans)
// {
//     //string str=r;
//     for(ll i=0;i<sz(r);i++) 
//     {
//         p[r[i]]++;
//     }
//     for(it=p.begin();it!=p.end();it++) 
//     {
//         if(it->second%2!=0) 
//         {
//             return false;
//         }
//     }
//     return true;
// }
bool solve(string str)
{
    ll arr[26];
    memset(arr,0,sizeof(arr));
    for(ll i=0; i<sz(str); ++i)
    {
        ll id=(int)str[i]-97;
        arr[id]=arr[id]+1;
    }
    for(ll i=0; i<26; ++i)
    {
        if(arr[i]%2!=0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    bool cnt=0;
    FastRead;
    string s;
    cin >> s;
    for (ll i =sz(s)-1;i>=0; i--)
    {
        string x=s.substr(0,i);
        if(solve(x))
        {
            string z="",y="";
            for(ll j=0;j<sz(x)/2;j++) z+=x[j];
            for(ll j=sz(x)/2;j<sz(x);j++) y+=x[j];
            if(z==y)
            {
                cout<<sz(x)<<endl;
                return 0;
            }
        }
    }
    cout<<"0"<<endl;
    return 0;
    // ll test=1;
    // //cin>>test;
    // while(test--)
    // {
    //     string str;
    //     cin>>str;
    //     for(ll i=sz(str)-1; i>=0; --i)
    //     {
    //         string ans=str.substr(0,i);
    //         if(solve(ans))
    //         {
    //             if(ans.substr(0,sz(ans)/2LL)==ans.substr(sz(ans)/2LL,sz(ans)/2LL))
    //             {
    //                 cout<<sz(ans)<<endl;
    //                 return 0;
    //             }
    //         }
    //     }
    //     cout<<0<<endl;
    // }
    // return 0;
}

Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
import collections
N = int(input())
A_list = list(map(int, input().split()))

ans = 1
color_list = [0, 0, 0]
for i in range(N):
    pattern_num = 0
    for j in range(len(color_list)):
        if color_list[j] == A_list[i]:
            pattern_num += 1
    for j in range(len(color_list)):
        if color_list[j] == A_list[i]:
            color_list[j] += 1
            break
    ans *= pattern_num

print(ans % (10 ** 9 + 7))

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

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

using namespace std;

#define MAX_V 100000

typedef long long ll;

int V,E,K,S;
ll P,Q,mini[MAX_V];
bool zombi[MAX_V];
vector<int> G[MAX_V];
bool danger[MAX_V];

struct Data2 {
  int cur, TL;
  bool operator < ( const Data2 &data ) const {
    if( TL != data.TL ) return TL < data.TL;
    return cur < data.cur;
  }
};

struct Data {
  int cur;
  ll cost;
  bool operator < ( const Data &data ) const {
    if( cost != data.cost ) return cost > data.cost;
    return cur < data.cur;
  }
};

void preprocess() {
  priority_queue<Data2> Q;
  rep(i,V) if( zombi[i] ) {
    Q.push((Data2){i,S});
    danger[i] = true;
  }
  while( !Q.empty() ) {
    Data2 data = Q.top(); Q.pop();
    if( data.TL <= 0 ) continue;
    rep(i,(int)G[data.cur].size()) {
      int next = G[data.cur][i];
      if( danger[next] ) continue;
      danger[next] = true;
      Q.push((Data2){next,data.TL-1});
    }
  }
  zombi[0] = zombi[V-1] = false;
}

void compute() {
  preprocess();
  rep(i,V) mini[i] = LLONG_MAX;
  mini[0] = 0;
  priority_queue<Data> pq;
  pq.push((Data){0,0});
  while( !pq.empty() ) {
    Data data = pq.top(); pq.pop();
    if( data.cur == V-1 ) {
      cout << data.cost << endl;
      return;
    }
    rep(i,(int)G[data.cur].size()) {
      int next = G[data.cur][i];
      if( zombi[next] ) continue;
      ll cost =  data.cost + (danger[next]?Q:P);
      if( next == V-1 ) cost = data.cost;
      if( mini[next] > cost ) {
	mini[next] = cost;
	pq.push((Data){next,mini[next]});
      }
    }
  }
  assert(false);
}

int main() {
  scanf("%d %d %d %d",&V,&E,&K,&S);
  cin >> P >> Q;
  int tmp,tmp2;
  rep(i,K) {
    scanf("%d",&tmp);
    --tmp;
    zombi[tmp] = true;
  }
  rep(i,E) {
    scanf("%d %d",&tmp,&tmp2);
    --tmp, --tmp2;
    G[tmp].push_back(tmp2);
    G[tmp2].push_back(tmp);
  }
  compute();
  return 0;
}

Measured memory_bytes: 8916
{-# LANGUAGE FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Data.Array.ST
import Data.List
import Data.Array

type Node = Int
type Cost = Int
type Edge = (Node, Cost)
type Graph = Array Node [Edge]

inf = div maxBound 2 :: Int

warshall_floyd :: Graph -> Array (Node,Node) Cost
warshall_floyd graph = runST $ do
  let (s,e) = bounds graph
  dp <- newArray ((s,s),(e,e)) inf :: ST s (STUArray s (Node,Node) Cost)

  forM_ [s..e] $ \i -> do
    writeArray dp (i,i) 0

  forM_ [s..e] $ \i -> do
    forM_ (graph ! i) $ \(j,c) -> do
      writeArray dp (i,j) c

  forM_ [s..e] $ \k -> do
    forM_ [s..e] $ \i -> do
      forM_ [s..e] $ \j -> do
        a <- readArray dp (i,j)
        b <- readArray dp (i,k)
        c <- readArray dp (k,j)
        writeArray dp (i,j) $ min a (b+c)

  freeze dp

main = do
  (h:w:_) <- map read . words <$> getLine :: IO [Int]
  
  graph <- array (0,9) <$>
           (forM [0..9] $ \i -> do
               edges <- zip [0..9] . map read . words <$> getLine :: IO [(Int,Int)]
               return $ (i, edges)
           )
  
  let cost = warshall_floyd graph

  print =<< (sum . concat . map (map ((\x -> if x == -1 then 0 else cost!(x,1)) . read) . words) . lines <$> getContents) 


Measured memory_bytes: 2428
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

    long long n;
    cin >> n;
    long long ans = 0;
    rep(i, n) {
        long long a;
        cin >> a;
        ans += a;
    }

    cout << ans - n * (n + 1) / 2 << '\n';

}



Measured memory_bytes: 3108
#include <iostream>
using namespace std;
 
int main()
{
    while(true){
        int h, w;
        cin >> h >> w;
 
        if(h==0 && w==0)
            break;
 
        int d = h*h+w*w;
 
        int H = 150;
        int W = 150;
        int D = 150*150+150*150;
 
        for(int y=1; y<=150; y++){
            for(int x=y+1; x<=150; x++){
                int z = y*y+x*x;
 
                if(z<=d){
                    continue;
                }
                else{
                    if(z<D){
                        H = y;
                        W = x;
                        D = z;
                    }
                    break;
                }
            }
        }
 
        for(int y=h+1; y<150; y++){
            bool flg = false;
 
            for(int x=y+1; x<=150; x++){
                int z = y*y+x*x;
 
                if(z==d){
                    H = y;
                    W = x;
                    D = z;
 
                    flg = true;
                }
 
                if(z>=d)
                    break;
            }
 
            if(flg)
                break;
        }
 
        cout << H << ' ' << W << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
using namespace std;

int dp[100005];
int n;
vector <int> v;

int solve(int ind){
    if(ind > n) return INT_MAX;
    if(ind == n) return 0;
    if(dp[ind] != -1) return dp[ind];
    long long ans = INT_MAX;
    int curr_height = v[ind],next_height;
    next_height = v[ind+1];
    ans = min(ans, solve(ind+1)+abs(next_height-curr_height));
    if(ind <= n-2){
        next_height = v[ind+2];
        ans = min(ans, solve(ind+2)+abs(next_height-curr_height));
    }
    return dp[ind] = ans;
}

int32_t main()
{
    cin>>n;
    v.resize(n+1);
    for(int i=1 ; i<=n ; i++) cin>>v[i];
    memset(dp,-1,sizeof dp);
    cout<<solve(1);
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
	int n, m;
	int p;
	vector<int> g;
	while (1){
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 0; i < n; i++){
			cin >> p;
			g.push_back(p);
		}
		for (int i = 0; i < n; i++){
			for (int i2 = 0; i2 < n; i2++){
				g.push_back(g[i] + g[i2]);
			}
		}
		int x, y;
		x = 0; y = g.size() - 1;
		int maxv = 0;
		sort(g.begin(), g.end());
		while (1){
			if (g[x] + g[y] > maxv&&g[x] + g[y] <= m)maxv = g[x] + g[y];
			if (g[x] + g[y] <= m)x++;
			if (g[x] + g[y] > m)y--;
			if (x > y)break;
		}
		cout << maxv << endl;
		g.clear();
	}
}

Measured memory_bytes: 7312
#include <stdio.h>
int N, X[50], Y[50], sx, sy;
int main() {
	scanf("%d", &N);
	for(int i = 0; i < N; i++) {
		scanf("%d%d", &X[i], &Y[i]);
		sx += X[i];
		sy += Y[i];
	}
	if(N % 2 == 1) {
		printf("NA\n");
	}
	else {
		bool flag = true;
		for(int i = 0; i < N / 2; i++) {
			flag = flag && ((1.0 * sx / N - X[i]) * 2 == (X[N / 2 + i] - X[i]) && (1.0 * sy / N - Y[i]) * 2 == (Y[N / 2 + i] - Y[i]));
		}
		if(flag) {
			printf("%.9f %.9f\n", 1.0 * sx / N, 1.0 * sy / N);
		}
		else {
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2752
#include <iostream>
#include <stdio.h>

int main()
{
	int H, W;
	while (std::cin >> H >> W, H || W)
	{
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if ((i + j) % 2 == 0)
				{
					std::cout << "#";
				}
				else
				{
					std::cout << ".";
				}
			}
			std::cout << '\n';
		}
		std::cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 3008
#include<iostream>
using namespace std;
#include <string>
int main()
{
    // 整数の入力
    int a;
    cin >> a;
  if(a<30)
  {
      
    // 出力
    cout <<  "No" << endl;
  }
  else
  {
      
    // 出力
    cout << "Yes" << endl;
  }
 
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	List<Integer> list = new ArrayList<Integer>();
	for(int i = 0; i < 10; i++){
	    list.add(scan.nextInt());
	}

	Collections.sort(list);
	System.out.println(list.get(list.size()-1));
	System.out.println(list.get(list.size()-2));
	System.out.println(list.get(list.size()-3));
    }
}

Measured memory_bytes: 26344
#include<bits/stdc++.h>
using namespace std;
long long q,x,y;
main(){
  cin>>q;
  while(q--){
    cin>>x>>y;
    if(x>y)swap(x,y);
    long double k=sqrt(x*y-0.75)-x+0.5;
    cout<<(int)(x-1+k+(x*y-1)/(x+k))-(x!=y)<<endl;
  }
}


Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long ans = 0;
    long long A_max = 0;
    int N;
    cin >> N;
    for ( int i = 0; i < N; i++ ) {
        long long A,B;
        cin >> A >> B;
        
        if ( A_max < A ) {
            A_max = A;
            ans = A + B;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	const int N = 31;
	int n,i,j,s;
	while(scanf("%d",&n),n)
	{
		int a[N][N+3]={1};
		for(i=0;i<n;++i)
		{
			for(j = 0; j < n; ++j)
			{
				a[i+1][j+3] += a[i][j];
				a[i+1][j+2] += a[i][j];
				a[i+1][j+1] += a[i][j];
			}
		}
		for(s=i=0;i<n;++i)s+=a[i][n];
		printf("%d\n", (s/10-1)/365+1);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int a[] = new int[n];
        for (int i=0; i<n; i++) a[i] = sc.nextInt();

        int sum = 0;
        for (int i=0; i<n; i++) sum += a[i];
        int max = 0;
        for (int d=1; d*d<=sum; d++){
            if (sum%d==0){
                if (check(a, n, k, d)){
                    max = (int)Math.max(max, d);
                }
                if (check(a, n, k, sum/d)){
                    max = (int)Math.max(max, sum/d);
                }
            }
        }
        System.out.print(max);
    }

    static boolean check(int arr[], int n, int k, int d){
        int newarr[] = new int[n];
        for (int i=0; i<n; i++) newarr[i] = arr[i] % d;
        Arrays.sort(newarr);

        int a = 0;
        int b = n-1;
        while(a<n && newarr[a]==0) a++;
        int c = 0;
        while(b>a){
            c += newarr[a];
            k -= newarr[a];
            while(newarr[b] +c >= d && b>a){
                c -= (d - newarr[b]);
                b--;
            }
            a++;
        }
        return k>=0;
    }
}

Measured memory_bytes: 26532
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> h(n+1);
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }

    vector<vector<int>> dest(n+1);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        dest[a].push_back(b);
        dest[b].push_back(a);
    }

    vector<bool> isgood(n+1, true);
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < dest[i].size(); j++){
            if(h[dest[i][j]] >= h[i]) isgood[i] = false;
        }
    }

    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(isgood[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8780
from sys import stdin
A,B,C,X,Y = [int(x) for x in stdin.readline().rstrip().split()]
ans = 10**9
for i in range(0,2*(max(X,Y)+1)):
    total = A*max((X-(i//2)),0) + B*max((Y-(i//2),0)) + i*C
    #print(total,i)
    if total > 0 and total < ans:
        ans = total
print(ans)

Measured memory_bytes: 3064
A = input()
B = input()
if len(A) > len(B):
    print("GREATER")
elif len(A) < len(B):
    print("LESS")
else:
    for a, b in zip(A, B):
        if a > b:
            print("GREATER")
            break
        elif a < b:
            print("LESS")
            break
    else:
        print("EQUAL")


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

using namespace std;

int n;
int l[110];
int ans = 0;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> l[i];
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = i + 1; j <= n; j++)
		{
			for(int k = j + 1; k <= n; k++)
			{
				if(l[i] != l[j] && l[j] != l[k] && l[i] != l[k])
				{
					if(l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i])
					{
						ans++;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 3652
// include
#include <array>
#include <algorithm>
#include <set>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <unordered_map>


// pow(10, 15) 10の15乗

//  多倍長整数
#include <boost/multiprecision/cpp_int.hpp>
using big_int = boost::multiprecision::cpp_int;


// ============================================
int main() {
    int a;
	std::cin >> a;

    int result = a + (a*a) + (a*a*a);
  
    std::cout << result << std::endl;

    return 0;
}



Measured memory_bytes: 3184
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

vector<ll> counter;
vector<vector<ll>> ADJ;
void dfs(ll u,ll val,ll p=-1)
{
	counter[u]+=val;
	val=counter[u];
	trav(v,ADJ[u])
	{
		if(v!=p)
		{
			dfs(v,val,u);
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	READV(N);
	counter.resize(N+1,0);
	ADJ.resize(N+1);
	READV(Q);
	FORI(i,0,N-1)
	{
		READV(u);
		READV(v);
		ADJ[u].pb(v);
		ADJ[v].pb(u);
	}
	FORI(i,0,Q)
	{
		READV(p);
		READV(x);
		counter[p]+=x;
	}
	dfs(1,0);
	FORI(i,1,N+1)
	{
		cout<<counter[i]<<" ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 24320
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, max_value = -1;
    bool flag = false;
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++){
        cin >> array[i];
    }

    for(int i=0;i<n;i++){
        if(max_value > array[i] + 1){
            flag = true;
            break;
        }
        if(max_value < array[i]) max_value = array[i];
    }

    if(flag) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>

int W[2000000];
int H[2000000];

int main(void) {
    while(true) {
        int n,m;
        int w[2000], h[2000];
        int res=0;

        scanf("%d%d",&n,&m);
        if(!n) break;

        memset(W, 0, sizeof(W));
        memset(H, 0, sizeof(H));
        memset(w, 0, sizeof(w));
        memset(h, 0, sizeof(h));

        int last=0;
        for(int i=1; i<=n; i++) {
            int t;
            scanf("%d",&t);
            last+= t;
            h[i] = last;
        }
        last = 0;
        for(int i=1; i<=m; i++) {
            int t;
            scanf("%d",&t);
            last+= t;
            w[i] = last;
        }

        for(int i=0; i<=n; i++)
            for(int j=i+1; j<=n; j++)
                H[h[j]-h[i]]++;
        for(int i=0; i<=m; i++)
            for(int j=i+1; j<=m; j++)
                W[w[j]-w[i]]++;

        for(int i=0; i<1600000; i++) {
            res += W[i] * H[i];
        }

        printf("%d\n",res);

    }
    return 0;
}

Measured memory_bytes: 16672
#include<bits/stdc++.h>
using namespace std ;
 int main()
 {
    string s;
    cin>>s; int l=s.length();int r=0,p=0; int c[l][2];
    for(int i=0;i<s.length();i++)
    {
     c[i][0]=r;
     c[l-1-i][1]=p;
     if(s[i]=='R')
     r++;
     else
     r=0;
     if(s[l-1-i]=='L')
     p++;
     else
     p=0;

    }  int ans[l]={0};
    for(int i=0;i<l-1;i++)
    {
        if(s[i]=='R'&&s[i+1]=='L')
        {
           ans[i]=c[i][0]/2+c[i][1]/2+1;
           ans[i+1]=c[i+1][0]/2+c[i+1][1]/2+1;
           i++;
        }
        else
        {
            ans[i]=0;
        }
    }
    
    for(int i=0;i<l;i++)
    cout<<ans[i]<<' ';
 }

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
	int a, b, price;
	scanf("%d %d", &a, &b);

	price = b * 10;
	for(int i = price; i < price + 10; i++){
		if((i * 8 )/ 100 == a){
		printf("%d\n", i);
		return 0;
		}
	}

	puts("-1");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  multiset<int> st;

  for (int i = 0; i < n; i++) {
    auto itr = st.upper_bound(-a[i]);
    if (itr == st.end()) st.insert(-a[i]);
    else {
      st.erase(itr);
      st.insert(-a[i]);
    }
  }
  cout << st.size() << endl;
  return 0;
} 

Measured memory_bytes: 5376
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define ll int
#define bits_count __builtin_popcountll
#define endl '\n'
#define double double
#define ld double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
#define sz(x) (ll)x.size()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5 + 10;
vector<int> graph[MAXN];
int color[MAXN];
int ans[MAXN];
vector<int> col[3];

void dfs(int u,int p){
    color[u] = 1 - color[p];
    for(int v:graph[u]){
        if(v == p) continue;
        dfs(v,u);
    }
}

void solve(){
    int n; cin>>n;

    FOR(i,1,n-1){
        int u,v; cin>>u>>v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1,0);

    int zero = 0,one = 0;
    FOR(i,1,n) if(color[i] == 0) zero++; else one++;

    if(one < zero) {
        FOR(i,1,n) color[i] = 1 - color[i];
        swap(one,zero);
    }

    RFOR(i,1,n) col[i%3].push_back(i); 

    if(zero <= sz(col[0])){
        FOR(i,1,n) if(color[i] == 0) ans[i] = col[0].back(),col[0].pop_back();
        vector<int> tot;
        FOR(i,0,2) while(col[i].size()) tot.push_back(col[i].back()),col[i].pop_back();
        FOR(i,1,n) if(color[i] == 1) ans[i] = tot.back(),tot.pop_back();
    }else {
        FOR(i,1,n) if(color[i] == 0 && col[1].size()) ans[i] = col[1].back(),col[1].pop_back();
        FOR(i,1,n) if(color[i] == 1 && col[2].size()) ans[i] = col[2].back(),col[2].pop_back();
        FOR(i,1,n) if(ans[i] == 0) ans[i] = col[0].back(),col[0].pop_back();
    }

    FOR(i,1,n) cout<<ans[i]<<" ";
}

signed main(){

   FastRead;    


    int t = 1; 
    // cin>>t; 
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int N;
  cin >> N;
  vector<int> result(4);
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    if(s == "AC") result[0]++;
    else if(s == "WA") result[1]++;
    else if(s == "TLE") result[2]++;
    else result[3]++;
  }
  cout << "AC x " << result[0] <<endl;
  cout << "WA x " << result[1] <<endl;
  cout << "TLE x " << result[2] <<endl;
  cout << "RE x " << result[3] <<endl;
}

Measured memory_bytes: 3652
N = int(input())  
 
data = ([int(input()) for i in range(N)])

data.insert(0, 0)

i = 1
cnt = 0

push_button = {}

while True:
  
  trans_value = data[i]
  i = trans_value
  
  cnt += 1
  
  if trans_value == 2:
    break
  
  elif trans_value in push_button:
    cnt = -1
    break
    
  else:
    pass
  
  push_button[trans_value] = "PUSH"

print(cnt)

Measured memory_bytes: 16292
fun c() {
    val (h, w, k) = readLine()!!.split(" ").map(String::toInt)
    val c = Array(h) {
        readLine()!!
    }
    var result: Int = 0
    for (caseH in 0 until (1 shl h)) {
        for (caseW in 0 until (1 shl w)) {
            var black: Int = 0
            for (i in 0 until h) {
                for (j in 0 until w) {
                    if ((caseH shr i) and 1 == 0 && (caseW shr j) and 1 == 0 && c[i][j] == '#') {
                        black++
                    }
                }
            }
            if (black == k) result++
        }
    }
    println(result)
}

fun main() {
    c()
}

Measured memory_bytes: 36728
n,x = gets.split.map &:to_i
a = gets.split.map &:to_i
ans = 0
n.pred.times{|i|
  tona = a[i] + a[i+1]
  if tona > x
    z = [a[i+1], tona-x].min
    a[i+1] -= z
    ans += z
    tona = a[i] + a[i+1]
    if tona > x
      a[i] -= tona-x
      ans += tona-x
    end
  end
}

p ans

Measured memory_bytes: 11148
#include <iostream>
#include <vector>
using namespace std;
int main(){
	int N, x;
	cin >> N >> x;
	vector<int> a(N);
	for (int i = 0; i < N; ++i){
		cin >> a[i];
	}

	vector<int> minA = a;
	long long minTTTime = 9223372036854775807;
	for (int ms = 0; ms < N; ++ms){
		for (int i = 0; i<N; ++i){
			int mIndex = i - ms;
			if (mIndex<0)	mIndex += N;
			if (minA[i]>a[mIndex])	minA[i] = a[mIndex];
		}
		long long sum = 0;
		for (auto &el : minA){
			sum += (long long)el;
		}
		sum += (long long)ms*x;
		if (sum < minTTTime)	minTTTime = sum;
	}
	cout << minTTTime << endl;
	cin >> N;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a[9];
  int n;
  for(int i=0;i<9;i++)
  {
      cin>>a[i];
  }
  cin>>n;
  int b[n];
  for(int i=0;i<n;i++) cin>>b[i];
  bool m[10];
  memset(m,0,10);
  for(int i=0;i<9;i++)
  {
  	for(int j=0;j<n;j++)
  	{
  		if(b[j]==a[i])
  		m[i] = 1;
	  }
  }
   if(m[0]==1&&m[1]==1&&m[2]==1)
  cout<<"Yes"<<endl;
   else if(m[3]==1&&m[4]==1&&m[5]==1)
  cout<<"Yes"<<endl;
   else if(m[6]==1&&m[7]==1&&m[8]==1)
  cout<<"Yes"<<endl;
   else if(m[0]==1&&m[3]==1&&m[6]==1)
  cout<<"Yes"<<endl;
   else if(m[1]==1&&m[4]==1&&m[7]==1)
  cout<<"Yes"<<endl;
   else if(m[2]==1&&m[5]==1&&m[8]==1)
  cout<<"Yes"<<endl;
   else if(m[0]==1&&m[4]==1&&m[8]==1)
  cout<<"Yes"<<endl;
   else if(m[2]==1&&m[4]==1&&m[6]==1)
  cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, m;
vector<vector<i64>> v;
int main() {
  cin >> n >> m;
  init_n(v, m + 1);
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a <= m) {
      v[a].push_back(b);
    }
  }

  i64 ans = 0;
  priority_queue<int> pq;
  for (int i = 1; i <= m; ++i) {
    for (int b : v[i]) pq.push(b);
    if (!pq.empty()) {
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5504
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def combination_mod(n, r):
    # mod取りながらcombination
    if r > n:
        return 0  # このような通りの数は無いため便宜上こう定義する
    r = min(r, n - r)
    nf = rf = 1
    for i in range(r):
        nf = nf * (n - i)
        rf = rf * (i + 1)
    return nf // rf


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc057/tasks/abc057_d
# ソートしておけば、平均の最大化は簡単 (上位A個選べばよい)
# 通りの数は？
# もし単調増加なら必ず1通り

# 平均の最大化が変わらないとは...?
# 大きい方からA個目の数(cとする)が複数ある場合は別のを選らべる(通りが増える)
# 具体的にはn_c C rの通りの数が存在する(rは上位A個の中に存在するcの数)

# 三種類の場合があるな
# 単調増加のときは簡単

N, A, B = read_ints()
V = read_ints()
V.sort(reverse=True)
V_A = V[:A]
ans1 = sum(V_A) / A
# 単調増加の場合
if V[A] != V[A - 1]:
    print(ans1)
    print(1)
    exit()

# A個選ぶのが最適の場合
if V_A[0] != V_A[-1]:
    c = V_A[-1]
    n_c = V.count(c)
    r = V_A.count(c)
    # print(n_c, r)
    ans2 = combination_mod(n_c, r)
    print(ans1)
    print(ans2)
    exit()

# 全部同じ場合
n_same = V.count(V[0])
if n_same > A:
    ans2 = 0
    r_max = min(n_same, B)  # 最大これだけ選べる
    for i in ra(A, r_max + 1):
        ans2 += combination_mod(n_same, i)
    print(ans1)
    print(ans2)
    exit()


raise ValueError('CE出てほしい')


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
str s;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){cout<<9;}
        else{cout<<1;}
    }cout<<endl;


}


Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(
				new InputStreamReader (System.in));
		String line=br.readLine();
		String[] str = line.split(" ");
		int a=Integer.parseInt(str[0]);
		int b=Integer.parseInt(str[1]);
		int c=Integer.parseInt(str[2]);
		if(a<b && b<c) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 24440
r,g,b,n = map(int, input().split())

ans = 0
for i in range(n+1):
    for j in range(n+1):
        if (n - i*r - j*g) >= 0 and (n -i*r -j*g)%b == 0:
            ans += 1
            
print(ans)

Measured memory_bytes: 41196
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"

int32_t main()
{
	boost;

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    int s=0;
    for(int i=k;i<n;i++)
        s+=a[i];
    cout<<s<<endl;
    
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  ll n, m;
  cin >> n >> m;
  ll ans = n;
  vector<ll> h(n, 0);
  vector<bool> v(n, true);
  rep(i, n){
    cin >> h[i];
  }
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(h[a] == h[b]){
      if(v[a]){
        v[a] = false;
        ans--;
      }
      if(v[b]){
        v[b] = false;
        ans--;
      }
    }else if(h[a] > h[b]){
      if(v[b]){
        v[b] = false;
        ans--;
      }
    }else{
      if(v[a]){
        v[a] = false;
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, M, Q;
int a[100010], b[100010];
bool us[100010];
int pos[100010];
int nums[100010];
bool inc[100010];

int main() {
	cin >> N >> M >> Q;

	rep(i, Q) cin >> a[i];
	int now = 0;
	for (int i = Q-1; i >= 0; --i) {
		if (!us[a[i]]) {
			us[a[i]] = 1;
			b[now++] = a[i];
		}
	}

	for (int i = 1; i <= M; ++i) {
		if (!us[i]) {
			b[now++] = i;
		}
	}

	rep(i, M) {
		pos[b[i]] = i;
	}

	inc[M] = 1; b[M] = 2e5;

	for (int i = M-1; i >= 0; --i) {
		inc[i] = inc[i+1] && (b[i] < b[i+1]);
	}

	nums[0] = N;

	for (int i = Q-1; i >= 0; --i) {
		int p = pos[a[i]];

		if (nums[p] > 0) {
			--nums[p];
			++nums[p+1];
		}
	}

	for (int i = 0; i < M; ++i) {
		if (nums[i] > 0 && !inc[i]) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

int main() {
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<long> s(N);
    for(auto& i : s)cin >> i;
    long ans{0};
    for(unsigned long i = 1; i < N; ++i){
        long tmp{0};
        for(unsigned long j = 0, k = N - 1; k > i && (k % i != 0 || j < k); j += i, k -= i)ans = max(ans, tmp += s[j] + s[k]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main(void){
  string s;
  cin>>s;
  cout<<"ABC"<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <cstdlib>  // abs() for integer
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;

int main (){
    int N;
    cin >> N;
    cout << N*N*N;
    }
    
    


Measured memory_bytes: 256
/*
 * b.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_VN = 100000;
const int MAX_EN = 200000;

/* typedef */

typedef vector<int> vi;

/* global variables */

int as[MAX_VN];
bool used[MAX_VN][26];
vi nbrs[MAX_VN];

/* subroutines */

/* main */

int main() {
  int vn, en;
  cin >> vn >> en;

  for (int i = 0; i < vn; i++) {
    char ai;
    cin >> ai;
    as[i] = (ai == '?') ? -1 : ai - 'a';
  }

  for (int i = 0; i < en; i++) {
    int si, ti;
    cin >> si >> ti;

    nbrs[si].push_back(ti);
    if (as[ti] >= 0) used[si][as[ti]] = true;

    nbrs[ti].push_back(si);
    if (as[si] >= 0) used[ti][as[si]] = true;
  }

  for (int i = 0; i < vn; i++) {
    if (as[i] < 0) {
      for (int j = 0; j < 26; j++)
	if (! used[i][j]) {
	  as[i] = j;
	  break;
	}

      vi &nbri = nbrs[i];
      for (vi::iterator vit = nbri.begin(); vit != nbri.end(); vit++)
	used[*vit][as[i]] = true;

    }

    putchar(as[i] + 'a');
  }
  putchar('\n');

  return 0;
}


Measured memory_bytes: 10864
n = int(input())
a = list(map(int, input().split()))

p = 0
q = 0

a = sorted(a, reverse=True)

for i in range(n):
    if i % 2 == 0:
        p = p + a[i]
    else:
        q = q + a[i]

print(p - q)


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int ans = 999999999;
        for (int i = 0; i < N; i++) {
            if (N <= K + (K - 1) * (i - 1)) {
                ans = Math.min(ans, i);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 50720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, c; cin >> n >> c;
  vector<int> a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
  }
  vector<vector<ll>> v(n, vector<ll>(c+1, 0));
  for(int i=0;i<n;++i) {
    vector<ll> tmp;
    ll su = 0;
    for(int j=a[i];j<=b[i];++j) {
      tmp.push_back(1);
      su += 1;
      su %= MOD;
    }
    for(int j=0;j<=c;++j) {
      v[i][j] = su;
      su = 0;
      for(int k=a[i];k<=b[i];++k) {
        tmp[k-a[i]] *= k;
        tmp[k-a[i]] %= MOD;
        su += tmp[k-a[i]];
        su %= MOD;
      }
    }
  }
  vector<vector<ll>> dp(n+1, vector<ll>(c+1, 0));
  dp[0][0] = 1;
  for(int i=0;i<n;++i) {
    for(int j=0;j<=c;++j) {
      for(int k=0;k<=c;++k) {
        if(j - k < 0) break;
        dp[i+1][j] += dp[i][j-k] * v[i][k] % MOD;
        dp[i+1][j] %= MOD;
      }
    }
  }
  cout << dp[n][c] << endl;
}


Measured memory_bytes: 2816
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N, A, B = map(int, input().split())
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

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

for i in range(N):
    if A[i] <= B[i]:
        yoryoku = B[i] - A[i]
        A[i] = 0
        A[i+1] = max(0, A[i+1] - yoryoku)
    elif A[i] > B[i]:
        A[i] -= B[i]


print(total - sum(A))


# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 19232
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>

using namespace std;

int main(){
	int n,a[21],b[21],c[21];
	int ans=0;
	
	cin >> n;
	
	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-1;i++){
		cin >> c[i];
	}
	
	for(int i=0;i<n;i++){
		if(i==0)ans += b[a[0]-1];
		else if(a[i] - a[i-1] == 1)ans = ans + b[a[i]-1] + c[a[i]-2];
		else ans = ans + b[a[i]-1];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#import<ios>
int n,cnt,m,res;
char s[999];
int a[128],b[128];

int main()
{
	scanf("%d%s",&n,s);
	if (n==2)
	{
		if (s[0]==s[1])
		{
			printf("1");
		}
		else
			printf("0");
		return 0;
	}
	for (int i = 1; i < n-1; i++)
	{
//		printf("\ta : \n");
		for (int j = 0; j < i; j++)
		{
			a[s[j]]=1;
//			printf("s[%d] = %d\n",j,s[j]);
		}
//		printf("\tb : \n");
		for (int j = i; j < n; j++)
		{
			b[s[j]]=1;
//			printf("s[%d] = %d\n",j,s[j]);
		}
		for (int j = 0; j < 128; j++)
		{
			if(a[j]&&b[j])
				cnt++;
		}
//		printf("cnt = %d\n",cnt);
		if (m < cnt)
		{
			m = cnt;
		}
//		printf("max = %d\n",m);
		for (int j = 0; j < 128; j++)
		{
			a[j]=b[j]=0;
		}
		cnt=0;
	}
	printf("%d",m);
	return 0;
}

Measured memory_bytes: 128
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
c = 0
for a in A:
    if a == m:
        c += 1
if c == 1:
    mm = 0
    for i in range(N):
        a = A[i]
        if a == m:
            continue
        mm = max(a,mm)
    for i in range(N):
        a = A[i]
        if a == m:
            print(mm)
        else:
            print(m)
else:
    for i in range(N):
        print(m)

Measured memory_bytes: 18448
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

def main():
    S = deque(input())
    right = True
    for _ in range(ii()):
        q = input()
        if len(q) == 1:
            right ^= 1
        else:
            t, f, c = q.split()
            if right ^ (f=='1'):
                S.append(c)
            else:
                S.appendleft(c)
    if not right:
        S.reverse()
    print(*S, sep='')


main()







Measured memory_bytes: 14000
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

int C(int n) {
    return (n*(n+1))/2;
}

int add(int a, int b) {
    a %= mod; b %= mod;
    return ((a + b) % mod);
}

int sub(int a, int b) {
    a %= mod; b %= mod;
    return  ((a - b + mod) % mod);
}

int mul(int a, int b) {
    a %= mod; b %= mod;
    return ((a * b) % mod);
}

void solve() {
    int n, k; cin >> n >> k;
    int ans = 0;
    for(int i = k; i <= n+1; i++) {
        int s = C(i-1) % mod;
        int b = C(n)-C(n-i);
        ans = add(ans, sub(b+1,s));
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   //freopen("output.txt", "w", stdout);
    // #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}


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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int N;cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  v.push_back(-1);
  sort(v.rbegin(),v.rend());
  int now=0;
  while(now+1<v[now+1])now++;
  int tmp=now;
  int a=v[now]-now-1;
  int b=0;
  while(v[now+1]>tmp)now++,b++;
  if(a&1)fin("First");
  if(b&1)fin("First");
  fin("Second");
}


Measured memory_bytes: 1024