akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int A[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int saidai = 1;
	rep(i, N) {
		A[i] = getint();
		if (A[i] > saidai) saidai = A[i];
	}
	nth_element(A, A + N / 2, A + N);

	ll kotae = 0;
	for (int i = N / 2; i < N; i++) kotae += A[i];

	printf("%lld\n", kotae * 2 - saidai - N % 2 * A[N / 2]);

	Would you please return 0;
}

Measured memory_bytes: 2496
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
	string s,t;
	cin >> s >> t;
	int ans = 0;
	rep(i,3)(ans+= s[i] == t[i]);
	print(ans);
	return 0;
}


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

using namespace std;

int main(){
	int temp,temp1,temp2,n;
	std::vector<long double> v;
	long double gar,gar1;

	scanf("%d",&n);
	for(temp=0;temp<n;temp++){
		cin >> gar;
		v.push_back(gar);
	}
	sort(v.begin(),v.end());
	gar1=(v[0]+v[1])/2;
	for(temp=2;temp<n;temp++){
		gar1=(gar1+v[temp])/2;
	}
	cout << gar1;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
 
int main() {
    int N,K;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++)
    {
      cin>>A[i];
    }
    vector<int> a = A;
    for (int i = 0; i < K; i++) {
        vector<int> B(N+1, 0);
        for (int j = 0; j < N; j++) {
            B[max(0, j - a[j])]++;
            B[min(N, j + a[j] + 1)]--;
        }
 
        for (int j = 0; j < N; j++) {
            B[j + 1] +=B[j];
        }
      B.pop_back();
      if(a==B)break;
      a=B;
    }
    for(int i=0;i<N;i++)
    {
      cout<<a[i]<< (i == N - 1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 5608
#include<iostream>

using namespace std;
int main ()
{
    long long int n,i,a[15],mx=0,sum=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>mx)
            mx=a[i];

    }
    for(i=0;i<n;i++)
    {
        sum=sum+a[i];
    }
    cout<<(sum-(mx/2))<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n,m; cin >> n >> m;
    int sum = 0;
    int a[105];
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    int cnt = 0;
    for(int i=0;i<n;i++){
        if(a[i]*4*m >= sum) cnt++;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
ab = [list(map(int, readline().split())) for _ in range(n)]
cd = [list(map(int, readline().split())) for _ in range(m)]

for i in ab:
    l = []
    for j in cd:
        distance = abs(i[0]-j[0])+abs(i[1]-j[1])
        l.append(distance)
    print(l.index(min(l)) + 1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 1e9

using namespace std;

int N;

int main(void)
{
    cin >> N;
    vector<int> L(N, 0);
    rep(i, N)
    {
        cin >> L[i];
    }

    // sort(L.begin(), L.end());
    // L.erase(unique(L.begin(), L.end()), L.end());

    // N = L.size();

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (L[i] != L[j] && L[i] != L[k] && L[j] != L[k])
                {

                    if ((L[i] + L[j]) > L[k] &&
                        (L[i] + L[k]) > L[j] &&
                        (L[j] + L[k]) > L[i])
                    {
                        count++;
                    }
                }
            }
        }
    }

    cout << count;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <algorithm>
#include <math.h>
#include <string>
#define pi 3.1415926535897932384626
#include <cmath>
#define test(t) while(t--)

#define ll  long long int

#define in  cin>>
#define out cout<<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()  ios_base::sync_with_stdio(false);cin.tie(0);
#define double long double

using namespace std;
ll form(ll n){
return (n*(n+1))/2;
}
ll exponent(ll base, ll power){
   ll res = 1;
  ll m = 1000000007;
   while(power){
    if(power&1)
        res = (res*base)%m;
    base= (base*base)%m;
    power=power>>1;
   }
return res;}
bool count_one(ll n){
    ll cnt = 0;
    while(n>0){
            cnt+=1;
       n= n&(n-1);

    }
    if(cnt>1)
        return true;
    return false;
}
void solve()
{ ll n;
  cin>>n;
  ll a[n];
  for(ll i=0;i<n;i++)
      in a[i];
  ll k=a[0];
  sort(a,a+n);
  bool flag = true;
  if(a[0]!=0){
  for(ll i=1;i<n;i++){
      if((double)a[i]>=(double)1000000000000000001/k){
            flag = false;
        break;
      }
      else
        k=k*a[i];

  }
  if(flag==true)
    out k<<en;
  else
    out -1<<en;
  }
  else
    out 0<<en;
}



int main(){ fast()
             //freopen("input.txt","r",stdin);
             //freopen("output.txt","w",stdout);
             ll t=1;
           //cin>>t;
            test(t){
            solve();
            }
return 0;}


Measured memory_bytes: 4396
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mk make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		int a;
		cin >> a;
		while (a % 2 == 0) {
			a /= 2;
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
vector<ll> enum_div(ll n){
    vector<ll> res;
for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            res.push_back(i);
            if(i*i != n){
                res.push_back(n/i);
            }
        }
    }
    sort(res.begin(),res.end(),greater<int>());
    return res;
}
int main(){
    ll n,k;cin >> n >> k;
    ll a[n];
    ll sum=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    ll M=sum;
    const auto &res=enum_div(M);
    ll ans=0;
    for(int i=0;i<res.size();i++){
        ll cnt=0;
        ll r[n];
        rep(j,n){
           r[j]=a[j]%res[i];
        }
        sort(r,r+n);
        ll rsum=0;
        ll lsum=0;
        rep(j,n){
            rsum+=res[i]-r[j];
        }
        rep(j,n){
            lsum+=r[j];
            rsum-=res[i]-r[j];
            if(max(lsum,rsum)<=k){
                cout << res[i] << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	int[] as = readln.chomp.split.map!(to!int).array;
	
	int c = 0;
	foreach(a; as) if(a % 2) c += 1;
	
	string ans;
	if(c % 2) ans = "NO"; else ans = "YES";
	
	ans.writeln;
	
	}

Measured memory_bytes: 3384
n,a,b = map(int,input().split())

if n==1 and a!=b: print(0)
elif n==1 and a==b: print(1)
elif n>=2 and a>b: print(0)
elif n>=2 and a==b: print(1)
elif n>=2 and a<b: print(b*(n-2) - a*(n-2) + 1)

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2000010,M=10000010,P=1e9+7;
const int inf=0x3f3f3f3f;
inline ll read();
inline void write(ll x);
inline void writeln(ll x);
#define mem(a,b) memset(a,b,sizeof(a))
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define plus(a,b) a=(a+(b))%P
#define minus(a,b) a=(a-(b)+P)%P
#define mul(a,b) a=(a*(b))%P
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)

char s[N],t[N];
int n,m;
int fail[N],len[N];

int to[N],in[N],d[N];
bool visit[N];

inline ll read()
{
	ll s=0;
	bool flag=false;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') flag=true;
	for(;'0'<=ch&&ch<='9';ch=getchar()) s=(s<<3)+(s<<1)+(ch^48);
	if(flag) return -s;
	return s;
}
inline void write(ll x)
{
	if(!x)
	{
		putchar('0'),putchar(' ');
		return ;
	}
	if(x<0) putchar('-'),x=-x;
	char ch[20];
	int tot=0;
	while(x) ch[++tot]=x%10,x/=10;
	for(int i=tot;i;i--) putchar(ch[i]+'0');
	putchar(' ');
}
inline void writeln(ll x)
{
	write(x);
	putchar('\n');
}

queue<int> q;
int main()
{
	scanf("%s",s+1);
	scanf("%s",t+1);
	n=strlen(s+1),m=strlen(t+1);
	for(int i=1;i<=(m-1)/n+1;i++)
		for(int j=1;j<=n;j++) s[i*n+j]=s[j];
	int nn=strlen(s+1);
	for(int i=2;i<=m;i++)
	{
		int p=fail[i-1];
		while(p&&t[i]!=t[p+1]) p=fail[p];
		if(t[i]==t[p+1]) fail[i]=p+1;
	}
	for(int i=1;i<=nn;i++)
	{
		int p=len[i-1];
		while(p&&s[i]!=t[p+1]) p=fail[p];
		if(s[i]==t[p+1]) len[i]=p+1;
	}
	for(int i=1;i<=nn;i++)
		if(len[i]==m) in[i%n+1]++,to[(i-m+n)%n+1]=i%n+1;
	while(q.size()) q.pop();
	for(int i=1;i<=nn;i++) if(!in[i]) q.push(i);
	while(q.size())
	{
		int x=q.front();q.pop();
		visit[x]=true;
		if(!to[x]||visit[to[x]]) continue;
		in[to[x]]--,d[to[x]]=d[x]+1;
		q.push(to[x]);
	}
/*
	printf("%d %d\n",nn,m);
	for(int i=1;i<=nn;i++) printf("%d ",len[i]);
	putchar('\n');
	for(int i=1;i<=nn;i++) printf("%d ",to[i]);
	putchar('\n');
	for(int i=1;i<=nn;i++) printf("%d ",d[i]);
	putchar('\n');//*/
	int ans=0;
	for(int i=1;i<=nn;i++)
		if(to[i])
		{
			if(!d[to[i]])
			{
				printf("-1\n");
				return 0;
			}
			cmax(ans,d[to[i]]);
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 33920
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
const long long int  modu=1e9+7;
#define endl '\n'
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define inp(x)  for(auto &t:x) cin>>t;
#define itr     vector<int>::iterator
#define debug(a) cout << #a << "=" << a << ' '<<endl;
#define out(x)  for(auto &t:x) cout<<t<<" "; cout<<endl;
#define ff first
#define ss second
#define pb push_back
#define initialize(a,v)  for(int i=0;i<a.size();++i) a[i]=v;
#define all(x) x.begin(),x.end()
#define mpt(mp) for(auto it=mp.begin();it!=mp.end();it++)
#define trav(x) for(int i=0;i<(int)x.size();++i)
#define mkp(a,b) make_pair(a,b)
#define sz(x)  (int)x.size()

int noofdig(int N)
{
	return floor(log10(N))+1;
}


ll f(ll a)
{

return 0;

}



void pre()
{

}

int f(string w,string t)
{
   int n=t.length();
   int cnt=0;
   for(int i=0;i<n;++i)
   {
   	if(w[i]!=t[i])
   	cnt+=1;
   }
	
	return cnt;
}



void solve()
{
	string s,t;
	cin>>s>>t;
	string window;
	int n=s.length();
	int m=t.length();
   int ans=0;
	
	for(int i=0;i<m;++i)
	window+=s[i];
	
	//debug(window);
	
	ans=f(window,t);
	
	
	for(int i=m;i<n;++i)
	{
		window.erase(window.begin());
		window+=s[i];
		//debug(window);
		
		int tmp=f(window,t);
		//debug(tmp);
		
		ans=min(ans,tmp);
	}
	
	cout<<ans<<endl;
	
	
	






}



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 <iomanip>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	
	cout << a/b << " " << a%b << " " << flush;
	cout << fixed << setprecision(6) << (double)a/(double)b << endl;

	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <string>
#include <iomanip>

using namespace std;

class cEquation
{
public:
	string calc(vector<double> &);
};

string cEquation::calc(vector<double> &v)
{
	double a = v[0];
	double b = v[1];
	double c = v[2];
	double d = v[3];
	double e = v[4];
	double f = v[5];
	double x = (c*e - b*f) / (a*e - b*d);
	if (x == -0) x = 0;
	double y = (a*f - c*d) / (a*e - b*d);
	if (y == -0) y = 0;
	ostringstream oss;
	oss << fixed << setprecision(3) << x << " " << y;

	return string(oss.str());
}

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

	cEquation ct;
	vector<double> vd(6);

	for (;;)
	{
		cin >> vd[0] >> vd[1] >> vd[2] >> vd[3] >> vd[4] >> vd[5];
		if (cin.fail()) break;
		cout << ct.calc(vd) << endl;
	}

	return 0;
}

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int N;
vector<vector<int>>G(1005,vector<int>(1005));
bool judge(int i,int j){
    bool res=true;
    int now=G[i][j];
    res&=(now==G[N-i-1][j]);
    res&=(now==G[i][N-1-j]);
    res&=(now==G[N-1-i][N-j-1]);
    return res;
}
signed main(){
    int C;
    cin>>C>>N;
    rep(i,N){
        string s;cin>>s;
        rep(j,N){
            if(s[j]=='0')G[i][j]=0;
            else G[i][j]=1;
        }
    }
    int count=0;
    rep(i,N/2)rep(j,N/2){
        if(!judge(i,j))count++;
    }
    int ans=0;
    if(count==0)ans++;
    rep(qoo,C-1){
        int D;cin>>D;
        rep(popo,D){
            int i,j;cin>>i>>j;
            i--;j--;
            bool past=judge(i,j);
            G[i][j]=(1-G[i][j]);
            bool now=judge(i,j);
            if(past&&(!now))count++;
            if((!past)&&now)count--;
        }
        if(count==0)ans++;
    }
    cout<<ans<<endl;

}




Measured memory_bytes: 10644
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007

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

  int64_t ans = 0;
  int pow_n = 1;

  if((N % 2) == 0){
    while(pow(5,pow_n) < N){
      int64_t pow5n = pow(5,pow_n);
      ans += N / (pow5n * 2);
      pow_n++;
    }
  }else{
    //Nが奇数なら永遠に2の因数を持たない
    ans = 0;
  }

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


Measured memory_bytes: 512
#include<stdio.h>
#define NUM 13
 
int main(){
 int num[NUM*4-1],ncmp,n,i,j;
 char pcmp;
 for(i=0; i<NUM; i++){
  num[NUM*0+i] = i+1;
  num[NUM*1+i] = i+1;
  num[NUM*2+i] = i+1;
  num[NUM*3+i] = i+1;
 }
 scanf("%d", &n);
 for(i=0; i<n; i++){
  scanf(" %c %d",&pcmp,&ncmp);
  for(j=0; j<NUM; j++){
   switch(pcmp){
    case 'S': if(ncmp==num[NUM*0+j]){num[NUM*0+j] = -1;} break;     
    case 'H': if(ncmp==num[NUM*1+j]){num[NUM*1+j] = -1;} break;
    case 'C': if(ncmp==num[NUM*2+j]){num[NUM*2+j] = -1;} break;
    case 'D': if(ncmp==num[NUM*3+j]){num[NUM*3+j] = -1;} break;
   }
  }
 }
 for(i=0; i<NUM*4; i++){
  if(num[i]!=-1){
   if(i<NUM){printf("S %d\n", num[i]);}
   else if(NUM*1<=i&&i<NUM*2){printf("H %d\n", num[i]);}
   else if(NUM*2<=i&&i<NUM*3){printf("C %d\n", num[i]);}
   else if(NUM*3<=i&&i<NUM*4){printf("D %d\n", num[i]);}
  }
 }
 return 0;
}

Measured memory_bytes: 596
#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 <unordered_set>
#include <unordered_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 itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<int> A;
    inputVector(A, N);

    sort(all(A));

    vector<pair<int, int>> ret;
    REP(i, 1, N - 2) {
        if (A[i] < 0) continue;
        ret.push_back(mp(A[0], A[i]));
        A[0] -= A[i];
    }

    rep(i, N - 1) {
        if (i > 0 && A[i] >= 0) continue;
        ret.push_back(mp(A.back(), A[i]));
        A.back() -= A[i];
    }

    cout << A.back() << endl;
    for (auto &pr : ret) {
        cout << pr.first << " " << pr.second << endl;
    }

    return 0;
}


Measured memory_bytes: 4336
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;


int main(void)
{
    int N;
    cin >> N;
    vector<long> P(N);
    vector<int> idx(N + 1, -1);
    long ans = 0;
    for (int i = 0; i < N; i++){
        cin >> P[i];
        idx[P[i]] = i + 1;
    }
    sort(P.begin(), P.end(), greater<long>());
    multiset<int> S;
    for (int i = 0; i < 2; i++)
    {
        S.insert(0);
        S.insert(N + 1);
    }
    for (int i = 0; i < N; i++)
    {
        S.insert(idx[P[i]]);
        multiset<int>::iterator itr =  S.find(idx[P[i]]);
        int l1, l2, r1, r2;
        itr--; l1 = *itr;
        itr--; l2 = *itr;
        for (int j = 0; j < 3; j++) itr++;
        r1 = *itr;
        itr++; r2 = *itr;
        ans += ((l1 - l2) * (r1 - idx[P[i]]) + (r2 - r1) * (idx[P[i]] - l1)) * P[i];
        //cout << ans  << endl;
    }
    cout << ans << endl;
    return 0;
}

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

//pdf見て解答

int main(){
    ll n; cin >> n;
    ll m,a,r,c,h;
    m = a = r = c = h = 0;

    rep(i,n){
        string tmp; cin >> tmp;
        char head = tmp[0];
        if(head == 'M') m++;
        else if(head == 'R') r++;
        else if(head == 'A') a++;
        else if(head == 'C') c++;
        else if(head == 'H') h++;
    }

    ll ans = 0;
    ans += m * r * a;
    ans += m * r * c;
    ans += m * r * h;
    ans += m * a * c;
    ans += m * a * h;
    ans += m * c * h;
    ans += r * a * c;
    ans += r * a * h;
    ans += r * c * h;
    ans += a * c * h;

    put(ans);
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
LL f[1000005], rf[1000005];;
LL inv(LL a, LL b){
	LL res = 1;
	while(b){
		if(b%2 == 1) res = (res*a)%mod;
		a = (a*a)%mod;
		b/=2;
	}
	return res;
}

LL ncr(LL a, LL b){
	return f[a]*rf[b]%mod*rf[a-b]%mod;
}
int main(){
	f[0] = 1;
	for(int i=1;i<=1000000;i++) f[i] = (f[i-1]*i)%mod;
	for(int i=0;i<=1000000;i++) rf[i] = inv(f[i], mod-2);
	int n;
	scanf("%d", &n);
	int c = n%2, rem = (n+1)/2;
	LL ans = 0, pv = 0;

	for(int i=c;i<=n-2;i+=2,rem++){
		LL sum = ncr(rem-1, i)*f[rem]%mod*f[n-1-rem]%mod;
		LL res = (sum - pv + mod)%mod;
		ans = (ans + res*rem)%mod;
		pv = sum;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 16000
#include <stdio.h>
int main(void)
{
  int a, b, c;
  
  scanf("%d %d", &a, &b);
  if (a <= 9 && b <= 9) {
    c = a * b;
    printf("%d", c);
  } else {
    c = -1;
    printf("%d", c);
  }
  return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int res = 0;
  for (int i = A; i <= B; i++) {
    if ( (i/10000)==(i%10) && (i/1000)%10==(i/10)%10 ) res++;
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9+7;
const int INF = 0x3f3f3f3f;

int a[100001];

int mpow(int b, int e)
{
    int ret=1;
    for(int i=0; i<e; i++)
    {
        ret=ret*b%mod;
    }
    return ret;
}

ll x[100001];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, ans=0;
    cin >> n;
    ans=n/11;
    if(n%11==0) cout << ans*2;
    else if(n%11<7) cout << ans*2+1;
    else cout << ans*2+2;
}

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

int main(){

  int n,m;
  cin>>n;
  string u[n];

  for(int i=0;i<n;i++){
    cin>>u[i];
  }

  cin>>m;
  string t[m];
  
  for(int i=0;i<m;i++){
    cin>>t[i];
  }

  int b=0;

  for(int i=0;i<m;i++){
    int a=0;
    for(int j=0;j<n;j++){
      if(t[i]==u[j]){
	a=1;
      }
    }

    if(a==1){
      if(b==0){
	cout<<"Opened by "<<t[i]<<endl;
	b=1;
      }else{
	cout<<"Closed by "<<t[i]<<endl;
	b=0;
      }
    }else{
      cout<<"Unknown "<<t[i]<<endl;
    }

  } 


  return 0;

}

Measured memory_bytes: 3204
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
s = [int(input()) for _ in range(n)]

a = a1+a2+a3
ans = 'No'
for i in range(n):
    for j in range(9):
        if s[i] == a[j]:
            a[j] = 0
if a[0]==a[1]==a[2]==0 or a[3]==a[4]==a[5]==0 or a[6]==a[7]==a[8]==0:
    ans = 'Yes'
if a[0]==a[3]==a[6]==0 or a[1]==a[4]==a[7]==0 or a[2]==a[5]==a[8]==0:
    ans = 'Yes'
if a[0]==a[4]==a[8]==0 or a[2]==a[4]==a[6]==0:
    ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  int x=n;
  int sum=0;
  while(x){
    sum+=x%10;
    x/=10;
  }
  if(n%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n, 1);
  vector<i64> b(n + 1);
  for (i64 i = 1; i <= n; ++i) b[a[i]] = i;
  for (i64 i = 1; i <= n; ++i) cout << b[i] << ' ';
  cout << endl;
  return 0;
}



Measured memory_bytes: 2432
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n, k;
	cin >> n >> k;
	vll a(n);
	rep(i, n) cin >> a[i];

	ll ans = INFL;
	rep(i, 1 << n) {
		if(__builtin_popcount(i) < k) continue;
		ll _ans = 0;
		ll last_a = 0;
		rep(j, n) {
			if(i & (1 << j) && last_a >= a[j]) {
				_ans += last_a - a[j] + 1;
				last_a++;
			}
			else {
				last_a = max(a[j], last_a);
			}
		}
		ans = min(_ans, ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
x=list(map(int,input().split()))
max=max(x)
d=dict(Counter(x))
m=1000000
for i in range(1,max+1):
    s=0
    for key,vlaue in d.items():
        s+=(i-key)**2*vlaue
    m=min(s,m)
print(m)






Measured memory_bytes: 39024
N, K = map(int, input().split())
mod = 10**9 + 7

factorial = [1]
inverse = [1]

for i in range(1, N + 2):
    factorial.append(factorial[i - 1] * i % mod)
    inverse.append(pow(factorial[i], mod - 2, mod))


def C(n, r):
    if n < r:
        return 0
    return (factorial[n] * inverse[r] * inverse[n - r]) % mod


Atable = [0] * (K + 1)
for i in range(1, K + 1):
    Atable[i] = C(K - 1, i - 1)
Btable = [0] * (K + 1)
for i in range(1, K + 1):
    Btable[i] = C(N - K + 1, i)

for i in range(1, K + 1):
    print(int(((Atable[i] % mod) * (Btable[i] % mod)) % mod))

Measured memory_bytes: 3572
counts = [0, 9, 0, 900, 0, 90000]

n_str = gets.chomp
digits = n_str.size

if digits % 2 == 0
    puts counts[0..digits].inject(:+)
else
    n = n_str.to_i
    puts counts[0..(digits - 1)].inject(:+) + n - 10 ** (digits - 1) + 1
end


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

int main(void){
	char word;

	while(1){
		scanf("%c", &word);
		if(word == '\n') break;
		if(word >= 'a' && word <= 'z'){
			word -= 'a' - 'A';
		}else if(word >= 'A' && word <= 'Z'){
			word += 'a' - 'A';
		}

		printf("%c", word);
	}
	puts("");

	return 0;
}

Measured memory_bytes: 1112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100010;
int n,m,k,x,cnt;
map<int,int> s;
int main()
{
  cin>>n>>m;
  for(int i=1;i<=n;i++)
  {
    cin>>k;
    for(int j=1;j<=k;j++) cin>>x,s[x]++;
  }
  for(auto i:s) if(i.second==n) cnt++;
  cout<<cnt<<endl;
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  vector<int> l(n);
  rep(i, n) cin>>l.at(i);
  sort(l.begin(), l.end());
  long long ans = 0;
  int a,b,c;
  for(int i=0; i<n-2; i++){
    a=l.at(i);
    for(int j=i+1; j<n-1; j++){
      b=l.at(j);
      for(int k=j+1; k<n; k++){
        c=l.at(k);
        if(c<a+b && b-a<c){
          ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<ctime>
#include<map>
using namespace std;

#define INF (1 << 30)

struct treap_n{
  int value, pri, minimum, count;
  treap_n* right, *left;
  treap_n(int v){
    value = v;
    pri = rand() % INF;
    count = 1;
    minimum = v;
    right = left = 0;
  }
};

int node_count(const treap_n* r){
  if(r == 0)return 0;
  return r -> count;
}


int node_min(const treap_n* r){
  if(r == 0)return INF;
  return r -> minimum;
}

treap_n* update(treap_n* r){
  r -> count = node_count(r -> left) + node_count(r -> right) + 1;
  r -> minimum = min(node_min(r -> left), node_min(r -> right));
  r -> minimum = min(r -> minimum, r -> value);
  return r;
}

treap_n* merge(treap_n* a, treap_n *b){
  if(a == 0)return update(b);
  if(b == 0)return update(a);
  if(a -> pri > b -> pri){
    treap_n* tmp = a -> right;
    a -> right = merge(tmp, b);
    return update(a);
  }
  else{
    treap_n* tmp = b -> left;
    b -> left = merge(a, tmp);
    return update(b);
  }
}

pair<treap_n*, treap_n*> split(treap_n* r,int pos){
  if(r == 0) return make_pair((treap_n*)0, (treap_n*)0);
  int left_count = node_count(r -> left);
  if(pos > left_count){
    pair<treap_n*, treap_n*> tmp;
    tmp = split(r -> right, pos - left_count - 1);
    r -> right = tmp.first;
    return make_pair(update(r), tmp.second);
  }
  else{
    pair<treap_n*, treap_n*> tmp;
    tmp = split(r -> left, pos);
    r -> left = tmp.second;
    return make_pair(tmp.first, update(r));
  }
}

treap_n* insert(treap_n* r, int pos, treap_n* n){
  pair<treap_n*, treap_n*>tmp;
  tmp = split(r, pos - 1);
  r = merge(tmp.first, n);
  r = merge(r, tmp.second);
  return r;
}

treap_n* remove(treap_n* r,int pos){
  pair<treap_n*, treap_n*>tmp;
  tmp = split(r, pos - 1);
  r = merge(tmp.first, split(tmp.second, 1).second);
  return r;
} 

treap_n* node(treap_n* r, int pos){
  int left_count = node_count(r -> left);
  if(pos == left_count + 1){
    return r;
  }
  if(pos > left_count){
    return node(r -> right, pos - left_count - 1);
  }
  else{
    return node(r -> left, pos);
  }
}

treap_n* shift(treap_n* r, int left, int right){
  treap_n* tmp = node(r, right);
  r = remove(r, right);
  r = insert(r, left, tmp);
  return r;
}

int minimum(treap_n* r, int left, int right){
  pair<treap_n*, treap_n*> tmp1, tmp2 ;
  int res;
  tmp1 = split(r, left - 1);
  tmp2 = split(tmp1.second , right - left + 1);
  res = node_min(tmp2.first);
  r = merge(tmp1.first, merge(tmp2.first, tmp2.second));
  return res;
}

treap_n* change(treap_n* r, int pos, int val){
  r = remove(r, pos);
  r = insert(r, pos, new treap_n(val));
  return r;
}



int main(){
  int tmp, n, q, x, y, z;
  srand((unsigned int)time(0));
  cin >> n >> q;
  cin >> tmp;
  treap_n root(tmp);
  treap_n* r = &root;
  for(int i = 2;i <= n;i++){
    cin >> tmp;
    r = insert(r, i, new treap_n(tmp));
  }
  for(int i = 0;i < q;i++){
    cin >> x >> y >> z;
    if(x == 0){
      y++,z++;
      r = shift(r, y, z);
    }
    if(x == 1){
      y++,z++;
      cout << minimum(r, y, z) << endl;
    }
    if(x == 2){
      y++;
      r = change(r, y, z);
    }
  }
  return 0;
}

Measured memory_bytes: 13708
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    string s;
    cin >> s;
    int n = s.size();

    auto sa = suffix_array(s);
    auto lcp = lcp_array(s, sa);

    ll ans = 0;
    rep(i, n) {
        int len = n - sa[i];
        if (i > 0) len -= lcp[i-1];
        ans += len;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 15652
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll,int>P;


ll dp[200][200000];
int main(){
	int n,k;cin>>n>>k;
	if(k>150){
		puts("0");return 0;
	}
	for(int i=1;i<=n;i++){
		dp[1][i]=1;
	}
	for(int i=1;i<k;i++){
		for(int j=1;j<=n;j++){
			for(int t=j*2;t<=n;t+=j){
				dp[i+1][t]+=dp[i][j];
			}
		}
	}
	ll ans=0;
	for(int i=1;i<=n;i++)ans+=dp[k][i];
	cout<<ans<<endl;
}


Measured memory_bytes: 17912
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int main() {
    string s;
    cin >> s;
    string month = "";
    if((s[5] == '0' && s[6] == '1') || (s[5]=='0' && s[6] == '2') || (s[5] == '0' && s[6] == '3') || (s[5]=='0' && s[6] == '4')){
        cout << "Heisei" << endl;
        return 0;
    }  else {
        cout << "TBD"<< endl;
    }
   

}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
    
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    
#define int long long
#define double long double
    
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
    
#define ff first
#define ss second
#define mp make_pair
         
#define pb push_back
#define endl "\n" 
         
#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)    

#define bp __builtin_popcountll
#define inf 3e15
    
const int N=2e5+5;
const int M=1e9+7;
int h,w;
int p1=0,p2=0,ans=0;
char X[405][405];
bool vis[405][405];
bool val(int x,int y)
{
	if(vis[x][y])
	return false;
	if(x>=1 && x<=h && y>=1 && y<=w)
	return true;
	return false;
}
void dfs(int x,int y)
{
	vis[x][y]=true;
	if(X[x][y]=='.') p1++;
	else			 p2++;
	if(val(x+1,y) && X[x+1][y]!=X[x][y])
	{
		dfs(x+1,y);
	}
	if(val(x-1,y) && X[x-1][y]!=X[x][y])
	{
		dfs(x-1,y);
	}
	if(val(x,y+1) && X[x][y+1]!=X[x][y])
	{
		dfs(x,y+1);
	}
	if(val(x,y-1) && X[x][y-1]!=X[x][y])
	{
		dfs(x,y-1);
	}
}
void solve()
{
	cin>>h>>w;
	f(i,1,h) f(j,1,w) cin>>X[i][j];
	f(i,1,400) f(j,1,400) vis[i][j]=false;
	f(i,1,h)
	{
		f(j,1,w)
		{
			if(!vis[i][j])
			{
				p1=0,p2=0;
				dfs(i,j);
				ans+=(p1*p2);
			}
		}
	}
	cout<<ans;
	
}
signed main()  
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}



Measured memory_bytes: 13056
//ITNOA
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
const long long INF=1e9+10,MAX=2e5+1e4,MOD=1e9+7;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
void OUT(long double o,int x){
	 cout<<fixed<<setprecision(x)<<o;
	 return;
}
ll a[MAX];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1];
	return 0;
}


Measured memory_bytes: 256
# from math import ceil,sqrt,log,gcd,pi
# def ii():return int(input())
# def si():return input()
# def mi():return map(int,input().split())
# def li():return list(mi())

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    s=a[i]+a[i+1]
    if(s>b[i]):
        ans+=b[i]
        a[i+1]=min(a[i+1],(s-b[i]))
    else:
        ans+=s
        a[i+1]=0
    
print(ans)
   


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

int main() {
  int n, k, size, tmp;
  cin >> n >> k;
  set<int> st;
  for (int i = 0; i < n; i++) {
    cin >> size;
    for (int j = 0; j < size; j++) {
      cin >> tmp;
      st.insert(tmp);
    }
  }

  cout << n - st.size() << endl;
}

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

int main()
{
    long long int a,b,n,x;
    cin>>a>>b>>n;
    if(n<b)
     x = floor((a*n)/b)-a*floor(n/b);
    else
     x = floor((a*(b-1))/b)-a*floor((b-1)/b);

    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
int a,b,c,d,e,f,g,h,i;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    d=3*c-a-b;
    e=2*c-d;
    f=3*c-a-e;
    g=2*c-f;
    h=3*c-d-g;
    i=2*c-b;
    printf("%d %d %d\n%d %d %d\n%d %d %d\n",a,b,d,f,c,g,e,i,h);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int N, Ma, Mb, a[40], b[40], c[40], dp[41][401][401];
constexpr int inf{ numeric_limits<int>::max() / 3 };
int main() {
    cin >> N >> Ma >> Mb;
    for(int i{}; i < N; ++i)
        cin >> a[i] >> b[i] >> c[i];
    fill(dp[0][0], dp[41][0], inf);
    dp[0][0][0] = 0;
    for(int i{}; i < N; ++i)
        for(int j{}; j <= 400; ++j)
            for(int k{}; k <= 400; ++k) {
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                if(j + a[i] <= 400 && k + b[i] <= 400)
                    dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
    int ans{ inf };
    for(int i{ 1 }; i <= 400; ++i)
        for(int j{ 1 }; j <= 400; ++j)
            if(i * Mb == j * Ma)
                ans = min(ans, dp[N][i][j]);
    cout << (ans < inf ? ans : -1) << endl;
}


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

using namespace std;

//combinationを作る前処理
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;



long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long com(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
    int n, m;
    COMinit();
    cin >> n >> m;
  
    auto vec = prime_factorize(m);
  
    long long res = 1;
  
    for (int k=1;k<=m;k++) {
       
        res = ( com(m-1,k-1) * com(n-m+1,k)) % MOD;
    
    cout << res << endl;
}          
}


Measured memory_bytes: 5120
import itertools
import copy
n, k = map(int, input().split())
a = list(map(int, input().split()))

ans = 10 ** 100
for item in itertools.combinations(range(n), r=k):
    tmp = 0
    b = copy.copy(a)
    for i in item:
        b[i] = a[i] if i==0 else max(max(b[:i]) + 1, a[i])
        tmp += b[i] - a[i]
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 43868
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
void solve()
{   ll X,Y,Z;
    cin>>X>>Y>>Z;
    swap(X,Y);
    swap(X,Z);
    cout<<X<<" "<<Y<<" "<<Z;

    
}

int main()
{   //seive();
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
	
int main() {
	int n,res;
	for(;cin>>n;){
		int i;
		res=1;
		for(i=1;i<=n;i++){
			res+=i;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

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

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const int MOD = 1e9 + 7;

int madd(ll a, ll b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int msub(ll a, ll b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

ll mul(ll a, ll b) {
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (MOD)
  );
  return m;
}

vvll mat_mul(const vvll& A, const vvll& B){
	int n = isize(A);
	vvll C = vvll(n, vll(n, 0));
	rep(i, n){
		rep(j, n){
			rep(k, n){
				C[i][k] = madd(C[i][k], mul(A[i][j], B[j][k]));
				// C[i][k] = (C[i][k] + A[i][j] * B[j][k]) % MOD;
				// C[i][k] = madd(C[i][k], A[i][j] * B[j][k]);
			}
		}
	}
	return C;
}

vvll mat_exp(vvll M, ll k){
	int n = isize(M);
	vvll ans = vvll(n, vll(n, 0));
	rep(i, n){
		ans[i][i] = 1;
	}
	while(k){
		if (k % 2) ans = mat_mul(ans, M);
		k /= 2;
		M = mat_mul(M, M);
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	ll k; cin >> k;
	vvll A = vvll(n, vll(n, 0));
	rep(i, n){
		rep(j, n){
			int x; cin >> x;
			if (x) A[i][j] = 1;
		}
	}
	ll ans = 0;
	vvll M = mat_exp(A, k);
	rep(i, n){
		rep(j, n){
			ans = madd(ans, M[i][j]);
		}
	}
	cout << ans;
}	

Measured memory_bytes: 3728
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	int N;
	int mozi_n, kanban_n;
	int cnt = 0;
	bool flag = true;
	char mozi[102];
	char kanban[102];
	cin >> N >> mozi;
	mozi_n = strlen(mozi);
	for (int i = 0; i < N; i++){
		cin >> kanban;
		kanban_n = strlen(kanban);
		for (int j = 0; j < kanban_n ; j++){
			for (int k = 1; j + (mozi_n-1)*k < kanban_n; k++){
				for (int ii = 0; ii < mozi_n; ii++){
					if (mozi[ii] == kanban[j + k*ii]){
					}
					else {
						flag = false;
					}
				}
				if (flag == true) {
					cnt++;
					j = kanban_n - mozi_n;
				}
				flag = true;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3104
n=int(input())
a,b=0,n
for i in range(1,int(n**0.5)+1):
  j=n//i
  if j-i<b-a and i*j==n:
    a,b=i,j
a= a-1 if a>=1 else 0
b= b-1 if b>=1 else 0
print(a+b)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
 
int solve(vector<int> h)
{
  int n=h.size();
  vector<int> t(n,INT_MAX);
  t[0]=0;
  for(int i=0;i<n-1;++i)
  {
      if(i!=n-2)
      {
        t[i+2]=min(t[i]+abs(h[i]-h[i+2]), t[i+2]);
      }
 
       t[i+1]=min(t[i]+abs(h[i]-h[i+1]), t[i+1]);
  }
  return t[n-1];  
}
 
int main(){
  int n;
  cin>>n;
  vector<int> h;
  for(int i=0;i<n;++i){
    int ele ;
    cin>>ele;
    h.pb(ele);
  }
  cout<<solve(h)<<"\n";
return 0;
}

Measured memory_bytes: 1528
#include <stdio.h>

int main(void){
	char str[20];

	scanf("%s", str);

	for(int i=0; str[i] != '\0'; i++) {
		if(str[i] == ',') {
			printf(" ");
		}else{
			printf("%c", str[i]);
		}
	}

	return 0;
}


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

int main()
{
	int a, b, k;
	cin >> a >> b >> k;
	map<int, int> M;
	for (int i = 0; i < k; ++i)
	{
		if (a + i <= b)
		{
			cout << a + i << endl;
			M[a+i] = 1;
		}
	}
	for (int i = k-1; i >= 0; --i)
	{
		if (!M[b-i] && b - i >= a)
		{
			cout << b - i << endl;
		}
	}
	return 0;
}

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

const int MAX = 200;
const int INF = 1000;
const int D_x[4] = { -1,0,1,0 };
const int D_y[4] = { 0,1,0,-1 };

struct Node {
	Node() {
		for (int i = 0; i < 4; i++) {
			child[i] = NULL;
		}
	}
	Node* child[4];
};

void solve(Node* node, int x, int y, int& min_x, int& min_y, int& max_x, int& max_y) {
	min_x = min(x, min_x);
	min_y = min(y, min_y);
	max_x = max(x, max_x);
	max_y = max(y, max_y);

	for (int i = 0; i < 4; i++) {
		if (node->child[i]) {
			solve(node->child[i], x + D_x[i], y + D_y[i], min_x, min_y, max_x, max_y);
		}
	}
}

int main() {
	int N;
	while (true) {
		cin >> N;
		if (N == 0)break;
		Node node[MAX];
		int min_x = INF;
		int min_y = INF;
		int max_x = -INF;
		int max_y = -INF;

		for (int i = 1; i < N; i++) {
			int n, d;
			cin >> n >> d;
			node[n].child[d] = &node[i];
		}

		solve(node, 0, 0, min_x, min_y, max_x, max_y);

		cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3092