akhauriyash/Code-Regression huggingface dataset:
//ALDS1_9A
#include <iostream>
using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
 int H,i,A[MAX+1];
 cin>>H;
 for(i=1;i<=H;i++) cin>>A[i];
 for(i=1;i<=H;i++){
  cout<<"node "<<i<<": key = "<<A[i]<<", ";
  if(parent(i)>=1) cout<<"parent key = "<<A[parent(i)]<<", ";
  if(left(i)<=H) cout<<"left key = "<<A[left(i)]<<", ";
  if(right(i)<=H) cout<<"right key = "<<A[right(i)]<<", ";
  cout<<endl;
 }
 return 0;
}

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

#define pb push_back

#define int ll
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;

template<typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (const T& x : v)
    o << x << ",";
  return o << "]";
}

const int INF = 1e18;

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

  int n;
  cin >> n;
  vi as(n);
  for (int& ai: as)
    cin >> ai;

  vvi dp(3, vi(n, -INF));
  dp[0][0] = as[0];
  dp[1][1] = as[1];
  dp[2][2] = as[2];
  for (int k=0; k<3; ++k) {
    for (int p=0; p<n; ++p) {
      if (p >= 2)
        dp[k][p] = max(dp[k][p], dp[k][p-2] + as[p]);
      for (int off=1; off<=k && (p-off-2)>=0; ++off)
        dp[k][p] = max(dp[k][p], dp[k-off][p-off-2] + as[p]);
    }
  }
  //cerr << "DBG " << dp << endl;
  int sol;
  if (n%2 == 0) {
    sol = dp[1][n-1];
    if (n-2 >= 0)
      sol = max(sol, dp[0][n-2]);
  } else {
    sol = dp[2][n-1];
    if (n-2 >= 0)
      sol = max(sol, dp[1][n-2]);
    if (n-3 >= 0)
      sol = max(sol, dp[0][n-3]);
  }
  cout << sol << endl;
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
#define int ll
#define N 100005
#define pb push_back
#define pv(x) cout<<#x<<": ";for(auto k:x){ cout<<k<<" "; }cout<<endl;
#define dbg(x) cout<<#x<<": "<<x<<endl;

int n,m,ni,mi,x;
// int num[N];
int ok=false;

void solve(){
	cin >> x;
	int ans =0;
	ans+=1000*(x/500);
	x-=500*(x/500);
	ans+=5*(x/5);	
	cout<<ans<<endl;
}

