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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int A,B; cin >> A >> B;
    cout << A*B << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

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

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll h,w;
  char s[100][100];
  cin>>h>>w;
  reps(i,h+1){
    reps(j,w+1)cin>>s[i][j];
  }

  reps(i,h+1){
    reps(j,w+1){
      if(s[i][j]=='#'&&s[i-1][j]!='#'&&s[i][j-1]!='#'&&s[i+1][j]!='#'&&s[i][j+1]!='#'){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main(void){

  int a,b,c,i;

  scanf("%d %d %d",&a,&b,&c);

  for(i=0;a*i<=a*b;i++){
    if((a*i)%b==c){
      printf("YES\n");
      return 0;
    }
  }

  printf("NO\n");

  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,a[100],i,sum=0;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	sort(a+1,a+1+n);
	for(i=n-k+1;i<=n;i++){
		sum+=a[i];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
x = list(map(int, input().split()))
ans = float("inf")
for i in range(N - K + 1):
    left = x[i]
    right = x[K - 1 + i]
    if left * right >= 0:
        ans = min(ans, max(abs(left), abs(right)))
    else:
        ans = min(ans, min(abs(left), abs(right)) + abs(left - right))
print(ans)

Measured memory_bytes: 14252
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
P = [-1] + LI()
X = LI()
G = [[] for _ in range(n)]
for i in range(1, n):
    G[P[i] - 1] += [i]
    G[i] += [P[i] - 1]

def check(u):
    total = 0
    bit  = 1
    for v in G[u]:
        if v == P[u] - 1:
            continue
        if len(G[v]) == 1:
            total += X[v]
            bit |= bit << X[v]
        else:
            a, b = check(v)
            total += a + b
            bit =  bit << a | bit << b
    c = bin(bit)
    for j in range(X[u], -1, -1):
        if bit >> j & 1:
            total += X[u] - j
            return X[u], total - X[u]
    else:
        print('IMPOSSIBLE')
        exit()


if check(0):
    print('POSSIBLE')

Measured memory_bytes: 42972
import sys
N = int(input())
t = [0]*N
x = [0]*N
y = [0]*N
for i in range(N):
    t[i],x[i],y[i] = [int(n) for n in input().split()]
dt = t[0]
d = x[0] + y[0]
if(dt < d or dt%2 != d%2):
    print("No")
    sys.exit()
for i in range(1,N):
    dt = t[i] - t[i-1]
    d = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1])
    if(dt < d or dt%2 != d%2):
        print("No")
        sys.exit()
print("Yes")


Measured memory_bytes: 11732
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int N = 0;
	int num = 0;
	vector <int> a;
	int kisu = 0;
	int gusu2 = 0;
	int gusu4 = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> num;
		a.push_back(num);
		if (a[i] % 4 == 0) {
			gusu4++;
		}

		else if (a[i] % 2 == 0) {
			gusu2++;
		}
		else {
			kisu++;
		}




	}
	if (gusu2 == 0) {
		if (kisu <= (gusu4 + 1)) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	if (gusu2 > 0){
		if (kisu <= gusu4) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
}

	

	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)

template<class T>inline void chmin(T &a,T b){a=min(a,b);}
template<class T>inline void chmax(T &a,T b){a=max(a,b);}

int perm[2000005];
void init(){
	perm[0]=1;
	REP(i,2000005)perm[i]=perm[i-1]*i%mod;
}
int mod_pow(int x,int y){
	int res=1;
	while(y){
		if(y&1)res*=x;
		res%=mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
int comb(int x,int y){
	return perm[x]*mod_pow(perm[x-y],mod-2)%mod*mod_pow(perm[y],mod-2)%mod;
}
signed main(){
	init();
	int r1,c1,r2,c2;cin>>r1>>c1>>r2>>c2;
	int ans=0;
	for(int i=r1;i<=r2;i++){
		int ans1=comb(i+c2+1,i+1);
		int ans2=comb(i+c1,i+1);
		ans+=(ans1-ans2+mod)%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15872
N = int(input())

cnt = 0
A = 0
B = 0
AB = 0

for _ in range(N):
  s = input()
  if s[0] == 'B':
    B += 1
  if s[-1] == 'A':
    A += 1
  if s[-1] == 'A' and s[0] == 'B':
    AB += 1
  for i in range(len(s)-1):
    if s[i] == 'A' and s[i+1] == 'B':
      cnt += 1
    
cnt += min(A,B)
if A == AB and B == AB and AB > 0:
  cnt -= 1
  
print(cnt)

Measured memory_bytes: 75868
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

long long ans[300005]={},ansn=1,ansm=1;

int main()
{
  ios_base::sync_with_stdio(false);
  
  int n,m;
  
  cin >> n >> m;
  if( abs(n-m) > 1){
    cout << 0 << endl;
    return(0);
  }
  
  // ans[1] = ans[2] = 1;
  // ans[3] = ans[4] = 2;
  
  // for(int i=5;i<= (n+m+1) ;i++){
    // ans[i] = (ans[i-1]*(i/2)) % MOD;
  int i;
  for(i=1;i<n+1;i++){
    ansn=(i*ansn)%MOD;
  }
  
  for(i=1;i<m+1;i++){
    ansm=(i*ansm)%MOD;
  }

  if(n != m){
    //cout  << (ans[n+m]*max(n, m))%MOD << endl;
    cout<<(ansn*ansm)%MOD<<endl;
  } else{
    ///cout << (ans[n+m]*(n+m))%MOD << endl;
    cout<<(ansn*ansm*2)%MOD<<endl;
  }

  return(0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int K, A, B;
	cin >> K >> A >> B;
	bool flag = 0;
	for (int i = A; i <= B; i++)
	{
		if (i%K == 0)	flag = 1;
	}
	if (flag == 1)	cout << "OK" << endl;
	else cout << "NG" << endl;
}



Measured memory_bytes: 3588
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
long long int N, M;
int main()
{
    scanf("%lld%lld",&N,&M);

        long long int sum1, sum2, sum;
        sum1 = N;
        sum2 = (M-2*N)/4;
        sum = sum1+sum2;
        if(M/2<N)
            printf("%lld\n",M/2);
        else
            printf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 256
if __name__ == "__main__":
    n, m, l = map(lambda x: int(x), input().split())
    a_matrix = [[0] * m] * n
    b_matrix = [[0] * l] * m

    for idx in range(n):
        a_matrix[idx] = list(map(lambda x: int(x), input().split()))

    for idx in range(m):
        b_matrix[idx] = list(map(lambda x: int(x), input().split()))

    for row_idx in range(n):
        one_row_result = []
        for col_idx in range(l):
            one_row_result.append(sum(
                [a_matrix[row_idx][elem] * b_matrix[elem][col_idx]
                 for elem in range(m)]
            ))
        print(" ".join([str(elem) for elem in one_row_result]))



Measured memory_bytes: 6320
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>


using namespace std;

using ll = long long;

const ll MAX = 100;


ll edges[MAX][MAX];
bool finished[MAX] = {};
ll d[MAX];
ll n;


void dijkstra()
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, 0));

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        if (finished[p.second])
            continue;

        for (ll i = 0; i < n; i++) {
            if (!(edges[p.second][i] > 0) || finished[i])
                continue;
            pq.push(make_pair(p.first + edges[p.second][i], i));
        }
        finished[p.second] = true;
        d[p.second] = p.first;
    }
}


int main()
{
    cin >> n;
    for (ll i = 0; i < n; i++) {
        ll u, k;
        cin >> u >> k;
        for (ll j = 0; j < k; j++) {
            ll v, c;
            cin >> v >> c;
            edges[u][v] = c;
        }
    }

    dijkstra();

    for (ll i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }
}



Measured memory_bytes: 3172
N = int(input())

def df(n):
    if n == 0 or n == 1:
        return 0
    elif n % 2 == 1:
        return 0
    else:
        memo = {}
        ans = 0
        def calc(x):
            if x == 0:
                return 0
            if x not in memo:
                memo[x] = calc(x - 1) * 5 + 1
            return memo[x]

        while n >= 50:
            x = n // 2
            c = 0
            while x >= 5:
                x /= 5
                c += 1
            ans += calc(c)
            n -= 5 ** c * 2
        ans += n // 10
        return ans

print(df(N))

Measured memory_bytes: 38256
def main():
    N = int(input())
    X = list(map(int, input().split()))
    ans = float("inf")
    for p in range(1, 101):
        tmp = 0
        for x in X:
            tmp += (x-p)**2
        ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
  int N, M, X;
  cin >> N >> M >> X;

  int a;

  int l = 0;
  int r = 0;

  for (int i = 0; i < M; i++ ){
    cin >> a;
    if (a < X){
      l++;
    } else {
      r++;
    }
  }
  
  cout << min(l, r) << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int d1,d2,d3,d4;
  d1 = N%10; d2 = N/10%10; d3 = N/100%10; d4 = N/1000;
  if((d1==d2 && d2==d3)||(d2==d3 && d3==d4)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    ll N, K;
    cin >> N  >> K;
    ll A[N];
    rep(i,N) {
        ll a;
        cin >> a;
        A[i] = a;
    }

    rep(i,N) {
        if (i<K) continue;
        else {
            ll n = A[i];
            ll p = A[i-K];
            if (n>p) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" <<endl;
            }
        }
    }
}

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

int main(){
	int a,b, result;
	cin>>a>>b;
	if(a<b){
		for(int i=b; i>0; i--){
			result+=a*pow(10,i);
		}
		cout<<result/10;
	}else{
		for(int j=a; j>0; j--){
			result+=b*pow(10,j);
		}
		cout<<result/10;
	}
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())

tli = [ int(it)*2 for it in input().split() ]
vli = [ int(it)*2 for it in input().split() ]

vmax = [0]
for i in range(len(tli)):
  tmp = vmax.pop()
  vmax.append( min(tmp,vli[i]) )
  vmax.extend( [vli[i]]*(tli[i]) )
vmax[-1]=(0)
vmax[0]=0
T = len( vmax ) - 1

for j in range( 1000 ):
  for i in range( T ):
    vmax[i+1] = min( vmax[i]+1 , vmax[i+1] )
  for i in range( T,0,-1):
    vmax[i-1] = min( vmax[i]+1 , vmax[i-1] )
  if (j==0):
    pass
    #print ( vmax )
    
print ( 0.25 * sum(vmax) )


Measured memory_bytes: 44188
#include<stdio.h>

int main(void)
{
	int i,j,a[4],b[4],h,B;
	
	while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF)
	{
		h=0;
		B=0;
	    for(i=0;i<=3;i++)
	    {
		    scanf("%d",&b[i]);
	    }
		for(i=0;i<=3;i++)
		{
			if(a[i]==b[i]) h++;
		}
		for(i=0;i<=3;i++)
		{
			for(j=0;j<=3;j++)
			{
				if(i!=j && a[i]==b[j]) B++;
			}
		}
		printf("%d %d\n",h,B);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;

template <class T> void multiple_transform(::std::vector<T> &a) {
    int n = a.size();
    ::std::vector<bool> sieve(n, true);
    for (int p = 2; p < n; ++p) {
        if (sieve[p]) {
            for (int k = (n - 1) / p; k != 0; --k) {
                sieve[k * p] = false;
                a[k] = (a[k] + a[k * p])%mod;
            }
        }
    }
    for (int i = 0; ++i != n;) {
        a[i] = (a[i] + a[0])%mod;
    }
}

template <class T> void inverse_multiple_transform(::std::vector<T> &a) {
    int n = a.size();
    ::std::vector<bool> sieve(n, true);
    for (int i = 0; ++i != n;) {
        a[i] = (a[i] - a[0] + mod)%mod;
    }
    for (int p = 2; p < n; ++p) {
        if (sieve[p]) {
            for (int k = 1; k * p < n; ++k) {
                sieve[k * p] = false;
                a[k] = (a[k] - a[k * p] + mod)%mod;
            }
        }
    }
}

LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}

int main(){
    int n;cin >> n;
    vector<LL> a(1000001,0),A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        a[A[i]] += A[i];
    }
    auto b = a;
    multiple_transform(a);
    vector<LL> c(1000001);
    for (int i = 0; i <= 1000000; i++) {
        c[i] = a[i] * a[i];
    }
    inverse_multiple_transform(c);
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        c[A[i]] = (c[A[i]] + mod - (A[i] * A[i] %mod)) %mod;
    }
    for (int i = 1; i <= 1000000; i++) {
        ans = (ans + c[i] * fpow(2*i,mod-2))%mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 25344
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<random>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<stdlib.h>
#include<cstdlib>
#include<unordered_map>
#include<time.h>
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
#define int long long
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 999999999999999999;
using namespace std;
int n, a[100000];
signed main() {
	cin >> n;
	int four = 0, two = 0, one = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 4 == 0)
			four++;
		else if (a[i] % 2 == 0)
			two++;
		else
			one++;
	}
	if (four >= one || four == one - 1 && four + one == n) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No\n";
	}
	getchar(); getchar();
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    if (a + b == c
       || b + c == a
       || c + a == b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21972
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates



int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if ((x + d - 1) / d > k) {
        cout << x - k * d << endl;
    } else if ((k - x / d) % 2 == 0) {
        cout << x % d << endl;
    } else {
        cout << d - x % d << endl;
    }
    return 0;
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;                     
using namespace __gnu_pbds;
// assert(a[i]<n ) // if we want to check for special cond , used for debug
// make less_equal in order to make a multiset pbds
const ll Mod = (int)1e9;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}


ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;	
while(r)
{
	a = a*p;
	b = b*r;
	
	ll g = __gcd(a,b);
	
	a = a/g;
	b = b/g;
	
	p--;
	r--;	
}	
return a;
	
}

