akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using ll=long long int;

constexpr ll INF=(ll)1e15;

constexpr int MAX_N=300;

int n;

ll a[MAX_N][MAX_N];

ll dp[MAX_N][MAX_N];

int main() {

    std::cin>>n;

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            std::cin>>a[i][j];
            dp[i][j]=a[i][j];
        }
    }

    for(int k=0;k<n;++k){
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j)
                dp[i][j]=std::min(dp[i][j],dp[i][k]+dp[k][j]);
        }
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(dp[i][j]<a[i][j]){
                std::cout<<-1<<std::endl;
                return 0;
            }
        }
    }

    ll ans=0;

    for(int i=0;i<n;++i){
        for(int j=i+1;j<n;++j){
            for(int k=0;k<n;++k){
                if(i!=k&&j!=k&&dp[i][j]==dp[i][k]+dp[k][j])
                    goto a;
            }
            ans+=dp[i][j];
            a:;
        }
    }

    std::cout<<ans<<std::endl;

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {    
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int maxsum = 0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i + j > n)continue;
            else{
                vector<int> v;
                int sum = 0;
                for(int kp=0;kp<i;kp++){
                    v.push_back(a[kp]);
                    sum+=a[kp];
                }
                int g = n-1;
                for(int kp=0;kp<j;kp++){
                    v.push_back(a[g]);
                    sum+=a[g];
                    g--;
                }
                sort(v.begin(),v.end());
                
                if((int)v.size() > k)continue;
                else{
                    maxsum = max(maxsum,sum);
                    int h = 0;
                    for(int kp=v.size();(kp<k && h<(int)v.size());kp++){
                        if(v[h] < 0){
                            sum += abs(v[h]);
                            h++;
                            maxsum = max(maxsum,sum);
                        }else{
                            break;
                        }
                    }
                }
                //cout<<sum<<"\n";
            }
        }
    }
    cout<<maxsum<<"\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		int N = GetInt();
		int[,] gsb = new int[2, 3];
		for(int i = 0; i < 2; i++)
			for(int j = 0; j < 3; j++)
				gsb[i, j] = GetInt();

		long[] dpAB = new long[N + 1];
		for(int i = 1; i <= N; i++)
		{			
			dpAB[i] = (long)i;
			for(int j = 0; j < 3; j++)
			{
				if(i < gsb[0, j])
					continue;

				dpAB[i] = Math.Max(dpAB[i], dpAB[i - gsb[0, j]] + (long)gsb[1, j]);
			}
		}

		long maxAB = dpAB.Max();
		long[] dpBA = new long[maxAB + 1];
		for(int i = 1; i <= maxAB; i++)
		{
			dpBA[i] = (long)i;
			for(int j = 0; j < 3; j++)
			{
				if(i < gsb[1, j])
					continue;

				dpBA[i] = Math.Max(dpBA[i], dpBA[i - gsb[1, j]] + (long)gsb[0, j]);
			}
		}

		Console.WriteLine(dpBA.Max());
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 206304
#include <iostream>

/*
[x^Ny^K]  \sum_{t=0}^\infty [(M-1)(x+yx^2+y^2x^3+...)]^t
[x^Ny^K]  1/[1- (M-1)(x+yx^2+y^2x^3+...)]
[x^Ny^K]  1/[1- (M-1)x/(1-yx)]
[x^Ny^K]  (1-yx)/[1-yx - (M-1)x]
[x^Ny^K]  (1-yx) \sum_{i=0}^\infty (yx+(M-1)x)^i

[y^K]  (y+(M-1))^N - y (y+(M-1))^{N-1}
\binom{N}{K} (M-1)^{N-K} - \binom{N-1}{K-1} (M-1)^{N-K}
(M-1)^{N-K} \binom{N-1}{K}

\sum_{i=0}^K (M-1)^{N-i} \binom{N-1}{i}
M\sum_{i=0}^K (M-1)^{N-i-1} \binom{N-1}{i}
*/

int n, m, k;

constexpr int mod = 998244353;

using u64 = unsigned long long int;

int inv[200001];

