akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n;
string s, t[55];
set<char> vo{'a', 'i', 'u', 'e', 'o'};

signed main() {
    while (1) {
        cin >> n;
        if (n==0) break;
        rep(i,n) t[i].clear();
        rep(i,n) {
            cin >> s;
            t[i].push_back(s[0]);
            int m = s.size();
            reps(j,1,m) if (vo.count(s[j-1])) t[i].push_back(s[j]);
        }
        int res = -1;
        reps(i,1,55) {
            set<string> cd;
            rep(j,n) cd.insert((int)t[j].size()<i ? t[j] : t[j].substr(0,i));
            if (cd.size()==n) {
                res = i;
                break;
            }
        }
        cout << res << endl;
    }
}



Measured memory_bytes: 3196
#include <stdio.h>

#define WIDTH 12
#define HEIGHT 12

void del( int, int );

char field[ WIDTH + 2 ][ HEIGHT + 2 ] = {};
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int main( void ) {
	int x, y, sum;

	for ( ; ungetc( getchar(), stdin ) != EOF; printf( "%d\n", sum ) ) {
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				scanf( "%c ", field[ x ] + y );

		sum = 0;
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ )
				if ( field[ x ][ y ] == '1' ) {
					del( x, y );

					sum++;
				}
	}

	return 0;
}

void del( int x, int y ) {
	int i;

	field[ x ][ y ] = '0';

	for ( i = 4; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ] == '1' )
			del( nx, ny );
	}
}

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

int P[110];

int main(void) {
  int N, A, B;
  int less_a = 0, less_b = 0, more_b = 0;
  cin >> N >> A >> B;
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
    if (P[i] <= A) less_a++;
    else if (P[i] <= B) less_b++;
    else more_b++;
  }
  cout << std::min(std::min(less_a, less_b), more_b) << endl;
}


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

int getnumber(){
  int a;
  cin>>a;
  while (!((a <= 13) && (a >= 1))) {
    exit(0);
  }
  return a;
}

int main(){
  int a1,a2,a3,sum;
  a1=getnumber();
  a2=getnumber();
  a3=getnumber();
  sum= a1 + a2 + a3 ;
  if(sum>=22){
    cout<<  "bust"<<endl;
  }
  else
  {
    cout<<"win"<<endl;
  }
return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean b = true;
        //HashSetで空の箱を作る
		Set<Integer> set = new HashSet<>();
      
		for(int  i=0; i<N; i++) {
			int a= sc.nextInt();
          //set.addで空の箱に重複を除いたaを追加する
			b =	set.add(a);
		  //bがfalse(重複があるとき)はNO
			if(!b){
				System.out.println("NO");
				return;
			}
		}
		//最後まで重複しなかった場合
		System.out.println("YES");
	}		
}

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

int main(){
    int n, m; cin >> n >> m;
    vector<int> X(m);
    for(int i=0;i<m;i++){
        cin >> X.at(i);
    }
    sort(X.begin(), X.end());
    if(X.size() == 1) cout << 0 << endl;
    else{
        vector<int>dif(m-1);
        for(int i=0;i<m-1;i++){
            dif.at(i) = abs(X.at(i+1) - X.at(i));
        }
        sort(dif.begin(), dif.end());
        int cnt = 0;
        for(int i=0; i<dif.size()-min(n, m)+1; i++){
            cnt += abs(dif.at(i));
        }
        cout << cnt << endl;
    }

}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,m;
double h,w;

int main(){
	while(cin>>n){
		if(!n)return 0;
		int mm=0;
		double md;
		while(n--){
			cin>>m>>h>>w;
			double d=fabs(w*10000.0/h/h-22.0);
			if(!mm||d<md||d==md&&m<mm){md=d;mm=m;}
		}
		cout<<mm<<endl;
	}
}

Measured memory_bytes: 0
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    a -= 2
    b -= 2
    a %= 13
    b %= 13
    if a > b:
        print("Alice")
    elif a < b:
        print("Bob")
    else:
        print("Draw")
    return