void solve()
{
	ll n,l;
	cin>>n>>l;
	vector<string> v;
	//cin>>n>>l;
	
	for(ll i=0;i<n;i++)
	{
	string s;	
	cin>>s;
	cin.ignore();
	v.push_back(s);	
	}
	string ans;
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)
	{
		ans += v[i];	
	}
	
	
  //cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
  cout<<ans<<endl;
return ;
}


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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void) {
  int A, B, X;
  cin >> A >> B >> X;
  int Pmax = ceil(X/1000.0), Qmax = ceil(X/500.0), res = 100000;
  for (int P = 0; P <= Pmax; P++) {
    for (int Q = 0; Q <= Qmax; Q++) {
      if (A*P + B*Q < res && 1000*P+500*Q >= X) {
        res = A*P+B*Q;
      }
    }
  }
  cout << res << endl;
  return 0;
}



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

int main(){
    int n;
    cin >> n;
    long t[n];
    for(int i=0;i<n;++i) cin >> t[i];
    int m; cin >> m;
    int p[m];
    int x[m];
    for(int i=0;i<m;++i) cin >> p[i] >> x[i];
    int tmp;int ans=0;
    for(int i=0;i<m;++i){
        tmp=t[p[i]-1]; //Tの元の点数を保存
        t[p[i]-1]=x[i];
        for(int j=0;j<n;++j){
            ans+=t[j];
        }
        cout << ans << endl;
        ans=0; t[p[i]-1]=tmp; //Tを元の値に戻す
    }
}

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