int modpow(int a, int n){
  int r = 1;
  for(; n; n >>= 1){
    if(n & 1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}

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

  if(k == n - 1){
    std::cout << modpow(m, n) << std::endl;
    return 0;
  }

  u64 ans = 0;
  u64 r = modpow(m-1, n-1);
  u64 im = modpow(m-1, mod-2);
  inv[1] = 1;
  for(int i = 0; i <= k; i++){
    ans += r;
    r = r * im % mod;
    r = r * (n-1-i) % mod * inv[i+1] % mod;
    inv[i+2] = mod - (u64) inv[mod % (i+2)] * (mod / (i+2)) % mod;
  }
  ans %= mod;
  ans = ans * m % mod;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4132
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
const int mxn = 1*(1e5) + 5;
ll n, m;
 
void solve(){
    ll n, w;
    cin >> n >> w;
    ll weights[n], values[n];
    for(int i=0; i<n; i++) {
        cin >> weights[i] >> values[i];
    }
    ll dp[w+1] = {};
    for(int i=0; i<n; i++) {
        for(int j=w; j>=0; j--) {
            if(j+weights[i] <= w) {
                dp[j+weights[i]] = max(dp[j+weights[i]], dp[j] + values[i]);
            }
        }
    }
    ll ans=0;
    for(int i=0; i<=w; i++) ans = max(ans, dp[i]);
    cout<<ans;
}
 
int main(){
    fast;
    //  tt
        solve();
}

Measured memory_bytes: 4396
n,m = map(int,input().split())
a =  [int(input()) for i in range(m)]

dp =[0]*(n+1)

for i in a:
    dp[i] = -1

for i in [0,1]:
    if dp[i] == -1:
        dp[i] =0
    else:
        dp[i] =1

for i in range(2,n+1):
    if dp[i] == -1:
        dp[i] = 0
    else:
        if dp[i-1]==dp[i-2]==0:break
        dp[i] = (dp[i-2]+dp[i-1])

print(dp[-1]%1000000007)


Measured memory_bytes: 460020
n = int(input())
s = input()
point = 0

# 100の位
for i in range(10):
    # Sのn-2番目までにiがあるか
    now_i = -1
    str_i = str(i)
    for a in range(n-2):
        if s[a] == str_i:
            now_i = a
            break
    # 作れない場合以降の探索は打ち切り
    if now_i == -1:
        continue
    # 10の位
    for j in range(10):
        now_j = -1
        str_j = str(j)
        for b in range(now_i+1,n-1):
            if s[b] == str_j:
                now_j = b
                break
        if now_j == -1:
            continue
        # 1の位
        for k in range(10):
            str_k = str(k)
            for c in range(now_j+1,n):
                # 暗証番号がそろった
                if s[c] == str_k:
                    point += 1
                    break

print(point)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <set>

using namespace std;

const int MAXN = 2000 + 10;

int N;
char A[MAXN], B[MAXN];
int ToMove[MAXN], nToMove;
int One[MAXN * 3], nOne;
int Left[MAXN], Right[MAXN];

int dist(int from, int to)
{
	from = (from % N + N) % N;
	to = (to % N + N) % N;
	return min(abs(from - to), N - abs(from - to));
}

void Work()
{
	scanf("%s%s", A, B);
	if (strcmp(A, B) == 0)
	{
		printf("0\n");
		return;
	}
	N = strlen(A);
	nOne = 0;
	for (int i = 0; i < N; i ++)
		if (B[i] == '1')
		{
			One[nOne * 3 + 0] = i - N;
			One[nOne * 3 + 1] = i;
			One[nOne * 3 + 2] = i + N;
			nOne ++;
		}
	sort(One, One + nOne * 3);
	if (nOne == 0)
	{
		printf("-1\n");
		return;
	}

	int ans = 1000000000;
	for (int start = 0; start < N; start ++)
	{
		int ops = 0;
		nToMove = 0;
		for (int i = 0; i < N; i ++)
			if (A[(start + i) % N] != B[i])
			{
				ops ++;
				if (B[i] == '0')
					ToMove[nToMove ++] = (start + i) % N;
			}
		if (nToMove == 0)
		{
			ops += min(start, N - start);
			ans = min(ans, ops);
			continue;
		}
		for (int k = 0; k < nToMove; k ++)
		{
			int i = ToMove[k];
			Left[k] = i - (*(upper_bound(One, One + nOne * 3, i) - 1));
			Right[k] = (*lower_bound(One, One + nOne * 3, i)) - i;
		}
		
		vector < pair <int, int> > V;
		multiset <int> Set;
		V.clear();
		Set.clear();
		for (int k = 0; k < nToMove; k ++)
		{
			V.push_back(make_pair(Left[k], Right[k]));
			Set.insert(-Right[k]);
		}
		sort(V.begin(), V.end());
		int ansmv = 1000000000, l, r, curmv;;

		l = 0;
		r = -*Set.begin();
		curmv = min(l + l + r + dist(-r, start), r + r + l + dist(l, start));
		ansmv = min(ansmv, curmv);

		for (int k = 0; k < nToMove; k ++)
		{
			Set.erase(Set.find(-V[k].second));
			l = V[k].first;
			r = Set.empty() ? 0 : (-*Set.begin());
			curmv = min(l + l + r + dist(-r, start), r + r + l + dist(l, start));
			ansmv = min(ansmv, curmv);
		}

		ans = min(ans, ansmv + ops);
	}

	printf("%d\n", ans);
}

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


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define chushihua(x,y) memset(x,y,sizeof x)
using namespace std;
const int MAXX = 100000 + 10;
const double PI = 3.14159265358979323846;
const ll mod = 1000000007;
int main() {
	int t;
	ll n, m;
	ll sum = 0;
	while (cin >> t) {
		int flag = 0;
		ll minn = 0x3f3f3f3f;
		for (ll i = 0; i < t; i++) {
			scanf("%I64d%I64d", &n, &m);
			sum += n;
			if (n > m) {
				minn = min(m, minn);
			}
			if (n != m) {
				flag = 1;
			}
		}
		//cout << minn << endl;
		if (!flag) {
			cout << "0" << endl;
		}
		else {
			cout << sum - minn << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;



signed main(){
  int n,m;
  cin>>n>>m;
  vector<int> c(m);
  rep(i,m)cin>>c[i];
  vector<int> dp(n+1,INF);
  dp[0]=0;
  loop(i,1,n+1){
    rep(j,m){
      if(i-c[j]>=0){
        dp[i]=min(dp[i-c[j]]+1,dp[i]);
      }
    }
  }


  cout<<dp[n]<<endl;

  return 0;
}

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

class Dice {
	int *d;
public:
	Dice(int *pd);
	void roll(char dir);
	int me(int n);
	int top(int topn);
	int front(int frn);
};
Dice::Dice(int *pd) {
	d = pd;
}

void Dice::roll(char dir) {
	int tmp;
	if(dir=='E') {
		tmp = d[0];
		d[0] = d[3];
		d[3] = d[5];
		d[5] = d[2];
		d[2] = tmp;
		}
	else if(dir=='W') {
		tmp = d[0];
		d[0] = d[2];
		d[2] = d[5];
		d[5] = d[3];
		d[3] = tmp;
	}
	else if(dir=='S') {
		tmp = d[0];
		d[0] = d[4];
		d[4] = d[5];
		d[5] = d[1];
		d[1] = tmp;
	}
	else {
		tmp = d[0];
		d[0] = d[1];
		d[1] = d[5];
		d[5] = d[4];
		d[4] = tmp;
	}
}
int Dice::me(int n) {
	return d[n-1];
}
int Dice::top (int topn) {
	if(topn == d[1]) {
		roll('N');
		return 1;
	}
	else if(topn == d[2]) {
		roll('W');
		return 1;
	}
	else if(topn == d[3]) {
		roll('E');
		return 1;
	}
	else if(topn == d[4]) {
		roll('S');
		return 1;
	}
	else if(topn == d[5]) {
		roll('S');
		roll('S');
		return 1;
	}
	else return 0;	 
}
int Dice::front (int frn) {
	if(frn == d[2]) {
		roll('W');
		roll('S');
		roll('E');
		return 1;
	}
	else if(frn == d[3]) {
		roll('E');
		roll('S');
		roll('W');
		return 1;
	}
	else if(frn == d[4]) {
		roll('W');
		roll('S');
		roll('S');
		roll('E');
		return 1;
	}
	else return 0;
}
int hikaku(int *d1, int *d2)
{
	Dice dice1(d1), dice2(d2);
	for (int i = 0; i < 3; i++) {
		if(dice2.top(dice1.me(1))){}
		else {
			return 1;
			break;
		}		
		if(dice2.front(dice1.me(2))){}
		else {
			return 1;
			break;
		}
		if (
			(dice1.me(3) == dice2.me(3)) &&
			(dice1.me(4) == dice2.me(4)) &&
			(dice1.me(5) == dice2.me(5)) &&
			(dice1.me(6) == dice2.me(6))
		) {
			return 0;
			break;
		}
		else {
			if (i == 2)
				return 1;
			else {
				dice1.roll('N');
				dice1.roll('W');
			}
		}
	}
}
int main()
{
	int n, YN=1;
	int d1[6], d2[6];
	cin >> n;
	int *d = new int[n * 6];
	for (int i=0; i < n; i++)
		for (int j = 0; j < 6; j++)
			cin >> d[i * 6 + j];
	for (int j = 0; j <  n - 1; j++) {
		for(int k = j + 1; k < n; k++) {
			for (int i = 0; i < 6; i++) {
				d1[i] = d[j * 6 + i];
				d2[i] = d[k * 6 + i];
			}
			YN *= hikaku(d1,d2);
		}
	}
	if(YN) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  int ans = (x-z)/(y+z);
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	P ans;
	double now = -1.0;
	for (int i = 0; i * a * 100 <= f; i++) {
		for (int j = 0; (i + a + j * b) * 100 <= f; j++) {
			if (i + j == 0)continue;
			int w = (i*a + j * b) * 100;
			int ms = min(f - w, e*w / 100);
			for (int k = 0; k * c <= ms; k++) {
				int l = (ms - k * c) / d;
				int s = k * c + l * d;
				if (now < 100.0 * s / (s + w)) {
					now = 100.0*s / (s + w);
					ans = P(s + w, s);
				}
			}
		}
	}
	cout << ans.first << " " << ans.second << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
 
int main(){
    long A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;
    if (A > B){
        if (A-V*T<=B-W*T){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        if (A+V*T>=B+W*T){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

typedef long long ll;

ll N, M, X;
vector<ll> C;
vector<vector<ll>> A;
const ll INF = 1ll << 50;
ll Res = INF;

int main() {
  cin >> N >> M >> X;
  C.resize(N);
  A.resize(N);
  for (auto &Ai : A) Ai.resize(M);
  for (ll i = 0; i < N; ++i) {
    cin >> C[i];
    for (ll j = 0; j < M; ++j) cin >> A[i][j];
  }
  for (ll s = 0; s < (1 << N); ++s) {
    ll c = 0;
    vector<ll> a(M);
    for (ll i = 0; i < N; ++i) {
      if (s & (1 << i)) {
        c += C[i];
        for (ll j = 0; j < M; ++j) a[j] += A[i][j];
      }
    }
    bool good = true;
    for (ll j = 0; j < M; ++j)
      if (a[j] < X) good = false;
    if (good) Res = min(Res, c);
  }
  cout << (Res == INF ? -1 : Res) << endl;
  return 0;
}


Measured memory_bytes: 3640
def solve():
    seq1 = raw_input()
    seq2 = raw_input()
 
    a, b = len(seq1), len(seq2)
    x1 = [0 for i in range(b+1)]
    for i in range(a):
        e1 = seq1[i]
        x2 = x1+[]
        for j in range(b):
            if e1 == seq2[j]:
                x1[j+1] = x2[j] + 1
            elif x1[j+1]<x1[j]:
                x1[j+1] = x1[j]
    return x1[-1]
 
n = input()
for i2 in range(n):
 
    print solve()

Measured memory_bytes: 6512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
ll pow5(ll x)
{
    ll f=x>0?1:-1;
    x=abs(x);
    int t=5;
    ll rslt=1;
    while(t){
        if(t&1)rslt*=x;
        x=x*x;
        t>>=1;
    }
    return rslt*f;
}
void solve()
{
    ll X;
    cin>>X;
    for(int u=-120;u<=120;u++){
        for(int v=-120;v<=120;v++){
            if(pow5(u)-pow5(v)==X){
                cout<<u<<" "<<v<<"\n";
                return;
            }
        }
    }
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

int main() {
    char a, b;
    string c = "";
    cin>>a>>b;
    if (a > b) {
        for (int i = 0; i < (int)a-48; i++) {
            c = c + b;
        }
    }
    else {
        for (int i = 0; i < (int)b-48; i++) {
            c = c + a;
        }
    }
    cout<<c;
    return 0;
}


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

A = list(map(int,input().split()))

B = list(map(int,input().split()))

ans = 0

for i in range(N):

    if A[i] >= B[i]:

        A[i] = A[i] - B[i]
        ans += B[i]

    else:

        B[i] = B[i] - A[i]
        ans += A[i]

        if A[i+1] >= B[i]:

            A[i+1] = A[i+1] - B[i]
            ans += B[i]

        else:

            B[i] = B[i] - A[i+1]
            ans += A[i+1]
            A[i+1] = 0

print (ans)

        


Measured memory_bytes: 19132
// Problem : B - Iroha Loves Strings (ABC Edition)
// Contest : AtCoder - AtCoder Beginner Contest 042
// URL : https://atcoder.jp/contests/abc042/tasks/abc042_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    for(int i = 0; i < n; i ++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    for(string s:v){
        cout << s;
    }
   
}

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

using namespace std;

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

double x[400], y[400];

double EPS = 1e-8;

int main() {
  int n;
  for (;;) {
    cin >> n;
    if (n == 0) break;
    int res = 1;
    rep (i, n) cin >> x[i] >> y[i];
    rep (i, n) rep (j, n) if (i < j && sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2)) <= 2 + EPS) {
      double mx = (x[i] + x[j]) / 2, my = (y[i] + y[j]) / 2;
      double nx = -(my - y[i]), ny = (mx - x[i]);
      double d = sqrt(max(1 - (pow(x[i] - mx, 2) + pow(y[i] - my, 2)), 0.));
      double dx = nx / sqrt(nx * nx + ny * ny) * d;
      double dy = ny / sqrt(nx * nx + ny * ny) * d;
      double xx = mx + dx, yy = my + dy;
      //cout << i <<  " " << j << endl;
      //cout << d << endl;
      //cout << dx << " " << dy << endl;
      //cout << xx << " " << yy << endl;
      int count = 0;
      rep (k, n) {
	//cout << pow(x[k] - xx, 2) + pow(y[k] - yy, 2) << endl;
	if (pow(x[k] - xx, 2) + pow(y[k] - yy, 2) <= 1 + EPS * 10) ++count;
      }
      res = max(res, count);
      xx = mx - dx, yy = mx - dy;
      count = 0;
      rep (k, n) {
	//cout << pow(x[k] - xx, 2) + pow(y[k] - yy, 2) << endl;
	if (pow(x[k] - xx, 2) + pow(y[k] - yy, 2) <= 1 + EPS * 10) ++count;
      }
      res = max(res, count);
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 964
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long double pi = acos((long double)-1);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long double a, b, h, m;
  cin >> a >> b >> h >> m;
  h*=5;
  h+=((5*m)/60);
  if(m>=h){
    m-=h;
  }
  else{
    m = h - m;
  }
  long double an = m*6.0;
  cout << setprecision(20) << fixed << sqrt(((a*a)+(b*b))-((2*a*b)*cos((an*pi)/(long double)180.0))) << '\n';
  return 0;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int n;

ll a[20][20],dp[1<<16+5],s[1<<16+5];

vector <int> g[1<<16+5];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin >> a[i][j];
        }
    }
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            for(int t=0;t<j;t++){
                if((i&(1<<j)) && (i&(1<<t))){
                    s[i]+=a[j+1][t+1];
                }
            }
        }
    }
    for(int i=1;i<(1<<n);i++){
        for(int j=1;j<=i;j++){
            if((i&j)==j) dp[i]=max(dp[i],dp[i-j]+s[j]);
        }
    }
    cout << dp[(1<<n)-1];
}


Measured memory_bytes: 53504
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
 
int n, q, root[105000];
long long res;
int marked[105000];
pair<char, int> query[105000];
 
int r(int x){
    if(marked[x])return x;
    return root[x]=r(root[x]);
}
 
int main() {
    while(true){
	scanf("%d%d", &n, &q);
//	cin >> n >> q;
	if(n == 0 && q == 0)return 0;
	res = 0;
	fill(marked, marked + n + 2, 0);
	marked[0] = true;
	for(int i = 1;i < n;i++){
	    cin >> root[i];
	    root[i]--;
	}
	for(int i = 0;i < q;i++){
	    cin >> query[i].first >> query[i].second;
	    query[i].second--;
	    marked[query[i].second] += (query[i].first == 'M');
	}
	for(int i=q;i-- > 0;){
	    if(query[i].first=='M'){
		marked[query[i].second]--;
	    }else{
		res += r(query[i].second) + 1;
	    }
	}
	printf("%lld\n", res);
//	cout << res << endl;
    }
}

Measured memory_bytes: 2988
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

int main()
{
	ll N = 0;
	ll ret = 0;
	ll tmp = 0;
	ll a[100005]; // memo

	memset(a, 0, sizeof(a));

	cin >> N;
	Rep(i, N) {
		cin >> tmp;
		a[tmp]++;
	}

	Rep(i, 100000) {
		ret = max(ret, a[i] + a[i + 1] + a[i + 2]);
	}
	cout << ret << endl;

	return 0;
}


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

int main() {

  int N, H;
  cin >> N >> H;

  vector<int> a(N);
  vector<int> b(N);

  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());

  int answer = 0;

  for (int i = 0; i < N; i++) {
    if (a[0] <= b[i] && 0 < H) {
      answer++;
      H -= b[i];
    } else {
      break;
    }
  }

  if (0 < H) {
    answer += ceil((double) H / a[0]);
  }

  cout << answer << endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,a,n) for(i=a;i<n;i++)
#define rf(i,a,n) for(i=a;i>=n;i--)
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vi vector<int>
#define vll vector<long long>
#define umii unordered_map<int,int>
#define umci unordered_map<char,int>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define all(v) begin(v),end(v)
#define mkp make_pair
#define setn1(a)  memset(a,-1,sizeof(a))
#define set0(a) memset(a,0,sizeof(a))
#define setl(b) memset(a,1000000001,sizeof(a))
#define M 1000000007
#define I 1000000000000000001
#define TakeInput freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);


using namespace std;

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

int main()
{
	#ifndef ONLINE_JUDGE
	//TakeInput
	#endif
	fast;
	ll h,n,i;
	cin >> h >> n;
	ll a[n],sum=0;
	f(i,0,n)
	{
		cin >> a[i];
		sum += a[i];
	}
	if (sum >= h)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}


Measured memory_bytes: 1024
h, w = map(int, input().split())
s = [input() for _ in [0]*h]
cnt = [[0]*w for _ in [0]*h]
for i in range(h):
    for j in range(w):
        if i>0:
            if s[i-1][j]=='#': cnt[i][j] += 1
            if j>0:
                if s[i-1][j-1]=='#': cnt[i][j] += 1
            if j<w-1:
                if s[i-1][j+1]=='#': cnt[i][j] += 1
        if i<h-1:
            if s[i+1][j]=='#': cnt[i][j] += 1
            if j>0:
                if s[i+1][j-1]=='#': cnt[i][j] += 1
            if j<w-1:
                if s[i+1][j+1]=='#': cnt[i][j] += 1
        if j>0:
            if s[i][j-1]=='#': cnt[i][j] += 1
        if j<w-1:
            if s[i][j+1]=='#': cnt[i][j] += 1
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            print('#', end='')
        else:
            print(cnt[i][j], end='')
    print()

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

int main() {
    using namespace std;

    long long N, K;
    cin >> N >> K;

    // std::vector<int> ary;

    // for (int i=0; i<N; i++) {
    //     int a, b;
    //     cin >> a >> b;
    //     for (int j=0; j<b; j++) {
    //         ary.push_back(a);
    //     }
    // }

    // std::sort(ary.begin(), ary.end());

    // cout << ary[K - 1] << endl;

    std::vector<std::pair<long long,long long>> ary;
    ary.reserve(N);
    for (long long i=0; i<N; i++) {
        long long a, b;
        cin >> a >> b;
        std::pair<long long, long long> pair = {a, b};
        ary.push_back(pair);
    }

    std::sort(ary.begin(), ary.end(), [](std::pair<long long, long long>& a, std::pair<long long, long long>& b) {
        return a.first < b.first;
    });

    long long n = 1;
    for (long long i=0, total=0; i<N,total<K; i++) {
        total += ary[i].second;
        n = ary[i].first;
    }

    cout << n << endl;


    return 0;
}

Measured memory_bytes: 1792
count = 0
m = 0
g_string = ''

def insertionSort(numbers, n, g):
    global count    
    for i in range(g, n):
        v = numbers[i]
        j = i - g
        while j >= 0 and numbers[j] > v:
            numbers[j + g] = numbers[j]
            count += 1
            j = j - g
        numbers[j + g] = v

def shellSort(numbers, n):
    global count
    global m
    global g_string
    count = 0
    m = 1
    gs = [1]
    i = 1
    while (i * 3 + 1) <= n:
        gs.append(i * 3 + 1)
        m += 1
        i = i * 3 + 1
    for i in range(m - 1, -1, -1):
        g_string += str(gs[i])
        g_string += " "
        insertionSort(numbers, n, gs[i])

n = int(input())
nums = []
for i in range(n):
    nums.append(int(input()))
shellSort(nums, n)
print(m)
print(g_string.rstrip())
print(count)
for i in range(n):
    print(nums[i])


Measured memory_bytes: 45528
#include<stdio.h>
#define N 2000001
void max(int);
int data[N], n=0;

int main(){
  int i;
  char o[10];

  while(1){
    scanf(" %s",o);

    if(o[0]=='i'){
      scanf("%d",&data[++n]);

      for(i=n/2;i>0;i/=2) max(i);
    }
    
    else if(o[0]=='e'){
      if(o[1]=='n') break; 
      
      if(o[1]=='x'){
	printf("%d\n",data[1]);
	data[1]=data[n--];
	max(1);
      }
    }
  }

  
  return 0;
}

void max(int i){
  int le=i*2, ri=i*2+1, ma;
  
  if(le<=n && data[le]>data[i]) ma=le;
  else ma=i;
  if(ri<=n && data[ri]>data[ma]) ma=ri;

  if(ma!=i){
    le=data[i];
    data[i]=data[ma];
    data[ma]=le;

    max(ma);
  }
}


Measured memory_bytes: 5648
N = int(input())
words = []
for _ in range(N):
  words.append(('plus', input()))
M = int(input())
for _ in range(M):
  words.append(('minus', input()))
ans = 0
for i in range(N):
  point = 1
  for j in range(N+M):
    if words[i][1] == words[j][1] and i != j:
      if words[j][0] == 'plus':
        point += 1
      else:
        point -= 1
  ans = max(ans, point)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<cstdio>
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}

  double abs(){return sqrt(norm());}

  double norm(){return (x*x+y*y);}
};
typedef Point Vector;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){return (a.x*b.y-a.y*b.x);}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

int main()
{
  Point A,B,C,D;
  int n;

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y>>D.x>>D.y;
    Vector a=A-B,b=C-D;
    if(isOrthogonal(a,b))cout<<1<<endl;
    else if(isParallel(a,b))cout<<2<<endl;
    else cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC16４4
//
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const int MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  int N;
  cin >> N;
  
  map<string, int> S;
  
  REP(i,N){
    string G;
    cin >> G;
    S[G]=1;
  }

  cout << S.size() << endl;

  return;
   
}



#define TESTCASES 1

int main() {


    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {
ll N;
cin >> N;
ll ans = (N-2) * 180;
cout << ans << endl;


}

Measured memory_bytes: 256
a,b,c,d=[int(i) for i in input()]
l=7-a
f=[-1,-1,-1]
for i in range(2):
    for j in range(2):
        for k in range(2):
            l_sub=l
            if i==0:
                l_sub-=(b)
            else:
                l_sub-=(-b)
            if j==0:
                l_sub-=(c)
            else:
                l_sub-=(-c)
            if k==0:
                l_sub-=(d)
            else:
                l_sub-=(-d)
            if l_sub==0:
                f=[i,j,k]
        if f!=[-1,-1,-1]:
            break
    if f!=[-1,-1,-1]:
        break
s=str(a)
if f[0]==0:
    s+="+"
else:
    s+="-"
s+=str(b)
if f[1]==0:
    s+="+"
else:
    s+="-"
s+=str(c)
if f[2]==0:
    s+="+"
else:
    s+="-"
s+=str(d)
s+="=7"

print(s)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  int n;
  double money=0;
  cin >> n;
  vector<double> x(n);
  vector<string> u(n);
  for(int i=0;i<n;i++){
    cin >> x.at(i) >> u.at(i);
  }

  for(int i=0;i<n;i++){
    if(u.at(i)=="BTC"){
      money+= 380000.0*x.at(i);
    }else if(u.at(i)=="JPY"){
      money+= x.at(i);
    }
  }

  cout << money ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A<C){
        if(C>B){
            cout<<0<<endl;
        }else if(D<B){
            cout<<D-C<<endl;
        }else{
            cout<<B-C<<endl;
        }
    }else{
        if(A>D){
            cout<<0<<endl;
        }else if(B<D){
            cout<<B-A<<endl;
        }else{
            cout<<D-A<<endl;
        }
    }
}