#B
def B():
    n, m = LI()
    a = SR(n)
    b = SR(m)
    if a == b:
        print("Yes")
        return
    for y in range(n - m):
        for x in range(n - m):
            if a[y][x] == b[0][0]:
                flg = 0
                for yi in range(m):
                    for xi in range(m):
                        if b[yi][xi] == a[y + yi][x + xi]:
                            continue
                        flg = 1
                        break
                    if flg:
                        break
                if flg:
                    continue
                print("Yes")
                return
    print("No")
    return

#C
def C():
    n, m = LI()
    edg = [[] for i in range(n)]
    for _ in range(m):
        a, b = LI_()
        edg[a].append(b)
        edg[b].append(a)
    def dfs(i, c):
        res = 0
        c[i] = False
        if not (True in c):
            c[i] = True
            return 1
        for e in edg[i]:
            if c[e]:
                res += dfs(e, c)
        c[i] = True
        return res
    print(dfs(0, [True] * n))
    return

#D
def D():
    n, Ma, Mb = LI()
    abc = LIR(n)
    dp = [[inf] * (10 * n + 1) for i in range(10 * n + 1)]
    dp[0][0] = 0
    for a, b, c in abc:
        for i in range(10 * n, a - 1, -1):
            for j in range(10 * n, b - 1, -1):
                dp[i][j] = min(dp[i - a][j - b] + c, dp[i][j])
    ans = inf
    ma = Ma
    mb = Mb
    i = 1
    while 1:
        ans = min(ans, dp[ma * i][mb * i])
        i += 1
        if ma * i > 10 * n or mb * i > 10 * n:
            break
    if ans == inf:
        print(-1)
        return
    
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()

Measured memory_bytes: 52700
a,b = map(int,input().split())
while b != 0:
  a,b = b,a%b
pr = set()
i = 2
while i ** 2 <= a:
  while a % i == 0:
    a //= i
    pr.add(i)
  i += 1
pr.add(a)
pr.add(1)
print(len(pr))

Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *
 
N, M = MAP()
A = sorted(LIST())
BC = [LIST() for _ in range(M)]

BC.sort(key = lambda x: (-x[1],-x[0]))

i = 0
for b, c in BC:
	for j in range(b):
		if N <= i+j or c <= A[i+j]:
			print(sum(A))
			exit()
		A[i+j] = c
	i += b


print(sum(A))