int main()
{
	int p[100010];
	int acc[100010];
	int Q;
	int r, l;
	fill(begin(p), end(p), 1);
	p[0] = p[1] = 0;
	for (int i = 2; i*i <= 100010; i++)
	{
		if (p[i] == 1)
		{
			for (int j = 2; i*j <= 100000; j++)
			{
				p[i*j] = 0;
			}
		}
	}
	for (int i = 1; i < 100010; i++)
	{
		acc[i] = acc[i - 1];
		if (i % 2 == 1 && p[i] == 1 && p[(i + 1) / 2] == 1)
		{
			acc[i]++;
		}
	}
	cin >> Q;
	for (int i = 0; i < Q; i++)
	{
		cin >> l >> r;
		cout << acc[r] - acc[l - 1] << endl;
	}

	return 0;
}

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

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



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

  if(a<=8&&b<=8){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
  return 0;
}


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

int main()
{  int n,i,j,k;
  cin>>n;
  int x[3],y[3] ;
  cin>>x[0]>>x[1]>>x[2];
  for( i=1;i<n;i++)
  {
    int a,b,c;
    cin >>a>>b>>c; 
   y[0]= max( x[1],x[2] )+a;
   y[1]= max(x[0],x[2])+b;
    y[2]= max(x[0],x[1])+c;
    x[0]=y[0];x[1]=y[1];x[2]=y[2];}
    x[0]>max(x[1],x[2])?cout<<x[0]:cout<<max(x[1],x[2]);
   return 0; }
    

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  int ans = 0;
  in(string, a, b);
  rep(i, a.size()) if (a[i] != b[i])++ ans;
  out(ans);
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;
    
    int l = 0;
    int r = S.size()-1;

    int cnt = 0;
    while (l <= r) {
        if (S[l] == S[r]) {
            l++; r--;
        } else {
            if (S[l] == 'x') {
                cnt++; l++;
            } else if (S[r] == 'x') {
                cnt++; r--;
            } else {
                cout << -1 << endl;
                return 0;
            }
        }
        // cout << l << " " << r << endl;
    }

    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 512