Measured memory_bytes: 256
from collections import deque


n,m = map(int,input().split())


ar = [[] for _ in range(n)]

ans = [0  for _ in range(n)]
#print(ar[0])
for i in range(m):
    a,b = map(int,input().split())
    ar[a-1].append(b)
    ar[b-1].append(a)

#print(ar)
#print(ans)
ans[0] = -1
d = deque()


for i in ar[0]:
    d.append(i)
    ans[i-1] = 1

#print("-----")
#print(d)
while d:
    i = d.popleft()
    #print(i)
    #print(d)
    for x in ar[i-1]:
        if(ans[x-1] == 0):
            ans[x-1] = i
            d.append(x)


#print(d)
#print(ans)
print("Yes")
for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 34204
//500-yen, 100-yen, 50-yen, 10-yen, 5-yen, and 1-yen coins
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int x,n,s;
	cin>>x;
	if (x<500)
	{
		x/=5;
		cout<<x*5;
	}
	else if (x>=500)
	{
		n=x/500;
		s=x%500;
		s/=5;
		cout<<s*5+n*1000;
	}
	return 0;
}

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

using namespace std;
int cost(int N, vector <vector<int>> dp)
{
	for (int i = N-1; i >= 0; i--)
	{
		for (int j = 0; j < 3; j++)
		{
			if (i == N - 1)
			{
				continue;
			}
			else if (j == 0)
				dp[i][j] = max(dp[i + 1][1], dp[i + 1][2]) + dp[i][j];
			else if (j == 1)
				dp[i][j] = max(dp[i + 1][0], dp[i + 1][2]) + dp[i][j];
			else
				dp[i][j] = max(dp[i + 1][0], dp[i + 1][1]) + dp[i][j];


		}
	}
	return max({ dp[0][0], dp[0][1], dp[0][2] });
}

