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

const int N = 1e5 + 5;
typedef long long LL;

int n;
LL x[N], s, p[N];

LL calc(int l, int r, int last) {
	if(x[r] < s) return s - x[l];
	if(x[l] > s) return x[r] - s;
	if(p[l] >= p[r]) {
		p[l] += p[r];
		return (r == last)*(x[r] - x[l]) + calc(l, r - 1, l);
	}
	else {
		p[r] += p[l];
		return (l == last)*(x[r] - x[l]) + calc(l + 1, r, r);
	}
}

int main() {
	cin>>n>>s;
	for(int i = 1; i <= n; i++)
		scanf("%lld%lld", &x[i], &p[i]);
	cout<<calc(1, n, (p[1] < p[n]) ? 1:n)<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc126_c.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int loga(int x, int a) {
  if (x == 0 || x == 1) return 0;
  int cnt = 0;
  while (x != 0) {
    x /= a;
    cnt++;
  }
  return cnt;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  double ans;
  repi(i, 1, N + 1) {
    ll f = i;
    double p = 1;
    while (K > f) {
      f *= 2;
      p /= 2;
    }
    ans += p;
  }
  printf("%.12lf", ans / N);
}

Measured memory_bytes: 256
#include <cstdio>
using namespace std;
inline int read(){
    int x(0),w(1); char c = getchar();
    while(c^'-' && (c<'0'||c>'9')) c = getchar(); if(c == '-') w = -1, c = getchar();
    while(c>='0' && c<='9') x = (x<<3) + (x<<1) + c - '0', c = getchar();
	return x*w;
}
char a,b,c,d;
int s[2],lim[20]={0,31,29,31,30,31,30,31,31,30,31,30,31,0};
inline bool check(int a, int b, int c, int d){
	a -= '0';
	b -= '0';
	c -= '0';
	d -= '0';
	int x=a*10+b,y=c*10+d;
	if(x<1 || x>12) return 0;
//	if(y<1 || y>lim[x]) return 0;
	return 1;
}
int main(){
	a = getchar();
	b = getchar();
	c = getchar();
	d = getchar();
	if(check(a,b,c,d)) s[1]++;
	if(check(c,d,a,b)) s[0]++;
	if(s[0]==1 && s[1]==0){
		printf("YYMM");
	}
	if(s[0]==0 && s[1]==1){
		printf("MMYY");
	}
	if(s[0]==1 && s[1]==1){
		printf("AMBIGUOUS");
	}
	if(s[0]==0 && s[1]==0){
		printf("NA");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int t, ans;
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cout<< fixed<< setprecision(10) << x << endl;
	cin>>t;
	ans = t;
	ans = ans * ans * ans;
    cout<<ans<<"\n";
}

Measured memory_bytes: 256
import math

n = int(input().strip())
H = list(map(int, input().strip().split(' ')))
H.reverse()
ans = 0
count = 0
for i in range(n-1):
    if H[i] <= H[i+1]:
        count = count + 1
        if count > ans:
            ans = count
    else:
        count = 0
print(ans)



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

using namespace std;

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

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

const ll mod = 1e9 + 7LL;
const ll MAXK = 1e5 + 1LL;

ll cnt[MAXK];

ll modpow(ll a, ll n)
{
    if(n==0LL)return 1LL;
    ll vrednost = modpow(a,n/2)%mod;
    ll resenje = (vrednost*vrednost)%mod;
    if(n%2==0)
    {
        return resenje;
    }
    else
    {
        return (resenje*a)%mod;
    }
}

int main()
{
    ll n, k;
    cin >> n >> k;

    cnt[k]=1LL;

    ll resenje = k;

    for(ll g = k-1; g >= 1; --g)
    {
        ll kolkoIma=k/g;
        cnt[g]=modpow(kolkoIma, n);

        for(ll i = 2LL * g; i <= k; i += g)
        {
            cnt[g] -= cnt[i];
            if(cnt[g] < 0)
            {
                cnt[g]+=2*mod;
            }
            cnt[g]%=mod;
        }

        resenje = (resenje + (cnt[g]*g)%mod)%mod;
    }

    cout << resenje << '\n';

    return 0;
}


Measured memory_bytes: 4320
import sys
gp_a = [1,3,5,7,8,10,12]
gp_b = [4,6,9,11]

x, y = list(map(int, input().split()))

if x == 2 or y == 2:
  print("No")
  sys.exit()
if (x in gp_a) and (y in gp_a):
  print("Yes")
elif (x in gp_b) and (y in gp_b):
  print("Yes")
else:
  print("No")

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

using namespace std;

int main(){
    long long a, b, rez=1, cm, d=2;
    cin>>a>>b;
    cm=__gcd(a,b);
    for(d; d*d<=cm; ++d){
        if(cm%d==0){
            rez++;
            while(cm%d==0){
                cm/=d;
            }
        }
    }
    if(cm>1) rez++;
    cout<<rez;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,flag=0; cin>>n; long long a[n];
  for(int i=0;i<n;i++){ cin>>a[i]; if(!a[i]) flag=1;}
  if(flag) { cout<<0<<endl; return 0;}
  long long c=1e18;
  long long prod=1;
  for(int i=0;i<n;i++){
    long long rem=c/prod;
    if(rem<a[i]) { prod=-1; break; }
    else prod*=a[i]; 
  }
  cout<<prod<<endl;
}

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

int main()
{
string s;
cin >> s;
if(s.size()<=2)
{
    if(s[0]==s[1])
        cout << 1 << " " << 2 << endl;
    else
     cout << -1 << " " << -1 << endl;
     return 0;
}
bool mrk = 0 ;
int lf , rt ;
for(int i=1; i<s.size()-1; i++)
{
    if(s[i]==s[i+1] && s[i]==s[i-1])
    {
        lf = i-1;
        rt = i+1;
        mrk = 1;
        break;
    }
    else if(s[i]==s[i+1] && s[i]!=s[i-1])
    {
         lf = i-1;
        rt = i+1;
        mrk = 1;
        break;

    }
    else if(s[i-1]==s[i+1] && s[i]!=s[i-1])
    {
         lf = i-1;
        rt = i+1;
        mrk = 1;
        break;
    }
    else if(s[i]==s[i-1] && s[i]!=s[i+1])
    {
         lf = i-1;
        rt = i+1;
        mrk = 1;
        break;

    }

}
if(mrk)
{
    cout << lf+1 << " " << rt+1 << endl;
}
else
    cout << -1 << " " << -1 << endl;


 }


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> c(N);
  for (int i = 0; i < N; i++) {
    cin >> c[i];
  }

  vector<pair<int, int>> bcPair(M);

  for (int i = 0; i < M; i++) {
    cin >> bcPair[i].second >> bcPair[i].first;
  }

  sort(c.begin(), c.end());

  sort(bcPair.begin(), bcPair.end());
  reverse(bcPair.begin(), bcPair.end());

  vector<int> BC(N, 0);
  int count = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < bcPair[i].second; j++) {
      BC[count] = (bcPair[i].first);
      count++;
      if (count == N) break;
    }
    if (count == N) break;
  }

  long long ans = 0;

  for (int i = 0; i < N; i++) {
    ans += max(c[i], BC[i]);
  }

  cout << ans << endl;
};