Measured memory_bytes: 46972
#include<iostream>
using namespace std;
int main() {
    int m, f, r;
    while (1) {
        cin >> m >> f >> r;
        if (m==-1&&f==-1&r==-1) break;
        if (m==-1 || f==-1){
            cout << "F" << endl;
        } else {
            if (m+f>=80) {
            cout << "A" << endl;
        } else if (m+f>=65) {
            cout << "B" << endl;
        } else if (m+f>=50) {
            cout << "C" << endl;
        } else if (m+f>=30) {
            if (r>=50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else {
            cout << "F" << endl;
        }
        }
        
    }
}


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

typedef long long ll;

int main() {
    int H, W, di[4] = {1, 0, -1, 0}, dj[4] = {0, 1, 0, -1};
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    string ans = "Yes\n";
    rep(i, H) {
        rep(j, W) {
            if (s[i][j] == '.') continue;
            ans = "No\n";
            rep(k, 4) {
                int ni = i + di[k], nj = j + dj[k];
                if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
                if (s[ni][nj] == '#') ans = "Yes\n";
            }
            if (ans == "No\n") {
                cout << ans;
                return 0;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
     
using namespace std;
     
typedef long long ll;
     
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
     
#define MOD 1000000007

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  rep(i,k,n){
    if(v[i-k]<v[i]){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5364
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		sc.close();
		if(a + b <= 2 * c){
			ou.print(a * x + b * y + "\n");
		}else{
			if(x < y) ou.print(Math.min(x * c * 2 + (y - x) * b , Math.max(x , y) * 2 * c) + "\n");
			else ou.print(Math.min(y * c * 2 + (x - y) * a , Math.max(x , y) * 2 * c) + "\n");
		}
		ou.flush();
    }
}

Measured memory_bytes: 38644
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
using namespace std;


int main() {

	while (true) {
		int n, field = 0, a[101], b[101];
		bool check[201] = { false };

		scanf("%d", &n);
		if (n == 0) {
			break;
		}
		int temp;
		for (int i = 1; i <= n; i++) {
			scanf("%d", &temp);
			check[temp] = true;
			a[i] = temp;
		}
		sort(a + 1, a + n + 1);
		for (int i = 1, j = 1; i <= n * 2; i++) {
			if (check[i] == false) {
				b[j] = i;
				j++;
			}
		}

		int turn = -1, card_a = n, card_b = n;
		bool success;
		while (true) {
			turn++;
			if (turn % 2 == 0) {
				if (field == 0) {
					field = a[1];
					a[1] = 999;
					sort(a + 1, a + card_a + 1);
					card_a--;
				}
				else {
					success = false;
					for (int i = 1; i <= card_a; i++) {
						if (a[i] > field) {
							field = a[i];
							a[i] = 999;
							sort(a + 1, a + card_a + 1);
							card_a--;
							success = true;
							break;
						}
					}
					if (success == false) {
						field = 0;
					}
				}
			}
			else {
				if (field == 0) {
					field = b[1];
					b[1] = 999;
					sort(b + 1, b + card_b + 1);
					card_b--;
				}
				else {
					success = false;
					for (int i = 1; i <= card_b; i++) {
						if (b[i] > field) {
							field = b[i];
							b[i] = 999;
							sort(b + 1, b + card_b + 1);
							card_b--;
							success = true;
							break;
						}
					}
					if (success == false) {
						field = 0;
					}
				}
			}

			if (card_a == 0 || card_b == 0) {
				break;
			}
		}

		printf("%d\n%d\n", card_b, card_a);

	}

	return 0;
}

Measured memory_bytes: 1048
use std::io::*;
use std::str::FromStr;
use std::f64;

fn main() {
	let n: f64 = read();
	let k: f64 = read();
	println!("{}", digit(n, k) + 1);
}

fn digit(n: f64, k: f64) -> u32 {
	n.log(k).floor() as u32
}


fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



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

#define F firts
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

const int N = 310;

int dp[N][N][N];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	int n = s.size(), k;
	cin >> k;

	for(int i=0; i<n; i++)
		for(int j=0; j<=k; j++)
			dp[i][i + 1][j] = 1;

	for(int c=0; c<=k; c++)
		for(int len=2; len<=n; len++)
			for(int l=0; l+len<=n; l++)
			{
				int r = l + len;
				dp[l][r][c] = max(dp[l][r - 1][c], dp[l + 1][r][c]);
				if(s[l] == s[r - 1])dp[l][r][c] = max(dp[l][r][c], 2 + dp[l + 1][r - 1][c]);
				else if(c >= 1)dp[l][r][c] = max(dp[l][r][c], 2 + dp[l + 1][r - 1][c - 1]);
			}

	cout << dp[0][n][k] << endl;

}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (A + B == 3)
    cout << 3 << endl;
  if (A + B == 4)
    cout << 2 << endl;
  if (A + B == 5)
    cout << 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int k;
	cin >> k;
	vector<ll> array;
	for (int i = 1; i <= 9; i++) array.push_back(i);
	while (1) {
		if (k <= array.size()) {
			cout << array[k - 1] << endl;
			return 0;
		}
		k -= array.size();
		vector<ll> old;
		swap(array, old);
		for (ll x : old) {
			if (x % 10 == 0) {
				array.push_back(10 * x);
				array.push_back(10 * x + 1);
			}
			else if (x % 10 == 9) {
				array.push_back(10 * x + 8);
				array.push_back(10 * x + 9);
			}
			else {
				array.push_back(10 * x + x % 10 - 1);
				array.push_back(10 * x + x % 10);
				array.push_back(10 * x + x % 10 + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4672
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int N, K;
  cin >> N >> K;
  ll c = 0;
  for (int b = K + 1; b <= N; b++) {
    int p = floor(N / b);
    c += p * max(0, b - K) + max(0, (N % b) - K + 1);
    if (K == 0)
      c--;
  }
  cout << c << endl;

  return 0;
}

Measured memory_bytes: 256
<?php
$n = intval(fgets(STDIN));
$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));

$p = "*";
$ans = 1;
for($i = 0; $i < $n; $i++){
    $a = $A[$i];
    $b = $B[$i];
    if($a==$b){
        if($p == "*")$ans*=3;
        if($p == "A")$ans*=2;
        if($p == "B")$ans*=1;
        $p = "A";
    }else{
        if($p == "*")$ans*=6;
        if($p == "A")$ans*=2;
        if($p == "B")$ans*=3;
        $p = "B";
        $i++;
    }
    $ans%=1000000007;
}
echo $ans,"\n";

Measured memory_bytes: 4604
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;



int main(void){
  int N;

  string a,b,c;
  cin >> a >> b >> c;

  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());

  char state = 'a';
  while(1){
    switch(state){
      case 'a':
        if(a.size() == 0){
          cout << "A" << endl;
          return 0;
        }
        state = *(a.end()-1);
        a.pop_back();
        break;
      case 'b':
        if(b.size() == 0){
          cout << "B" << endl;
          return 0;
        }
        state = *(b.end()-1);
        b.pop_back();
        break;
      case 'c':
        if(c.size() == 0){
          cout << "C" << endl;
          return 0;
        }
        state = *(c.end()-1);
        c.pop_back();
        break;
    }
  } 
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

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

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

signed main(){
	IOS
	int n,k;cin>>n>>k;
	vi v(n);
	forn(i,n) cin>>v[i];
	vi DP(k+2);
	DP[0]=0;
	for(int i=1;i<=k;i++){
		bool win=0;
		for(int x:v){
			if(x<=i && DP[i-x]==0) {
				win=1;
				break;
			}
		}
		if(win)
			DP[i]=1;
		else
			DP[i]=0;
	}
	cout<<(DP[k]?"First":"Second");
}


Measured memory_bytes: 1024
import sys, math
from functools import lru_cache
from collections import defaultdict, Counter
import bisect
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    S = input()
    dp = [0]*(N+1)
    dp[0] = S.count('.')
    for i in range(N):
        dp[i+1] = dp[i]-1 if S[i] == '.' else dp[i]+1
    print(min(dp))

if __name__ == '__main__':
    main()


Measured memory_bytes: 17600
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    from operator import itemgetter
    import heapq

    n = int(readline())
    cities = [list(map(int, readline().split())) + [i] for i in range(n)]
    uf = UnionFind(n)

    cx = sorted(cities, key=itemgetter(0))
    cy = sorted(cities, key=itemgetter(1))

    edge = []

    for i in range(1, n):
        dx = cx[i][0] - cx[i - 1][0]
        heapq.heappush(edge, (dx, cx[i][2], cx[i - 1][2]))

    for i in range(1, n):
        dy = cy[i][1] - cy[i - 1][1]
        heapq.heappush(edge, (dy, cy[i][2], cy[i - 1][2]))

    ans = 0
    while edge:
        cost, u, v = heapq.heappop(edge)
        if not uf.same(u, v):
            uf.union(u, v)
            ans += cost

    print(ans)


if __name__ == '__main__':
    main()


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

int main(void){

    int N, noBrick, counter;
    bool satisfiable = false;

    cin >> N;
    counter = 1;
    for(int i=0; i<N; i++){
        cin >> noBrick;
        if(noBrick == counter){
            counter++;
            satisfiable = true;
        }
    }    

    if(satisfiable){
        cout << N-counter+1 << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n;
  cin >> n;
  ivec l(n);
  REP(i, n) cin >> l[i];

  sort(RALL(l));
  int mn = l[0];
  ll sum = 0;
  FOR(i, 1, n) sum += l[i];
  bool ok = mn < sum ? true : false;

  print(ok ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;

int main(void) {
    int n;
    cin >> n;
    vll num_of_i(n);
    for (int i = 0; i < n; ++i) {
        cin >> num_of_i[i];
    }
    ll ans = 0;
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += num_of_i[i];
        if (num_of_i[i] == 0 || i == n - 1) {
            ans += sum / 2LL;
            sum = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = n/100;
    int y = (n-x*100)/10;
    int z = n-((x*100)+(y*10));
    // System.out.println(x);
    // System.out.println(y);
    // System.out.println(z);
    if(x==7){
      System.out.println("Yes");
    }else if(y==7){
      System.out.println("Yes");
    }else if(z==7){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

int main()
{
    long l, r;
    cin >> l >> r;
    if (r - l > 2018)
    {
        cout << 0 << endl;
        return 0;
    }
    else
    {
        long min = 2019;
        for (long i = l; i < r; i++)
        {
            for (long j = i + 1; j <= r; j++)
            {
                if (min > i * j % 2019)
                    min = i * j % 2019;
            }
        }
        cout << min << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		double a=sc.nextDouble();
		int b=sc.nextInt();
				
		System.out.println(a/b);
	}
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <math.h>

using namespace std;

int main()
{
    long long n, t;
    int k;
    int count = 0;
    cin>>n>>k;
    if(n>2){
        for(int i = 0;t<n;i++) {
            t=pow(k,i);
            count++;
        }
        if(pow(k,count-1) == n){
            cout<<count;
        }
        else{
            cout<<count-1;
        }
    }

    else if(n==2){
        cout<<"2";
    }
    else{
        cout<<"1";
    }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = read()
    if (n[n.length - 1] == '3') {
        println("bon")
        return
    }
    if (n[n.length - 1] == '0' || n[n.length - 1] == '1' || n[n.length - 1] == '6' || n[n.length - 1] == '8') {

        println("pon")
        return
    }
    println("hon")



}

fun read() = readLine()!!

fun readInt() = read().toInt()

fun readLong() = read().toLong()

fun readDouble() = read().toDouble()

fun readListString() = read().split(" ")

fun readListInt() = readListString().map { it.toInt() }

fun readListLong() = readListString().map { it.toLong() }

fun readListDouble() = readListString().map { it.toDouble() }

fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 34484
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
    using namespace std;
    //long long p = 998244353;
    long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
    vel kai(max_kai, 1);
    vel inv_kai;
    int rui(int a, int n, int mod) {
        if (n == 0) { return 1 % mod; }
        int x = rui(a, n / 2, mod);
        x *= x; x %= mod;
        if (n % 2 == 1) { x *= a; x %= mod; }
        return x;
    }
    vel pa;
    int root(int x) {
        if (pa[x] == -1) { return x; }
        int ans = root(pa[x]); pa[x] = ans;
        return ans;
    }
    void marge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) { pa[x] = y; }
    }
    int gcd(int x, int y) {
        if (x < y) { return gcd(y, x); }
        if (y == 0) { return x; }
        return gcd(y, x % y);
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
signed main() {
    int n; cin >> n;
    if (n % 2 == 1) { cout << 0 << endl; }
    else {
        n /= 2;
        int ans = 0;
        while (n != 0) {
            n /= 5; ans += n;
        }
        cout << ans << endl;
    }
    return 0;
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 1408
fun main(args: Array<String>) {
    abc108b()
}

fun abc108b() {
    val (x1, y1, x2, y2) = readLine()!!.split(" ").map { it.toInt() }

    val x1x2 = x1 - x2
    val y1y2 = y1 - y2

    val x3 = x2 + y1y2
    val y3 = y2 - x1x2

    val x4 = x1 + y1y2
    val y4 = y1 - x1x2

    println("""$x3 $y3 $x4 $y4""")
}


Measured memory_bytes: 37776
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
counter = 0
for i in range(N):
    A = list(map(int,input().split()))
    tmp = 0
    for j in range(M):
        tmp += A[j]*B[j]
    if tmp+C > 0 :
        counter += 1
print(counter)

Measured memory_bytes: 3060
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
n,t = ma()
A = lma()
INF=10**15

mns = [INF]*(n+1) ##mxs[i] :: max(A[i:n])
for i in range(n):
    mns[i] = min(mns[i-1],A[i])
c = 0
dmx = -1
for i in range(1,n):
    if A[i]-mns[i] >dmx:
        dmx=A[i]-mns[i]
        c=1
    elif A[i]-mns[i] ==dmx:
        c+=1
print(c)


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


int main(){
  long long n,i;
  cin >> n;
  vector<long long> a(n);
  for(i=0;i<n;++i){
    cin >> a[i];
  }
  long long x=0;
  for(i=0;i<n;++i){
    if(i%2) x -= a[i];
    else x +=a[i];
  }

  vector<int> ans(n);
  ans[0]= x/2;
  for(i=0;i<n-1;++i){
    ans[i+1]=a[i]-ans[i];
  }
  for(i=0;i<n;++i){
    ans[i] *=2;
  }
  for(i=0;i<n;++i){
    printf("%d%c",ans[i],i==n-1?'\n':' ');
  }
  return 0;

}


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

int main() {
	int n; cin >> n;
	vector<int> y(n);
	rep(i, n) cin >> y.at(i);
	int ans = 0;
	sort(y.begin(), y.end());
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (y.at(k) < y.at(i) + y.at(j)) ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

//1 - - 4 5 - - - 9 - - 12
const int LOG = 20;
int main() {
	int n;
	cin >> n;
	vector <int> x(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
	}
	int l;
	cin >> l;
	vector<vector<int>> nxt(n + 1, vector<int>(LOG, MOD));
	int r = n;
	for (int i = n - 1; i >= 1; i--) {
		while(x[r] > x[i] + l) r--;
		nxt[i][0] = r;
	}
	for (int j = 1; j < LOG; j++) {
		for (int i = 1; i <= n; i++) {
			if (nxt[i][j - 1] != MOD)
				nxt[i][j] = nxt[nxt[i][j-1]][j-1];
		}
	}
	//debug(nxt);
	int q;
	cin >> q;
	while(q--) {
		int a, b;
		cin >> a >> b;
		if (a > b)
			swap(a, b);
		int ans = 0;
		while (a != b) {
			int cur = -1;
			for (int j = 0; j < LOG; j++) {
				if (nxt[a][j] > b) {
					cur = j - 1;
					break;
				}
			}
			if (cur == -1) {
				ans += 1;
				break;
			}
			ans += (1 << cur);
			a = nxt[a][cur]; 
		}
		cout << ans << "\n";
	}
}


Measured memory_bytes: 14848
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <cctype>
#include <deque>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {

	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";

    return out;

}

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {

	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}

		out << "\n";
	}
		
    return out;

}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	int sum = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			sum += di[i] * di[j];
		}
	}

	cout << sum << "\n";

	return 0;

}

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



int main(){
   int n;
   cin >> n;
   vector<int> d(n);
   rep(i,n) cin >> d[i];

   sort(d.begin(),d.end());
   int ans;
   if(d[n/2]==d[n/2-1]) ans =0;
   else ans = d[n/2]-d[n/2-1];
   cout << ans << endl;
   
   }

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

int main() {
  string s;
  cin >> s;
  if (s.at(0) != s.at(1) && s.at(1) != s.at(2) && s.at(2) != s.at(3)) {
    cout << "Good" <<endl;
  }
  else {
    cout << "Bad" << endl;
  }
}



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

int main() {
	int h, w;
	scanf("%d %d", &h, &w);
	while (1) {
		if (h == 0 && w == 0) break;
		for (int j = 0; j < h; j++) {
			for (int i = 0; i < w; i++) {
				printf("#");
				if (i == w - 1) printf("\n");
			}
		}
		printf("\n");
		scanf("%d %d", &h, &w);
	}


	return 0;

}


Measured memory_bytes: 2056
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		long a = 0;
		long b = 0;
		while (scanner.hasNext()) {
			a = scanner.nextLong();
			b = scanner.nextLong();

			long lcm = calcLCM(a, b);
			long gcd = calcGCD(a, b, lcm);
			System.out.println(gcd + " " + lcm);
		}

	}

	/**
	 * ?????§??¬?´???°????±???????
	 * @param a ?¬¬????????°
	 * @param b ?¬¬????????°
	 * @return ?????§??¬?´???°
	 */
	private static long calcLCM(long a, long b) {
		long large = a >= b ? a : b;
		long small = a >= b ? b : a;
		long base = a >= b ? b : a;
		while (true) {
			long result = calc(large, small, base);
			if (large == result) {
				return result;
			} else if (large < result) {
				small = large;
				large = result;
				base = base == a ? b : a;
			} else {
				small = result;
			}
		}
	}

	private static long calc(long large, long small, long base) {
		int count = 0;
		while (true) {
			if (large <= base * count + small) {
				return base * count + small;
			}
			count++;
		}
	}

	/**
	 * ????°???¬?????°????±???????
	 * @param a ?¬¬????????°
	 * @param b ?¬¬????????°
	 * @param gcd ?????§??¬?´???°
	 * @return ????°???¬?????°
	 */
	private static long calcGCD(long a, long b, long gcd) {
		return (a * b) / gcd;
	}
}

Measured memory_bytes: 18748
import java.util.Scanner;

public class Main {

	static int N;

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	N = sc.nextInt();
    	sc.close();
    	System.out.println(dfs(0, false, false, false));
    }

    static int dfs(long now, boolean is3, boolean is5, boolean is7){
    	if(now > N) return 0;
    	int ans = 0;
    	if(is3 && is5 && is7) ans++;
    	ans += dfs(now * 10 + 3, true, is5, is7);
    	ans += dfs(now * 10 + 5, is3, true, is7);
    	ans += dfs(now * 10 + 7, is3, is5, true);
    	return ans;
    }
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

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

	vector<int> a(n + 1);
	vector<int> b(n);

	rep(i,n + 1){
		cin >> a[i];
	}
	rep(i,n){
		cin >> b[i];
	}

	ll sum = 0;
	rep(i, n){
		int k = min(a[i], b[i]);
		sum += k;
//		a[i] -= k;
		b[i] -= k;
		int l = min(a[i + 1], b[i]);
		sum += l;
		a[i + 1] -= l;
	}		


/*
		if(a[i] >= b[i]){
			sum += b[i];
		}else{
			sum += a[i];
			b[i] -= a[i];
			if(a[i + 1] >= b[i]){
				a[i + 1] -= b[i];
				sum += b[i];
			}else{
				sum += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}
*/
	cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	
	static int di[] = {0, 0, 1, -1};
	static int dj[] = {1, -1, 0, 0};
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		char[][] grid = new char[H][];
		int iFrom = sc.nextInt() - 1;
		int jFrom = sc.nextInt() - 1;
		int iTo = sc.nextInt() - 1;
		int jTo = sc.nextInt() - 1;
		for (int i = 0; i < H; i++) {
			grid[i] = sc.next().toCharArray();
		}
		int[][] dist = new int[H][W];
		for (int i = 0; i < H; i++) {
			Arrays.fill(dist[i], Integer.MAX_VALUE);
		}
		int[][] forb = new int[H][W];
		Deque<Integer> cola = new ArrayDeque<>();
		dist[iFrom][jFrom] = 0;
		cola.addLast(iFrom * W + jFrom);
		while (!cola.isEmpty()) {
			int val = cola.pollFirst();
			int ii = val / W;
			int jj = val % W;
			int nextDist = dist[ii][jj] + 1;
			for (int k = 0; k < 4; k++) if ((forb[ii][jj] & (1<<k)) == 0) {
				for (int steps = 1; steps <= K; steps++) {
					int ni = ii + di[k]*steps;
					int nj = jj + dj[k]*steps;
					if (0 <= ni && ni < H && 0 <= nj && nj < W && grid[ni][nj] == '.') {
						if (dist[ni][nj] >= nextDist) {
							if (steps < K) {
								forb[ni][nj] |= 1 << k;
							}
							if (dist[ni][nj] > nextDist) cola.addLast(ni * W + nj);
							dist[ni][nj] = nextDist;
						} else break;
					} else break;
				}
			}
		}
		out.println(dist[iTo][jTo] == Integer.MAX_VALUE ? -1 : dist[iTo][jTo]);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 64040
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! dbg { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let mut ans = 0;
    for a in 1..=n {
        ans += (n - 1) / a;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2196
#include <iostream>
#include <algorithm>
#include <vector>
#include <climits>
#include <queue>
#include <list>
#include <set>
using namespace std;
static const int MAX = 100000;
static const int INFTY = 1 << 29;

class disjointset {
public:
	vector<int> rank, p;
	disjointset(){}
	disjointset(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i = 0; i < size; i++) makeset(i);
	}

	void makeset(int x) {
		p[x] = x;
		rank[x] = 0;
	}

	bool same(int x, int y) {
		return findset(x) == findset(y);
	}

	void unite(int x, int y)
	{
		link(findset(x), findset(y));
	}

	void link(int x, int y)
	{
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y++];
			}
		}
	}

	int findset(int x)
	{
		if (x != p[x]) {
			p[x] = findset(p[x]);
		}
		return p[x];
	}
};

class edge {
public:
	int source, target, cost;
	edge(int source = 0, int target = 0, int cost = 0) :source(source), target(target), cost(cost) {}
	bool operator < (const edge &e) const {
		return cost < e.cost;
	}
};

int kruskal(int n, vector<edge> edges)
{
	int totalCost = 0;
	sort(edges.begin(), edges.end());

	disjointset dset = disjointset(n + 1);

	for (int i = 0; i < n; i++) {
		dset.makeset(i);
	}

	int source, target;
	for (int i = 0; i < edges.size(); i++) {
		edge e = edges[i];
		if (!dset.same(e.source, e.target)) {
			totalCost += e.cost;
			dset.unite(e.source, e.target);
		}
	}
	return totalCost;
}

int main()
{
	int n, m, cost;
	int source, target;

	cin >> n >> m;

	vector<edge> edges;
	for (int i = 0; i < m; i++) {
		cin >> source >> target >> cost;
		edges.push_back(edge(source, target, cost));
	}

	cout << kruskal(n, edges) << endl;

	return 0;
}

Measured memory_bytes: 3616
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){	
	fastio;
	int H,W,h,w;cin>>H>>W>>h>>w;
	cout<<(H-h)*(W-w)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  
  string s;
  cin >> s;
  int counter = 0;
  
  if(s[0] == '1') ++counter;
  if(s[1] == '1') ++counter;
  if(s[2] == '1') ++counter;
  
  cout << counter << endl;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
*A, = map(int, input().split())
cnt = 0
for a in A:
    if a < 0:
        cnt += 1
if cnt % 2 == 0:
    print(sum([abs(a) for a in A]))
else:
    print(sum([abs(a) for a in A])-2*min([abs(a) for a in A]))


Measured memory_bytes: 14332