akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main()
{
    int n, ans = 0;
    cin >> n;
    rep(i, n)
    {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

    long long n=0, m=0;
    cin >> n >> m;
    vector<int> v;
    long long hw=0;
    for(int i=0;i<m;++i)
    {
        long long in;
        cin >> in;
        hw+=in;
    }
    // cout << hw << endl;
    if(n >= hw)
    {
        cout << n-hw << endl;
    }
    else
    {
        cout << "-1" << endl;
    }
    


    return 0;
}

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

using namespace std;

string cutzero(const string& s)
{
	for(int i=0;i<s.size();i++)
		if(s[i]!='0')
			return s.substr(i);
	return "";
}

bool comp(const string& a,const string& b)
{
	return a.size()==b.size()?a<b:a.size()<b.size();
}

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vector<string> a(h);
		for(int i=0;i<h;i++)
			cin>>a[i];
		
		vector<vector<string> > dp(h,vector<string>(w));
		if(isdigit(a[0][0])) dp[0][0]+=a[0][0];
		for(int i=1;i<h;i++)
			if(isdigit(a[i][0]))
				dp[i][0]=cutzero(dp[i-1][0])+a[i][0];
		for(int j=1;j<w;j++)
			if(isdigit(a[0][j]))
				dp[0][j]=cutzero(dp[0][j-1])+a[0][j];
		for(int i=1;i<h;i++)
			for(int j=1;j<w;j++)
				if(isdigit(a[i][j]))
					dp[i][j]=cutzero(max(dp[i-1][j],dp[i][j-1],comp))+a[i][j];
		
		string res="";
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				res=max(res,dp[i][j],comp);
		cout<<res<<endl;
	}
	
	return 0;
}

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

map<int, int> m;

void prime_factorize(int x) {
    for (int i = 2; i * i <= x; i++) {
        while (x % i == 0) {
            m[i]++;
            x /= i;
        }
    }
    if (x != 1) m[x]++;
}

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

    for (int i = 2; i <= N; i++)
        prime_factorize(i);

    long long res = 1;
    int mod = 1000000007;
    for (int i = 2; i <= N; i++) {
        if (m[i]) {
            res *= m[i] + 1;
            res %= mod;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
 
int main() {
  
  int N;
  cin >> N;

  long long sum = 0;
  for(int i = 1;i <= N;i++) {
    if(i%3 != 0 && i % 5 != 0) sum += i;
  }

  cout << sum << endl;

}


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

//#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int N;
int x[100000],y[100000];//(x,y)
int ox[100000],oy[100000];//order
int sx[100000],sy[100000];//state(?) 0->A or B 1->A 2->B

bool make(int *z,int *o,int *s,int l,int col){
    int cur=0;
    while(cur<N&&z[o[cur]]-z[o[0]]<=l)cur++;
    rep(i,cur)s[o[i]]=0;
    reps(i,cur,N)s[o[i]]=3-col;

    if(cur!=N){
        cur=N-1;
        while(cur>=0&&z[o[N-1]]-z[o[cur]]<=l)cur--;
        for(int i=cur;i>=0;i--){
            if(s[o[i]]==3-col)return false;
            s[o[i]]=col;
        }
    }
    return true;
}

bool C(int l){
    if(!make(x,ox,sx,l,1))return false;
    if(!make(y,oy,sy,l,1))return false;

    bool isok=true;
    rep(i,N)if(sx[i]*sy[i]==2)isok=false;
    if(isok)return true;

    make(y,oy,sy,l,2);
    rep(i,N)if(sx[i]*sy[i]==2)return false;
    return true;
}

signed main(){
    cin>>N;
    rep(i,N)cin>>x[i]>>y[i];
    rep(i,N){
        int xx=x[i]+y[i],yy=x[i]-y[i];
        x[i]=xx;y[i]=yy;
    }
    vpint vx,vy;
    rep(i,N){
        vx.pb(pint(x[i],i));
        vy.pb(pint(y[i],i));
    }
    sort(all(vx));sort(all(vy));
    rep(i,N){
        ox[i]=vx[i].se;
        oy[i]=vy[i].se;
    }

    int lb=0,ub=444444;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }
    cout<<ub<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(), v.end());
  cout << v[2] * 10 + v[1] + v[0] << endl;
  return 0;
}

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


