akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main() {
    long lns[100000];
    std::queue<long> q;
    for (int i=1;i<=9; i++) {
        q.push(i);
    }
    int i = 0;
    while (!q.empty() && i < 100000) {
        long n = q.front();
        q.pop();
        lns[i] = n;
        int last = n % 10;
        if (last == 0) {
            q.push(n*10 + last);
            q.push(n*10 + last+1);
        } else if (last == 9) {
            q.push(n*10 + last-1);
            q.push(n*10 + last);
        } else {
            q.push(n*10 + last-1);
            q.push(n*10 + last);
            q.push(n*10 + last+1);
        }
        i += 1;
    }
    int k;
    std::cin >> k;
    std::cout << lns[k-1] << std::endl;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define run  ios_base::sync_with_stdio(false);cin.tie(NULL);
  //  mid =(l+r) >> 1 


  
int main()
 {

 ll n,i,m;
 cin>>n>>m;
 ll a[m],b[m],c=0;
 
 for(i=0;i<m;i++)
    cin>>a[i]>>b[i];
    
    ll h[100009];
    for(i=0;i<100009;i++)
        h[i]=1;

  ll  red[100009]={0};
      red[1]=1;
  
    for(i=0;i<m;i++)
    {
      if(red[a[i]]!=0)
      {
          if(h[a[i]]==1)
          {
             red[a[i]]=0;
             
             if(red[b[i]]==0)
                red[b[i]]++;
             
          }
             
          else if(h[a[i]]>1&&red[b[i]]==0)
                  red[b[i]]++;
      }
      h[a[i]]--;
      h[b[i]]++;
      
    }
    
   // for(i=0;i<100009;i++)
    //  cout<<red[i]<<" ";
     // cout<<endl;
      
    for(i=0;i<100009;i++)
    {
        if(red[i]==1)
          c++;
    }
   cout<<c;
 }

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

using namespace std;

int main (void) {
    int N, M;
    cin >> N >> M;
    int a;
    priority_queue<int> q;
    for ( int i=0; i<N; i++ ) {
        cin >> a;
        q.push(a);
    }

    int a_max;
    for ( int i=0; i<M; i++ ) {
        a_max = q.top(); q.pop();
        q.push(a_max / 2);
    }

    long long ans = 0;
    for ( int i=0; i<N; i++ ) {
        ans += q.top(); q.pop();
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include <iostream>

#include <unordered_set>

using std::cin;
using std::cout;
using std::endl;

using std::unordered_set;

int
main()
{
  int N;
  cin >> N;
  unordered_set<int> A;
  for (int n = 0; n < N; n++)
  {
    int a;
    cin >> a;
    if (A.find(a) == A.end())
    {
      A.insert(a);
    }
    else
    {
      A.erase(a);
    }
  }
  cout << A.size() << endl;
  return 0;
}


Measured memory_bytes: 4388
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

const int DR[] = {0, 0, 1, -1};
const int DC[] = {1, -1, 0, 0};
struct Tag {
    int r, c, distance;
    Tag() {}
    Tag(int r, int c, int d) : r(r), c(c), distance(d) {}
};
bool visited[1000][1000];

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

    int H, W, N;
    cin >> H >> W >> N;
    vector<string> field(H);
    pair<int,int> cur;
    for(int i = 0; i < H; ++i) {
        cin >> field[i];
        size_t spos = field[i].find('S');
        if(spos != string::npos) {
            cur = make_pair(i, spos);
        }
    }
    int ans = 0;
    for(int target = 1; target <= N; ++target) {
        for(int i = 0; i < H; ++i) {
            fill_n(visited[i], W, false);
        }
        Tag route;
        queue<Tag> q;
        q.push(Tag(cur.first, cur.second, 0));
        while(!q.empty()) {
            Tag t = q.front();
            q.pop();
            for(int i = 0; i < 4; ++i) {
                int nr = t.r + DR[i];
                int nc = t.c + DC[i];
                if(0 <= nr && nr < H && 0 <= nc && nc < W) {
                    if(field[nr][nc] != 'X' && !visited[nr][nc]) {
                        visited[nr][nc] = true;
                        if(field[nr][nc] == '0'+target) {
                            route = Tag(nr, nc, t.distance+1);
                            goto found;
                        }
                        q.push(Tag(nr, nc, t.distance+1));
                    }
                }
            }
        }
found:
        ans += route.distance;
        cur = make_pair(route.r, route.c);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[200010];
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    int mi=INF,ans=0;
    rep(i,n){
        if(mi>a[i]){
            mi=a[i];
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  string s;
  int tmp;
  bool flag;

  cin >> s;
  flag = true;

  for (int i = 0; i < s.length(); i++)
  {
    tmp = 0;
    for (int j = 0; j < s.length(); j++) 
    {
      if (s[j] == s[i]) tmp++;
    }

    if (tmp%2 != 0)
    {
        flag = false;
        break;
    } 
  }

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

Measured memory_bytes: 504
n,W = map(int,input().split())
w1,v = map(int,input().split())
c = [[] for _ in range(4)]
c[0].append(v)
for i in range(n-1):
    w,v = map(int,input().split())
    c[w-w1].append(v)

for i in c:
    i.sort(reverse=True)
#print(c)
l = [len(c[i]) for i in range(4)]
sum_c = []
for _ in range(4):
    k = [0]
    for i in range(l[_]):
        k.append(k[-1] + c[_][i])
    sum_c.append(k)
ans = 0
for p1 in range(l[0]+1):
    for p2 in range(l[1]+1):
        for p3 in range(l[2]+1):
            for p4 in range(l[3]+1):
                now = w1*p1+(w1+1)*p2+(w1+2)*p3+(w1+3)*p4
                if now<=W:
                    ans = max(ans,sum_c[0][p1]+sum_c[1][p2]+sum_c[2][p3]+sum_c[3][p4])
                    #print(p1,p2,p3,p4)


print(ans)

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

int inv(int x) {
    return ppow(x, mod - 2);
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    sort(all(a));
    vector<int> pref(n);
    for (int i = 0;i < n;i++) {
        pref[i] = a[i];
        if (i) {
            pref[i] += pref[i - 1];
        }
    }

    vector<int> len(n);

    for (int i = 0;i < n - 1;i++) {
        len[i] = pref[n - 1] - pref[i] - pref[n - 2 - i];
        len[i] %= mod;
        if (len[i] < 0) {
            len[i] += mod;
        }
    }

    int MAXN = 1e5 + 100;
    vector<int> fac(MAXN), invert(MAXN);
    fac[0] = 1;
    invert[0] = 1;
    for (int i = 1;i < MAXN;i++) {
        (fac[i] = fac[i - 1] * i) %= mod;
        (invert[i] = invert[i - 1] * inv(i)) %= mod;
    }

    int ans = 0;
    auto cc = [&](int n, int k) {
        return fac[n]*invert[n - k]%mod*invert[k]%mod;
    };

    for (int i = 0;i < n;i++) {
        int cur = len[i];
        if (i >= k - 2) {
            //cout << cur << '\n';
            cur *= cc(i, k -2);
            cur %= mod;
            ans += cur;
            ans %= mod;
        }
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long int n;
  scanf("%ld",&n);
  long int ans=n*(n+1)/2;
  long int i,sum=0;
  
  for(i=5;i<=n;i+=5)
     {
         if(i%3==0)
           continue;
           
         else
           sum+=i;
     }
     
    for(i=3;i<=n;i+=3)
      {
          sum+=i;
      }
      
    cout<<ans-sum;  
     
  
}

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

using ll = long long;

ll mod_pow(ll x, ll n, ll p) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) {
            res = (res * x) % p;
        }
        x = (x * x) % p;
        n >>= 1;
    }
    return res;
}

template <typename T>
class fenwick_tree {
public:
    fenwick_tree(int n) : n(n), dat(n, 0) {}

    void add(int i, T value) {
        for(; i<n; i |= i + 1) {
            dat[i] += value;
        }
    }

    T sum(int i, ll M) const {
        T res = 0;
        for(; i>=0; i = (i & (i+1)) - 1) {
            (res += dat[i]) %= M;
        }
        return res;
    }

    T sum(int l, int r, ll M) const {
        return sum(r-1, M) - sum(l-1, M);
    }

private:
    const int n;
    std::vector<T> dat;
};

int main() {
    ll A, B, P;
    while(cin >> A >> B >> P, A) {
        const ll L = B - A + 1;
        vector<string> s(L);
        for(ll i=A; i<=B; ++i) {
            s[i-A] = to_string(i);
        }
        sort(s.begin(), s.end());
        fenwick_tree<ll> bit(L);
        ll res = 0;
        for(int i=0; i<L; ++i) {
            ll r = stol(s[i]) - A;
            ll t = bit.sum(0, r, P);
            assert(t >= 0);
            (res += t + 1) %= P;
            bit.add(r, t + 1);
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define ll long long int
#define vl vector<ll> 
#define loop(i,a,b) for(ll i=a; i<b; i++)
using namespace std;
#define MAXN 1000001
#define MOD 1000000007
void solve(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum=0;
    if(k<=a){
        cout<<k;
        return;
    }
    else if(k<=a+b){
        cout<<a;
        return;
    }
    else{
        sum+=a;
        k-=(a+b);
        sum-=k;
        cout<<sum;
    }

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

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <queue>

using namespace std;
string str, tmp;
int K;
unordered_set<string> vs;
priority_queue<string> pq;

bool flag = false;

void work() {
	int ind = 0;
	for (int i = 0; i < str.size(); i++) {
		for (int j = i; j < str.size(); j++) {
			int len = j - i + 1;
			if (len > K) {
				continue;
			}
			tmp = str.substr(i, len);
			if (vs.count(tmp))
				continue;
			vs.insert(tmp);
			if (ind < K)
				pq.push(tmp);
			else {
				if (pq.top() > tmp) {
					pq.pop();
					pq.push(tmp);
				}
			}
			ind++;
		}
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> str >> K;
	work();

	cout<<pq.top()<<endl;
	return 0;
}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

def numberlize(n):
    k="000000"
    u=6-len(str(n))
    return k[0:u]+str(n)
#print(numberize(5))
    
    
n,m=MI()
lis=[[]for i in range(n)]
for i in range(m):
    a,b=MI()
    lis[a-1].append([i+1,b])
#print(lis)
for j in range(n):
    lis[j]=sorted(lis[j],key=lambda x:x[1])
    for k in range(len(lis[j])):
        lis[j][k][1]=k+1
#print(lis)

ans=[0 for i in range(m)]
for j in range(n):
    for s in lis[j]:
        ans[s[0]-1]=[j+1,s[1]]
#print(ans)
for a in ans:
    print(numberlize(a[0])+numberlize(a[1]))

Measured memory_bytes: 42664
def main():
    s = input()
    n = len(s)
    a = 0
    b = 0
    for i in range(n):
        if i & 1:
            if s[i] == '1':
                a += 1
            else:
                b += 1
        else:
            if s[i] == '1':
                b += 1
            else:
                a += 1
    print(min(a, b))
    return 0
main()

Measured memory_bytes: 3188
#include<iostream>
#include<stdlib.h>
using namespace std;
int main(){
	int long long a;
	cin>>a;
	int d=642,e;
	while(a>99){
		e=a%1000;
		if(d>abs(753-e))
			d=abs(753-e);
		if(d==0)
			break;
		a=a/10;
	}
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DSL_3_D: Sliding Minimum Elements
# heapq and lazy delete

from heapq import heappush, heappop


def run():
    _, size = [int(x) for x in input().split()]
    heap = []
    removed = set()
    result = []
    n = 0
    for i, v in enumerate(input().split()):
        heappush(heap, (int(v), i))
        n += 1
        if n > size:
            removed.add(i - size)
            n -= 1

        if n == size:
            while len(heap) > 0:
                minv, k = heap[0]
                if k in removed:
                    removed.remove(k)
                    heappop(heap)
                else:
                    result.append(str(minv))
                    break
    print(" ".join(result))


if __name__ == '__main__':
    run()



Measured memory_bytes: 363864
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){const int mm=1000000007;x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()

pi comp(pi x) {
	int a=x.fi,b=x.se;
	int s=(a/abs(a))*(b/abs(b));
	int g = gcd(abs(a),abs(b));
	a = abs(a); b = abs(b);
	a /= g, b /= g;
	pi t;
	t.fi = -s*b; t.se = a;
	return t;
}

int__ main() {
	fast;

	int n; cin >> n;
	int mod = 1000000007;
	map<pi,int> mp;

	for(int i=0;i<n;i++) {
		int a,b; cin >> a >> b;
		if(a==0 and b==0) {
			mp[{0,0}]++; continue;
		}

		if(a==0){
			mp[{0,1}]++;
			continue;
		}
		if(b==0) {
			mp[{1,0}]++;
			continue;
		}

		int s=(a/abs(a))*(b/abs(b));
		int g = gcd(abs(a),abs(b));
		a = abs(a); b = abs(b);
		a /= g, b /= g;
		mp[{s*a,b}]++;
	}

	int ans=1;
	map<pi,int> vis;
	for(auto y:mp) {
		pi x = y.fi;
		if(x.fi==0 or x.se==0) continue;
		if(vis[x] or vis[comp(x)]) continue;
		pi cmp = comp(x);
		vis[x]++; vis[cmp]++;

		int t = Pow(2,mp[x]);
		t += Pow(2,mp[cmp]);

		t %= mod;

		t = Mod(t-1);

		ans = Mod(ans * t);
	}

	// 1,0 cases
	int t = Pow(2,mp[{1,0}]);
	t += Pow(2,mp[{0,1}]);

	t %= mod;

	t = Mod(t-1);

	ans = Mod(ans * t);


	cout << Mod((ans-1) + mp[{0,0}]) << endl;
}

Measured memory_bytes: 53548
#include <stdio.h>
int main(void)
{
	int S;
	scanf("%d", &S);
    
	int m, h;
	m = S / 60;
	S %= 60;
	h = m / 60;
	m %= 60;
	printf("%d:%d:%d\n",h,m,S);
    return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e6+7;
int n,k;
ll ans;
int tot;
int x;
int sum;
bool vis[maxn];
int main()
{

    scanf("%d",&n);
    sum=inf;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x<0) tot++;
        sum=min(sum,abs(x));
        ans+=abs(x);
    }
    if(tot%2==0)
        printf("%lld\n",ans);
    else
        printf("%lld\n",ans-sum-sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define umpl unordered_map<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 2e18
#define EPS 1e-3
#define PI 3.1415926535897932385
const double h = 1e-6;
const int MAX_  = 100005;
#define display(v) f(v.size())cout << v[i] << " "
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
ll dp[405][405];

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   int n;   cin>> n;
   vi arr(n);   f(n)cin>>arr[i];
   ll pre[n];   pre[0] = arr[0];
   for(int i =1;i<n;i++)
   {
       pre[i] = pre[i-1] + arr[i];
   }
   for(int l = n-1;l>=0;l--)
   {
       for(int r = l ; r  < n;r++)
       {
           if(l==r)
           {
               dp[l][r] = 0;
           }
           else
           {
               ll sum = 0;
               dp[l][r] = inf;
               if(l!=0)
               {
                   sum = pre[r] - pre[l-1];
               }
               else
               {
                   sum = pre[r];
               }
               for(int i =l;i<=r-1;i++)
               {
                   dp[l][r] = min(dp[l][r] , dp[l][i] + dp[i+1][r] + sum);
               }
               
           }
           
       }
   }
   cout << dp[0][n-1];
   
   return 0;
}

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

int main() {
	long long int N, W;
	cin >> N >> W;
	vector<long long int> w(N, 0), v(N, 0);
	for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];
	vector<vector<long long int> >dp(N+1, vector<long long int>(W+1, 0));
	for(int i = 1; i <= N; ++i){
		for(int j = 1; j <= W; ++j){
			dp[i][j] = max(dp[i-1][j], j-w[i-1] >= 0 ? dp[i-1][j - w[i-1]] + v[i-1] : dp[i][j-1]);
		}
	}
	cout << dp[N][W];
	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  cin >> n;
  VI a(n+1),b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];
  
  ll sum=0;
  rep(i,n){
    if(b[i] <= a[i]){
      sum += b[i];
      a[i] -= b[i];
    }else{
      sum += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if(b[i] <= a[i+1]){
        sum += b[i];
        a[i+1] -= b[i];
      }else{
        sum += a[i+1];
        b[i] -= a[i+1];
        a[i+1] = 0;
      }
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 1024
N,M,K = map(int,input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
a.insert(0,0)
b.insert(0,0)
b_num = sum(b)
b_best = M
j = M
a_num = 0
maxmize = 0
for i in range(N+1):
  #print(i)
  X = 0
  a_num += a[i]
  if a_num>K:
    break
  X +=a_num
  handan = True
  j = b_best
  while handan ==True:
    #print('max',maxmize)
    X +=b_num
    #print(X,K)
    if X<=K:
      b_best = j
      maxmize = max(i+j,maxmize)
      handan=False
    else:
      X -=b_num
      b_num -=b[j]
      j-=1
    #print('max1',maxmize)
    
print(maxmize) 

Measured memory_bytes: 111012
import sys

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


def main():
    n, q = list(map(int, readline().split()))
    event = [0] * (2 * n + q)

    for i in range(n):
        s, t, x = list(map(int, readline().split()))
        event[i * 2] = (s - x, x, 0)
        event[i * 2 + 1] = (t - x, x, 1)

    for i in range(q):
        d = int(input())
        event[2 * n + i] = (d, 0, 2)

    from operator import itemgetter
    event.sort(key=itemgetter(0))
    stop = set()
    res = INF

    for t, x, ev_type in event:
        if ev_type == 0:
            stop.add(x)
            if res == -1:
                res = x
            elif res > x:
                res = x
        elif ev_type == 1:
            stop.discard(x)
            if res == x:
                if stop:
                    res = min(stop)
                else:
                    res = -1
        else:
            if stop:
                print(res)
            else:
                print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 142108
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((b * 10 + c) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	int z;
	cin >> z;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int main() {
	int a, b;
	read(a), read(b);
	int d = b - a;
	writeln((1 + d) * d / 2 - b);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define WRAP(x,y,w,h) (0<=x && x<w && 0<=y && y<h)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n,n) {
		int w, h;
		cin >> w >> h;
		vvi cell(h,vi(w,0));
		REP(i, n) {
			int x, y;
			cin >> x >> y;
			x--;
			y--;
			cell[y][x]++;
		}
		int ans = 0;
		int s, t;
		cin >> s >> t;
		REP(i,h-(t-1)) {
			REP(j, w - (s - 1)) {
				int res = 0;
				REP(k,t)
					REP(l, s) {
					res += cell[i+k][j+l];
				}
				ans = max(ans, res);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3160
n = int(input())
j = [0]*4
s = []

for i in range(n):
    si = input()
    s.append(si)

for i in range(n):
    if s[i] == "AC":
        j[0] += 1
    elif s[i] == "WA":
        j[1] += 1
    elif s[i] == "TLE":
        j[2] += 1
    else :
        j[3] += 1

print("AC x "+str(j[0]))
print("WA x "+str(j[1]))
print("TLE x "+str(j[2]))
print("RE x "+str(j[3]))

Measured memory_bytes: 16276
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int x, y;
	cin >> x >> y;
	
	cout << gcd(x, y) << endl;

	return 0;
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 1e5+5;

int a[N], dp[N], k;

int calc (int n) {
	if (dp[n] == -1) {
		dp[n] = calc(n-1)+abs(a[n]-a[n-1]);
		for (int i = 2; i <= k; i++) {
			if (n-i >= 1)
			dp[n] = min(dp[n],calc(n-i)+abs(a[n]-a[n-i]));
		}
	}
	return dp[n];
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

    memset(dp, -1, sizeof(dp));
    int n;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
    	cin >> a[i];
    }
    dp[1] = 0;
    calc(n);
    cout << dp[n];
    return 0;
}

Measured memory_bytes: 29952
s=str(input())
if(int(s[:4])<2019):
    print('Heisei')
elif(int(s[:4])>2019):
    print('TBD')
elif(int(s[5:7])<4):
    print('Heisei')
elif(int(s[5:7])>4):
    print('TBD')
elif(int(s[8:])<=30):
    print('Heisei')
else:
    print('TBD')
    


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll) 1000000007
#define P pair<ll, ll>

ll cnt[110000], n, m;
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}
	REP(i, 110000) {
		if (cnt[i] % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
XY = [list(mapint()) for _ in range(N)]
XY.sort(key=lambda x:x[0]+x[1])
ans_1 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
XY.sort(key=lambda x:x[0]-x[1])
ans_2 = abs(XY[0][0]-XY[-1][0])+abs(XY[0][1]-XY[-1][1])
print(max(ans_1, ans_2))

Measured memory_bytes: 117628
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, M = zz()
X = zz()
X = sorted(X)
if (M <= N):
    print(0)
    exit()
distance = [0]*(M-1)
for i in range(M-1):
    # print(X[i+1] - X[i])
    distance[i] = X[i+1] - X[i]
distance = sorted(distance, reverse=True)
distance = distance[N-1:]
print(sum(distance))

Measured memory_bytes: 38288
#include<bits/stdc++.h>
 
using namespace std;
 
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define B begin()
#define E end()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define nl "\n"
#define fat 1000000007

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

    vector<vi> G(n + 1);
    for(int i = 0; i < m; i++)
    {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }

    double min_ = 1e9;
    vector<double> DP(n + 1, 0);
    vi max_child(n + 1, -1);
    for(int i = n - 1; i > 0; i--)
    {
        int size = 0;
        int idx = -1;
        double max = 0;
        loop(q, G[i])
        {
            DP[i] += DP[q];
            if(max < DP[q]) max = DP[q], idx = q;
            size++;
        }
        max_child[i] = idx;
        if(size) DP[i] /= size;
        DP[i]++;
    }
    min_ = DP[1];

    for(int j = 1; j < n; j++)
    {
        pii z = {j, max_child[j]};
        if((int)G[j].size()==1) continue;
        fill(DP.B, DP.E, 0.0);
        for(int i = n - 1; i > 0; i--)
        {
            int size = 0;
            loop(q, G[i])
            {
                if(i == z.F && q == z.S) continue;
               // if(q!=n && DP[q]==0)continue;
                DP[i] += DP[q];
                size++;
            }
            // if(size)
            // {
            DP[i] /= size;
            DP[i]++;
          //  }
            // else DP[i] = 0;
        }
        //if(DP[1]==0)continue;
        min_ = min(min_, DP[1]);
    }

    cout << fixed << setprecision(9) << min_ << nl;
    return 0;
}


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

int N;
int main(){
	cin >> N;
	long long ans = 0,val = 1,a;
	for(int i=0;i<N;i++){
		cin >> a;
		if(val<a){
			if(val==1){
				val++;
				ans += a-1;
			}else{
				ans += a/val;
				if(a%val==0) ans--;
			}
		}else{
			val = max(a+1,val);
		}
	}
	cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return result;
}



int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    IOS

    int h,w,k;
    cin>>h>>w>>k;
    char s[h][w];
    for(int i=0;i<h;i++)
    	for(int j=0;j<w;j++)
    		cin>>s[i][j];

    int mask1=1<<h,mask2=1<<w;
    int ans=0;

    for(int i1=0;i1<mask1;i1++)
    {
    	for(int j1=0;j1<mask2;j1++)
    	{
    		int black=0;
    		for(int i2=0;i2<h;i2++)
    			for(int j2=0;j2<w;j2++)
    				black+=!((i1>>i2)&1)&&!((j1>>j2)&1)&&(s[i2][j2]=='#');

    		ans+=(black==k);
    	}
    }

    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll n, d;
	cin >> n >> d;
	ll ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		ll x, y;
		cin >> x >> y;
		ll s = sqr(x) + sqr(y);
		if(d*d >= s)
			ans ++;
	}
	cout << ans;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<utility>
#include<vector>
using namespace std;

int solve(){
  float a, b; cin >> a >> b;
  for(int i=12; i<=1000; i++){
    if((int)(0.08*(float)i)==a && (int)(0.1*(float)i)==b){
       cout << i << endl;
       return 0;
     }
  }
  cout << -1 << endl;
  return 0;
}

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


Measured memory_bytes: 256
// AtCoder-Template.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define FORREV(i,N,_cnt) for(auto i=N-1,cnt=_cnt; cnt > 0; --i, --cnt)
#define ALL(x) x.begin(), x.end()



int main() {

	ll N; cin >> N;
	vector<ll> A(N); FOR(i, N) cin >> A[i];
	ll ans = 0;
	vector<ll> POS(N+1, -1);
	vector<ll> NEXT(N+1, -1);  // NEXT[i] = iよりも大きい方から降ってきた自分より大きいものの、最大のインデックス-1
	vector<ll> PREV(N+1, -1);  // PREV[i] = iよりも小さい方から降ってきた自分より大きいものの、最小のインデックス+1

	FOR(i, N) {
		POS[A[i]] = i; // A[i] の位置はi 
		NEXT[i] = i + 1; // 
		PREV[i] = i - 1; 
	}
	//FOR(i,N+1) {
	//}

	FOR(_i, N) {
		auto i = N - 1 - _i;
		auto ip1 = N - _i;
		auto indx = POS[ip1];  
		
		auto up = NEXT[indx] - indx;
		auto down = indx - PREV[indx];
		//ans += ip1 * (NEXT[indx] - indx) * (indx - PREV[indx]); // 初期状態だと、これはどちらも1になる。
		auto amount = ip1 * up * down;
		ans += amount;


		if ( NEXT[indx] < N)
			PREV[NEXT[indx]] = PREV[indx];
		if (PREV[ indx ] >= 0)
			//NEXT[indx - 1] = NEXT[indx];
			NEXT[PREV[indx]] = NEXT[indx];

			//PREV[indx + 1] = PREV[indx];
	}
	

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;
        const int N=500;
        void solve()
        {
            ll i,j,k,n,m,c=0,ans=0;
            string s;
            cin>>n>>m>>k;
            vector < ll > v1(n),v2(m);
            rep(i,0,n) cin>>v1[i];
            rep(i,0,m) cin>>v2[i];
            vector < ll > pre(n),pre1(m);
            pre[0]=v1[0];
            rep(i,1,n)
            {
                pre[i]=pre[i-1]+v1[i];
            }
              pre1[0]=v2[0];
            rep(i,1,m)
            {
                pre1[i]=pre1[i-1]+v2[i];
            }
            int id0=0,id1=0;
            ans=0;
            rep(i,0,n)
            {
                if(pre[i]<=k) {ans++; id0=i;}
                else break;
            } c=0;
            rep(i,0,m)
            {
                if(pre1[i]<=k) {c++; id1=i;}
                else break;
            }
            ans=max(ans,c);
            if(k>=pre[n-1]+pre1[m-1])
            {
                cout<<n+m; return;
            }
            if(ans==0)
            {
                cout<<0; return;
            }
            j=0;
            rep(i,0,m)
            {
                if(pre[id0]+pre1[i]<=k) ans=max(ans,id0+1+i+1);
                else break;
            }
           // cout<<ans<<endl;
            //cout<<id0<<" ";
            rep(i,0,m)
            {
                ll a1=0;
                //cout<<id0<<" ";
                if(id0-1-i>=0)
                {
                    a1=pre[id0-1-i];
                    ll rem=k-a1;
                    //cout<<a1<<" "<<rem<<endl;
                    while(j<m and rem>=pre1[j])
                    {
                        j++;
                    }
                    //if(j<m and rem<pre[j]) j--;
                    //cout<<j<<" ";
                   // cout<<id0+j<<endl;
                    
                    ans=max(ans,id0-i+j);
                }
                else break;
            }
            cout<<ans;




    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 9484
#include<bits/stdc++.h>
using namespace std;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<char>>P(H,vector<char>(W));
  for(int i=0;i<H;i++){
  string s;
    cin>>s;
    for(int j=0;j<W;j++)
      P.at(i).at(j)=s.at(j);
  }
  vector<vector<char>>P2(2*H,vector<char>(W));
  for(int i=0;i<2*H;i++){
  for(int j=0;j<W;j++)
  P2.at(i).at(j)=P.at(i/2).at(j);
  }for(int i=0;i<2*H;i++){
  for(int j=0;j<W-1;j++)
    cout<<P2.at(i).at(j);
    cout<<P2.at(i).at(W-1)<<endl;
  
  }
   return 0;
}

Measured memory_bytes: 256
n = int(input())
t_input = list(map(int,input().split()))
m = int(input())
ans_li = []
for i in range(m):
    p,x = map(int,input().split())
    tmp=0
    for i in range(n):
        if p-1==i:
            tmp+=x
        else:
            tmp+=t_input[i]
    ans_li.append(tmp)

for a in ans_li:
    print(a)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;



int main() {
	int N;

	cin >> N;
	vector<int> P(N);

	for (int i=0; i<N; i++) cin >> P.at(i);

	int cnt = 0;
	for (int i=0; i<N-2; i++) {
		if(P.at(i) < P.at(i+1) || P.at(i+2) < P.at(i+1)) {
			if(P.at(i+1) < P.at(i) || P.at(i+1) < P.at(i+2)) {
				cnt++;
			}
		}
	}
	

	cout << cnt;


}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;

struct Node {
  int value;
  Node* left;
  Node* right;
  Node* parent;
};
void print_pre_order(Node& root) {
  cout << " " << root.value;
  if (root.left)
    print_pre_order(*root.left);
  if (root.right)
    print_pre_order(*root.right);
}
void print_in_order(Node& root) {
  if (root.left)
    print_in_order(*root.left);
  cout << " " << root.value;
  if (root.right)
    print_in_order(*root.right);
}
void print_post_order(Node& root) {
  if (root.left)
    print_post_order(*root.left);
  if (root.right)
    print_post_order(*root.right);
  cout << " " << root.value;
}
int main() {
  IN(N);

  Node nodes[N];
  REP(i, N) {
    nodes[i].value = i;
    nodes[i].left = nullptr;
    nodes[i].right = nullptr;
    nodes[i].parent = nullptr;
  }
  REP(i, N) {
    IN(id);
    IN(left);
    IN(right);
    if (left != -1) {
      nodes[id].left = &nodes[left];
      nodes[left].parent = &nodes[id];
    }
    if (right != -1) {
      nodes[id].right = &nodes[right];
      nodes[right].parent = &nodes[id];
    }
  }
  int root = 0;
  while (nodes[root].parent)
    ++root;
  cout << "Preorder" << endl;
  print_pre_order(nodes[root]); cout << endl;
  cout << "Inorder" << endl;
  print_in_order(nodes[root]); cout << endl;
  cout << "Postorder" << endl;
  print_post_order(nodes[root]); cout << endl;

  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  string S;
  cin>>S;
  int N=S.size(),ans=0,cnt=0;
  for(int i=0;i<N;i++){
    if(S[i]=='B')
      cnt++;
    else
      ans+=cnt;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    int cnt[n+1];
    fill(cnt,cnt+n+1,0);
    rep(i,0,k){
        int d;cin>>d;
        rep(j,0,d){
            int a;cin>>a;
            cnt[a]++;
        }
    }
    int ans=0;
    rep(i,1,n+1)if(cnt[i]==0)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i=0; i<s.length(); i++) {
    if(s[i]=='C') {
      for(int j=i+1; j<s.length(); j++) {
        if(s[j]=='F') {
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

typedef long long ll;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll bef_x = -1;
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    ll x;
    cin >> x;
    if (bef_x != -1) { ans += min((x-bef_x)*a, b); }
    bef_x = x;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256