int main()
{
	int N;
	cin >> N;
	vector <vector <int>> vac;

	for (int i = 0; i < N; i++)
	{
		vector <int> D;
		int x;
		for (int j = 0; j < 3; j++)
		{
			cin >> x;
			D.push_back(x);
		}
		vac.push_back(D);
	}
	int value =  cost(N, vac);
	cout << value;
	return 0;

}

Measured memory_bytes: 11184
unittest
{
	assert( [ "3", "cbaa", "daacc", "acacac" ].parse.expand.solve == "aac" );
	assert( [ "3", "a", "aa", "b" ].parse.expand.solve == "" );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ss = new dchar[][ n ];
	foreach( ref s; ss )
	{
		input.popFront;
		s = input.front.to!( dchar[] );
	}
	return tuple( ss );
}

auto solve( dchar[][] ss )
{
	dchar[] ans;
	
	// 答えが辞書順指定なので並び替えておく
	ss.each!( sort );
	
	LOOP: while( true )
	{
		// 各文字列の先頭で一番大きい文字を検索
		auto cb = ss.map!( ( a ) => a[ 0 ] ).reduce!( max );
		
		// 全文字列の先頭が一番大きい文字か判定
		auto eq = ss.map!( ( a ) => a[ 0 ] == cb ).reduce!( ( a, b ) => a && b );
		if( eq )
		{
			// 一番大きかった文字を答えに追加
			ans ~= cb;
			
			// 各文字列から先頭文字を削除
			foreach( ref s; ss )
			{
				s.popFront;
				if( s.empty ) break LOOP;
			}
		}
		else
		{
			// 各文字列の先頭から一番大きかった文字の手前まで削除
			foreach( ref s; ss )
			{
				s = s.find!( ( c ) => cb <= c );
				if( s.empty ) break LOOP;
			}
		}
	}
	
	return ans;
}


Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