int main() {
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m,0);
    rep(i,m)cin >> b.at(i);
    vector< vector<int>> a(n,vector<int>(m,0));
    rep(i,n){
        rep(j,m){
            cin >> a.at(i).at(j);
        }
    }
    int ans=0;
    rep(i,n){
        int result=0;
        rep(j,m){
            result += a.at(i).at(j)*b.at(j);
        }
        result += c;
        if(result > 0)ans++;
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
	int top=0;
	int S[200];
void push(int x){
	
	top++;
	S[top]=x;
}
int pop(){
	
	top--;
	return S[top+1];
}

int main()
{
	
	int a,b,c;
	char s[200];
	while(scanf("%s",s) !=EOF){
		if(s[0]=='+')
		{
			a=pop();
			b=pop();
			b+=a;
			push(b);
		}
		else if(s[0]=='-')
		{
			a=pop();
			b=pop();
			b-=a;
			push(b);
		}
		else if(s[0]=='*')
		{
			a=pop();
			b=pop();
			b*=a;
			push(b);
		}
		else
		{	
			c=atoi(s);
			push(c);
		}
	}
	a=pop();
	printf("%d\n",a);
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>

using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;

    string res = "";

    for (int i = 0; i < dx; ++i) res += "R";
    for (int i = 0; i < dy; ++i) res += "U";
    for (int i = 0; i < dx; ++i) res += "L";
    for (int i = 0; i < dy; ++i) res += "D";
    res += "D";
    for (int i = 0; i <= dx; ++i) res += "R";
    for (int i = 0; i <= dy; ++i) res += "U";
    res += "L";
    res += "U";
    for (int i = 0; i <= dx; ++i) res += "L";
    for (int i = 0; i <= dy; ++i) res += "D";
    res += "R";
    cout << res << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, T: int, A: "List[int]", B: "List[int]"):

    # DP1
    # 1からi番目の料理でj分以内に完食できる美味しさの合計の最大値
    DP1 = [[0 for _ in range(T+1)] for __ in range(N+1)]
    for i in range(1, N+1):
        for j in range(1, T+1):
            if j-A[i-1] >= 0:
                DP1[i][j] = max(DP1[i][j], DP1[i-1][j-A[i-1]]+B[i-1])
            DP1[i][j] = max(DP1[i][j], DP1[i-1][j], DP1[i][j-1])

    # DP2
    # i番目からN番目の料理でj分以内に完食できる美味しさの合計の最大値
    DP2 = [[0 for _ in range(T+1)] for __ in range(N+2)]
    for i in range(N, 0, -1):
        for j in range(1, T+1):
            if j-A[i-1] >= 0:
                DP2[i][j] = max(DP2[i][j], DP2[i+1][j-A[i-1]]+B[i-1])
            DP2[i][j] = max(DP2[i][j], DP2[i+1][j], DP2[i][j-1])

    # i番目以外の料理でT-1分以内に完食できる美味しさの合計の最大値
    ans = 0
    for i in range(1, N+1):
        bns = 0
        for j in range(T):
            bns = max(bns, DP1[i-1][j] + DP2[i+1][T-j-1])
        ans = max(ans, bns+B[i-1])
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, T, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 193160
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int k, x;
  cin >> k >> x;
  for(int i = x - k + 1; i < x + k; i++){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

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

int main(){
string a,b;
  cin>>a>>b;
  if(a.size()>b.size())
    cout<<"GREATER"<<endl;
  else if(a.size()<b.size())
    cout<<"LESS"<<endl;
  else{
  for(int i=0;i<a.size();i++){
    if(a.at(i)>b.at(i)){
    cout<<"GREATER"<<endl;
      break;
    }
  else if(a.at(i)<b.at(i)){
    cout<<"LESS"<<endl;
    break;
  }
    else if(i==a.size()-1)
      cout<<"EQUAL"<<endl;
  }
  }
}


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

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  char s[3];
  cin>>s;
  int ans = 700;
  for(int i = 0 ; i<3;i++){
    if(s[i]=='o') ans+=100;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
<?php
    fscanf(STDIN, "%d %d %d", $N, $A, $B);
    $x = explode(" ", trim(fgets(STDIN)));
    $ans = 0;

    for ($i = 0; $i < $N-1; $i++) {
        $dist = $x[$i+1] - $x[$i];
        if ($dist * $A > $B) {
            $ans += $B;
        } else {
            $ans += $dist * $A;
        }
    }

    echo $ans . PHP_EOL;


Measured memory_bytes: 10868
s = input().split()[0]
t = input().split()[0]

if set(s) != set(t):
    ans = 'No'
elif s == t:
    ans = 'Yes'
else:
    is_match = False
    for i in range(len(s)):
        part_1 = s[-i-1:]
        part_2 = s[:-i-1]
        # print('{} - {}'.format(part_1, part_2))
        work = part_1 + part_2
        if t == work:
            is_match = True
            break
    ans = 'Yes' if is_match else 'No'

print(ans)

Measured memory_bytes: 3064
/*
g++ --std=c++17 C.cpp
*/

#include <iostream>
#include <iomanip> //! for setprecision(20)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int INF = 1000000000;
const int MOD = 1000000007;
using mint = static_modint<MOD>;

/*
  == AC Library Cheat sheet
  documentation: file:///Users/nobu/Downloads/ac-library/document_ja/index.html

  mint
    mint m.pow(int p)  //! return m^p
    mint m.inv() //! returns i that gives (m * i).val() == 1 
    int m.val() 

  fenwick_tree (BIT)
    fenwick_tree<T> fw(int n) //! init a[0] .. a[n-1] with all 0
    void fw.add(int idx, T x); //! a[idx] += x
    T fw.sum(int l, int r); //! return a[l] + .. + a[r-1]

  dsu (UnionFind)
    dsu d(int n)  //! prepare dsu with n nodes
    void d.merge(int x, int y)  //! connect node x and y
    bool d.same(int x, int y)  //! return true if node x and y are connected
    int d.leader(int x)  //! return the leader node of the connected group
    int d.size(int x) //! return the size of the group that node x belongs to
    vector<vector<int>> d.groups() //! return a vector of vectors that contain the nodes in each group

  scc_graph
    scc_graph　g(int n)  //! create a directed graph with n nodes
    g.add_edge(int from, int to)  //! create a directed edge from node from to node to
    vector<vector<int>> g.scc()  //! return the vector of strongly connected components that are topologically sorted

  segtree
    segtree<S, op, e>
      S: type of the monoid 
      op: function to return the product of two elements
      e: function to return the identity element such that op(x, e) == x fo any x 

  lazy_segtree
    lazy_segtree<S, op, e, F, mapping, composition, id>
      F: type of parameters to define the operation applied to the target elements
      mapping: function to return the element after applying the operation to the target element
      composition: function to combine the two sets of operation parameters to one
      id: function to return the operation parameter i such that mapping(i, x) = x for any x

      using S = int;
      S op(S a, S b) { return min(a, b); }
      S e() { return INF; }
      using F = int;
      S mapping(F f, S x) { return min(f, x); }
      F composition(F f, F g) { return min(f, g); }
      F id() { return INF; }

  floor_sum(ll n, ll m, ll a, ll b)   
*/



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

  int n, m;
  cin >> n >> m;
  dsu d(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    d.merge(a, b);
  }
  vector<vector<int>> g = d.groups();

  cout << (g.size()-1) << endl;

  return 0;
}


Measured memory_bytes: 9004
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int p,a,b,c,d,x,y;
	cin>>p;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	x=a/c;
	if(a%c)
	x++;
	y=b/d;
	if(b%d)
	y++;
	cout<<p-max(x,y)<<endl;
return 0;
}

Measured memory_bytes: 1164
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>
#include <math.h>
#include <string> 
#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    int number;
    cin >> S;
    size_t size = S.length();
    for(size_t i=0;i<size;i++){
        S.replace(i,1,"x");
    }
    cout << S << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    double pi = 3.1415;
    double x;
    cin >> x;
    cout << x * pi * 2.0 << endl;

    return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  ll n; cin >> n;
  if(n%2==1) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;

  ll nn = 10;
  // while(n>=nn){
  //   ans += n/nn;
  //   nn *= 10LL;
  // }
  ans += n/nn;
  nn = 50;
  while(n>=nn){
    ans += n/nn;
    // ans -= n/(nn*2);
    nn *= 5LL;
  }

  cout << ans << endl;

}

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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    double d,t,s;
    cin>>d>>t>>s;
    double res = d/s;
    if (res <= t) {
        cout << "Yes\n";
    }else {
        cout << "No\n";
    }
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3736
# seishin.py
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def gen(N, K):
    if K == 0:
        yield 0
        return
    v = (1 << K) - 1
    N2 = (1 << N)
    while v < N2:
        yield v
        x = v & -v; y = v + x
        v = ((v & ~y) // x >> 1) | y

def solve():
    R, C = map(int, readline().split())
    S = [readline().strip() for i in range(R)]
    C2 = (1 << C)
    bc = [0]*C2
    for state in range(1, C2):
        bc[state] = bc[state ^ (state & -state)] + 1

    LI = [None]*(C+1)
    RI = [None]*(C+1)
    for sl in range(C+1):
        r0 = [None]*(C+1)
        r1 = [None]*(C+1)
        for j in range(C+1):
            sr = sl - (C-j)
            e0 = []
            for k in range(max(sr, 0), min(sl, C)+1):
                e0.extend(gen(j, k))
            r0[j] = e0
            r1[j] = [state << (C-j) for state in e0]
        LI[sl] = r0
        RI[sl] = r1

    dp0 = [0]*C2; dp1 = [0]*C2
    zeros = [0]*C2
    s = S[0]; sl = len(s)
    for j in range(1, C):
        dp1[:] = zeros
        b0 = (1 << (j-1))
        b1 = (1 << j)
        for state in LI[sl][j]:
            ll = bc[state]
            dp1[state] = dp0[state]
            if ll < sl:
                if state & b0 and s[ll-1] == s[ll]:
                    dp1[state | b1] = dp0[state] + 2
                else:
                    dp1[state | b1] = dp0[state]
        dp0, dp1 = dp1, dp0
    for i in range(1, R):
        p = S[i-1]; pl = len(p)
        s = S[i]; sl = len(s)
        for j in range(C):
            dp1[:] = zeros
            b0 = (1 << (j-1)) if j else 0
            b1 = (1 << j)
            L0 = LI[sl][j]; R0 = RI[pl][C-j-1]
            for state1 in L0:
                ll = bc[state1]
                if ll < sl:
                    c = s[ll]
                    for state2 in R0:
                        rl = bc[state2]
                        state = state1 | state2
                        n_state = state | b1

                        if j < C-1:
                            dp1[state] = max(dp0[state], dp0[n_state]) if rl < pl else dp0[state]
                        r1 = max(dp0[state], (dp0[n_state] + 2 if (p[-rl-1] == c) else dp0[n_state])) if rl < pl else dp0[state]
                        if state & b0 and s[ll-1] == c:
                            dp1[n_state] = r1 + 2
                        else:
                            dp1[n_state] = r1
                else:
                    for state2 in R0:
                        state = state1 | state2
                        if bc[state2] < pl:
                            dp1[state] = max(dp0[state], dp0[state | b1])
                        else:
                            dp1[state] = dp0[state]
            dp0, dp1 = dp1, dp0
    write("%d\n" % max(dp0))
solve()


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

void zero(long long &a){
    if(a < 0)a = 0;
}

int main(){
    int N;
    cin >> N;
    vector<long long> A(N + 1);
    vector<long long> B(N);
    for(int i = 0; i <= N; i++)cin >> A[i];
    for(int i = 0; i < N; i++)cin >> B[i];
    
    long long ans = 0;
    for(int i = 0; i < N; i++){
        ans += min(A[i], B[i]);
        B[i] -= A[i];
        zero(B[i]);
        ans += min(A[i + 1], B[i]);
        A[i + 1] -= B[i];
        zero(A[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
// TOPSIC001_0

#include <bits/stdc++.h>

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;


int main(){
    int N,T;cin >> N >> T;
    vi c(N),t(N);
    REP(i,N){
        cin >> c.at(i);
        cin >> t.at(i);
    }

    int ans = 10000;
    REP(i,N){
        if(t.at(i) <= T){
            ans = min(c.at(i), ans);
        }
    }

    if(ans == 10000){
        cout << "TLE";
        return 0;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N,M;cin >> N >> M;
    vector<ll> x(N),y(N),z(N);
    rep(i,N)cin >> x[i] >> y[i] >> z[i];
    int sign[2] = {1,-1};
    ll res = 0;
    rep(i,2)rep(j,2)rep(k,2){
        vector<ll> cakes(N);
        rep(c,N){
            cakes[c] = x[c]*sign[i]+y[c]*sign[j]+z[c]*sign[k];
        }
        sort(All(cakes));
        reverse(All(cakes));
        ll tmp = 0;
        rep(c,M)tmp += cakes[c];
        res = max(res,tmp);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define Maxn 100010

using namespace std;

int arr[Maxn], check[Maxn] = {0};
int main()
{
	int N;
	cin >> N;
	for(int i = 0; i < N; i++)
		cin >> arr[i];
	for(int i = 0; i < N-1; i++)
		if(arr[i] >= arr[i+1])
			check[i] = 1;
	int sum = 0, max = 0;
	for(int i = 0; i < N-1; i++)
	{
		if(check[i])sum++;
		else
			sum = 0;
		if(sum >= max)
			max = sum;
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int f[100010],v[100010];
int fa(int a)
{
    if(f[a]==a)
        return a;
    int t=f[a];
    f[a]=fa(f[a]);
    v[a]+=v[t];
    return f[a];
}
bool connect(int x,int y,int d)
{
    int fx=fa(x);
    int fy=fa(y);
    if(fx!=fy)
    {
        f[fy]=fx;
        v[fy]=v[x]-v[y]+d;
    }
    else if(v[y]-v[x]!=d)
        return 1;
    return 0;
}
int main()
{
    int n,m,h=0,l,r,d;
    scanf("%d%d",&n,&m);
    for(int j=1;j<=n;j++)
        f[j]=j;
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&l,&r,&d);
        h+=connect(l,r,d);//true失败
    }
    if(!h)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    string n;
    cin >> n;
    for(int i=0;i<3;i++){
        if(n[i]=='1'){
            n[i]='9';
        }else{
            n[i]='1';
        }
    }
    cout << n << endl;
}


Measured memory_bytes: 256
#include <iostream>

#define MAX 1000

using namespace std;

class Contest {
public:
  Contest() {}
  Contest(int _id, int _cost, int _vote) {
    id = _id;
    cost = _cost;
    vote = _vote;
  }

  bool compare_cost(int _cost) {
    return cost <= _cost;
  }

  bool compare_vote(int _vote) {
    return vote < _vote;
  }

  void output_id() {
    cout << id << endl;
  }

  void voting(int _vote) {
    vote += _vote;
  }

  int getVote() {
    return vote;
  }

private:
  int id, cost, vote;
};


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

  Contest *contests = new Contest[MAX];
  int cost;
  for(int i = 0; i < n; i += 1){
    cin >> cost;
    contests[i] = Contest(i+1, cost, 0);
  }

  for(int i = 0; i < m; i += 1) {
    cin >> cost;

    for(int j = 0; j < n; j += 1) {
      if(contests[j].compare_cost(cost)){
	contests[j].voting(1);
	break;
      }
    }
  }

  Contest contest = contests[0];
  for(int i = 1; i < n; i += 1) {
    if(contest.compare_vote(contests[i].getVote())){
      contest = contests[i];
    }
  }

  contest.output_id();

  delete[] contests;

  return 0;
}

Measured memory_bytes: 1204
////////////////////////////////////////////////////////////////
//
//    (☝ ՞ਊ ՞)☝ << Be accept!!
//
//    C++ format for competitive professional v1.0
//
//    need gcc & boost::c++
//
////////////////////////////////////////////////////////////////
//#define BOOST
#define CGCC
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#ifdef BOOST
#include<boost/multiprecision/cpp_int.hpp>// cpp_int
using namespace boost::multiprecision;
#endif
#define rep(i,n) for(int i = 0;i < n;i++)
using ll = long long;
using namespace std;
#ifdef CGCC
#pragma once
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
int inline setup(void) {//set
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return 0;
}
int lenght(char* str){//getcharlengh
    int i = 0;
    while (str[i]) {
        i++;
    }
    return i;
}
int gcd(long long a, long long b) {
    if (a < b)return gcd(b, a);
    long long r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
int iinput(void) {
    int a = 0;
    cin >> a;
    return a;
}
int dinput(void) {
    double a = 0;
    cin >> a;
    return a;
}
string sinput(void) {
    string a = "";
    cin >> a;
    return a;
}
int kuriup(double a) {
    int b = int(a);
    if (a != b) {
        return b+1;
    }
    else {
        return b;
    }
}
int kuridown(double a) {
    int b = int(a);
    return b;
}
#define DEBUG
int main(int argc, const char* argv[]) {
    setup();

    int n;
    cin>>n;
    vector<int> list(n);
    rep(i,n)cin>>list[i];

    sort(list.begin(),list.end());
    rep(i,n){
      if(list[i] == list[i+1]){
          cout<<"NO"<<endl;
          return 0;
        }
    }

    cout<<"YES"<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;

	int coin = 0, count = 0;
	while(true){
		count++;
		coin += (count%7!=0) ? a : a + b;
		if(coin>=c) break;
	}
	
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3112
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;


int func(P arr[] , int n , int total){


    int dp[n][total+1] = {};

    for(int i=0; i<=total; i++) {
        dp[0][i] = 0;
    }

    dp[0][arr[0].F] = arr[0].S;


    for(int i=1; i<n; i++) {

        for(int j=0; j<=total; j++) {

            //if we do not take the curr value
            dp[i][j] = dp[i-1][j];


                //if we take the curr value
            if(j >= arr[i].F)
                dp[i][j] = max(dp[i][j] , arr[i].S + dp[i - 1][j - arr[i].F]);
        }
    }

    int ans = 0;

    for(int i=0; i<=total; i++) {

        ans = max(dp[n-1][i] , ans);
    }

    return ans;
}

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n>>a;
    P arr[n];
    for(int i=0;i<n;i++){
      cin>>arr[i].F;
      cin>>arr[i].S;
    }

    ans = func(arr , n , a);

    cout<<ans<<endl; 
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 78336
#! /usr/bin/env python3

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N = int(readline())
ans = ""

while N > 0:
    N -= 1
    ans = chr(97 + N % 26) + ans
    N //= 26

print(ans)


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

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    vector<char> row(w,'.');
    vector<char> row2(w,'x');
    REP(i,h){
        REP(j,w){
            cin >> a.at(i).at(j);
        }
        if(a.at(i) == row){
            a.at(i) = row2;
        }
    }
    REP(j,w){
        bool flag = true;
        REP(i,h){
            if(a.at(i).at(j) == '#')flag = false;
        }
        if(flag){
            REP(i,h)a.at(i).at(j) = 'x';
        }
    }
    REP(i,h){
        bool flag = false;
        REP(j,w){
            char out = a.at(i).at(j);
            if(out != 'x'){
                flag = true;
                cout << out;
            }
        }
        if(flag)cout << endl;
    }
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<usize>();
    let l = {
        let mut temp = (0..n).map(|_| input()).collect::<Vec<i64>>();
        temp.sort();
        temp
    };

    let ans = if l[n - 1] < l.iter().take(n - 1).sum() {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
string OUT(int a) {
	string res;
	while (a > 0) {
		res.push_back((a % 10) + '0');
		a /= 10;
	}
	while ((int)res.size() < 12) {
		res.push_back('0');
	}
	reverse(res.begin(), res.end());
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<pair<int,int> > > A(N);
	int p, y;
	for (int i = 0; i < M; i++) {
		cin >> p >> y;
		p--;
		A[p].emplace_back(y, i);
	}
	vector<int> res(M);
	for (int i = 0; i < N; i++) {
		sort(A[i].begin(), A[i].end());
		for (int j = 0; j < A[i].size(); j++) {
			res[A[i][j].second] = (j + 1) + 1000000 * (i + 1);
		}
	}
	for (int i = 0; i < res.size(); i++) {
		cout << OUT(res[i]) << endl;
	}
}

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

long int gcd(long int a, long int b) {
    while(true) {
        if(a < b) swap(a, b);
        if(!b) break;
        a %= b;
    }
    return a;
}

int main() {
    int N, X;
    cin >> N >> X;
    long int town[(int)1e5 + 1];
    for (int i = 0; i < N; ++i) {
        cin >> town[i];
        town[i] = abs(X - town[i]);
    }
    long int minimum = town[0];
    for (int i = 0; i < N - 1; ++i) {
        minimum = min(minimum, gcd(town[i], town[i + 1]));
    }
    cout << minimum << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int gcd(int a,int b){
	if(b==0)return a;
	
	return gcd(b,a%b);
}	
int main(){
	int w,h,c;
	cin>>w>>h>>c;
	int x=w*h/gcd(w,h);
	cout<<x/w*x/h*c<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define N 200005 
#define MOD 2019
#define ll long long 
int n,s,vs[MOD];ll ans;char a[N];
int main()
{
	vs[0]=1;scanf("%s",a+1);n=strlen(a+1);
	for(int i=n,t=1;i>=1;--i,t=t*10%MOD)
		s=(s+(a[i]-'0')*t)%MOD,ans+=vs[s],++vs[s];
	printf("%lld\n",ans);return 0;
}

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep2(i,n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using vi = vector<int>;
template <class T>
using Grid = vector<vector<T>>;

int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = v[0];
    for (int i = 1; i < N; i++) {
        ans = (ans + v[i]) / 2.0;
    }
    printf("%.12f\n", ans);
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstring>
#include <deque>
using namespace std;
int main()
{
  deque <char> str;
  char s[10000000];
  cin>>s;
  int i;
  for(i=0;i<strlen(s);i++)
  {
    str.push_back(s[i]);
  }
  int q;
  cin>>q;
  int parity=0;
  while(q--)
  {
  	
    int f;
    cin>>f;
    if(f==1)
      parity=parity^1;
    if(f==2)
    {
    	
      int x;
      char ch;
      cin>>x;
      cin>>ch;
      if(x==1)
      {
      	if(parity==1)
        str.push_back(ch);
      else
         str.push_front(ch);
      }
      else
      {
      	if(parity==0)
        str.push_back(ch);
      else
         str.push_front(ch);
      }
      
    }
  }
   if(parity==0)
        {
        	for(auto i=str.begin();i!=str.end();++i)
        	{
        		cout<<*i;
        	}
        }
   else
         {
         	for(auto i=str.rbegin();i!=str.rend();++i)
        	{
        		cout<<*i;
        	}
         }
  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

#define INF 1e18 + 7

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

    std::vector<long long> r(n);
    for(int i = 0; i < n; ++i){
        std::cin >> r.at(i);
    }

    long long min = (long long)INF, diffMax = (long long)-INF;
    for(int i = 0; i < n; ++i){
        // The minmum element of "vec" is set as "min" in the former steps of each loop.
        // Therefore, "r.at(i) - min" expresses a maximum variance at each step, and comparing the value with diffMax garantees that the diffMax after the final comparison is the maximum variance amid every step.
        diffMax = std::max(diffMax, r.at(i) - min);
        min = std::min(min, r.at(i));
    }
    
    std::cout << diffMax << std::endl;

    return 0;
}


Measured memory_bytes: 4432
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main() {
  int a, b;
  // int mt;
  // vector<int> m;

  cin >> a >> b;
  // for (int i = 0; i < n; ++i) {
  //   cin >> mt;
  //   m.push_back(mt);
  // }
  // for (auto l : m) {
  //   cout << l << endl;
  // }

  vector<int> v;
  v.push_back(0);
  v.push_back(1);
  for (auto i = 2; i < 1000; ++i) {
    v.push_back(i+v[i-1]);
  }

  int d = b-a;
  int rec = -1;
  for (int i = 2; i < 1000; ++i) {
    int df = v[i] - v[i-1];
    if(df==d){
      rec=i;
    }
  }

  cout<<v[rec]-b<<endl;
  // int minn = *min_element(p.begin(), p.end());
  // cout << minn << endl;
}


Measured memory_bytes: 256
r,c = map(int,input().split())
a = [[0]*c for i in range(r+1)]
for i in range(r):
    a[i] = list(map(int,input().split()))
for j in range(c):
    for i in range(r):
        a[r][j] += a[i][j]
for i in range(r+1):
        ans = 0
        for j in range(c):
            ans += a[i][j]
            print(a[i][j],end=' ')
        print(ans)


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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

ll tim[200200];

signed main()
{
	ll T;
	int N;
	cin >> N >> T;
	rep(i, N) cin >> tim[i];
	sort(tim, tim+N);
	ll now = 0;
	ll res = 0;
	rep(i, N) {
		res += min(tim[i] + T - now, T);
		now = tim[i] + T;
	}
	cout << res << endl;

}



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

int check(long s);

long p[80000],pc=0;

int main(void){
	long n,i,ans;
	
	while(scanf("%ld",&n)!=EOF){
		ans=0;
		
		for(i=2;i<=n;i+=2){
			if(check(i)==0)ans++;
			if(i==2)i-=1;
		}
		
		printf("%d\n",ans);
		
	}
	return 0;
}


int check(long s){
	long i;
	
	if(s%2==0 && s!=2)return -1;
	
	i=sqrt(s);
	if(i*i==s)return -1;
	
	for(i=0;i<pc;i++){
		if(p[i]>sqrt(s))break;
		if(s%p[i]==0)return -1;
	}
	
	if(s>p[pc-1] || pc==0){
		p[pc]=s;
		pc++;
	}
	
	return 0;
}

Measured memory_bytes: 712
#include <stdio.h>

int main(){
	int a,b;
	int i,j;
	
	int cards[13] = {2,3,4,5,6,7,8,9,10,11,12,13,1};
	
	scanf("%d %d",&a,&b);
	
	for(i=0;i<13;i++) if(a==cards[i]) break;
	for(j=0;j<13;j++) if(b==cards[j]) break;
	
	if(i>j){
		printf("Alice\n");
	}else if(i<j){
		printf("Bob\n");
	}else{
		printf("Draw\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#if __has_include(<string_view>)
#include <string_view>
#endif
#if __has_include(<optional>)
#include <optional>

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

using namespace std;

template <class T>
constexpr const T& max(const T& a, const std::optional<T>& b)
{
    return b ? max(a, *b) : a;
}

template <class T>
constexpr const T& max(const std::optional<T>& a, const T& b)
{
    return a ? max(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& max(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a > *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

template <class T>
constexpr const T& min(const T& a, const std::optional<T>& b)
{
    return b ? min(a, *b) : a;
}

template <class T>
constexpr const T& min(const std::optional<T>& a, const T& b)
{
    return a ? min(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& min(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a < *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

#endif
#if __has_include(<any>)
#include <any>
#endif

template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
istream& operator>>(istream& is, valarray<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::priority_queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::stack<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

void solution()
{
    int n;
    cin >> n;
    vector<int> as(n);
    cin >> as;
    int64_t max_a = 0;
    int64_t buf = 0;
    for(int64_t a : as){
        max_a = max(a, max_a);
        buf += max(max_a - a, int64_t(0));
    }
    cout << buf << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>
int main(int argc, char const *argv[])
{
  int a,b,c;
  int x,y;
  int i,j,k;
  int n=0;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&x);
  for(i=0;i<a+1;i++){
    if(i*500>x) break;
    for(j=0;j<b+1;j++){
      y=x-i*500-j*100;
      if(y<0) break;
      if(y<=50*c) n++;
    }
  }
  printf("%d",n);
  return (0);
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); ++(i))
typedef long long ll;
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pair<int, int> > t(n);
  rep(i, n){
    cin >> t[i].second >> t[i].first;
  }

  sort(t.begin(), t.end(), greater<pair<int,int> >());

  vector<int> limit(n);
  limit[0] = t[0].first - t[0].second;
  for(int i = 1;  i < n; ++i){
    limit[i] = min(limit[i - 1], t[i].first) - t[i].second;
  }

  string s = "Yes";
  if(limit[n -1 ] < 0){
    s = "No";
  }

  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n, m; cin >> n >> m;
	P e[100000];
	rep(i, m){
		int a, b; cin >> a >> b; a--; b--;
		e[i] = { a,b };
	}
	sort(e, e + m);
	int cnt = 0;
	int now = 0;
	while (now < m) {
		int y = e[now].second;
		while (now < m&&e[now].first < y) {
			now++; y = min(y, e[now].second);
		}
		cnt++;
	}
	cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main(){
  int adj[4][2]={{-1,0},{+1,0},{0,-1},{0,+1}};
  int H,W;cin>>H>>W;
  vector<vector<int>>dist(H,vector<int>(W,-1));
  queue<pair<int,int>>q;
  for(int i=0;i<H;i++){
    string s;cin>>s;
    for(int j=0;j<W;j++){
      if(s[j]=='#'){dist[i][j]=0;q.push(pair<int,int>(i,j));}
    }
  }
  //幅優先
  int ans=0;
  while(q.size()){
    pair<int,int>yx=q.front();q.pop();
    for(int i=0;i<4;i++){
      if(yx.first+adj[i][0]>=0 && yx.first+adj[i][0]<H 
         && yx.second+adj[i][1]>=0 && yx.second+adj[i][1]<W 
         && dist[yx.first+adj[i][0]][yx.second+adj[i][1]]==-1){
        dist[yx.first+adj[i][0]][yx.second+adj[i][1]]=dist[yx.first][yx.second]+1;
        q.push(pair<int,int>(yx.first+adj[i][0],yx.second+adj[i][1]));
        ans=max(ans,dist[yx.first+adj[i][0]][yx.second+adj[i][1]]);
      }
    }
  }
  cout<<ans;
  
  
  
}

Measured memory_bytes: 12432
k,a,b = map(int,input().split())

if k <= a:
    print(k+1)
    exit()

kouho = [k+1]
k = k - (a-1)
r = a
if a+2 <= b:
    r += (k//2)*(b-a)+k%2
kouho.append(r)
print(max(kouho))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long  int
#define all(x) (x).begin(), (x).end()
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
// #define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
// getting string line
// getline(cin,word);
// -> priority_queue < int > pq; // max_heap
// -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap


ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}

template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}

struct Triplet{
    ll x,y,z;
};

ll modularexpo(ll x,ll n,ll mod){
    ll res = 1;
    while(n>0){
        if(n%2==1){
            res = (res*x)%mod;
        }
        x = (x*x);
        n = n/2;
    }
    return res;
}

ll n;
ll dp[1000005][2][2];

ll func(ll i,ll f,ll g){
    if(f==1 && i==n && g==1){
        return 1;
    }
    if(i==n){
        return 0;
    }
    if(dp[i][f][g]!=-1){
        return dp[i][f][g];
    }
    ll ans = 0;
    for(int j=0;j<=9;j++){
        if(j==0)
            ans = (ans+func(i+1,1,g))%mod;
        else if(j==9){
            ans = (ans+func(i+1,f,1))%mod;
        }
        else{
            ans = (ans+func(i+1,f,g))%mod;
        }
    }
    return dp[i][f][g] = ans;
}

int main(){
    cin>>n;
    memset(dp,-1,sizeof(dp));
    cout<<func(0,0,0)%mod<<endl;
    
    return 0;
}

Measured memory_bytes: 112748