import sys
readline = sys.stdin.readline


def solve():
    N = int(readline())
    X = [0] * N
    Y = [0] * N
    U = [0] * N

    for i in range(N):
        x, y, u = readline().split()
        X[i] = int(x)
        Y[i] = int(y)
        U[i] = u
    
    ans = 10 ** 10

    _U,D,L,R = 'U','D','L','R'

    rs = [(X[i], Y[i]) for i in range(N) if U[i] == R]
    ls = [(X[i], Y[i]) for i in range(N) if U[i] == L]
    ans = min(ans, horizon(rs, ls))

    rs = [(Y[i], X[i]) for i in range(N) if U[i] == _U]
    ls = [(Y[i], X[i]) for i in range(N) if U[i] == D]
    ans = min(ans, horizon(rs, ls))


    # cross
    rs = [(X[i], Y[i]) for i in range(N) if U[i] == R]
    ds = [(X[i], Y[i]) for i in range(N) if U[i] == D]
    ans = min(ans, cross(rs, ds))

    rs = [(X[i], -Y[i]) for i in range(N) if U[i] == R]
    ds = [(X[i], -Y[i]) for i in range(N) if U[i] == _U]
    ans = min(ans, cross(rs, ds))

    rs = [(-X[i], Y[i]) for i in range(N) if U[i] == L]
    ds = [(-X[i], Y[i]) for i in range(N) if U[i] == D]
    ans = min(ans, cross(rs, ds))

    rs = [(-X[i], -Y[i]) for i in range(N) if U[i] == L]
    ds = [(-X[i], -Y[i]) for i in range(N) if U[i] == _U]
    ans = min(ans, cross(rs, ds))

    if ans == 10 ** 10:
        print('SAFE')
    else:
        print(ans)