vector<int> G[300000];
int dad[300000];

void bfs(int v){
    queue<int> que;
    que.push(v);
    int p, i;
    while(!que.empty()){
        p = que.front();
        que.pop();
        for(i=0; i<G[p].size(); i++){
            if(dad[G[p][i]]<0){
                dad[G[p][i]] = p;
                que.push(G[p][i]);
            }
        }
    }

}

int main(){
    int N, M;
    cin >> N >> M;
    int A, B;
    int i;
    for(i=1; i<=M; i++){
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    dad[1]=1;
    for(i=2; i<=N; i++){
        dad[i]=-1;
    }
    bfs(1);
    bool renketsu=1;
    for(i=1; i<=N; i++){
        if(dad[i]<0){
            renketsu=0;
        }
    }
    if(renketsu==0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        for(i=2; i<=N; i++){
            cout << dad[i] << endl;
        }
    }
    system("pause");
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int N;
  cin >> N;
  cout << "ABC" << N << endl;
}



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

int main() {
    long long l, r;
    int i, j, k;
    const int MOD = 2019;
    cin >> l >> r;
    if (r - l > 2019) {
        cout << 0 << endl;
        return 0;
    }
    l = l % MOD;
    r = r % MOD;
    int ans = 19999;
    for (i = l; i < r; i++) {
        for (j = i + 1; j <= r; j++) {
            ans = min(i * j % MOD, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a[203030],b[202020],ali[404][404],p[404];
int main()
{
	int n,m,i,ans=0,j,x,y,k;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
		scanf("%d%d",&a[i],&b[i]);
	for(i=1;i<=n;i++)
	{
		ali[i][i]=1;
		for(j=m;j>=1;j--)
		{
			x=a[j],y=b[j];
			if(ali[i][x]+ali[i][y]==0)
				continue;
			if(ali[i][x]+ali[i][y]==2)
				p[i]=1;
			ali[i][x]=ali[i][y]=1;
		}
	}
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
			if(p[i]||p[j])
				continue;
			for(k=1;k<=n;k++)
				if(ali[i][k]&&ali[j][k])
					break;
			if(k>n)
				ans++;
		}
	printf("%d\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 1664
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
p = 10**9+7
N,K = map(int,input().split())
A = [1 for _ in range(N+1)]
for i in range(2,N+1):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(N+1)]
B[N] = pow(A[N],p-2)
for i in range(N-1,1,-1):
    B[i] = (B[i+1]*(i+1))%p
for i in range(1,K+1):
    a = (((A[K-1]*B[i-1])%p)*B[K-i])%p
    if i>N-K+1:
        b = 0
    else:
        b = (((A[N-K+1]*B[i])%p)*B[N-K+1-i])%p
    print((a*b)%p)

Measured memory_bytes: 3444
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

import math
class segtree:
    def __init__(self, n, init_val = None, init = 0):
        self.n = n
        self.init_val = init_val
        self.init = init
        self.k = math.ceil(math.log2(n))

        try:init_val[0]
        except:raise ValueError('init_val should be list')

        self.bins = [self.init] * (1<<(self.k+1))
        for idx, i in enumerate(range(1<<self.k, 1<<(self.k+1))):
            if len(self.init_val)>idx:
                self.bins[i] = init_val[idx]

        self.caliculate()

    def compare(self, l, r):
        # modify!!
        #print(l, r)
        return max(l, r, key = lambda x:x[0])

    def caliculate(self):
        k = self.k
        while k:
            for i in range(1<<k, 1<<(k+1)):
                if not i%2:
                    self.bins[i//2] = self.compare(self.bins[i], self.bins[i+1])
                else:continue
            k -= 1

    def update(self, idx, val):
        '''idx : 0-started index'''
        k = (1<<self.k) + idx
        self.bins[k] = val
        while k>1:
            self.bins[k // 2] = self.compare(self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1])
            k = k//2


    def eval(self, l, r):
        ret = self.init
        l = (1 << self.k) + l
        r = (1 << self.k) + r
        #print(l, r)
        while True:
            #print(l, r)
            if r - l == 1:
                ret = self.compare(ret, self.bins[l])
                ret = self.compare(ret, self.bins[r])
                break
            elif l == r:
                ret = self.compare(ret, self.bins[l])
                break
            else:
                done = False
                if l % 2:
                    ret = self.compare(ret, self.bins[l])
                    l += 1
                    done = True
                if not r % 2:
                    ret = self.compare(ret, self.bins[r])
                    r -= 1
                    done = True
                if not done:
                    l = l // 2
                    r = r // 2
        #print(ret)
        return ret

    def value(self, ind):
        return self.bins[(1<<self.k) + ind]


def run():
    N,M = map(int, sysread().split())
    A = list(map(int, sysread().split()))
    A_with_idx = [(a, i) for i, a in enumerate(A)]
    st = segtree(len(A_with_idx), init_val = A_with_idx, init = (0, -1))
    for i in range(M):
        a, idx = st.bins[1]
        st.update(idx, (a // 2, idx))

    ret = 0
    for i in range(N):
        ret += st.value(i)[0]
    print(ret)



if __name__ == "__main__":
    run()


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

constexpr ll mod = 1000000007;

class modint {
	static constexpr std::int_fast64_t Modulus = 1e9 + 7;
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
};

void solve(int n, vector<P> ds) {
	vector<P> outputs(n);	
	rep(i, n) {
		vector<P> rs;
		ll r = ds[i].second;
		ll seed = ds[i].first;
		ll sum = 0;
		while (r > 0) {
			if (r & 1) {
				rs.emplace_back(seed, sum);
			}
			r /= 2;
			seed += seed;
			sum = sum*2+1;
			while (seed >= 10) {
				seed = seed / 10 + seed % 10;
				sum++;
			}
		}
		ll v = 0;
		ll t = 0;
		for (int j = 0; j < rs.size(); j++) {
			v += rs[j].first;
			t += rs[j].second;
			if (j > 0) t++;
			while (v >= 10) {
				v = v / 10 + v % 10;
				t++;
			}
		}
		outputs[i] = { v, t };
	}
	ll ans = 0;
	rep(i, n) {
		ans += outputs[i].second;
	}
	int current = outputs[0].first;
	rep(i, n - 1) {
		ans++;
		current += outputs[i + 1].first;
		while(current >= 10) {
			ans++;
			current = current % 10 + current / 10;
		}
	}
	cout << ans << endl;
}

void solve2(int n, vector<P> ds) {
	vector<int> values;
	for (auto p : ds) {
		for (int i = 0; i < p.second; i++) {
			values.push_back(p.first);
		}
	}
	int current = values[0];
	ll sum = 0;
	for (int i = 1; i < values.size(); i++) {
		current += values[i];
		sum++;
		while(current >= 10) {
			current = current / 10 + current % 10;
			sum++;
		}
	}
	cout << sum << endl;
}

int main() {
	int n;
	cin >> n;
	vector<P> ds(n);
	rep(i, n) {
		cin >> ds[i].first >> ds[i].second;
	}
	solve(n, ds);
	//solve2(n, ds);
	return 0;
}



Measured memory_bytes: 12740