Measured memory_bytes: 1792
# coding=utf-8
# Date: 2020-01-08
# Author: lee215

get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: map(int, raw_input().strip().split())
getss = lambda n: [gets() for _ in xrange(n)]

H, N = gets()
AB = getss(N)
AB.sort(key=lambda a_b: -a_b[0] * 1.0 / a_b[1])

a0, b0 = AB[0]
dp = [0] + [float('inf')] * (H + a0)

cur = 0
while cur <= H + a0:
    dp[cur] = cur / a0 * b0
    cur += a0


for a, b in AB[1:]:
    for i in xrange(a, H + a0 + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
print min(dp[H:])


Measured memory_bytes: 33132
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

struct data {
	int a, b;
}arr[100005];

bool cmp(data aa, data bb);

int main(void) {
	std::ios::sync_with_stdio(false);
	int n;
	while(cin >> n) {
		for(int i = 1; i <= n; i++) {
			arr[i].a = i;
			cin >> arr[i].b;
		}
		sort(arr+1, arr+1+n, cmp);
		for(int i = 1; i <= n; i++) {
			cout << arr[i].a << ' ';
		}
		cout << endl;
	}
}

bool cmp(data aa, data bb) {
	return aa.b < bb.b;
} 

Measured memory_bytes: 1664
def lcs(str1, str2):
    '''文字列str1, str2の最長共通部分列(Lowest Common Subsequence, LCS)を求める
    計算量O(len(str1)*len(str2))  
    '''
    dp = [[0]*(len(str2) + 1) for _ in range(len(str1) + 1)]
    for i in range(len(str1)):
        for j in range(len(str2)):
            if str1[i] == str2[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j])

    '''復元を実行
    最長の長さを求めるなら return dp[len(str1)][len(str2)] をするとよい'''
    res = ''
    i, j = len(str1), len(str2)
    while i > 0 and j > 0:
        if dp[i][j] == dp[i-1][j]:
            i -= 1
        elif dp[i][j] == dp[i][j-1]:
            j -= 1
        else:
            res = str1[i-1] + res
            i -= 1
            j -= 1
    return res