def horizon(rights, lefts):
    Y = {}
    for rx, ry in rights:
        if ry not in Y:
            Y[ry] = []
        Y[ry].append(rx)
    for k in Y:
        Y[k].sort()

    res = 10 ** 10
    
    for lx, ly in lefts:
        if ly not in Y:
            continue
        xs = Y[ly]
        t = bisect_right(xs, lx)
        if t == -1:
            continue
        else:
            res = min(res, (lx - xs[t]) * 5)
    
    return res

def bisect_right(xs, x):
    l, r = -1, len(xs)
    while l + 1 < r:
        m = (l + r) // 2
        if xs[m] < x:
            l = m
        else:
            r = m
    return l

def cross(rights, downs):
    x_seps = {}
    
    for x, y in rights:
        xsep = x - y
        if xsep not in x_seps:
            x_seps[xsep] = []
        
        x_seps[xsep].append(x)
    
    for k in x_seps:
        x_seps[k].sort()
    
    res = 10 ** 10

    for x, y in downs:
        xsep = x - y
        if xsep not in x_seps:
            continue
        xs = x_seps[xsep]
        t = bisect_right(xs, x)
        if t != -1:
            res = min(res, (x - xs[t]) * 10)

    return res

solve()

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

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

  struct Cake {
    long long x, y, z;
    Cake(long long x, long long y, long long z) : x(x), y(y), z(z) {}
  };

  vector<Cake> cakes;
  cakes.reserve(N);
  for (int i = 0; i < N; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    cakes.emplace_back(x, y, z);
  }

  long long ans = -(1ll << 60);
  for (int b = 0; b < (1 << 3); b++) {
    vector<long long> scores;
    for (auto&& c : cakes) {
      long long score = 0;
      score += (b & 1) ? c.x : -c.x;
      score += (b & 2) ? c.y : -c.y;
      score += (b & 4) ? c.z : -c.z;
      scores.push_back(score);
    }
    sort(scores.begin(), scores.end());
    reverse(scores.begin(), scores.end());
    long long s = 0;
    for (int i = 0; i < M; i++) {
      s += scores[i];
    }
    if (ans < s) ans = s;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
count = 0

1.upto(n-1) do |i|
  (n-1).downto(i) do |j|
    if a[j-1] > a[j]
      a[j-1], a[j] = a[j], a[j-1]
      count += 1
    end
  end
end

puts a.join(' '), count

Measured memory_bytes: 6104
#include <iostream>
typedef long long LL;
using namespace std;
int main(int argc, char* argv[])
{
	LL A,B,K;
	cin>>A>>B>>K;
	LL i=1;
	bool bTaka=true;
	for (i=1;i<=K;i++){
		if (bTaka){
			if (A%2==1){
				A--;
			}
			A/=2;
			B+=A;
			bTaka=false;
		}else{
			if (B%2==1){
				B--;
			}
			B/=2;
			A+=B;
			bTaka=true;
		}
	}
	cout<<A<<" "<<B<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m,x=map(int,input().split())
a=input().split()
a=list(map(int,list(a)))
c=0
d=0
k=x
while (x<n):
    if x in a:
        c+=1
    x+=1
while (0<k):
    if k in a:
        d+=1
    k-=1
print(min(c,d))


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

using namespace std;


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

    vector<int> a(N);
    for (int i=0; i<N; i++) cin >> a[i];

    int next_num = 0;
    int count = 0;

    while (count < N){

        if (a[next_num] == 2){
            if ((count+1) < N){
                cout << count+1 << endl;
                return 0;
            }
        }

        next_num = a[next_num] - 1;

        count += 1;
    }

    cout << "-1" << endl;

}

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


int main(){
	int n, p;
    vector<int> x, y;

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> p;
        x.push_back(p);
        y.push_back(p);
    }

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

    for (int i = 0; i < n; i++){
        if(x[i] <= y[(n/2)-1]) cout << y[n/2] << endl;
        else cout << y[(n/2)-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,b,a) for(int i = (b); i --> int(a);)
#define trav(i,v) for(auto&i:v)
#define all(c) (c).begin(), (c).end()
#define sz(c) int((c).size())
#define vcr(v,n) vi v(n); trav(var,v) cin >> var;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	int n;
	cin >> n;
	ll a[100100], b[100100], add = 0;
	rep(i,0,n) cin >> a[i] >> b[i];
	rrep(i,n,0) add += (b[i]-(a[i]+add)%b[i])%b[i];
	cout << add << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#define N 100000

int lower_bound(int a[],int x,int n){
	int left=0;
	int right=n-1;
	int mid;
	
	while(left<=right){
	
		mid=(left+right)/2;
		
		if(a[mid]==x){
			for(int i=mid;i>=0;i--)
				if(a[i]!=x)return i+1;
			return 0;
		}
		
		else if(a[mid] > x){
			right=mid-1;
		}
		else if(a[mid] < x){
			left=mid+1;
		}
		
	}
	
	
	if(a[mid] < x){
		for(int i=mid;i<n;i++)
			if(a[i] >= x)return i;
		return n;
		
	}
	else {
		for(int i=mid;i>=0;i--)
			if(a[i] <= x)return i+1;
		return 0;
	}

	
}


int upper_bound(int a[],int x,int n){
	int left=0;
	int right=n-1;
	int mid;
	
	while(left<=right){
	
		mid=(left+right)/2;
		
		if(a[mid]==x){
			for(int i=mid;i<n;i++)
				if(a[i]!=x)return i;
			return n;
		}
		
		else if(a[mid] > x){
			right=mid-1;
		}
		else if(a[mid] < x){
			left=mid+1;
		}
		
	}
	
	
	if(a[mid] < x){
		for(int i=mid;i<n;i++)
			if(a[i] > x)return i;
		return n;
		
	}
	else {
		for(int i=mid;i>=0;i--)
			if(a[i] <= x)return i+1;
		return 0;
	}

	
}



int main(){
	int n,i,q,x;
	int a[N];
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
	
		scanf("%d",&x);
		printf("%d %d\n",lower_bound(a,x,n),upper_bound(a,x,n));
	
	}
	
	return 0;
	
}


Measured memory_bytes: 2244
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 200002;

int p[N];

int main()
{
	int n = in(), ans = 0;
	for(int i = 0; i < n; i++)
	{
		p[i] = in() - 1;
		if(i > p[i])
			if(p[p[i]] == i)
				ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
V = list(map(int, input().split()))

answer = 0
limit = min(N, K)
for a in range(limit+1): #左から取り出す
    for b in range(limit-a+1): #右から取り出す
        for c in range(K-(a+b)+1):
            use = V[:a] + V[N-b:]
            use.sort()
            s = sum(use[c:])
            answer = max(answer, s)

print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<pair<int,int> >adj[MAX];
int v[MAX];
int color[MAX];
void dfs(int src,ll tot)
{
    v[src]=1;
    for(auto i:adj[src])
    {
        int child=i.first;
        int w=i.second;
        if(!v[child])
        {
            if((w+tot)%2ll==0)
            {
                color[i.first]=0;
                dfs(child,tot+w);
            }
            else
            {
                color[i.first]=1;
                dfs(child,tot+w);
            }
        }
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++)
    {
        int a,b,c;
        cin>>a>>b>>c;
        adj[a].push_back({b,c});
        adj[b].push_back({a,c});
    }
    adj[0].push_back({1,0});
    dfs(0,0);
    for(int i=1; i<=n; i++)
        cout<<color[i]<<endl;


    return 0;
}


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

#define ll long long

ll x,ans;

int main()
{
//    freopen("a.in","r",stdin);
    cin>>x;
    ans=x/500;
    x-=ans*500;
    ans*=1000;
    x/=5;
    ans+=x*5;
    cout<<ans;
}




Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <list>
#include <map>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
#define LL long long
const int MAX = 1e6 + 10;
using namespace std;
int vis[MAX];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    for (int x = 1; x * x <= n; x++)
        for (int y = 1; y * y <= n; y++)
            for (int z = 1; z * z <= n; z++)
            {
                int u = x * x + y * y + z * z + x * y + y * z + z * x;
                vis[u]++;
            }
    for (int i = 1; i <= n; i++)
        cout << vis[i] << endl;
    return 0;
}


Measured memory_bytes: 3212
N, Q = map(int, input().split())
S = input()
Query = [list(input().split()) for i in range(Q)]


# 番兵を設置
S = 'x' + S + 'x'

# 左から何番目のゴーレムまで消えるか二分探索
ok, ng = 0, N + 1
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == 0:
            ok = m
            break
    else:
        ng = m
Left_ans = ok

# 右から何番目のゴーレムまで消えるか二分探索
ok, ng = N + 1, 0
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    x = (ok + ng) // 2

    for t, d in Query:
        if S[x] != t:
            continue

        if d == 'R':
            x += 1
        if d == 'L':
            x -= 1

        if x == N + 1:
            ok = m
            break
    else:
        ng = m
Right_ans = ok

print(N - min(N, Left_ans + (N + 1 - Right_ans)))


Measured memory_bytes: 90404
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define D deque
#define PII pair<int, int>
#define P pair
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(grid) (grid).begin(), (grid).end()
#define rall(grid) (grid).rbegin(), (grid).rend()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

template <typename T>
void read(T& a) {
  a = 0;
  char c;
  while ((c = cin.peek()) < 48 or c > 57) cin.get();
  while ((c = cin.get()) > 47 and c < 58) a = (a << 3) + (a << 1) + c - 48;
}

template <typename T, typename... Args>
void read(T& a, Args&&... args) {
  read(a);
  read(forward<Args>(args...)...);
}

template <typename T>
void write(const S& sep, const S& end, T n) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(end.c_str(), end.size() * sizeof(char));
}

template <typename T, typename... Args>
void write(const S& sep, const S& end, T n, Args&&... args) {
  char c[128] = {0};
  int i = 0;
  for (; n; ++i, n /= 10) c[i] = n % 10;

  for (--i; i >= 0; --i) cout.put(c[i] + 48);

  cout.write(sep.c_str(), sep.size() * sizeof(char));
  write(sep, end, forward<Args>(args...)...);
}
void solve() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  V<unsigned LL> red(a), green(b), colourless(c);
  FOR(i, a) {
      cin >> red[i];
  }
  FOR(i, b) {
      cin >> green[i];
  }
  FOR(i, c) {
      cin >> colourless[i];
  }
  sort(rall(red));
  sort(rall(green));
  FOR(i, x) {
      colourless.push_back(red[i]);
  }
  FOR(i, y) {
      colourless.push_back(green[i]);
  }
  sort(rall(colourless));
  auto res = 0ULL;
  for (int i = 0; i < x + y; ++i) {
      res += colourless[i];
  }
  cout << res << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}