int32_t main(){cin.tie(0);ios_base::sync_with_stdio(NULL);
	int t=1;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
for _ in range(0, n):
    a.append(int(input()))
first = max(a)
second_1 = sorted(a)
second = second_1[-2]
for i in range(0, n):
    if a[i] == first:
        print(second)
    else:
        print(first)

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N;
  vector<ll> v;
  cin >> N;
  rep(i,5){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;
  rep(i,5){
    ll tmp = (N + v[i] - 1) / v[i] + 4; 
    ret = max(ret, tmp);
  }

  cout << ret << endl;
  
  return 0;
}


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

using namespace std;

bool a_In_b(string a, vector<string> b) {
    for (string x : b) {
        if (a == x) {
            return true;
        }
    }
    return false;
}

string s;

bool comp(const string::size_type &lh, const string::size_type &rh) {
    int n;

    if (lh < rh) {
        n = s.size() - rh;
    }
    else {
        n = s.size() - lh;
    }
    // cout << s.substr(lh, n) << endl;
    // cout << s.substr(rh, n) << endl;
    // cout << s.substr(lh, n).compare(s.substr(rh, n)) << endl;
    return s.substr(lh, n).compare(s.substr(rh, n)) < 0;
}

int main(void) {
    int K;
    vector<string::size_type> pos_v;
    vector<string> ans;

    cin >> s >> K;

    for (char c = 'a'; c <= 'z'; c++) {
        string::size_type pos = s.find(c);
        if (pos == string::npos) {
            continue;
        }
        pos_v.push_back(pos);
        while ((pos = s.find(c, pos+1)) != string::npos) {
            pos_v.push_back(pos);
        }
        // for (string::size_type x : pos_v) {
        //     cout << x << endl;
        // }
        sort(pos_v.begin(), pos_v.end(), comp);
        // for (string::size_type x : pos_v) {
        //     cout << x << endl;
        // }
        for (string::size_type x : pos_v) {
            for (int i = 1; i + x <= s.size() && ans.size() <= K; i++) {
                if (!a_In_b(s.substr(x, i), ans)) {
                    // cout << s.substr(x, i) << endl;
                    ans.push_back(s.substr(x, i));
                }
            }
        }
        if (ans.size() >= K) {
            cout << ans[K-1] << endl;
            break;
        }
    }


    return 0;
}

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

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, C, K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for (int i = 0; i < N; i++) cin >> T[i];
	sort(T.begin(), T.end());
	int ans = 0;
	for (int i = 0, j = 0; i < N; ) {
		int tar = T[i] + K;
		int cnt = 1;
		j = i + 1;
		while (j < N) {
			if (cnt >= C) break;
			if (T[j] <= tar && tar <= T[j] + K) {
				cnt++;
				j++;
			} else {
				break;
			}
		}
		ans++;
		i = j;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

using namespace std;

string l={"abcdefghijklmnopqrstuvwxyz"};

int main(){

    string str;
    cin >> str;
    int n;
    cin >> n;

    rep(i,str.size()){
      
      if(str.size()-1==i) str[i]=l[((str[i]-'a')+n)%26];
      else if(26-(str[i]-'a') <= n && str[i]-'a'!=0){
        int num = 26-(str[i]-'a');
        n=n-num;
        str[i]=l[((str[i]-'a')+num)%26];
      }
    }
    
    cout << str << endl;
}




Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define ll long long
#define N 1010
char mp[N][N];
int vis[N][N];
int n,m;
int d[4][2]={0,1, 0,-1, 1,0, -1,0};
queue<pair<int,int> >q;
int bfs()
{
    int t=0;
    while(!q.empty())
    {
        int sz=q.size();
        for(int i=1;i<=sz;i++)
        {
            pair<int,int>now=q.front();
            q.pop();
            for(int j=0;j<4;j++)
            {
                int dx=now.first+d[j][0];
                int dy=now.second+d[j][1];
                if(dx<1||dx>n||dy<1||dy>m||vis[dx][dy])continue;
                vis[dx][dy]=1;
                q.push({dx,dy});
            }
        }
        if(!q.empty())t++;
    }
    return t;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
       scanf("%s",mp[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        if(mp[i][j]=='#')
        q.push({i,j}),vis[i][j]=1;
    }
    printf("%d\n",bfs());
    return 0;
}


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

using namespace std;
using ll = long long;

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

struct UnionFind {
  vector<int> p;

  UnionFind(int n) : p(n, -1) {}

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

  bool unite(int x, int y) {
    if (same(x, y)) return false;
    x = find(x);
    y = find(y);

    if (-p[x] < -p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  int find(int x) {
    if (p[x] < 0) return x;
    return p[x] = find(p[x]);
  }

  int size(int x) { return -p[find(x)]; }
};

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

  UnionFind uf(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
  }

  int ans = 0;
  rep(i, n) { ans = max(ans, uf.size(i)); }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); 
    int[] h = new int[N];  
    int max = 0; 
    int idx = 0; 
    for (int i=0; i < N ;i++) {
      h[i] =  sc.nextInt();
      if(h[i]>max){
        max = h[i];
        idx = i;
      }
    }
    int max2 = 0; 
    // int idx2 = 0; 
    for (int i=0; i < N ;i++) {
      if(i !=idx){
      if(h[i]>max2){
        max2 = h[i];
      }
    }
    }
    for (int i=0; i < N ;i++) {
      if(i !=idx){
        System.out.println(max);
       }else{
      System.out.println(max2);
    }
  }
}
}



Measured memory_bytes: 109636
#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;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set


int main() 
{
	ll r;
	cin>>r;
	double v = ((double)(2*M_PI*r));
	cout<<fixed<<setprecision(12)<<v<<endl;

	return 0;
}  


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
pair<ll, ll> extgcd(const ll a, const ll b)
{
    if (b == 0) { return pair<ll, ll>{1, 0}; }
    const auto p = extgcd(b, a % b);
    return {p.second, p.first - p.second * (a / b)};
}
ll inverse(const ll a) { return (MOD + extgcd(a, MOD).first % MOD) % MOD; }
int main()
{
    while (true) {
        ll N, D, X;
        cin >> N >> D >> X;
        if (N == 0 and D == 0 and X == 0) { break; }
        vector<ll> dp1(N + 1, 1), dp2(N + 1, 0);
        auto get = [&](const ll i) { return (dp1[i - 1] + MOD - (i < X ? 0 : dp1[i - X])) % MOD; };
        for (ll i = 1; i <= N; i++) {
            for (ll j = N; j >= 1; j--) { dp1[j] = get(j); }
            dp2[i] = dp1[N], dp1[0] = 0;
            for (int j = 1; j <= N; j++) { (dp1[j] += dp1[j - 1]) %= MOD; }
        }
        auto comb = [&](const ll k) {
            if ((D % MOD) < k or D < k) { return 0LL; }
            ll ans = 1;
            for (ll j = D; j > D - k; j--) { (ans *= (j % MOD)) %= MOD; }
            for (ll j = 1; j <= k; j++) { (ans *= inverse(j)) %= MOD; }
            return ans;
        };
        ll ans = 0;
        for (ll i = 0; i <= N; i++) { (ans += (dp2[i] * comb(i) % MOD)) %= MOD; }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

struct Node
{
  long counter{0};
  std::vector<Node*> children;
};

struct Operation
{
  int node_id;
  int point;
};

using Nodes = std::vector<Node>;
using Operations = std::vector<Operation>;

void update(Node& node, int sum)
{
  node.counter += sum;
  for (auto* child : node.children) {
    update(*child, node.counter);
  }
}

void solve(long n, long q, Nodes& nodes, const Operations& operations)
{
  for (const auto& op : operations) {
    nodes[op.node_id - 1].counter += op.point;
  }

  update(nodes[0], 0);
}

int main()
{
  long n, q;
  std::cin >> n >> q;

  Nodes nodes(n);
  for (long i = 0; i < n - 1; ++i) {
    int a, b;
    std::cin >> a >> b;
    nodes[a - 1].children.push_back(&nodes[b - 1]);
  }

  Operations operations(q);
  for (auto& o : operations) {
    std::cin >> o.node_id >> o.point;
  }

  solve(n, q, nodes, operations);

  std::cout << nodes.front().counter;
  for (auto it = nodes.begin() + 1; it != nodes.end(); ++it) {
    std::cout << " " << it->counter;
  }
  std::cout << std::endl;
}


Measured memory_bytes: 22656
#include <bits/stdc++.h>
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define MOD 1000000007
#define FOR(i, n) for(ll i = 0; i < n; i++)
using namespace std;
const long long INF = 3*1e18;

int main() {
    ios::sync_with_stdio(0);    
    cin.tie(0);
    ll K, A, B;
    cin >> K >> A >> B;
    ll last = B/K;
    if(last*K >= A && last*K <= B) cout << "OK\n";
    else cout << "NG\n";    
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double
typedef boost::multiprecision::cpp_int bigint;

lin n, x[200011], xx, tx[200011];

lin sum(lin ed)
{
    return tx[ed+1];
}

bigint solve(lin i)
{
    lin idx = n - 1;
    bigint res = 5 * sum(idx) + (i + n) * xx;
    
    idx -= i * 2;

    while(idx >= 0)
    {
        res += (bigint)(2 * sum(idx));
        idx -= i;
    }

    return res;
}

int main(void)
{
    cin >> n >> xx;
    //n = 200000;
    //xx = 1000000000;

    tx[0] = 0;
    rep(i,n)
    {
        cin >> x[i];
        //x[i] = i + 1000000000 - 200000;
        tx[i+1] = tx[i] + x[i];
    }

    auto res = solve(1);

    for(int i = 2; i <= n; i++)
    {
        res = min(res, solve(i));
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> P1;
typedef pair<P,pair<double,double> > P2;
typedef pair<pair<double,double>,P> P3;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int p[500005],q[500005],n,k;
set<P>S[500005];
struct RMQ{
	#define s (1<<20)
	int seg[s];
	void init(){
		fill(seg,seg+s,INF);
	}
	void update(int k,int a){
		k+=s/2-1; seg[k]=a;
		while(k>0){
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int query(int a,int b,int k,int l,int r){
		if(r<a || b<l) return INF;
		if(a<=l && r<=b) return seg[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2+1,r);
			return min(vl,vr);
		}
	}
	int query(int a,int b,int k){
		return query(a,b,k,0,s/2-1);
	}
}rmq;
int mn[500005],ans[500005],nxt=1;
bool in[500005];
int main(){
	scanf("%d%d",&n,&k);
	repn(i,n){
		scanf("%d",&p[i]); 
		q[p[i]] = i;
	}
	rmq.init();
	repn(i,n){
		S[(q[i]-1)/k].insert(mp(i,q[i]));
		rmq.update(q[i],i);
	}
	priority_queue<P,vector<P>,greater<P> >que;
	for(int i=0;i<=(n-1)/k;i++){
		P p = *S[i].begin();
		int x = rmq.query(max(1,p.sc-k+1),min(n,p.sc+k-1),0);
		if(p.fi == x){
			que.push(mp(p.sc,p.fi));
			in[p.fi] = 1;
		}
	}
	while(!que.empty()){
		P p = que.top(); que.pop();
		mn[nxt++] = p.fi;
		S[(p.fi-1)/k].erase(S[(p.fi-1)/k].find(mp(p.sc,p.fi)));
		rmq.update(p.fi,INF);
		for(int id=max(0,(p.fi-1)/k-1);id<=min((n-1)/k,(p.fi-1)/k+1);id++){
			if(S[id].empty()) continue;
			P q = *S[id].begin();
			if(in[q.fi]) continue;
			int x = rmq.query(max(1,q.sc-k+1),min(n,q.sc+k-1),0);
			if(q.fi == x){
				que.push(mp(q.sc,q.fi));
				in[q.fi] = 1;
			}
		}
	}
	repn(i,n) ans[mn[i]] = i;
	repn(i,n) printf("%d ",ans[i]);
	puts("");
}

Measured memory_bytes: 66796
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//絶対値
long long int change_plus(long long int a) {
	if (a < 0) { return -a; }
	if (a >= 0) { return a; }
}
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

int main() {
	long long int n, m, k,p=3;
	char str[30],str2[15],str3[15];
	scanf("%lld%lld%lld",&n,&m,&k);
	if (n == m) { p--; }
	if (k == m) { p--; }
	if (n == k) { p--; }
	if (p==0) { p++; }
	
		printf("%lld",p);

	
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
    
int main()
{
  int a, b;
  cin >> a >> b;
  if(a<b)
  {
    cout << "a < b\n";
  }
  else if (a>b)
  {
    cout << "a > b\n";
  }
  else
  {
    cout << "a == b\n";
  }
    
  return 0;
}

Measured memory_bytes: 1124
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n;
    int s[1000];
    double m;
    double alpha;

    while ( 1 ) {
        m = 0.0;
        alpha = 0.0;
    
        scanf("%d", &n);
        if ( n == 0 ) {
            break;
        }
        
        for ( int i = 0; i < n; i++ ) {
            scanf("%d", &s[i]);
            m += s[i];
        }
        m /= (double)n;

        for ( int i = 0; i < n; i++ ) {
            alpha += s[i] * s[i];
        }
        alpha /= (double)n;
        alpha -= pow(m, 2.0);
        alpha = sqrt(alpha);
        
        printf("%lf\n", alpha);
    }
    
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <climits>
#include <cstdlib>

using namespace std;

struct Tag {
    int score, idx, has;

    Tag() {}
    Tag(int s, int i, int h) : score(s), idx(i), has(h) {}

    bool operator < (const Tag &other) const {
        return score > other.score;
    }
};

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<pair<int, int> > v;
        for(int i = 0; i < N; ++i) {
            int P, T;
            cin >> P >> T;
            v.push_back(make_pair(P, T));
        }

        int ans = INT_MAX;
        vector<vector<int> > dp(N, vector<int>(4, INT_MAX));
        vector<int> visited(N, 0);
        priority_queue<Tag> q;
        if(v[0].first <= v[0].second) q.push(Tag(v[0].first, 0, 1));

        while(!q.empty()) {
            Tag t = q.top();
            q.pop();

            if(t.idx == N-1) {
                ans = min(ans, t.score + v[t.idx].first);
                continue;
            }
            if(dp[t.idx][t.has] <= t.score) continue;
            dp[t.idx][t.has] = t.score;
            visited[t.idx] = 1;

            //Bring baloons home
            if(t.has > 0) {
                const int nt = v[t.idx].second + v[t.idx].first*(t.has+1) + v[t.idx+1].first;
                const int ns = t.score + v[t.idx].first + v[t.idx+1].first;
                if(nt <= v[t.idx+1].second && dp[t.idx+1][1] > ns) {
                    q.push(Tag(ns, t.idx+1, 1));
                }
            }

            //Go forward
            if(t.has < 3) {
                const int dist = abs(v[t.idx].first - v[t.idx+1].first);
                const int nt = v[t.idx].second + dist*(t.has+1);
                const int ns = t.score + dist;
                if(nt <= v[t.idx+1].second && dp[t.idx+1][t.has+1] > ns) {
                    q.push(Tag(ns, t.idx+1, t.has+1));
                }
            }
        }
        if(ans == INT_MAX) {
            int missed;
            for(int i = 0; i < N; ++i) {
                if(!visited[i]) {
                    missed = i+1;
                    break;
                }
            }
            cout << "NG " << missed << endl;
        }
        else {
            cout << "OK " << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <string>
#define ll long long
using namespace std;

int main() {
	int ans[3];
	int a, b;
	cin >> a >> b;

	cout << max({ a + b,a - b,a * b });

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string T;
  cin >> T;
  int N = 0, E = 0, S = 0, W = 0;
  for(int i = 0; i < T.size() ;i++){
    if(T.at(i) == 'N')N++;
    else if(T.at(i) == 'E')E++;
    else if(T.at(i) == 'S')S++;
    else if(T.at(i) == 'W')W++;
  }
  int flag = 1;
  if(N == 0 && S != 0)flag = 0;
  if(N != 0 && S == 0)flag = 0;
  if(W == 0 && E != 0)flag = 0;
  if(W != 0 && E == 0)flag = 0;
  cout << (flag?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
//****** @author mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p);

void solve() {
    ll n;cin>>n;
    string a;
    string b;
    vector<ll> v;
    for(ll i=1;i<=n;i++){
        v.EB(i);
    }
    for(ll i=0;i<n;i++){
        char c;cin>>c;
        a.push_back(c);
    }
    for(ll i=0;i<n;i++){
        char c;cin>>c;
        b.push_back(c);
    }
    ll f=0,s=0;
    ll count=0;
    do{
        string check;
        for(ll i=0;i<n;i++)check.push_back(v[i]+'0');
        if(check==a)f=count;
        if(check==b)s=count;
        count++;
    }while (next_permutation(ALL(v)));
    cout<<abs(f-s)<<endl;
}

int main()
{
    IOS;
    ll test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

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

using namespace std;

int p;
int x1[128], _y1[128], x2[128], y2[128];

bool ok(int Y1, int X1, int Y2, int X2)
{
    for (int i = 0; i < p; i++){
        if (x1[i] <= X1 && X2 <= x2[i] && _y1[i] <= Y1 && Y2 <= y2[i])
            return (false);
    }
    return (true);
}

int main()
{
    int T;
    
    scanf("%d", &T);
    
    while (T--){
        int mp[16][16] = {0};
        int w, h;
        scanf("%d %d", &w, &h);
        
        mp[0][0] = 1;
        
        scanf("%d", &p);
        for (int i = 0; i < p; i++){
            scanf("%d %d %d %d", x1 + i, _y1 + i, x2 + i, y2 + i);
            if (x1[i] > x2[i]) swap(x1[i], x2[i]);
            if (_y1[i] > y2[i]) swap(_y1[i], y2[i]);
        }
        
        for (int i = 0; i <= h; i++){
            for (int j = 0; j <= w; j++){
                if (i && ok(i - 1, j, i, j)) mp[i][j] += mp[i - 1][j];
                if (j && ok(i, j - 1, i, j)) mp[i][j] += mp[i][j - 1];
            }
        }
        
        if (mp[h][w] <= 0) printf("Miserable Hokusai!\n");
        else printf("%d\n", mp[h][w]);
    }
    
    return (0);
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template<class T> void chmin(T& a, T b) {
//      cout << "a= " << a << ",b= " << b << endl;
        if (b < a) a = b;
        return;
}

int main()
{
        ll INF = 1LL << 60;
        int N; cin >> N;
        vector<int> h(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> h[i];
        }
        vector<ll> dp(N, INF);
        dp[0] = 0;
        for (int i = 0; i < N; ++i) {
                chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
                if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
        cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}


int main(){
  int N; cin >> N;
  vi p(N);
  rep(i,N) cin >> p.at(i);

  int d = 2000000;
  int ans = 0;
  rep(i,N){
    if(p.at(i) < d){
      ans++;
      d=p.at(i);
    }
  }
  cout << ans << endl;
}


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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll H, W, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> H >> W;
    if(H%3==0||W%3==0) {
        cout << 0 << endl;
        return 0;
    }
    else {
        ans = min(H, W);
        for(int i=1;i<W;i++) {
            tmp = H/2;
            ll S1 = i*H;
            ll S2 = (W-i)*tmp;
            ll S3 = S2;
            if(H%2==1) S3 += W-i;
            tmp = max(abs(S1-S2), abs(S2-S3));
            tmp = max(tmp, abs(S3-S1));
            ans = min(ans, tmp);
        }
        for(int i=1;i<H;i++) {
            tmp = W/2;
            ll S1 = i*W;
            ll S2 = (H-i)*tmp;
            ll S3 = S2;
            if(W%2==1) S3 += H-i;
            tmp = max(abs(S1-S2), abs(S2-S3));
            tmp = max(tmp, abs(S3-S1));
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)

int main() {
	ll x, a, b;
	cin >> x >> a >> b;
	cout << (x - a) % b << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long 
#define pb push_back
const ll mod = (ll)(1000000007); 
using namespace std ; 
ll init(ll n , ll a){	
	ll ans = 1 ; 	  
for(ll i = n   ; i >= (n - a + 1) ; --i){
	ans= (1LL*ans*i)%mod ; 
	ans = ans %mod ; 
}
 return (ans%mod) ; 
}
ll power(ll x , ll y){
	ll base = 1 ; 
	while (y > 0 ){
		if(y% 2 != 0 ){
		  base = (base * x )%mod  ; 
	  }
		  y = y/2 ; 
		  x = (x*x)%mod  ; 
	  }
	  
	  return (base%mod) ; 
  }
  ll fact(ll a){
	  ll ans = 1 ; 
	  for(ll i = 1 ; i <= a ; ++i){
		  ans = (1ll*ans*i)%mod  ; 
		  ans = ans%mod ; 
		  
	  }
	  return (ans%mod) ; 
	  
  }
	
int main(){
	ll n , a , b ; 
	cin>> n >> a >> b ; 
	ll m = (power(2 , n )) - 1 ; 
	ll x = init(n , a) ; 
	ll y = init(n , b) ; 
	ll x1 = power(fact(a) , mod - 2)%mod ; 
	ll y1 = power(fact(b) , mod - 2)%mod  ; 
	ll ans = (mod + m - (1ll*x*x1 )%mod - (1ll*y*y1)%mod  )%mod ; 
	 ans = (ans + mod)%mod ; 
	cout<<ans<<endl;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "5 2 4" ].parse.expand.solve == 1 );
	assert( [ "5 2 3" ].parse.expand.solve == 2 );
	
	assert( [ "3 2 3" ].parse.expand.solve == 1 );		// 追加ケース
	assert( [ "3 1 2" ].parse.expand.solve == 1 );		// 追加ケース
	assert( [ "10 2 5" ].parse.expand.solve == 3 );		// 追加ケース
	assert( [ "11 6 9" ].parse.expand.solve == 4 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nab = input.front.split.to!( long[] );
	return tuple( nab[ 0 ], nab[ 1 ], nab[ 2 ] );
}

auto solve( long n, long a, long b )
{
	auto d = b - a;
	if( d % 2 == 0 )
	{
		// 卓aと卓bの間の卓に集まる
		return d / 2;
	}
	else
	{
		auto da = a;
		auto db = n - b + 1;
		return min(
			da + ( b - da ) / 2,			// 一人目が卓1で一回勝ってから卓1と卓bの間の卓に集まる
			db + ( ( n - a ) - db ) / 2		// 二人目が卓nで一回勝ってから卓1と卓bの間の卓に集まる
		);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	string s; cin >> s;
	int n = s.size();
	vector<string> u(4);
	u[0] = "dream";
	u[1] = "dreamer";
	u[2] = "erase";
	u[3] = "eraser";
	rep(i,4) REV(u[i]);
	REV(s);
	int x = 0;
	while(x<n){
		bool end = true;
		rep(i,4){
			int m = u[i].size();
			if(u[i]==s.substr(x,m)){
				x += m;
				end = false;
				break;
			}
		}
		if(end){
			cout << "NO" << endl;
			return 0;
		}		
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long a,b,c;
int main()
{
 	cin>>a>>b>>c;
  if(c-a-b>=0)cout<<(4ll*a*b<(c-a-b)*(c-a-b)?"Yes":"No");
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1003];
int main()
{
  cin >> n >> k;
  for (int i = 1; i <= n; i+=1) cin >> a[i];
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for(int i = 1; i <= k; i+=1) ans += a[i];
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  int kotae=0;
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
      count++;
      kotae=max(kotae,count);
    }else{
      kotae=max(count,kotae);
      count=0;
    }
  }
  cout<<kotae<<endl;
  return 0;
}
      

  

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int sum = 0;
  sum = a + b + c;
  if(sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

Measured memory_bytes: 256
def set_values():
	values = []
	for i in range(num):
		values.append(int(input()))
	return values

num = int(input())
values = set_values()
max_value = values[1] - values[0]
min_value = values[0]

for i in range(1, num):
	max_value = max(max_value, (values[i] - min_value))
	min_value = min(min_value, values[i])

print(max_value)


Measured memory_bytes: 13596
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

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

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def main():
    n = I()
    a = [LI() for _ in range(n)]
    for i in range(n):
        ai = a[i]
        for j in range(i+1,n):
            aij = ai[j]
            aj = a[j]
            for k in range(n):
                if ai[k] + aj[k] < aij:
                    return -1

    r = 0
    ij = sorted(list(itertools.chain.from_iterable([[[a[i][j], i, j] for j in range(i+1,n)] for i in range(n)])))
    uf = UnionFind(n)
    aa = [[inf] * n for _ in range(n)]
    for i in range(n):
        aa[i][i] = 0
    for k,i,j in ij:
        if uf.union(i,j):
            aa[i][j] = aa[j][i] = k
            r += k
        elif aa[i][j] > k:
            f = True
            for l in range(n):
                if f and aa[l][i] + aa[l][j] <= k:
                    aa[i][j] = aa[j][i] = aa[l][i] + aa[l][j]
                    f = False
                elif aa[l][i] + aa[l][j] < aa[i][j]:
                    aa[i][j] = aa[j][i] = aa[l][i] + aa[l][j]

            if f:
                aa[i][j] = aa[j][i] = k
                r += k

    for i in range(n):
        ai = a[i]
        aai = aa[i]
        for j in range(i+1,n):
            if ai[j] != aai[j]:
                return -1

    return r


print(main())





Measured memory_bytes: 84952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int H, W, K;
string field[10];
 
int main() {
    cin >> H >> W >> K;
    for(int h = 0; h < H; h++) cin >> field[h];
    int ans = 1e9;
    for(int bits = 0; bits < (1 << (H-1)); bits++) {
        vector<vector<int>> v;
        v.push_back({0});
        for(int i = 1; i < H; i++) {
            if(!(bits & (1 << (i-1)))) v.back().push_back(i);
            else v.push_back({i});
        }
        int n = v.size();
        int val = __builtin_popcount(bits);
        vector<int> num(n);
        //cerr << "n:" << bits << " " << n << endl;
        for(int w = 0; w < W; w++) {
            vector<int> now(n);
            for(int i = 0; i < v.size(); i++) {
                for(auto tmp : v[i]) {
                    if(field[tmp][w] == '1') now[i]++;
                }
                if(now[i] > K) {
                    w = W;
                    val = 1e9;
                    break;
                }
            }
            bool cut = false;
            if(val == 1e9) break;
            for(int i = 0; i < n; i++) {
                num[i] += now[i];
                //cerr << "now:" << i << " " << now[i] << endl;
                if(num[i] > K) cut = true;
            }
            if(cut) {
                //cerr << bits << " " << w << endl;
                val++;
                for(int i = 0; i < n; i++) {
                    num[i] = 0;
                }
                w--;
            }
        }
        //cerr << bits << " "<< val << endl;
        chmin(ans, val);
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
  int N; cin >> N;
  if(N%10==3){
    cout << "bon" << endl;
  }else if(N%10==0||N%10==1||N%10==6||N%10==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vi b(n);
    int c[10001];
    auto countingSort = [&](int k) {
        for(int i = 0; i <= k; ++i) {
            c[i] = 0;
        }
        for(int j = 1; j <= n; ++j) {
            c[a[j-1]]++;
        }
        for(int i = 1; i <= k; ++i) {
            c[i] = c[i] + c[i-1];
        }
        for(int j = n; j > 0; j--) {
            b[c[a[j-1]]-1] = a[j-1];
            c[a[j-1]]--;
        }
    };
    countingSort(10000);
    rep(i, n) {
        cout << b[i] << (i == n-1?'\n':' ');
    }
}


Measured memory_bytes: 18272
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
vector<int>g[3][110];
int G[110][110];
int dp[110][110];
//int bfs[8][110];
int bfs[1010];
int u[110];
int main(){
	int a,b,c,d,e;
	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		G[p][q]=1;
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<110;j++)for(int k=0;k<a;k++)dp[j][k]=0;
		dp[0][i]=1;
		for(int j=0;j<c;j++){
			for(int k=0;k<a;k++){
				if(!dp[j][k])continue;
				for(int l=0;l<a;l++)if(G[k][l])dp[j+1][l]=1;
			}
		}
		for(int j=0;j<a;j++)if(dp[c][j])g[0][i].push_back(j);
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<110;j++)for(int k=0;k<a;k++)dp[j][k]=0;
		dp[0][i]=1;
		for(int j=0;j<d;j++){
			for(int k=0;k<a;k++){
				if(!dp[j][k])continue;
				for(int l=0;l<a;l++)if(G[k][l])dp[j+1][l]=1;
			}
		}
		for(int j=0;j<a;j++)if(dp[d][j])g[1][i].push_back(j);
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<110;j++)for(int k=0;k<a;k++)dp[j][k]=0;
		dp[0][i]=1;
		for(int j=0;j<e;j++){
			for(int k=0;k<a;k++){
				if(!dp[j][k])continue;
				for(int l=0;l<a;l++)if(G[k][l])dp[j+1][l]=1;
			}
		}
		for(int j=0;j<a;j++)if(dp[e][j])g[2][i].push_back(j);
	}
	for(int i=0;i<110;i++)bfs[i]=999999999;
	bfs[a-1]=0;
//	bfs[0][a-1]=bfs[1][a-1]=bfs[2][a-1]=0;

	for(int i=0;i<a;i++){
		for(int j=0;j<a;j++){
			int cost=0;
			for(int k=0;k<3;k++){
				int v=999999999;
				for(int l=0;l<g[k][j].size();l++){
					v=min(v,bfs[g[k][j][l]]);
				}
				cost=max(cost,v);
			}
			bfs[j]=min(bfs[j],cost+1);
		}
	}
	if(bfs[0]>9999999)printf("IMPOSSIBLE\n");
	else printf("%d\n",bfs[0]);
	
//	if(bfs[0][0]<0||bfs[1][0]<0||bfs[2][0]<0)printf("IMPOSSIBLE\n");
//	else printf("%d\n",max(bfs[0][0],max(bfs[1][0],bfs[2][0])));
}

Measured memory_bytes: 1172
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        final long MOD = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        String ans = "No";
        for (int i = 0;i<n;++i)
        {
            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == b) ++count;
            else count = 0;

            if (count >= 3)
            {
                ans = "Yes";
                break;
            }
        }
        System.out.println(ans);
        sc.close();
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

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

int main(){
  int n;
  cin>>n;
  vector<bool> flag(100);
  int num[100];
  for(int i=0;i<100;i++){
    num[i] = i*2 +1;
  }
  for(int i=0;i<200;i++){
    flag[i] = false;
  }
  for(int i=1;i<100;i++){
    int count=0;
    for(int j=0;j<i+1;j++){
      if(num[i]%num[j]==0){
        count++;
      }
    }
    if(count==8) flag[2*i] = true;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(flag[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}


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

int main() { 
  int n;
  cin >> n;
  vector<int> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll ans = 0;
  rep(i, n){
    if(a[i] >= b[i]){
      ans += (ll)b[i];
    }else{
      int tmp = b[i] - a[i];
      ans += (ll)min(b[i], a[i]+a[i+1]);
      a[i+1] = max(a[i+1]-tmp, 0);
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 4020
function main(input) {
  input = input.trim();
  const [a, b, c, d, e, f] = input.split(" ").map(n => Number(n));
  const ws = [];
  for(let i = 0; i < 10000; i++) {
    if (f < 100*a*i) break;
    for (let j = 0; j < 1000; j++) {
      const water = 100*a*i + 100*b*j;
      if (f < water) continue;
      ws.push(water);
    }
  }
  const ss = [];
  for (let i = 0; i < 10000; i++) {
    if( f < c*i) break;
    for (let j = 0; j < 1000; j++) {
      const sugar = c*i + d*j;
      if (f < sugar) continue;
      ss.push(sugar);
    }
  }

  const result = [0, 0];
  let max = -1;
  for (const water of ws) {
    for(const sugar of ss) {
      if (water === 0) continue;
      if (f < water + sugar) continue;
      if (e*water/100 < sugar) continue;
      const c = sugar/(water + sugar);
      if (max < c) {
        max = c;
        result[0] = water + sugar;
        result[1] = sugar;
      }
    }
  }
  console.log(result.join(" "));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 13004
if __name__ == '__main__':
    a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    s = int(input())
    print(a[int(s)-1])


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

pub 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")
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn lcm(x: i64, y: i64) -> i64 {
    x * (y / gcd(x, y))
}

fn main() {
    let n: usize = read();
    let mut ans: i64 = 1;
    for _ in 0..n {
        let a: i64 = read();
        ans = lcm(ans, a);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define pb          push_back
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pi          3.14159265358979323



const int N = 2e3+5;
ll fact[N];

long long binpow(long long val, long long deg)
{
        if (!deg) return 1 % mod;
        if (deg & 1) return binpow(val, deg - 1) * val % mod;
        long long res = binpow(val ,deg >> 1);
        return (res*res) % mod;
}

void initfact()
{
        fact[0] = 1;
        for(ll i = 1; i < N; i++)
       {
                fact[i] = (fact[i-1] * i);
                fact[i] %= mod;
        }
}

long long nCr(ll n, ll i)
{
        long long res = fact[n];
        long long div = fact[n-i] * fact[i];
        div %= mod;
        div = binpow(div, mod - 2);
        return (res * div) % mod;
}

ll dis(ll a, ll b)
{
       ll ans = nCr(a+b-1,b-1);
       return ans;
}

void solve()
{
      ll n,k; cin>>n>>k;
      ll r=n-k, b=k;
      //cout<<nCr(5,2)<<endl;
      ll mx=min(k,r+1);
      for(ll i=1; i<=mx; i++)
      {
             //
             ll ans=(dis(k-i,i)*dis(r-i+1,i+1))%mod;
             cout<<ans<<endl;
      }
      for(ll i=mx+1; i<=k; i++) cout<<0<<endl;
}


int main() {
	int T = 1;
	initfact();
//     pre();
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


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

int main() {
  int h, w, K;
  cin >> h >> w >> K;

  vector<vector<char>> c(h + 1, vector<char>(w + 1, '.'));
  int black = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> c[i][j];
      if (c[i][j] == '#') black++;
    }
  }

  vector<int> yoko(h + 1);
  for (int i = 0; i < h; i++) {
    int b = 0;
    for (int j = 0; j < w; j++) {
      if (c[i][j] == '#') b++;
    }
    yoko[i] = b;
  }
  vector<int> tate(w + 1);
  for (int j = 0; j < w; j++) {
    int b = 0;
    for (int i = 0; i < h; i++) {
      if (c[i][j] == '#') b++;
    }
    tate[j] = b;
  }

  int ans = 0;

  for (int i = 0; i < pow(2, h); i++) {
    int after = black;
    set<int> row_set;

    for (int k = 0; k < h; k++) {
      if ((i >> k) & 1) {
        // k行目を選択
        row_set.insert(k);
        after -= yoko[k];
      }
    }

    for (int j = 0; j < pow(2, w); j++) {
      int start = after;

      for (int k = 0; k < w; k++) {
        if ((j >> k) & 1) {
          // k列目を選択
          start -= tate[k];

          for (auto row : row_set) {
            if (c[row][k] == '#') start++;
          }
        }
      }

      if (start == K) ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
 
using namespace std;
 
 
int a[6000];
int b[6000];
int y = 0;
void ss(){
	int f= 1;
	memset(a, 0, sizeof(a));
	for(int i= 2; i <= 55555; i++){
		int x = sqrt(i);
		for(int j = 2; j <= x; j++){
			if(i % j == 0){
				 f= 0;
				 break;
			}
		}
		if(f){
			a[y] = i ;
			y++;
		}
		f = 1;
	}
}
 
int main(){
	ss();
	memset(b, 0, sizeof(b));
	int n;
	scanf("%d", &n);
	int d = 5;
	int k = 0, kkk = 0;
	for(int i = 0; i <= 6000; i++){
		if(a[i] % 10 == 3){
			b[k] = a[i];
			k++;
			d = a[i];
		}
	}
	for(int i = 0; i < n; i++)	
		printf("%d ", b[i]);
	printf("\n");
}

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
map<int, int> primeFactors(int  n)
{
	mii factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors[2]++;

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		int count = 0;
		while (n % i == 0)
		{
			factors[i]++;
			n /= i;
		}
	}
	if (n > 2)
		factors[n]++;
	return factors;
}


// Graph------------------------------------------------------------------------

int32_t main()
{
	FIO;
	// c_p_c();
// --------------------------------------------------
// Never GIVE UP !!!!
	string s, t;
	cin >> s;
	cin >> t;
	int n = s.length(), ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] != t[i])
			ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3776
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0
i=0
j=0
k=0
while i <= A:
  while j <= B:
    while k <= C:
      sum=500*i+100*j+50*k
      if sum== X:
        cnt+=1
      k+=1
    j+=1
    k=0
  i+=1
  j=0
  k=0
print(cnt)

Measured memory_bytes: 3064