s = input()
t = input()
print(lcs(s, t))

Measured memory_bytes: 112732
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

    string S;

    cin >> S;

    int year = stoi(S.substr(0, 4));
    int month = stoi(S.substr(5, 2));
    
    if(year < 2019){
        cout << "Heisei" << endl;
    }else if(month < 5){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
#include <map>
 
using namespace std;

typedef long long ll;

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

    int N;

    cin >> N;

    map<string, ll> m;

    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        m[s]++;
    }

    ll count = 0;

    for(auto& i : m) {
        count += i.second * (i.second - 1) / 2;
    }

    cout << count << endl;
}


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

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int sum = 0;
  int min = A * X + B * Y;
  for(int i = 0; i <= 100000; i++) {
    sum = 2 * C * i + max( X - i , 0 ) * A + max( Y - i, 0 ) * B;
    if(min > sum) min = sum;
  }

  cout << min; 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

#include <sstream>
#include <istream>

using namespace std;

//typedef pair<int,int> P;
typedef long long ll;

int main(){
	int D, G, p[11], c[11];
	cin >> D >> G;
	for(int i=0;i<D;i++){
		cin >> p[i] >> c[i];
	}

	int ans = 1000000;
	for(int mask=0; mask<(1<<D); mask++){
		int s = 0;
		int num = 0;
		int rest_max = -1;
		for(int i=0;i<D;i++){
			if( (mask>>i) & 1){
				s += 100 * (i+1) * p[i] + c[i];
				num += p[i];
			}else{
				rest_max = i;
			}
		}
		if(s<G){
			int s1 = 100 * (rest_max+1);
			int need = (G - s + s1 - 1) / s1;
			if(need >= p[rest_max]){
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
open Array
let modulo = 1000000007
let (+@) a b = (a + b) mod modulo
let ( *@ ) a b = (a * b) mod modulo

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let x = init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let y = init m (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let xw = init (n-1) (fun i -> (x.(i+1)-x.(i)) *@ (i+1) *@ (n-1-i)) |> fold_left (+@) 0 in
  let yw = init (m-1) (fun i -> (y.(i+1)-y.(i)) *@ (i+1) *@ (m-1-i)) |> fold_left (+@) 0 in
  Printf.printf "%d\n" (xw *@ yw)

Measured memory_bytes: 6400
def LI(): return list(map(int,input().split()))
N,K = LI()
a = LI()
ans = float('INF')
for i in range(2**(N-1)):
    bit = [i>>j&1 for j in range(N-1)]
    if K-1!=sum(bit):
        continue
    cost,kijun = 0,a[0]
    for k in range(N-1):
        if bit[k]==0:
            kijun = max(kijun,a[k+1])
        else:
            if a[k+1]>=kijun+1:
                kijun = a[k+1]
                continue
            cost += (kijun+1)-a[k+1]
            kijun += 1
    ans = min(ans,cost)
print(ans)


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

using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

ll F(ll A, ll B){
  return max(to_string(A).size(), to_string(B).size());
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    cin>>x;
    ll ans=1e9;
    FOR(i,1,sqrt(x)+3){
      if(x%i==0){
        ans = min(ans, F(i, x/i));
      }
    }
    cout<<ans<<endl;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
	long long n, m, x = 0;
	cin>>n>>m;
	while (m--) {
		int a;
		cin>>a;
		x += a;
	}
	if (n-x < 0) cout<<-1<<"\n";
	else cout<<n-x<<"\n";
	return 0;
}

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

using namespace std;

int n;
bool flag = true;
int cnt = 0;

int main () {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    for (int i=0; i<n; i++) {
        for (int j=i; j>=0; j--) {
            if (a[i] < a[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cnt++;
        }
        flag = true;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n,m,a[510][510],tot;
struct node { int x,y; } d[500*500+10];
vector<pair<node,node> > ans;
int main() {

	read(n); read(m);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++) read(a[i][j]);
	for (int i=1;i<=n;i++)
		if (i%2==0) {
			for (int j=1;j<=m;j++) d[++tot]=(node){i,j};
		} else for (int j=m;j>=1;j--) d[++tot]=(node){i,j};
	for (int i=1,j;i<=tot;i++)
		if (a[d[i].x][d[i].y]&1) {
			for (j=i+1;j<=tot;j++)
				if (a[d[j].x][d[j].y]&1) break;
			if (j>tot) break;
			for (int k=i;k<j;k++)
				ans.push_back(make_pair(d[k],d[k+1]));
			i=j;
		}
	printf("%d\n",ans.size());
	for (int i=0;i<ans.size();i++) printf("%d %d %d %d\n",ans[i].first.x,ans[i].first.y,ans[i].second.x,ans[i].second.y);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 8152
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>

using namespace std;

#define TT1T2 template<class T1, class T2>
TT1T2 void debug_print_array(const T1 &a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cerr << a[i] << (i + 1 != sz ? "," : ""); cout << endl; }
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DA(a,n) cerr<<#a<<"=["; debug_print_array(a,n); cerr<<"]\n"
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <typename T, const int N> using Graph = vector <T> [N];

int64_t calc(int64_t a, int64_t b) {
    if (a == 0 || b == 0) {
        return -max(a, b);
    }
    if (a < b) {
        swap(a, b);
    }
    int64_t ss = b * (a / b);
    return 2 * ss + calc(a - ss, b);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(20);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int64_t n, x;
    cin >> n >> x;

    cout << n + calc(x, n - x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  string S;
  string T;
  cin >> S >> T;
  int s = S.length(), t = T.length();
  if (s >= t) {
    for (int i = s-t; i >= 0; --i) {
      bool flag = true;
      for (int j = 0; j != t; ++j) {
        if (S[i+j] != '?' && S[i+j] != T[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        for (int j = 0; j != s; ++j) {
          if (S[j] == '?') {
            if (j >= i && j < i + t) S[j] = T[j-i];
            else S[j] = 'a'; 
          }
        }
        cout << S << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> A(N);
  rep (i, N) {
    ll X, L;
    cin >> X >> L;
    A[i] = make_pair(X-L, X+L);
  }
  sort(A.begin(), A.end());

  ll a = A[0].first;
  ll ans = 0;

  rep (i, N) {
    if (A[i].first >= a) {
      a = A[i].second;
      ans++;
    }
    if (a > A[i].second) a = A[i].second;
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a,b,c,d[10000000],cmp,cmpp,m,h,w,x,y,sum=0,pos,t[10000000];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=false;

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

       cin >> n;
       rep(i,n)cin >> d[i];
       cin >> m;
       rep(i,m)cin >> t[i];
       map<int,int> mp,mpp;
       rep(i,n){
           mp[d[i]]++;
       }
       rep(i,m){
           mpp[t[i]]++;
       }
       rep(i,m){
           cmp=t[i];
           if(mp[cmp]<mpp[cmp]){
               Cout("NO");
               return 0;
           }
       }
       Cout("YES");
return 0;
}


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

const int mod = 1000000007;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll S = K * (K - 1) / 2 % mod;
    ll ans = 0;
    rep(i, N) {
        ll x = 0;
        ll y = 0;
        rep(j, N) {
            if (A[i] > A[j]) {
                ++x;
                if (i < j) ++y;
            }
        }
        ans = (ans + (S * x % mod + y * K % mod) % mod) % mod;
    }
    cout << ans << endl;
}

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


#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
using namespace std;


int n, k;
vector<int> nums;

bool ok(int max_size) {
    ll total_cuts=0;
    for(int i=0; i<n; i++){
        int val=nums[i];
        total_cuts+=(val/max_size+(val%max_size!=0)-1);
    }
    return total_cuts<=k;

}

void solve() {
    cin >> n >> k;
    nums=vector<int>(n);
    int mx=0;
    for (int i=0; i<n; i++) {
        cin >> nums[i];
        mx=max(mx, nums[i]);
    }
    
    int l=1, r=mx;
    int ans = INT_MAX;
    while (l<=r) {
        int mid=l+(r-l)/2;

        if(ok(mid)){
            ans=min(ans, mid);
            r=mid-1;
        } else {
            l=mid+1;
        }
    }

    cout << ans << endl;
}

int main() {
    FAST_INPUT;
    
    solve();
    
    return 0;
}


Measured memory_bytes: 3952
x,y = input().split()

d={
"A":11,
  "B":12,
  "C":13,
  "D":14,
  "E":15,
  "F":16,
}

if d[x]==d[y]:
  print("=")
elif d[x]>d[y]:
  print(">")
else:
  print("<")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT

ll N, M, P;

// i番目の要素を採用できるか否か
bool f(vector<ll> a, ll V, ll i) {
  if (i < P)
    return true;

  // printf("before a[%lld]=%lld: ", i, a[i]);
  // for (auto e : a) {
  //   cout << e << " ";
  // }
  // cout << endl;


  // 自分自身
  a[i] += M; V--;
  if (a[P-1] > a[i])
    return false;

  // 自分自身より小さいもの
  for (ll j=i+1; j<N; j++) if (V > 0) { a[j] += M; V--; }
  //t += (N-1 -i +1) * M;

  // 1 ~ P-1番目のものはどうでもよい
  for (ll j=0; j<P-1; j++)   if (V > 0) { a[j] += M; V--; }
  //t += (P-1) * M;

  if (V <= 0)
    return true;

  // P番目までは逆転したい -> j = P-1 ~ i-1 に、つまりできるだけ分散させたい
  ll t = 0;
  for (ll j=P-1; j<i; j++) {
    t += min(M, max(0ll, a[i] - a[j]));
  }

  return t >= M * V;
}

signed main() {
  ll V;
  cin >> N >> M >> V >> P;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  sort(begin(a), end(a), greater<ll>());
  ll ok = -1, ng = N;
  while (ok + 1 < ng) {
    ll m = (ok+ng)/2;
    if (f(a, V, m)) ok = m;
    else ng = m;
  }
  cout << ng << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#if 0
int main(void) {
	int x;
	int i;
	int res = 0;
	if (scanf("%d", &x) != 1) return 1;
	for (i = 0; i < x - 1; i++) {
		res = (res * 10 + 1) % x;
	}
	printf("%d\n", res);
	return 0;
}
#else
int main(void) {
	int n;
	if (scanf("%d", &n) != 1) return 1;
	if (n == 0) puts("1");
	else if (n == 1) puts("2");
	else if (n == 2) puts("1");
	else puts("0");
	return 0;
}
#endif



Measured memory_bytes: 2148
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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; }

int main(){
	ll N, M;
	vector<string> s,t;
	set<string> setS;
	cin >> N ;
	rep(i, 0, N){
		string temp;
		cin >> temp;
		s.push_back(temp);
		setS.insert(temp);
	}
	cin >> M;
	rep(i, 0, M){
		string temp;
		cin >> temp;
		t.push_back(temp);
		setS.insert(temp);
	}
	ll sum = 0;
	for (set<string>::iterator i = begin(setS); i != end(setS); i++){
		ll cnts = count(begin(s), end(s), *i);
		ll cntt = count(begin(t), end(t), *i);
		chMax(sum, cnts - cntt);
	}
	cout << sum << endl;
	return 0;
}


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

int main(){
  vector<char> n(4);
  for(int i=0;i<4;i++){
    cin >> n.at(i);
  }
  if(n.at(0)==n.at(1)&&n.at(1)==n.at(2)){
    cout << "Yes" << endl;
  }else if(n.at(1)==n.at(2)&&n.at(2)==n.at(3)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pii pair <int, int>
#define F first
#define S second
#define ll long long
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define M_PI 3.14159265358979323846
const int N = 200005;
const int mod = 1e9 + 7;
ll pre[N];
int main() {
    io;
    int n, a[N];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        pre[i] = a[i];
        if(i) pre[i] += pre[i - 1];
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += (pre[i] - a[i]) % mod * a[i] % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5992
#include<stdio.h>
int main()
{
    double a,b,c,d,e,f,n,r,j,k,l,m,x,y,i,v,q,s,g,h,o,z;
       while( scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)==6){

        y=((d*c)-(a*f))/((d*b)-(a*e));

    x=(c-b*y)/a;

    printf("%.3lf %.3lf\n",x,y);}
    return 0;
}

Measured memory_bytes: 1764
s = int(input())

ans = [s]
idx = 1
tmp = s
while True:
    if tmp % 2 == 0:
        tmp = tmp//2
    else:
        tmp = (3*tmp) + 1
    idx +=1

    if tmp in ans:
        print(idx)
        exit()
    else:
        ans.append(tmp)

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    str s, t;
    cin >> s >> t;
    int n = sz(s);
    bool ok = true;
    for (int i = 0; i < n; i++)
        ok &= s[i] == t[i];
    cout << (ok ? "Yes" : "No") << endl;
    GAME_OVER;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000") 
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define set0(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
using namespace std;
string s;
int ans,n,sum;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s;
	n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]>'0')ans=max(ans,sum+s[i]-'1'+(i==n-1)+(n-1-i)*9);
		sum+=s[i]-'0';
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1<<30
const int mod = 1e9+7;


int main(){
    ll n; cin >> n;
    vl a(n);
    map<ll,ll> mp;
    rep(i,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    ll ans = 0;
    for(auto i : mp){
        if(i.first<=i.second) ans += i.second-i.first;
        else ans += i.second;
    }
    cout << ans << endl;
}


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

using namespace std ;

vector < pair < long long , long long > > v ;


int main () {

    long long n , i,x,y,sum=0 ,k=0;

    cin >> n ;

    for(i=0;i<n;i++) {
        cin >> x >> y ;
        v.push_back(make_pair(y,x)) ;
    }

    sort(v.begin(),v.end()) ;

    for(i=0;i<n;i++){
       sum+=v[i].second ;
       if (sum>v[i].first)
        k=1;
    }
    if (k)
        cout << "No" ;
    else
        cout << "Yes" ;

    return 0 ;
}


Measured memory_bytes: 6384
#include<cstdio>
int a[55][55],b[55][55],n,m;
int check(int x,int y)
{
	for(int i=1;i<=m;i++)
	for(int j=1;j<=m;j++)
	if(b[i][j]!=a[x+i-1][y+j-1]) return 0;
	return 1;
}
int main()
{
	char c;
	scanf("%d%d\n",&n,&m);
	for(int i=1;i<=n;i++,getchar())
	for(int j=1;j<=n;j++)
	{
		c=getchar();
		a[i][j]=c=='#'?1:0;
	}
	for(int i=1;i<=m;i++,getchar())
	for(int j=1;j<=m;j++)
	{
		c=getchar();
		b[i][j]=c=='#'?1:0;
	}
	for(int i=1;i<=n-m+1;i++)
	for(int j=1;j<=n-m+1;j++)
	if(check(i,j)) {printf("Yes\n");return 0;}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
import sys

input = sys.stdin.readline


def main():
    A, B, C, D = [s for s in input().rstrip()]

    ops = ["+", "-"]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                eq = "".join([A, op1, B, op2, C, op3, D])
                res = eval(eq)
                if res == 7:
                    ans = eq + "=" + str(res)
                    break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n=int(input())
h=list(map(int,input().split()))
for i in range(n-1,0,-1):
    if h[i-1]>h[i]:h[i-1]-=1
s='Yes'
for i in range(n-1):
    if h[i]>h[i+1]:s='No';break
print(s)

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

using ll=long long; 

void solve(){
	string s;
	cin>>s;
	vector<char> ans;
	for(auto e:s){
		if(e=='B'){
			if(ans.size()>0){
				ans.pop_back();
			}
		}
		else{
			ans.push_back(e);
		}
	}
	for(auto e:ans)cout<<e;
	cout<<endl;
}

signed main(){
	//while(1)
	solve();
}

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

#define ORZ_lqs2015
#define ORZ_EVERYBODY

int main() {
    int a, b, c, d, res = 0;
    cin >> a >> b >> c >> d;
    for (int i = a; i < d; i++)
        if (i < b && i >= c) res++;
    cout << res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const int mod=1000000007;
int main(){
    int h,w;cin >> h >> w;
    vector<vector<char>> grid(h,vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> grid[i][j];
        }
    }
    vector<vector<ll>> dp(h,vector<ll>(w));
    dp[0][0]=1;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(i+1<h){
                if(grid[i+1][j]!='#'){
                    dp[i+1][j]+=dp[i][j];
                    dp[i+1][j]%=mod;
                }
            }
            if(j+1<w){
                if(grid[i][j+1]!='#'){
                    dp[i][j+1]+=dp[i][j];
                    dp[i][j+1]%=mod;
                }
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define MAX (ll)(1e3 + 7)
#define INF (ll)(1e18)
#define MOD (ll)(998244353)

using namespace std;
using ll = long long;
using cd = complex<double>;

int main () {
	int n, k;
	cin >> n >> k;
	int ar[n], br[n + 8] = {};
	for (int i = 0; i < n; i++) {
		cin >> ar[i];	
	}
	bool fl = 1;
	for (int i = 0; i < k && fl; i++) {
		for (int j = 0; j < n; j++) {
			int l = max (j - ar[j], 0), r = min (n, j + ar[j] + 1);
			br[l]++;
			br[r]--;
		}
		int vv = 0;
		fl = 0;
		for (int j = 0; j < n; j++) {
			vv += br[j];
			ar[j] = vv;
			br[j] = 0;
			if (ar[j] != n) {
				fl = 1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ar[i] << " ";
	}
	cout << "\n";
}


Measured memory_bytes: 5184
#include<stdio.h>
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  do{
    c=c-b;
    if(c<=0){
      printf("Yes");
      return 0;
    }
    a=a-d;
    if(a<=0){
      printf("No");
      return 0;
    }
  }while(a>0||c>0);
}

Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
//#include <string>
//#include <math.h>
//#include <istream>
//#include <sstream>
using namespace std;

int main()
{
	int a,b,c1,c2,c3,ANS;
	ANS = 0;
	cin >> a;
	cin >> b;
	
	c1 = max(a, b);
	c2 = min(a, b);
	ANS = c1;
	c1 = c1 - 1;
	c3 = max(c1, c2);
	ANS = ANS + c3;
	cout << ANS << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
money = 1000
for i in range(N-2):
    today, tomorrow = A[i], A[i+1]
    if today < tomorrow:
        money = (money//today)*tomorrow + money%today
if A[N-2]< A[N-1]:
    money = (money//A[N-2]) * A[N-1] + money%A[N-2]

print(money)


Measured memory_bytes: 61792
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
ll x[100010];

combination comb( 100010 );

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> x[i];

  mint c = 0, ans = 0;

  rep( i, N-1 )
  {
    c += comb.fact[N-1]*mint(i+1).inv();
    ans += c*(x[i+1]-x[i]);
  }

  std::cout << ans.x << std::endl;

  return 0;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

res = 0
for i in range(len(B)):
  res += min(A[i], B[i])
  rem = B[i] - A[i]
  if rem > 0 and i+1 < len(A):
    res += min(A[i+1], rem)
    A[i+1] = max(0, A[i+1]-rem)

print(res)

Measured memory_bytes: 82020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int[] a = sc.IntArray();

        int odd = a.Where(i => i % 2 == 1).Count();

        string answer = odd % 2 == 0 ? "YES" : "NO";

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 19680
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for i in range(D)]

t = [int(input()) for i in range(D)]

last = [0]*26
S = 0
for d in range(1, D+1):
    # last更新
    for j in range(26):
        if j == t[d-1]-1:
            last[j] = d

    # plus部分
    S += s[d-1][t[d-1]-1]

    # minus部分
    m = 0
    for j in range(26):
        m += c[j] * (d-last[j])
    
    S -= m
    
    print(S)

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

/*** 0007 */
public class Main {

	/*** 利子 */
	private final static double INTEREST = 1.05;
	/*** 切り上げ額 */
	private final static double REVALUATION = 1000;
	/*** 借金 */
	private static int debt = 100000;
	/*** 文字型入力ストリーム（標準入力） */
	private static BufferedReader br;
	/*** 週 */
	private static int weekNum;

	/*** 初期化 */
	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * メインメソッド<br>
	 * 借金の残高を出力する
	 *
	 */
	public static void main(String[] args) throws IOException {

		weekNum = Integer.parseInt(br.readLine());	// 週を取得

		System.out.println(getTotalDept());	// 借金の残高の出力

	}

	/**
	 * 借金の残高を取得し利子をかけた週の合計の借金を計算して返す
	 */
	private static int getTotalDept() {
		double debtTemp = debt / REVALUATION;
		for (; weekNum > 0; weekNum--) {
			debtTemp = Math.ceil(debtTemp * INTEREST); // 切り上げ
		}
		return (int) (debtTemp * REVALUATION);
	}

}

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    ans = n / (a + b) * a + min(a, n % (a + b));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include <string.h>
using namespace std;

#define MAX_NUM 1001
int fLength;
int sLength;

int memo[MAX_NUM][MAX_NUM];
string f, s;

/*******************
  Longest Common Subsequence
  ??¨??????????????§??????????????????(??¨??????????????§?????????)
 *********************/

void solve() {
  for(int i = 0; i < fLength; i++) {
    for(int j = 0; j < sLength; j++) {
      if(f[i] == s[j]) {
        memo[i + 1][j + 1] = memo[i][j] + 1;
      }
      else {
        memo[i + 1][j + 1] = max(memo[i + 1][j], memo[i][j + 1]);
      }
    }  
  }
}


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


  //?????????
  memset(memo, 0, sizeof(memo));
  for(int i = 0; i < n; i++) {
    cin >> f >> s;
    fLength = f.size();
    sLength = s.size();
    solve();
    cout << memo[fLength][sLength] << endl;
  }
  return 0;
}

Measured memory_bytes: 5124
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int32_t main() {
    //ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m;
    cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2 << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
using R = double;
using Data = pair < ll, vector <ll>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
struct edge { ll from; ll to; ll cost; };
typedef tuple<ll, ll, ll>T;
typedef pair<ll, ll>pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

vector<ll>e[101010];
vector<ll>num(101010);
vector<ll>c;
priority_queue<ll>pq;

void bfs(ll n){
	queue<ll>q;
	q.push(n);
	while (q.size()) {
		ll tp = q.front();
		q.pop();
		fore(x, e[tp]) {
			if (num[x] == 0) {
				num[x] = pq.top();
				pq.pop();
				q.push(x);
			}
		}
	}
}

int main(){
	ll n;
	cin >> n;
	vector<ll>y(n);
	vector<pair<ll, ll>>ma(n-1);
	rep(i, 0, n - 1) {
		ll a, b;
		cin >> a >> b;
		a--, b--;
		e[a].pb(b);
		e[b].pb(a);
		ma[i] = { a,b };
		y[a]++;
		y[b]++;
	}
	c.resize(n);
	rep(i, 0, n) {
		cin >> c[i];
		pq.push(c[i]);
	}
	sort(all(c));
	reverse(all(c));

	vector<pair<ll,ll>>li(n);
	rep(i, 0, n) {
		li[i] = {y[i],i};
	}
	sort(all(li));
	reverse(all(li));

	num[li[0].second] = c[0];
	pq.pop();
	bfs(li[0].second);

	ll ans = 0;
	rep(i, 0, n - 1) {
		ans += min(num[ma[i].first],num[ma[i].second]);
	}
	cout << ans << endl;
	rep(i, 0, n) {
		if (i)cout << " ";
		cout << num[i];
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstdlib>
#include <vector>
#include <cstdint>
#include <numeric>

#define _rep_overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _rep_overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define _rrep_overload3(_1,_2,_3,name,...) name
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _rrep_overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

using namespace std;

// Globals

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N;
  cin >> N;
  
  int ans = 1e9;
  for (int i=0; i<N+1; i+=9) {
    int p9 = 0;
    for (int x=i; x>0; x/=9) {
      p9 += x%9;
    }
    int p6 = 0;
    for (int x=N-i; x>0; x/=6) {
      p6 += x%6;
    }
    ans = min(ans, p9 + p6);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets
num = [0]
until n.nil?
 nn = n.chomp
 x = nn.split("")

 x.each do |k|
  num << k
 end
 maru = num.each_with_index.select{|e, i| e == "o"}.map{|e| e[1]}
 batu = num.each_with_index.select{|e, i| e == "x"}.map{|e| e[1]}
  if maru.include?(2) && maru.include?(1) && maru.include?(3)
   puts "o"
  elsif maru.include?(4) && maru.include?(1) && maru.include?(7)
   puts "o"
  elsif maru.include?(6) && maru.include?(3) && maru.include?(9)
   puts "o"
  elsif maru.include?(8) && maru.include?(7) && maru.include?(9)
   puts "o"
  elsif maru.include?(5) && maru.include?(2) && maru.include?(8)
   puts "o"
  elsif maru.include?(5) && maru.include?(1) && maru.include?(9)
   puts "o"
  elsif maru.include?(5) && maru.include?(3) && maru.include?(7)
   puts "o"
  elsif maru.include?(5) && maru.include?(4) && maru.include?(6)
   puts "o"
  elsif batu.include?(2) && batu.include?(1) && batu.include?(3)
   puts "x"
  elsif batu.include?(4) && batu.include?(1) && batu.include?(7)
   puts "x"
  elsif batu.include?(6) && batu.include?(3) && batu.include?(9)
   puts "x"
  elsif batu.include?(8) && batu.include?(7) && batu.include?(9)
   puts "x"
  elsif batu.include?(5) && batu.include?(2) && batu.include?(8)
   puts "x"
  elsif batu.include?(5) && batu.include?(1) && batu.include?(9)
   puts "x"
  elsif batu.include?(5) && batu.include?(3) && batu.include?(7)
   puts "x"
  elsif batu.include?(5) && batu.include?(4) && batu.include?(6)
   puts "x"
  else
   puts "d"
  end
  
 n = gets
 num = [0]
end


Measured memory_bytes: 6876