Measured memory_bytes: 7840
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Card struct{ Number, Stock int }
type Cards []Card

func (c Cards) Len() int           { return len(c) }
func (c Cards) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c Cards) Less(i, j int) bool { return c[i].Number > c[j].Number }

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	var sum int64 = 0
	for i := range as {
		sc.Scan()
		as[i], _ = strconv.Atoi(sc.Text())
		sum += int64(as[i])
	}
	sort.Ints(as)

	var cs Cards = make([]Card, m)
	for i := range cs {
		sc.Scan()
		cs[i].Stock, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		cs[i].Number, _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(cs)

	var p int
lb:
	for _, v := range cs {
		for i := 0; i < v.Stock; i++ {
			if p >= len(as) || v.Number < as[p] {
				break lb
			}
			sum += int64(v.Number - as[p])
			p++
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 5120
# ABC135
# greedy algorithm
def main():
    n = int(input())
    A = list(map(int, input().rstrip().split()))
    B = list(map(int, input().rstrip().split()))
    ans = 0
    for i in range(n):
        cur1 = min(A[i], B[i])
        cur2 = min(A[i + 1], B[i] - cur1)
        A[i] -= cur1
        A[i + 1] -= cur2
        ans += cur1 + cur2
    print(ans)


if __name__ == "__main__":
    main()

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

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  int n;
  std::cin>>n;
  
  int result=(1000-n%1000)%1000;
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  map<int,int> p;
  string ss="";
  int now=0;
  rep(i,n){
    if(p.count(s[i]-'a')) ss+=('a'+p.at(s[i]-'a'));
    else {
      p[s[i]-'a']=now;
      ss+=('a'+now);
      now++;
    }
  }

  map<int,int> q;
  string tt="";
  now=0;
  rep(i,n){
    if(q.count(t[i]-'a')) tt+=('a'+q.at(t[i]-'a'));
    else {
      q[t[i]-'a']=now;
      tt+=('a'+now);
      now++;
    }
  }

  cout << (ss==tt?"Yes":"No") << endl;
}

Measured memory_bytes: 1168
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int item[3002][3002];
ll dp[3002][3002][4];

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

int main(){
	int r, c, k;
	cin >> r >> c >> k;
	for (int i = 0; i < k; i++){
		int a, b;
		cin >> a >> b;
		cin >> item[a][b];
	}

	if (item[1][1]){
		dp[1][1][1] = item[1][1];
	}

	for (int i = 1; i <= r; i++){
		for (int j = 1; j <= c; j++){
			for (int k = 0; k <= 3; k++){
				if (item[i][j+1]){
					if (k != 3){
						dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + item[i][j+1]);
					}
				}
				if (item[i+1][j]){
					dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][k] + item[i+1][j]);
				}
				dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
				dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= 3; i++){
		ans = llmax(ans, dp[r][c][i]);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
 int h,a;
 cin >> h >> a;
 int ans = 0;
 while(h > 0){
      h -= a;
      ans ++ ;
 }
 cout << ans << endl; 
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
s1 = 0
s2 = 0
ans1 = 0
ans2 = 0

for i in range(n):
    s1 += a[i]
    s2 += a[i]
    if i%2 == 0 and s1 >= 0:
        ans1 += s1
        ans1 += 1
        s1 = -1
    elif i%2 != 0 and s1 <= 0:
        ans1 -= s1
        ans1 += 1
        s1 = 1
    if i%2 == 0 and s2 <= 0:
        ans2 -= s2
        ans2 += 1
        s2 = 1
    elif i%2 != 0 and s2 >= 0:
        ans2 += s2
        ans2 += 1
        s2 = -1

print(min(ans1, ans2))

Measured memory_bytes: 14468
A, B, C = map(int, input().split())
if A == B == C and A % 2 == 0:
  print(-1)
else:
  count = 0
  while 0 == A % 2 == B % 2 == C % 2:
    _A = (B + C) // 2
    _B = (C + A) // 2
    _C = (A + B) // 2
    A = _A
    B = _B
    C = _C
    count += 1
    # print("A: {}, B: {}, C: {}".format(A, B, C))
  print(count)
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
    int n;
    cin >>n;
    vector<int>h(n);
    rep(i,n)cin >> h[i];
    reverse(h.begin(),h.end());
    rep(i,n-1){
        if(h[i+1]-h[i]>=2){
            cout << "No" <<endl;
            return 0;
        }
        if(h[i+1]-h[i]==1){
            h[i+1]--;
        }
    }
    cout << "Yes" <<endl;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}

ll memop[2000000];
ll mkai(ll i){
    if(i==0){
        return 1;
    }
    if(memop[i]!=0){
        return memop[i];
    }else{
        ll ans=(mkai(i-1)*hpow(i,i_7-2))%i_7;
        memop[i]=ans;
        return ans;
    }
}

ll memok[2000000];
ll kai(ll i){
    if(i==0){
        return 1;
    }
    if(memok[i]!=0){
        return memok[i];
    }else{
        ll ans=(kai(i-1)*i)%i_7;
        memok[i]=ans;
        return ans;
    }
}

ll comb(ll n,ll k){
    ll ans=(kai(n)*mkai(k))%i_7;
    ans=(ans*mkai(n-k))%i_7;
    return ans;
}

int main(){
    ll n,m,k;cin>>n>>m>>k;
    ll s=0,t=0;
    rep(i,1,n-1)s=(s+i*(n-i))%i_7;
    s=((s*m)%i_7*m)%i_7;
    rep(i,1,m-1)t=(t+i*(m-i))%i_7;
    t=((t*n)%i_7*n)%i_7;
    ll sum=s+t;
    ll c=comb(n*m-2,k-2);
    ll ans=(c*sum)%i_7;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 8960
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define int long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc =(calc* calc)%mod;
       }
       else
       {
         calc = (base*power(base, exp-1))%mod;
       }
       return calc%mod;
    }
}
    int32_t main()
    {
        std::ios::sync_with_stdio(false);
        int n,n1;
        cin>>n>>n1;
        cout<<n*n1<<endl;
        
        return 0;
    }



Measured memory_bytes: 3652
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan =new Scanner(System.in);
String R=scan.next();
double r=Double.parseDouble(R);
double a=r*r*3.141592653589;
double b=r*2.0*3.141592653589;
System.out.printf("%f %f\n",a,b);
}
}

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

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

  int N;
  cin >> N;
  N++;
  ll count = 0;
  rep(i, N){
    if(i%3 != 0 && i%5 != 0){
      count += i;
    }
  }
  cout << count << "\n";
}




Measured memory_bytes: 3648