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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;

signed main() {
    cin >> N;
    int ans = 0;
    while (N != 0) {
        int cur = 1;
        int sei = 0, fu = 0;
        for (int i = 0; i < 40; i++) {
            if (cur > 0)sei += cur;
            else fu += cur;
            if (N > 0 && sei >= N || N < 0 && fu <= N) {
                ans += 1LL << i;
                N -= cur;
                goto check;
            }
            cur *= -2;
        }
check:;
    }
    if (ans == 0) {
        cout << ans << endl;
        return 0;
    }
    bitset<40> a(ans);
    bool flag = false;
    for (int i = 39; i >= 0; i--) {
        if (a[i])flag = true;
        if (flag)cout << a[i];

    } cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX

int n, m, q;
int a[51], b[51], c[51], d[51];
int ans = 0;

void s1(vi& curr, int p)
{
    if(curr.size()==n)
    {
        
        int ans1 = 0;
        rep(i,0,q-1)
        {
            if(curr[b[i]-1]-curr[a[i]-1]==c[i])
                ans1 += d[i];

        }
        ans = max(ans, ans1);
        return;
    }

    rep(i,p,m)
    {
        curr.pb(i);
        s1(curr, i);
        curr.pop_back();
    }
}

 
void solve()
{
    cin >> n >> m >> q;
    rep(i,0,q-1)
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    vi curr;
    s1(curr, 1);
    cout << ans << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3648
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	String s;

	void run(){
		for(int n=sc.nextInt(); n>0; n--){
			s=sc.next();
			println(equation(0).val+"");
		}
	}

	R equation(int p){
		R r=factor(p);
		for(;;){
			char c=s.charAt(r.p);
			if(c=='+'||c=='-'){
				R q=factor(r.p+1);
				if(c=='+')
					r.val+=q.val;
				else
					r.val-=q.val;
				r.p=q.p;
			}else{
				break;
			}
		}
		return r;
	}

	R factor(int p){
		R r=term(p);
		for(;;){
			char c=s.charAt(r.p);
			if(c=='*'||c=='/'){
				R q=term(r.p+1);
				if(c=='*')
					r.val*=q.val;
				else
					r.val/=q.val;
				r.p=q.p;
			}else{
				break;
			}
		}
		return r;
	}

	R term(int p){
		if(s.charAt(p)=='('){
			R r=equation(p+1);
			r.p++; // skip ')'
			return r;
		}else{
			boolean minus=false;
			if(s.charAt(p)=='-'){
				p++;
				minus=true;
			}
			long val=0;
			for(; Character.isDigit(s.charAt(p)); p++){
				val=val*10+(s.charAt(p)-'0');
			}
			if(minus){
				val=-val;
			}
			return new R(p, val);
		}
	}

	class R{
		int p;
		long val;

		R(int p, long val){
			this.p=p;
			this.val=val;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    
    int ans = 0;

    if (K < A) {
        ans = K;
    }
    else if (A <= K && K < A + B) {
        ans = A;
    }
    else if (A + B <= K && K <= A + B + C) {
        ans = A - (K - A - B);
    } 

    cout << ans << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int main(){
  int a,b,m;
  cin >> a >> b >> m;
  vector<int> ap(a);
  vector<int> bp(b);
  
  int amin = inf,bmin = inf;
  rep(i,a){
    cin >> ap.at(i);
    amin = min(amin,ap.at(i));
  }
  
  rep(i,b) {
    cin >> bp.at(i);
    bmin = min(bmin,bp.at(i));
  }
  
  int keep1 = amin + bmin;;
  int keep2 = inf;
  
  rep(i,m){
    int x,y,c;
    cin >> x >> y >> c;
    x--;
    y--;
    keep2 = min(keep2,ap.at(x)+bp.at(y)-c);
  }
  
  cout << min(keep1,keep2) << endl;
  
  
}

Measured memory_bytes: 1152
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program{
    static void Main(string[] args){
        var opss =
            from n1 in Enumerable.Range(0,2)
            from n2 in Enumerable.Range(0,2)
            from n3 in Enumerable.Range(0,2)
            select new List<int>(){n1, n2, n3};
        string s = Console.ReadLine();
        var nums = s.ToCharArray().Select(c => int.Parse(c.ToString()));
        var ans_ops = opss.First(ops => calc(nums, ops) == 7);
        Console.WriteLine(makeEquation(nums, ans_ops));
    }

    static int calc(IEnumerable<int> nums, IEnumerable<int> ops){
        int ans;
        int c = ops.Count();
        if(c == 0){
            ans = nums.First();
        }else{
            if(ops.Last() == 0){
                ans = calc(nums.Take(c), ops.Take(c-1)) + nums.Last();
            }else{
                ans = calc(nums.Take(c), ops.Take(c-1)) - nums.Last();
            }
        }
        return ans;
    }

    static string makeEquation(IEnumerable<int> nums, IEnumerable<int> ops){
        var numsTostr = nums.Select(i => i.ToString());
        var opsTostr = ops.Select(i => i == 0 ? "+" : "-");
        var eq = numsTostr.Take(1).Concat(numsTostr.Skip(1).Zip(opsTostr, (n, op) => op + n));
        return String.Join("", eq)+"=7";
    }
}


Measured memory_bytes: 13652
#include <stdio.h>

int main(void) {
    int a, b, c, k, i, max, tmp;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    
    max = a-b>=0 ? a : b;
    max = c-max>=0 ? c : max;
    tmp = a+b+c-max;
    for(i=0; i<k; i++) {
        max *= 2;
    }

    printf("%d", max+tmp);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
map<long long,int>ma;
long long n,a[1000010],ans;
long long sum[1000010];
int main()
{
	 cin>>n;ma[0]=1;
	 for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i];
	 for(int i=1;i<=n;i++)
	 {
	 	ans+=ma[sum[i]];
	 	ma[sum[i]]++;
	 }
	 cout<<ans;
	 return 0;
}

Measured memory_bytes: 18432
//Half and Half
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf=1e18;
const int N=2e5+10;
ll factorial(ll x){//階乗の計算
    if(x==0||x==1) return 1;
    return x*factorial(x-1);
}
ll gcd(ll a ,ll b){return b ? gcd(b,a%b) : a;}//最大公約数
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}//最小公倍数
int num_digit(ll a){//桁数を求める
    int num_dig = 0;
    while(a!=0){
        a /= 10;
        ++num_dig;
    }
    return num_dig;
}
vector<ll> digit(ll a){//桁の数字を求める
    vector<ll> dig(num_digit(a));
    for(int i=num_digit(a)-1; i>=0; --i){
        dig[i] = a%10;
        a /= 10; 
    }
    return dig;
}

int main(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 1e9;
    int M = 0; 

    for(int c=0; c<=2*1e5; c+=2){
        int a = max(0,(X - c/2));
        int b = max(0,(Y - c/2));
        M = A*a + B*b + C*c;
        if(ans>M){
            ans = M;
        }
    }
    cout(ans);
    return 0;
}

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

using namespace std;

int cnt[26] = {};
string s;

int main() {
	cin >> s;
	for (int i = 0; i < s.size(); i++)cnt[s[i] - 'a']++;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
int main(){
	int h,w,hi,wi;
	while (1){
		scanf("%d %d",&h,&w);
		if (h == 0) break;
		for (hi=0; hi<h; hi++){
			for (wi=0; wi<w; wi++)
				printf((hi+wi)%2==0 ? "#":".");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
n,q=map(int, input().split())
go_list=[[] for i in range(n+1)]
cnt=[0]*(n+1)
Oya=[False]*(n+1)
Oya[1]=True
for i in range(n-1):
    a,b=map(int, input().split())
    go_list[a].append(b)
    go_list[b].append(a)

for i in range(q):
    p,x=map(int, input().split())
    cnt[p]+=x

from collections import deque
que=deque()

que.append(1)
sumi=[False]*(n+1)
sumi[1]=True
while que:
    ne=que.popleft()
    for i in go_list[ne]:
        if not sumi[i]:
            cnt[i]+=cnt[ne]
            sumi[i]=True
            que.append(i)

cnt.pop(0)
print(*cnt)


Measured memory_bytes: 127932
H,W,h,w = map(int,input().split())

if(H%h==0)&(W%w==0):
    print('No')
    exit()

print('Yes')

if(W%w!=0):
    base = [1000] * (w-1) + [-1000 * (w-1) -1]
    col = []
    for i in range(1 + W//w):
        col = col + base
    col = col[:W]
    for i in range(H):
        print(' '.join(map(str,col)))

else:
    base = [1000] * (h-1) + [-1000 * (h-1) -1]
    row = []
    for i in range(1 + H//h):
        row = row + base
    row = row[:H]
    for i in row:
        col = [i] * W
        print(' '.join(map(str,col)))

Measured memory_bytes: 73348
#include<stdio.h>
int main(void)
{
  int m,f,r;
  do{  
      scanf("%d %d %d",&m,&f,&r);
      if((m==-1)&&(f==-1)&&(r==-1)){
       break;
     }
     if((m==-1)&&(f==-1)&&(r==-1)){
       break;
     }else if((m==-1)||(f==-1)){
       printf("F\n");
     }else if((m+f)>=80){
       printf("A\n");
     }else if((m+f)>=65){
       printf("B\n");
     }else if((m+f)>=50){
       printf("C\n");
     }else if((m+f)>=30){
       if(r>=50){
         printf("C\n");
       }else{
         printf("D\n");
       }
     }else if((m+f)<30){
       printf("F\n");
     }
   }while(1);
   return 0;
}
     
       





       


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

int main(){
  int n; cin>>n;
  vector<int> a1(n),a2(n);
  for (int i=0; i<n; i++) cin>>a1[i];
  for (int j=0; j<n; j++) cin>>a2[j];
  
  vector<int> b1(n+1),b2(n+1);
  b1[0]=0;
  b2[0]=0;
  for (int k=1; k<n+1; k++){
    b1[k]=a1[k-1]+b1[k-1];
    b2[k]=a2[k-1]+b2[k-1];
  }
  
  int ans=0;
  for (int l=1; l<n+1; l++){
    int t_candy=b1[l]+(b2[n]-b2[l-1]);
    ans=max(ans,t_candy);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main()
{
    int n;
    cin>>n;
    ll a[200005];
    ll sum = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin>>a[i];
        sum+=a[i];
    }
    sum %= mod;
    for(int i = 0; i < n-1; i++){
        sum -= a[i];
        sum = (sum + mod) % mod;
        ans += sum * a[i];
        ans %= mod;
    }
    cout<<ans;
    return 0;
}


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

int main()
{
  int N;
  int res=0;
  cin >> N;
  priority_queue<pair<int, int> > pq;
  
  rep(i,N) {
    int a;
    cin >> a;
    pq.push(make_pair(a,i));
  }

  pair<int,int>  maxnum = pq.top();
  pq.pop();
  pair<int, int> secondnum = pq.top();

  rep(i,N){
    if (maxnum.second != i) cout << maxnum.first << endl;
    else cout << secondnum.first << endl;
  }
}

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

#define endl '\n'

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

    int n, k; cin >> k >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];

    int resp = 0, maior=0;
    for (int i=0; i<n-1; i++){
        maior = max(maior, abs(a[i] - a[i+1]));
        resp += abs(a[i] - a[i+1]);
    }
    maior = max(maior, k - a[n-1] + a[0]);
    resp += k - a[n-1] + a[0];
    cout << resp - maior << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b;
    cin >> a >> b;
    if(a == b)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int a,b,c=1;
cin>>a>>b;
    for(int i=0;i<a;i++)
	{
        if(c>b)c+=b;
        else c+=c;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int h[n];
    for(int i=0;i<n;i++)cin >> h[i];

    vector<long>dp(n,1<<30);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        if(i+1 < n){
            dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        }

        if(i+2 < n){
            dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
        }
    }
    cout << dp[n-1]<<endl;
}

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

 int main() {
   ll n, ai, aj;
   cin >> n;

   vector<ll> a(n);
   rep(i, 0, n) cin >> a.at(i);

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

   ai = a.at(n - 1);

   auto itr = lower_bound(a.begin(), a.end(), ai / 2);
   int d = distance(a.begin(), itr);

   if (d == 0) aj = a.at(0);
   else if (ai % 2 == 0) {
     if (a.at(d) == ai / 2) aj = a.at(d);
     else aj = a.at(d) - ai / 2 < ai / 2 - a.at(d - 1) ? a.at(d) : a.at(d - 1);
   }
   else {
     auto itr2 = lower_bound(a.begin(), a.end(), ai / 2 + 1);
     if (*itr == ai / 2) aj = *itr;
     else if (*itr2 == ai / 2 + 1) aj = *itr2;
     else aj = *itr2 - (ai / 2 + 1) < ai / 2 - a.at(d - 1) ? *itr2 : a.at(d - 1);
   }

   cout << ai << " " << aj << endl;
 }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

//refering to exp.
int main(){
	string s,t;
	cin>>s>>t;
	
	string ss=s+s;
	vvi p(26);
	REP(i,ss.size()) p[ss[i]-'a'].push_back(i+1);
	
	llong ans=0;
	int now_p=0;
	REP(i,t.size()){
		if(p[t[i]-'a'].size()==0){
			cout<<-1<<endl;
			return 0;
		}
		
		auto itr=upper_bound(ALL(p[t[i]-'a']),now_p);
		ans+=*itr-now_p;
		now_p=*itr;
		if(now_p==ss.size()) now_p=0;
		if(now_p>=s.size()) now_p-=s.size();
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 1980
n,m,x=map(int,input().split())
a=[]
cost=[]
for i in range(n):
    p=list(map(int,input().split()))
    cost.append(p[0])
    a.append(p[1:])
ans=-1
for i in range(pow(2,n)):
    temp=0
    lev=[0 for i in range(m)]
    for j in range(n):
        if i&(pow(2,j)):
            temp += cost[j]
            for k in range(m):
                lev[k] += a[j][k]
    if min(lev)>=x:
        if ans==-1:
            ans=temp
        else:
            ans=min(ans,temp)
print(ans)

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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

void output(int x, int y, int s, int t, int m){
  if(x==s&&y==t){
    cout << m << endl;
  }
}

int main() {
  int a,b;
  cin >> a >> b;
  output(a,b,1,2,3);
  output(a,b,2,1,3);
  output(a,b,2,3,1);
  output(a,b,3,2,1);
  output(a,b,1,3,2);
  output(a,b,3,1,2);

  return 0;

}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double PI=3.14159265358979323846;
ll dp;

int main(){
   ll n,ans=0,z[402020]={};
   cin>>n;
   rep(i,n){
      ll a;
      cin>>a;
      if(i>=a)ans+=z[i-a];
      if(i+a<401010)z[a+i]++;
      //cout<<ans<<endl;
   }
   cout<<ans<<endl;
   
}


Measured memory_bytes: 6740
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m;cin>>n>>m;
	ll h[n];
	for(int i=0;i<n;i++){cin>>h[i];}
	vector<int>v[n+1];
	for(int i=0;i<m;i++){
		ll a,b;cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		bool x=true;
		for(auto j:v[i]){
			x=x and (h[i-1]>h[j-1]);
		}
		if(x){ans+=1;}
	}
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


Measured memory_bytes: 10244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e4+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
//#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    int sum=0;
    priority_queue<int,vector<int>, greater<int>> p;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum=sum+x;
        p.push(x);
    }
    while(!p.empty()&&sum%10==0){
        if((sum-p.top())%10!=0){
            sum=sum-p.top();
            break;
        }
        p.pop();
    }
    // cout<<sum<<' ';
    cout<<((sum%10==0)?0:sum);
}

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    ll n;
    cin>>n;
    vector<ll> a(n,0);

    rep(i,n)cin>>a.at(i);

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

    int j=0;
    rep(i,n-1){
        if(a.at(i)==a.at(i+1)){
            j=1;
            cout<<"NO"<<endl;
            break;
        }
    }

    if(j==0)cout<<"YES"<<endl;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> h(N);
    rep(i, N) { cin >> h[i]; }
    auto count = [&A, &B](ll h, ll t) {
        return (ll)ceil(double(h - B * t) / (A - B));
    };
    // 解の存在範囲(lb, ub]
    ll lb = -1, ub = (ll)(*max_element(all(h)));
    while (ub - lb > 1) {
        ll t = (lb + ub) / 2;
        ll cnt = 0;
        for (auto &hi : h) {
            if (hi > (t * B)) {
                cnt += count(hi, t);
            }
            if (cnt > t) break;
        }
        if (cnt <= t) {
            ub = t;
        } else {
            lb = t;
        }
    }
    cout << ub << endl;
    return 0;
}

Measured memory_bytes: 1024
N, M, X, Y = map(int, input().split())
*x, = map(int, input().split())
*y, = map(int, input().split())
ans = [i for i in range(X+1, Y+1) if max(x) < i and min(y) >= i]
if ans:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
/*16D8103005J 相良和希 ayachi0117 C++*/
#include<iostream>
#include<cmath>
bool Pnumber(int x)
{
	
	for(int i=2;i<=std::sqrt(x);i++){
		if(x%i == 0){
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	std::cin >> n;
	int x[n];
	int cou=0;
	for(int i=0;i<=n-1;i++){
		std::cin >> x[i];
	}
	for(int i=0;i<=n-1;i++){
		if(Pnumber(x[i])){
			cou++;
		}
	}
	std::cout << cou << "\n" ;
	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

void paint(vector<string> &board, int y, int x) {
	queue<int> q;
	q.push(y * 100 + x);
	board[y][x] = '0';
	while (!q.empty()) {
		int now = q.front(); q.pop();

		int nowX = now % 100;
		int nowY = now / 100;

		for (int ay = -1; ay <= 1; ay++) {
			for (int ax = -1; ax <= 1; ax++) {
				int nx = nowX + ax;
				int ny = nowY + ay;
				if (nx < 0 || nx >= board[0].size() || ny < 0 || ny >= board.size()) continue;
				if (board[ny][nx] == '0') continue;

				q.push(ny * 100 + nx);
				board[ny][nx] = '0';
			}
		}
	}
}

signed main() {
	while (true) {
		int w, h;
		cin >> w >> h;

		if (w == 0) break;

		vector<string> board;
		rep(y, h) {
			string tmp = "";
			rep(x, w) {
				tmp += nextChar();
			}
			board.push_back(tmp);
		}

		int ret = 0;
		rep(y, h) {
			rep(x, w) {
				if (board[y][x] == '1') {
					paint(board, y, x);
					ret++;
				}
			}
		}

		cout << ret << endl;
	}

    return 0;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    int A[N],b[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        b[i] = 0;
    }

    for (int i = 0; i < N; ++i){
        b[A[i]] += 1;
    }
    sort(b,b+N,greater<int>());
    int count = 0;
    for(int i = 0; i < K; ++i){
        count += b[i];
    }
    int ans = N - count;
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(b/a,c) << endl;
}


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

template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define str string
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Forrev(i,s,e) for (ll i=(s); i>=(e); i--)
#define all(v) v.begin(),v.end()

#define vll vector<ll>
#define vs vector<string>
#define mapll map<ll,ll>
#define pll pair<ll,ll>
#define initialise(a, x) memset(a, x, sizeof(a))
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll> ,greater<ll>>

#define ff first
#define ss second
#define endl "\n"
#define mp make_pair
const ll mod=1e9 + 7;

ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

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

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}

void solve()
{
	ll n,k;
	cin>>n>>k;

	ll sumarr[n+1]={0};
	For(i,1,n+1)
		sumarr[i]=(i+sumarr[i-1])%mod;

	ll ans=0;
	For(i,k,n+1)
	{
		ll val1=sumarr[i-1];
		val1=(val1-1+mod)%mod;
		ll val2=(sumarr[n]-sumarr[n-i]+mod)%mod;
		//cout<<val1<<" "<<val2<<endl;
		ans=(ans+val2-val1+mod)%mod;
	}
	ans=(ans+1)%mod;
	cout<<ans<<endl;
}

signed main() 
{
    fast_cin();
    // #ifndef ONLINE_JUDGE
    // freopen("C:/IO/in.txt", "r", stdin);
    // freopen("C:/IO/out.txt", "w", stdout);
    // #endif
    
    int t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
    
    
    return 0;    
}

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

bool isPrime(int n)
{
	for (int i = 2; i * i <= n; i++)
	{
		if (n % i == 0)return false;
	}

	return true;
}

int main()
{
	int k;
	while (cin >> k && k != 0)
	{
		int min = k;
		int max = k;
		int length = 0;
		while (true)
		{
			bool primeMin = isPrime(min);
			bool primeMax = isPrime(max);

			if (primeMin && primeMax)break;
			if (!primeMin)
			{
				min--;
				length++;
			}

			if (!primeMax)
			{
				max++;
				length++;
			}
		}

		cout << length << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a<b){
		if(b<c) printf("Yes\n");
		else printf("No\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 2672
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

const int MAXN = 2000 + 10;
const int MAXM = 2000 + 10;

vector<int> G[MAXN+10];
vector<pii> E;

void addedge(int u, int v)
{
    G[u].push_back(v);
    G[v].push_back(u);
    E.push_back(pii(u, v));
}

void bfs(int n, int s, bool vis[], int d[])
{
    for (int i=1; i<=n; i++) vis[i] = false;
    queue<int> q;
    q.push(s);
    d[s] = 0;
    vis[s] = true;
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        for (auto v : G[u])
        {
            if (!vis[v])
            {
                vis[v] = true;
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }
}

bool vis[MAXN+10];
int d[MAXN+10], d1[MAXN+10];

int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    for (int i=1; i<=n-1; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        addedge(u, v);
    }
    int ans = n;
    if (k%2 == 0)
    {
        for (int u = 1; u <= n; u++)
        {
            bfs(n, u, vis, d);
            int cnt = 0;
            for (int v = 1; v <= n; v++)
            {
                if (d[v] > k/2) cnt++;
            }
            ans = min(ans, cnt);
        }
    }
    else
    {
        for (auto e : E)
        {
            int cnt = 0;
            int u = e.first;
            int v = e.second;
            bfs(n, u, vis, d);
            bfs(n, v, vis, d1);
            for (int i = 1; i <= n; i++)
            {
                if (min(d[i], d1[i]) > (k-1)/2) cnt++;
            }
            ans = min(ans, cnt);
        }
    }
    printf("%d", ans);
}

Measured memory_bytes: 512
N = gets.to_i
S = gets.chomp
s = S.unpack("C*")
a = Array.new
for i in 0..N-2
    a[i] = 0
    for j in 97..122
        if s.slice(0,i+1).include?(j) && s.slice(i+1,N-i-1).include?(j)
            a[i] += 1
        end
    end
end
puts a.max


Measured memory_bytes: 1916
#include <iostream>

int binarySearch (int ary[], int n, int key) {

    int left  = 0;
    int right = n;
    int mid   = n / 2;

    while (left < right) {

        if (ary[mid] == key)
          return 1;

        else if (key < ary[mid])
          right = mid;

        else
          left = mid + 1;

        mid = (left + right) / 2;
    }

  return 0;
}

int main () {

  int i, j, key, answer;
  int num_of_ary, num_of_key;
  int ary[100010];

  answer = 0;

  std::cin >> num_of_ary;
  for (i = 0; i <= num_of_ary - 1; i++) std::cin >> ary[i];

  std::cin >> num_of_key;
  for (i = 0; i <= num_of_key - 1; i++) {

    std::cin >> key;
    answer += binarySearch(ary, num_of_ary, key);
  }

  std::cout << answer << std::endl;
  return 0;
}



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

int main() {
    
    int a, b;
    cin >> a >> b;
    char ch[a], c;
    for(int i=1; i<=a; i++){
        cin >> ch[i];
        if(i==b){
            c = tolower(ch[i]);
            cout << c;
        }    
        else cout << ch[i];
    }
    cout << endl;
    
    
    
    
    
    
	return 0;
}

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

int main() {
  int N,X,T;
  cin >> N >> X >> T;
  
  if(N % X == 0){
    cout << (N / X) * T << endl;
  } else {
    cout << (N/X + 1)*T << endl;
  }
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const ll pa = 31, pb = 257, moda = 1e9+7, modb = 998244353;
const int M = 30;
int ct[M];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	vector<pair<int,int>> res;
	ll ans = 0;
	vector<pair<int,int>> vec;
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		for(int j=0;j<26;j++)
			ct[j] = 0;
		for(int j=0;j<sz(s);j++)
			ct[s[j]-'a']++;
		ll ha = 0, hb = 0;
		for(int j=sz(s)-1;j>=0;j--)
		{
			for(int p=0;p<26;p++)
			{
				if(ct[p])
				{
					ll z = p+1;
					int nha = (ha*pa + z)%moda;
					int nhb = (hb*pb + z)%modb;
					res.pb({nha,nhb});
				}
			}
			ll z = s[j]-'a'+1;
			ha = (ha*pa + z)%moda;
			hb = (hb*pb + z)%modb;
			ct[s[j]-'a']--;
		}
		vec.pb({ha,hb});
	}
	sort(all(vec));sort(all(res));
	int j = 0;
	ll val = 0;
	for(int i=0;i<sz(vec);i++)
	{
		if(i && vec[i] == vec[i-1])
		{
			ans += val;
			continue;
		}
		val = 0;
		while(j < sz(res) && res[j]<vec[i])
			j++;
		// cout<<res[j].ff<<" "<<res[j].ss<<" "<<vec[i].ff<<" "<<vec[i].ss<<endl;
		while(j<sz(res) && res[j]==vec[i])
		{
			j++;
			val++;
		}
		ans += val;
	}
	ans -= n;
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 266868
#include<bits/stdc++.h>
#define iii pair<pair<int,int>,int>
#define mp make_pair
#define st first
#define nd second
#define N 2005
using namespace std;

int n,k,x,y,ans,now;
int vis[N];
vector<int> v[N];

void bfs(int node,int mx) {

  queue<iii> q;
  q.push(mp(mp(node,0),0));
  while(!q.empty()) {
    iii t=q.front();
    q.pop();
    if(!vis[t.st.st]) {
      now++;
      vis[t.st.st]=1;
    }
    if(t.st.nd==mx) continue ;
    for(int i=0;i<v[t.st.st].size();i++) {
      if(v[t.st.st][i]!=t.nd) {
        q.push(mp(mp(v[t.st.st][i],t.st.nd+1),t.st.st));
      }
    }
  }

}

void mc(int node1,int node2) {

  memset(vis,0,sizeof(vis));
  bfs(node1,k/2);
  bfs(node2,k/2);
  ans=max(ans,now);
  now=0;

}

int main() {

  scanf("%d %d",&n,&k);
  for(int i=1;i<n;i++) {
    scanf("%d %d",&x,&y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(int i=1;i<=n;i++) {
    if(k%2==0) {
      mc(i,i);
    }
    else {
      for(int j=0;j<v[i].size();j++) {
        mc(i,v[i][j]);
      }
    }
  }
  printf("%d",n-ans);


}


Measured memory_bytes: 384
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
#define p push
const int MAX=2e5+5;
const int MAX2=2e6+4;
const int MAAX=2e18;
const int MOD=1e9+7;
int a[MAX];
in main()
{
int n,m;
cin>>n>>m;
int s=0;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    s+=a[i];
}
double d=1.0/(4*m*1.0);
d*=s;
int ans=0;
for(int i=0;i<n;i++)
{
    if(a[i]>=d)
    {
        ans++;
    }
}
if(ans>=m)
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
    return 0;
}



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

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif






 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;

    map<int, char> m;
    m[1] = 'a'; 
    m[2] = 'b';
    m[3] = 'c';
    m[4] = 'd';
    m[5] = 'e';
    m[6] = 'f';
    m[7] = 'g';
    m[8] = 'h';
    m[9] = 'i';
    m[10] = 'j';
    m[11] = 'k';
    m[12] = 'l';
    m[13] = 'm';
    m[14] = 'n';
    m[15] = 'o';
    m[16] = 'p';
    m[17] = 'q';
    m[18] = 'r';
    m[19] = 's';
    m[20] = 't';
    m[21] = 'u';  
    m[22] = 'v';
    m[23] = 'w';
    m[24] = 'x';
    m[25] = 'y';
    m[0] = 'z';

    ll n;

    cin>>n;

    string ans="";

    while(n)
    {
        ans +=m[n%26];

        if(n%26 == 0)n--;

        n /=26;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
   
}

Measured memory_bytes: 3648
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N;cin>>N;
  vector<ll> a(N+1),b(N+1),ans(N+1);
  rep(i,N+1) cin>>a[i];
  rep(i,N) cin>>b[i];
  b[N] = 0;
  ll tmp = 0;

  rep(i,N+1){
    tmp = min(a[i],tmp);
    b[i] += tmp;
    ans[i] = min(a[i],b[i]);
    tmp = max((ll)0,b[i]-ans[i]);
  }
  ll cnt = 0;
  rep(i,N+1) cnt += ans[i];
  cout<<cnt<<endl;


}


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

int main(void){
	double x[4], y[4];;
	
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])){
		if(x[0]==x[1]){
			if(y[2]==y[3]) printf("YES\n");
			else printf("NO\n");
		}else if(y[0]==y[1]){
			if(x[2]==x[3]) printf("YES\n");
			else printf("NO\n");
		}else{
			if((y[3]-y[2])*(y[1]-y[0])/(x[3]-x[2])/(x[1]-x[0])==-1) printf("YES\n");
			else printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();

		System.out.println((x - a) % b);

	}

}


Measured memory_bytes: 22612
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    int H, W, N; cin >> H >> W >> N;
    vi a(N);
    REP(i, N) cin >> a[i];
    vvi c(H, vi(W, -1));

    int x = 0, h = 0, d = 1;
    REP(i, N){
        REP(j, a[i]){
            c[h][x] = i+1;
            x += d;

            if (x == -1) {
                d = 1;
                x = 0;
                h++;
            } else if (x == W) {
                d = -1;
                x = W-1;
                h++;
            }
        }
    }

    REP(i, H){
        REP(j, W){
            cout << c[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
color = [0]*8
nizi = 0
for i in range(n):
         if a[i] >= 3200:
                  nizi += 1
         else:
                  if color[a[i]//400] == 0:
                           color[a[i]//400] += 1
print(max(1,sum(color)),sum(color) + nizi)
         


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
int Sosu(int N){
  int i=3;
if(N==2)return 1;
if(N<2 || N%2==0)return 0;
while(i<=sqrt(N)){
  if(N%i==0)return 0;
  i=i+2;
}
return 1;
}
int main(void){
int N;
int n,i;
int S=0,c=0;
while(1){
scanf("%d",&n);
if(n>=1 && n<=10000)break;
}
for(i=0 ; i<n ; i++){
  while(1){
  scanf("%d",&N);
  if(N>=2 && N<=100000000)break;
  }
  S+=Sosu(N);
}
printf("%d\n",S);
return 0;
}


Measured memory_bytes: 2064
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] instr = Console.ReadLine().Split(' ');
            int n = int.Parse(instr[0]);
            int m = int.Parse(instr[1]);

            if(n==m){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl l(n);
  rep(i,n){
    cin >> l[i];
  }
  ll total = 0;
  sort(all(l));
  for (ll i = 0; i < n - 2;i++){
    for (ll j = i + 1; j < n - 1;j++){
      for (ll k = j + 1; k < n;k++){
        if(l[i]+l[j]>l[k]){
          total++;
        }
        else{
          break;
        }
      }
    }
  }
  print(total);
}


Measured memory_bytes: 3624
class dice:
    def __init__(self,label):
        self.d = label
    def roll(self,op):
        d = self.d
        if   op=='N': self.d = [d[1],d[5],d[2],d[3],d[0],d[4]]
        elif op=='E': self.d = [d[3],d[1],d[0],d[5],d[4],d[2]]
        elif op=='W': self.d = [d[2],d[1],d[5],d[0],d[4],d[3]]
        elif op=='S': self.d = [d[4],d[0],d[2],d[3],d[5],d[1]]
    def print(self):
        print(self.d[0])

label = list(map(int,input().split()))
op_list = list(input())
d0 = dice(label)
for op in op_list:
    d0.roll(op)
d0.print()

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

const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

// 0-1 BFS 
int main()
{
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si; --sj; --ti; --tj;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w,INF));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si, sj);
    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        // if (dist[i][j] != d) continue;
        rep(v,4) {
            int ni = i+di[v], nj = j+dj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
            if (s[ni][nj] == '#') continue;
            if (dist[ni][nj] <= d) continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        for (int ei = -2; ei <= 2; ++ei) {
            for (int ej = -2; ej <= 2; ++ej) {
                int ni = i+ei, nj = j+ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') continue;
                if (dist[ni][nj] <= d+1) continue;
                dist[ni][nj] = d+1;
                q.emplace_back(ni, nj);
            }
        }

    }
    int ans = dist[ti][tj];
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


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


typedef long long ll;

using namespace std;


const ll mod=1000000000+7;





int main(){

    string S;

    cin>>S;

    int n=S.size();

    if(S[n-1]!='s'){

        cout<<S+"s"<<endl;
    }else{
        cout<<S+"es"<<endl;
    }

    


   

    

}



Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    int k;
    cin >> k;
    vector<ll> a(k);
    for(int i = 0; i < k; i++) cin >> a[i];
    ll min_n = 2, max_n = 2;
    for(int i = k-1; i >= 0; i--){
        ll min_num = ((min_n + a[i] - 1) / a[i]) * a[i];
        ll max_num = (max_n / a[i]) * a[i] + a[i] - 1;
        if(min_num > max_n || max_num < min_n){
            cout << -1 << endl;
            return 0;
        }
        min_n = min_num;
        max_n = max_num;
    }
    cout << min_n << " " << max_n << endl;
}

Measured memory_bytes: 1024