akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int N;
	cin>>N;
	string s,t;
	cin>>s;
	cin>>t;
	string ret;
	int i;
	int size=0;
	for(i=0;i<N;i++){
		string tmp;
		tmp=t.substr(0,i+1);
		if(s.substr(N-i-1,i+1)==tmp){
			size=i+1;
		}
	}
	ret=s+t.substr(size,N-size);
	cout<<ret.size()<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll p = (n + 999) / 1000;
    cout << (p * 1000 - n) << endl;
    return 0;
}


Measured memory_bytes: 3608
am = int(input())
arr = list(map(int,input().split()))
c = 0
for i in range(am):
    for g in range(am):
        for j in range(am):
            if i!=g and g!=j and j!=i and (arr[i] != arr[g] and arr[g]!=arr[j] and arr[j]!=arr[i]):
                if arr[j] < arr[i]+arr[g] and arr[i] < arr[g]+arr[j] and arr[g] < arr[i] + arr[j]:
                    c+=1
print(c//6)

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

const int Maxn = 105;

int n;
string s[Maxn];
int p[Maxn];
vector <int> seq;

bool Less(const int &a, const int &b)
{
    if (s[a] != s[b]) return s[a] < s[b];
    return p[a] > p[b];
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> p[i];
        seq.push_back(i);
    }
    sort(seq.begin(), seq.end(), Less);
    for (int i = 0; i < seq.size(); i++)
        printf("%d\n", seq[i] + 1);
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;

void main(){
    auto num = readln.chomp.to!int;
    string[] persons;
    for(auto i = 0; i < num; i++){
        persons ~= readln.chomp;
    }
    long[string] groups;
    groups.divide_march(persons);
    auto combinations = [
        "MAR","MAC","MAH","MRC","MRH","MCH",
        "ARC","ARH","ACH",
        "RCH"
    ];
    long answer = 0;
    combinations.each!((comb){
        long temp = groups[""~comb[0]] * groups[""~comb[1]] * groups[""~comb[2]];
        answer += temp;
    });
    writeln(answer);
}

void divide_march(ref long[string] groups, string[] persons){
    "MARCH".each!((c){
        auto index = ""~c;
        groups[index] = persons.filter!((p) => p[0] == c).array.length;
    });
}

Measured memory_bytes: 6012
N, X = map(int, input().split())

if X in [1, 2 * N - 1]:
    print("No")
    quit()

T = list(range(X + 2, 2 * N)) + list(reversed(range(1, X - 1)))
A = T[:N - 2] + [X - 1, X, X + 1] + T[N - 2:]

print("Yes")
print(*A, sep='\n')


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> store;
	for(int i=0;i<n;++i)cin >> v[i];
	int last = *max_element(v.begin(), v.end());
	for(int i=1;i<=last;++i){
		int ans = 0;
		for(int j = 0;j<n;++j){
			ans += pow(v[j] - i, 2);	
		}	
		store.push_back(ans);
	}
	cout << *min_element(store.begin(), store.end());
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 61;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;
typedef struct edge{
    ll to;
    ll cost;
}edge;
int main(){
    cin>>N>>M>>A>>B;
    --A; --B;
    vector<vector<edge> > G(N, vector<edge>(0));
    rep(i,M){
        cin>>L>>R>>C;
        --L; --R;
        edge e = {R,C};
        G[L].push_back(e);
        e.to = L;
        G[R].push_back(e);
    }
    vp memoA(N,P(INF,0)), memoB(N,P(INF,0)); //{Aからの距離、個数}
    priority_queue<P, vector<P>, greater<P> > pque;
    memoA[A] = mp(0,1);
    memoB[B] = mp(0,1);
    pque.emplace(0,A);
    while(!pque.empty()){
        P p = pque.top();
        ll now = p.se;
        pque.pop();
        if(p.fi > memoA[now].fi) continue;
        for(edge e : G[now]){
            if(memoA[now].fi + e.cost < memoA[e.to].fi){
                memoA[e.to].fi = memoA[now].fi + e.cost;
                memoA[e.to].se = memoA[now].se;
                pque.emplace(memoA[e.to].fi, e.to);
            }else if(memoA[now].fi + e.cost == memoA[e.to].fi){
                (memoA[e.to].se += memoA[now].se)%=MOD;
            }
        }
    }
    pque.emplace(0,B);
    while(!pque.empty()){
        P p = pque.top();
        pque.pop();
        ll now = p.se;
        if(p.fi > memoB[now].fi) continue;
        for(edge e : G[now]){
            if(memoB[now].fi + e.cost < memoB[e.to].fi){
                memoB[e.to].fi = memoB[now].fi + e.cost;
                memoB[e.to].se = memoB[now].se;
                pque.emplace(memoB[e.to].fi, e.to);
            }else if(memoB[now].fi + e.cost == memoB[e.to].fi){
                (memoB[e.to].se += memoB[now].se)%=MOD;
            }
        }
    }
    ll dist = memoA[B].fi;
    ll ans = (memoA[B].se*memoB[A].se)%MOD;
    if(dist == INF){
        cout<<0<<endl;
        return 0;
    }
    vector<bool> canU(N);
    rep(i,N) canU[i] = memoA[i].fi + memoB[i].fi == dist;
    rep(i,N){
        if(canU[i] && (memoA[i].fi * 2 <= dist)){
            if(memoA[i].fi * 2 != dist){
                for(edge e : G[i]){
                    if((memoA[e.to].fi * 2 > dist) && (memoA[i].fi + e.cost == memoA[e.to].fi) && canU[e.to]){
                        (ans += MOD - (((memoA[i].se * memoB[e.to].se) % MOD) * ((memoA[i].se * memoB[e.to].se) % MOD))%MOD) %=MOD;
                    }
                }
            }else{
                (ans += MOD - (((memoA[i].se * memoB[i].se)%MOD) * ((memoA[i].se * memoB[i].se)%MOD))%MOD)%=MOD;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i) >> b.at(i);
  }
  vector<pair<int, int> > p(n);
  for(i = 0; i < n; i++)
  {
    p.at(i) = make_pair(b.at(i), a.at(i));
  }
  sort(p.begin(), p.end());
  bool success = true;
  long long totaltime = 0;
  for(i = 0; i < n; i++)
  {
    totaltime += p.at(i).second;
    if(totaltime > p.at(i).first)
    {
      success = false;
      break;
    }
  }
  if(success)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main() {
	int A, B;
	scanf("%d%d", &A, &B);//1以上3以下の整数
	int i, C;
	for (i = 1; i <= 3; i++) {
		C = i;
		if ((A*B*C) % 2 == 1) {
			printf("Yes\n");
			break;
		}
		if (i == 3)
			printf("No\n");
	}
	
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, d;
    cin>>n>>d;
    vector<pair<int, int> > v(n);
    rep(i, n){
        int x, y;
        cin>>x>>y;
        v[i] = make_pair(x, y);
    }
    int ans = 0;
    rep(i, n){
        if(pow(v[i].first, 2)+pow(v[i].second, 2)<=pow(d, 2)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
    int n, m;
    while (cin >> n >> m, n) {
        vector<int> vn(n), vm(m);
        for (int i = 0; i < n; i++)
            cin >> vn[i];
        for (int i = 0; i < m; i++)
            cin >> vm[i];
        
        int p = 0;
        for (int i = 0; i < m; i++) {
            p += vm[i];
            p += vn[p];
            if (p >= n - 1) {
                cout << i + 1 << endl;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3008
n,m=map(int,input().split())
a=list(map(int,input().split()))
b=[a[i]//2 for i in range(n)]
from fractions import gcd
from functools import reduce
def lcm(x,y):
  return (x*y)//gcd(x,y)
x=reduce(lcm,b,1)
y=reduce(lcm,a,1)
if x>m:
  print(0)
else:
  z=(m-x)//y+1
  for i in b:
    if (x//i)%2==0:
      z=0
      break
  print(z)

Measured memory_bytes: 14356
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
//#define for(i, K, N)  for(int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main() {
ll L, R, Ans = 2019;cin >> L >> R;
if(R - L >= 2019){cout << 0;exit(0);}

for(ll i = L; i <= R; i++){
for(ll j = i + 1; j <= R; j++){
Ans = min(Ans, ((i%2019)*(j%2019))%2019);

}
}

cout << Ans%2019;
}

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

int banyak, n, maks;

int main() {
	cin>>n;
	int h[n];
	for (int i=0; i<n; i++) {
		cin>>h[i];
	}
	for (int i=1; i<n; i++) {
		if (h[i]<=h[i-1]) {
			banyak++;
			if (banyak>maks) maks=banyak;
		}
		else banyak=0;
	}
	cout<<maks<<endl;
}


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

int main(){
  int N,D,X;cin>>N>>D>>X;
  int ans=0;
  for(int i=0;i<N;i++){
    int A;cin>>A;
    int Y=(D-1)/A;
    ans+=Y+1;
  }
  cout<<ans+X<<endl;
}


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

using namespace std;
typedef long long ll;

const int N = 3010;
double p[N], dp[N][N];
int n;

double solve(int i, int h) {
    if (i == n + 1) {
        if (h >= (n + 1) / 2) {
            return 1.0;
        } else {
            return 0;
        }
    }
    if (dp[i][h] != -1.0) {
        return dp[i][h];
    }
    return dp[i][h] = p[i] * solve(i + 1, h + 1) + (1.0 - p[i]) * solve(i + 1, h);
}

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

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < N; i++) {
        fill_n(dp[i], N, -1.0);
    }
    double ans = solve(1, 0);
    cout << fixed << setprecision(12) << ans;

	return 0;
}


Measured memory_bytes: 71296
/*input
3
8 2 2 7 4 6 5 3 8
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int a[maxn];
multiset<int> st;
multiset<int,greater<int>> stt;
ll ans[maxn];

int main()
{
	//IOS;
	int n;
	cin>>n;
	REP(i,3*n) cin>>a[i];

	ll tt=0;
	REP(i,n){
		st.insert(a[i]);
		tt+=a[i];
	}
	REP(i,n+1){
		ans[i]=tt;
		st.insert(a[i+n]);
		tt+=a[i+n];
		tt-=*st.begin();
		st.erase(st.begin());
	}
	//REP(i,n+1) cout<<ans[i]<<" \n"[i==n];
	reverse(ans,ans+n+1);
	reverse(a,a+3*n);
	tt=0;
	REP(i,n){
		stt.insert(a[i]);
		tt+=a[i];
	}
	REP(i,n+1){
		ans[i]-=tt;
		stt.insert(a[i+n]);
		tt+=a[i+n];
		tt-=*stt.begin();
		stt.erase(stt.begin());
	}
	//REP(i,n+1) cout<<ans[i]<<" \n"[i==n];
	cout<<*max_element(ans,ans+n+1);

	return 0;
}


Measured memory_bytes: 11520
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 1000200;
typedef long long ll;
const int mod = 1e9 + 7;
const int inv3 = (mod + 1) / 3;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int fac[maxn], ifac[maxn], inv[maxn], pw[maxn];
inline int c(int x,int y,int z){ return (ll) fac[x + y + z] * ifac[x] % mod * ifac[y] % mod * ifac[z] % mod; } 
inline int c(int x,int y){ return (ll) fac[x + y] * ifac[x] % mod * ifac[y] % mod; }
int x, y, z;
inline void reduce(int & x) {
	x += x >> 31 & mod;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = pw[0] = 1;
	pw[1] = inv3;
	rep(i, 2, maxn - 1) {
		inv[i] = ll(mod - mod / i) * inv[mod % i] % mod;
		fac[i] = (ll) fac[i - 1] * i % mod;
		ifac[i] = (ll) ifac[i - 1] * inv[i] % mod;
		pw[i] = (ll) pw[i - 1] * inv3 % mod;
	}
	cin >> x >> y >> z;
	int ans = 0, a1 = 0;
	rep(i, 0, z + y) {
		static int v = 1;
		a1 = (a1 + (ll) c(x - 1, i) * pw[i] % mod * v) % mod;
		reduce(v += v - mod);
		if(y <= i) reduce(v -= c(i - y, y));
		if(z <= i) reduce(v -= c(i - z, z));
	}
//	cout << ans * pow(3, y + z) % mod << '\n';
	cout << a1 * pow(3, y + z) % mod << '\n';
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000000005
#define MOD 1000000007
#define N 100005
#define M 27000
#define LOG 1000000
#define KOK 650
#define EPS 0.000000001
using namespace std;

int n,x,y;
int dp[N][2];
vector<int> v[N];

void dfs(int node,int ata) {

	for(int i:v[node]) {

		if(i==ata) continue ;

		dfs(i,node);

	}

	int z=1,o=1;

	for(int i:v[node]) {

		if(i==ata) continue ;

		z=1ll*z*dp[i][0]%MOD;
		o=1ll*o*dp[i][1]%MOD;

	}

	dp[node][0]=(z+o)%MOD;
	dp[node][1]=z;

}

int main() {

	//freopen("input.txt","r",stdin);	

	scanf("%d",&n);

	for(int i=1;i<n;i++) {

		scanf("%d %d",&x,&y);

		v[x].pb(y);
		v[y].pb(x);

	}

	dfs(1,0);

	printf("%d",dp[1][0]);

}


Measured memory_bytes: 13440
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct node{
  int x,y,h;	
};
void solve(){
  int x,y;
  cin>>x>>y;
  int ans=x;
  ans+=y>>1;
  cout<<ans<<endl;
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 28;
int a[maxn];
int b[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

void maxi(string &s, string t){
	if(s == "imp")
		s = t;
	else if(s.size() < t.size())
		s = t;
	else if(s.size() == s.size() && t > s)
		s = t;
}
int main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++)
		cin >> a[i];
	vector <string> dp(maxn, "imp");
	dp[0] = "";
	for(int i = 0; i < n; i++)
		if(dp[i] != "imp"){
			for(int j = 0; j < m; j++)
				maxi(dp[i + b[a[j]]],dp[i] + char('0' + a[j]));
		}
	cout << dp[n];
}

Measured memory_bytes: 43648
#include<stdio.h>
#include<string.h>
int main(void){
int A,B,C,D,E,N,M,x,y,cou=0,cou2,v[1000000],w[1000000],min_i,en=0;
    char S[10],W[10],s[10],X,Y;
   scanf("%d",&A);
   printf("%d",A*800-(A/15)*200);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

#define ll long long

int main() {

    int a, b, c, k;
    int ans = 0;


    cin >> a >> b >> c >> k;

    if(a > 0){
        
        for(int count = 0; count < a && k > 0; count++){
            ans++;
            k--;
        }
    }
    if(b > 0){
        
        for(int count = 0; count < b && k > 0; count++){
            k--;
        }
    }
    if(c > 0){
        
        for(int count = 0; count < c && k > 0; count++){
            ans--;
            k--;
        }
    }

cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3552
import sys
X,N = map(int,input().split())
if N == 0:
    print(X)
    sys.exit()
p = sorted(list(map(int,input().split())))

c = 1
while True:
    if X in p:
        if not((X-c) in p):
            print(X-c)
            break
        if not((X+c) in p):
            print(X+c)
            break
        c += 1  
    else:
        print(X)
        break

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

using namespace std;

const int N = 1e5 + 2;

int n, dp[4][N];

int main(){
    cin >> n;

    for(int i = 1; i <= n; i ++){
        int a, b, c;
        cin >> a >> b >> c;
        dp[1][i] = max(dp[2][i - 1], dp[3][i - 1]) + a;
        dp[2][i] = max(dp[1][i - 1], dp[3][i - 1]) + b;
        dp[3][i] = max(dp[2][i - 1], dp[1][i - 1]) + c;
    }

    cout << max(dp[1][n], max(dp[2][n], dp[3][n])) << endl;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;

int dat[30];

int td[20]={};

int nt[25]={};

int dfs(int no){
	int res=100;
	if(no==n){
		rep(i,n){
			//printf(": %d\n",nt[i]);
			res = min(res,nt[i]);
			res = min(res,24-nt[i]);
			rep(j,i){
				res = min(res,abs(nt[j]-nt[i]));
			}
		}
		//printf("%d\n",res);
	}
	else{
		res=0;
		rep(i,2){
			int tt=dat[no];
			if(i)tt=24-tt;
			nt[no]=tt;
			res = max(res,dfs(no+1));
		}
	}
	return res;
}

int main(void){
	scanf("%d",&n);
	if(n>=24){
		puts("0");
		return 0;
	}
	
	rep(i,n){
		scanf("%d",&dat[i]);
		td[dat[i]]++;
	}
	
	bool ok=(td[0]<=0 && td[12]<=1);
	rep(i,12){
		if(td[i]>=3)ok=false;
	}
	if(!ok){
		puts("0");
		return 0;
	}
	if(n>=15){
		puts("1");
		return 0;
	}
	
	printf("%d\n",dfs(0));
	
	return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
main()
{
int a,b,c,x,y,z;
scanf("%d%d%d",&a,&b,&c);
 if(a > b){ 
    x = a;
    a = b;
    b = x;
  }
   
  if(b > c){
    y = b;
    b = c;
    c = y;
  }
   
  if(a > b){
    z = a;
    a = b;
    b = z;
  }
   
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repv(i,a,b) for(ll i=b-1;i>=a;i--)
#define MAXN 300005
#define endl "\n"
 
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;}
 
int dp[3005][3005];
string s,t;
char s1[3005],t1[3005];
 
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s>>t;
    // string q=t;
    // if(s.size()<t.size())
    for(int i=0;i<s.size();i++) s1[i+1]=s[i];
    for(int i=0;i<t.size();i++) t1[i+1]=t[i];
    for(int i=1;i<=s.size();i++)
    {
        for(int j=1;j<=t.size();j++)
        {
            if(s1[i]==t1[j])
                dp[i][j]=dp[i-1][j-1]+1;
            else 
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    int i=s.size(),j=t.size();
    string p="";
    while(i>0 && j>0)
    {
        if(s1[i]==t1[j])
        {
            p=s1[i]+p;
            i--;j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1]) i--;
            else j--;
        }
    }
    cout<<p<<endl;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int pref[n] = {0};
    int k = 0;
    for(int i = 0; i < n; i++){
        if(i < n - 1 && s[i] == 'A' && s[i+1] == 'C'){
            pref[i] = ++k;
            pref[i+1] = k;
        }
        else
        pref[i] = pref[i-1];
        
        // cout << pref[i] << " ";
    }
    int l, r;
    while(q--){
        cin >> l >> r;
        l--;
        r--;
        int v1 = pref[l], v2 = pref[r];
        if(l == r){
        cout << 0 << endl;
        continue;
        }
        
        if(r + 1 < n && s[r] =='A' && s[r+1] == 'C')
        v2--;
        if(l+1 < n && s[l] == 'A' && s[l+1] == 'C')
        v1--;
        //cout << v1 << ":" << v2 << endl;
        cout << v2 - v1 << endl;
    }
    return 0;
}

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


public class A
{
	public static void Main()
	{
		long N = GetLong();
		long A = GetLong();
		long B = GetLong();
		Console.WriteLine(Math.Max(0, (N - 1) * (B - A) + A - B + 1));
	}
}


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: 13140
#include <iostream>
#include <cmath>

double getArea(double const& a, double const& b, double const& C){
    double S = (0.5) * a * b * std::sin(M_PI * C / 180);
    double len = std::sqrt(a*a+b*b-2*a*b*std::cos(M_PI*C/180));
    return S; 
}
double getLap(double const& a, double const& b, double const& C){
    double len = std::sqrt(a*a+b*b-2*a*b*std::cos(M_PI*C/180));
    return a+b+len; 
}
double getHeight(double const& a, double const& b, double const& C){
    double S = (0.5) * a * b * std::sin(M_PI * C / 180);
    return 2*S/a; 
}

int main(){
    double a, b, C;
	scanf("%lf %lf %lf",&a, &b, &C);
	printf("%f\n %f\n %f\n", getArea(a, b, C),getLap(a, b, C),getHeight(a, b, C));
}


Measured memory_bytes: 3432
#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<long> as(N);
	for (int i = 0; i < N; i++)
	{
		cin >> as[i];
	}

	vector<vector<long>> dp(N+1, vector<long>(N+1));

	for (int i = 1; i <= N; i++)
		for (int l = 0; l <= N-i; l++)
		{
			if ((N-i)&1)
			{
				dp[i][l] = min(dp[i-1][l+1]-as[l], dp[i-1][l]-as[i+l-1]);
			}
			else
			{
				dp[i][l] = max(dp[i-1][l+1]+as[l], dp[i-1][l]+as[i+l-1]);
			}
		}

	cout << dp[N][0] << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, M, X;
  cin >> N >> M >> X;
  vector<i64> C(N);
  vector<vector<i64>> A(N, vector<i64>(M));
  for (i64 i = 0; i < N; i++)
  {
    cin >> C[i];
    for (i64 j = 0; j < M; j++)
      cin >> A[i][j];
  }
  i64 ans = 1e9;
  for (i64 i = 0; i < (1 << N); i++)
  {
    i64 sum = 0;
    vector<i64> s(M);
    for (i64 j = 0; j < N; j++)
      if (i & (1 << j))
      {
        sum += C[j];
        for (i64 k = 0; k < M; k++)
          s[k] += A[j][k];
      }
    bool ok = true;
    for (i64 j = 0; j < M; j++)
      if (s[j] < X)
        ok = false;
    if (ok)
      ans = min(ans, sum);
  }
  if (ans == 1e9)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int k = 0;
    long long ans = 1;
    const int M = 1000000007;
    for (char c : s) {
        if ((c == 'B') == (k % 2 == 1)) ans = ans * k % M, k--;
        else k++;
    }
    if (k != 0) ans = 0;
    for (int i = 1; i <= n; i++) ans = ans * i % M;
    cout << ans << endl;
}


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


#define dhai_machli ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define loop(i,n) for(int i=0; i<n; i++)



using namespace std;

int main()
{

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

    dhai_machli;

    int n;
    cin >> n;

    ll a[n];
    ll ans = 0;

    loop(i, n)
    {
        cin >> a[i];


    }


    loop(i, n)
    {
        if (a[i] == 0)
        {
            cout << "0" << endl;
            return 0;
        }
    }



    ll prod = 1;


    loop(i, n)
    {
        if (a[i] <= 1000000000000000000/ prod)
        {
            prod *= a[i];
        }

        else
        {
            cout << "-1" << endl;
            return 0;
        }
    }


    cout << prod << endl;


    return 0;
}

Measured memory_bytes: 4424
#include <numeric>
#include <iostream>
using namespace std;
int main() {
    int k, q; cin >> k >> q;
    int d[k];
    for (int i = 0; i < k; i++) cin >> d[i];
    while (q--) {
        int n, x, m; cin >> n >> x >> m;
        long long s[k+1] = {0};
        for (int i = 1; i <= k; i++) {
            int t = d[i-1] % m;
            s[i] = (t > 0 ? t : m) + s[i-1];
        }
        int qn = (n-1)/k, r= (n-1)%k;
        long long an = x + qn * s[k] + s[r],
            q0 = x / m, q1 = an / m;
        cout << n - 1 - (q1 - q0) << endl;
    }
}


Measured memory_bytes: 384
use io::*;
use std::cmp::min;

fn main() {
	let con = read_string();
	let mut sc = Scanner::new(&con);

	let n: i32 = sc.next();
	let m: i32 = sc.next();
	
	let mut v: Vec<(i32, i32)> = (0..m).map(|_| (sc.next(), sc.next())).collect();

	v.sort();
	let mut ans = 1;
	let mut b = n;
	for i in 0..m as usize {
		if v[i].0 < b {
			b = min(b, v[i].1);
		} else {
			b = v[i].1;
			ans += 1;
		}
	}
	
	println!("{}", ans);
}

pub mod io {
    use std;
    use std::str::FromStr;
 
    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }
 
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
 
        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }
 
        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }
 
        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }
 
    pub fn read_string() -> String {
        use std::io::Read;
 
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
 
    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}

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

int main()
{
    bool ex = false;
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= x; i++){
        if(2 * i + 4 * (x - i) == y){
            ex = true;
            break;
        }
    }

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

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int k; 
    cin >> k;
    string ans = "";
    rep(_, k){
        ans += "ACL";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N; cin>>N;
  ll odd_count = 0;
  REP(i,N){
    ll a; cin>>a;
    if(a%2==1){++odd_count;}
  }
  cout << ( odd_count%2==0?LINY:LINN ) ;
}

Measured memory_bytes: 256
N,A,B = map(int, input().split())

def sum_10(n):
  ans = 0
  while n != 0:
    ans += n % 10 
    n //= 10
  return ans

ans = 0
for i in range(N+1):
  if A <= sum_10(i) <= B:
    ans += i
    
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll a,b,c,ans=1,n;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
		ll p;
		cin>>p;
		ll x=0;
		if(a==p)x++;
		if(b==p)x++;
		if(c==p)x++;
		ans=ans*x%M;
		if(a==p)a++;
		else if(b==p)b++;
		else if(c==p)c++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		long n=scanner.nextLong();
		int min=1000000000;
		for(int i=(int)Math.sqrt(n)+1;i>0;i--) {
			if(n%i==0) {
				min=Math.min(min, (int)Math.max(String.valueOf(i).length(), String.valueOf(n/i).length()));
			}
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 22996
//
// ABC120A :
//
//


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
using namespace std;

int F(int a, int b) {
	string a1 = to_string(a);
	string b1 = to_string(b);

	return max(a1.size(), b1.size());

}


int main() {
	long long A,B,C;
	cin >> A >> B >> C;

	int ans = 0;

	ans = B / A;

	if (ans > C) ans = C;

	cout << ans << endl;


	return 0;
}


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

#define f first
#define s second
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define px pair<db, db>
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define input(a) for (auto& el : a) cin >> el;
#define output(a) cout << '!'; for (auto& el : a) cout << el << ' '; cout << '\n'; cout.flush();
#define sz(el) int(el.size())
#define sq(a) ((a) * (a))
#define xll bitset<128>
#define xmin(a,b) a = min(a, b)
#define xmax(a,b) a = max(a, b)
#define sun(a) sort(all(a)); a.resize(unique(all(a)) - a.begin());
/**/  /// extra
//#define forn(i,n) for (int i = 0; i < n; ++i)
//#define rforn(i,n) for (int i = n - 1; i >= 0; --i)
#define bn '\n'
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
//#define G vector<vector<pii>>
#define GVE vector<vector<edge>>
#define usi unordered_set<int>
#define usp set<pii>
/**/

using namespace std;

const int INF = 1'000'000'017;
const ll LLINF = 1'000'000'000'000'000'017LL;
const ld inf = 1.0 / 0.0;
const ld eps = 1e-9;
const int MOD = 998244353;

//mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

//uniform_int_distribution<int> uid(l, r); [l, r]
//int x = uid(rng);

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

    int n;
    cin >> n;
    int m = (1 << n);
    multiset<int, greater<int>> mx;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        mx.emplace(x);
    }
    vector<int> cur = {*(mx.begin())};
    mx.erase(mx.begin());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < (1 << i); ++j) {
            auto it = mx.upper_bound(cur[j]);
            if (it != mx.end()) {
                cur.eb(*it);
                mx.erase(it);
            } else {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 13816
# /usr/bin/python
# -*- coding: utf-8 -*-
import math




N = int(input())
An = list(map(int, input().split()))
cnt = [0,0,0]
for a in An:
  if a%4 == 0:
    cnt[2] += 1
  elif a%2 == 0:
    cnt[1] += 1
  else:
    cnt[0] += 1

if cnt[2] >= cnt[0]:
  print('Yes')
elif cnt[0]-cnt[2]==1 and cnt[1]==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    int T;
    cin >> T;
    REP(_,T){
        long long N,a;
        vector<ll> A;
        string S;
        cin >> N;
        REP(i,N){cin >> a;A.push_back(a);}
        cin >> S;
        
        vector<ll> B;
        
        bool stop = false;
        RREP(i,N){
            ll e = A[i];
            REP(j,B.size()){
                e = min(e,e^B[j]);
            }
            if(e){
                B.push_back(e);
            }
            
            if(e && S[i]=='1'){
                cout << 1 << endl;
                stop = true;
                break;
            }
            
        }
        if(stop)continue;
        cout << 0 << endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3568
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] s = new char[h][w];
        int[][] dp = new int[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
            Arrays.fill(dp[i], Integer.MAX_VALUE);
        }
        dp[0][0] = 0;
        if (s[0][0] == '#') {
            dp[0][0] = 1;
        }
        int[][] dxdy = { { 1, 0 }, { 0, 1 } };
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                for (int k = 0; k < dxdy.length; k++) {
                    int x = i + dxdy[k][0];
                    int y = j + dxdy[k][1];
                    if (x >= h || y >= w) {
                        continue;
                    }
                    if (s[i][j] == '.' && s[x][y] == '#') {
                        dp[x][y] = Math.min(dp[i][j] + 1, dp[x][y]);
                    } else {
                        dp[x][y] = Math.min(dp[i][j], dp[x][y]);
                    }
                }
            }
        }
        System.out.println(dp[h - 1][w - 1]);
    }

}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int od=0,ev=0,e4=0;
	for(int i=0;i<n;i++){
		if(a[i]%4==0)
			e4++;
		else if(a[i]%2==0)
			ev++;
		else
			od++;
	}
	if(e4==n/2){
		cout<<"Yes\n";
		return 0;
	}
	if(od<=e4 ){
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
	return 0;
}

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

string s;

int main(void)
{
	int n, i, ans = 0;

	cin >> n >> s;

	for (i = 0; i < n - 2; i++)
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			++ans;

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;

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

typedef long long ll;

#define MAX_V 1010
#define MAX_E 2010

struct edge {int from, to, cost;};
vector<edge> es;
int d[MAX_V];
int V, E;
int INF = 1e9;

// trueのとき負の閉路は存在しない
bool bellman_ford(int start)
{
    for (int i = 0; i < V; ++i) {
        d[i] = INF;
    }
    d[start] = 0;
    int loop_cnt = 0;
    while (true) {
        ++loop_cnt;
        bool update = false;
        for (int i = 0; i < E; ++i) {
            edge e = es[i];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
                if (loop_cnt == V) return true;
            }
        }
        if (!update) break;
    }
    return false;
}

void Main()
{
    int r; cin >> V >> E >> r;
    rep(i,E) {
        int from, to, cost; cin >> from >> to >> cost;
        es.push_back(edge{from,to,cost});
    }
    if (bellman_ford(r)) {
        cout << "NEGATIVE CYCLE" << endl;
        return;
    }
    rep(i,V) {
        if (d[i] == INF) cout << "INF" << endl;
        else cout << d[i] << endl;
    }
}

int main()
{
    // cin.tie(nullptr);
	// ios_base::sync_with_stdio(false);
	Main();
}



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

int main() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << "Hello World" << endl;
		return 0;
	}
	else{
		int A, B;
		cin >> A >> B;
		cout << A + B << endl;
	}
	return 0;
}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 1;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    string s;
    cin >> s;

    if(s == "SUN"){
            cout << 7 << endl;
    }
    if(s == "MON"){
            cout << 6 << endl;
    }
    if(s == "TUE"){
            cout << 5 << endl;
    }
    if(s == "WED"){
            cout << 4 << endl;
    }
    if(s == "THU"){
            cout << 3 << endl;
    }
    if(s == "FRI"){
            cout << 2 << endl;
    }
    if(s == "SAT"){
            cout << 1 << endl;
    }
}

main(){

    int t = 1;
    //scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long hit(long x){
  if(x==1)return 1;
  else {
	long f=x/2;
    return 2*hit(f)+1;
  }
}
int main(){
  long h;
  cin>>h;
  long ans=hit(h);
  cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>
int main (void){
  int N,K,P,i;
  scanf("%d",&N);
  int a[N];
  for(i=1; i<=N; i++){
     scanf("%d %d",&K,&P);
         a[i] = K%P;
         if(K%P==0)
            a[i] = P;
  }
  for(i=1; i<=N; i++)
     printf("%d\n",a[i]);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1LL << 60;
const int MOD = 1'000'000'007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll total = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        total += a[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        total -= a[i];
        ans += a[i] * (total % MOD);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4768
let rs, cs, xys = Scanf.(scanf "%d %d" @@ fun n m -> Array.(make n 0, make n 1, init m @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b - 1))
let _ = rs.(0) <- 1; Array.(iter (fun (x, y) -> if rs.(x) = 1 then rs.(y) <- 1; cs.(y) <- cs.(y) + 1; cs.(x) <- cs.(x) - 1; if cs.(x) = 0 then rs.(x) <- 0) xys; fold_left (+) 0 rs) |> Printf.printf "%d\n"

Measured memory_bytes: 8320
n = int(input())
d = [[10**16]*n for i in range(n)]
L = []
ans = 0
for i in range(n):
    d[i][i] = 0
for i in range(n):
    L = list(map(int,input().split()))
    for j in range(i+1):
        d[i][j] = L[j]
        d[j][i] = L[j]
        ans += L[j]
flag = True
for i in range(n):
  for j in range(i+1):
    for k in range(n):
      if d[i][j] > d[i][k]+d[k][j]:
        print(-1)
        exit()
      else:
        if d[i][j] == d[i][k]+d[k][j] and i != k and k != j:
          ans -= d[i][j]
          break
print(ans)

Measured memory_bytes: 46300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll k,n;
    cin>>k>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans = 1e16;
    for(int i=0;i<n;i++){
        ll ret = 0;
        if(i+1<n){
            ret = a[i+1] - a[i];
            ret = k-ret;
        }
        else{
            ret = k+a[0] - a[n-1];
            ret = k - ret;
        }
        chmin(ans,ret);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
  string s;
  cin >> s;
  if(s[0] != s[1] && s[1] != s[2] && s[2] !=s[0]){
     cout <<"Yes\n";
  }else{
     cout <<"No\n";
  }
  return 0;
}

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

Measured memory_bytes: 18624
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: X: Yet Another Die Game
 */

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

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll x;
  cin >> x;

  ll n = (x / 11) * 2, r = x % 11;

  if (r > 6) n += 2;
  else if (r > 0) n++;
  printf("%lld\n", n);
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int r,g,b;
	cin >> r >> g >> b;
	cout << (((g*10+b)%4)?"NO":"YES") << endl;
	return 0;
}


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

int s[13],h[13],c[13],d[13];
int main(){
	char ID;
	int N,tmp;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>ID>>tmp;
		tmp--;
		if(ID=='S')
		{
			s[tmp]=1;
		}
		if(ID=='H')
		{
			h[tmp]=1;
		}
		if(ID=='C')
		{
			c[tmp]=1;
		}
		if(ID=='D')
		{
			d[tmp]=1;
		}
	}
	for(int i=0;i<13;i++){
		if(s[i]==0)
		cout<<"S "<<i+1<<endl;
	}
		for(int i=0;i<13;i++){
		if(h[i]==0)
		cout<<"H "<<i+1<<endl;
	}
		for(int i=0;i<13;i++){
		if(c[i]==0)
		cout<<"C "<<i+1<<endl;
	}
		for(int i=0;i<13;i++){
		if(d[i]==0)
		cout<<"D "<<i+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
using LLI = long long int;

#define Rep(i, N) for (int i = 0; i < N; i++)

// dp[k][p]k番目以降について、価値の合計がpちょうどとなる最小の重み
vector<vector<LLI>> dp(100, vector<LLI>(100*1000+1, -1));

int N, W;
vector<int> w, v;

// k番目以降について、価値の合計がpちょうどとなる最小の重み
LLI f(int k, int p) {
    if (k >= N) {
        if (p == 0) {
            return 0;
        } else {
            // INF
            return 1e15;
        }

    }

    if (dp[k][p] >= 0) {
        return dp[k][p];
    }

    if (v[k] > p) {
        dp[k][p] = f(k+1, p);
    } else {
        LLI c1 = f(k+1, p);
        LLI c2 = f(k+1, p-v[k]) + w[k];
        if (c2 <= W) {
            dp[k][p] = min(c1, c2);    
        } else {
            dp[k][p] = c1;
        }
    }

    return dp[k][p];
}

int main(int argc, char *argv[])
{
    cin >> N >> W;
    w.resize(N);
    v.resize(N);
    Rep(i, N) {
        cin >> w[i] >> v[i];
    }

    Rep(i, N) {
        Rep(j, 100*1000+1) {
            f(i, j);
        }
    }

    vector<int> P(100);
    Rep(i, 100) {
        auto it = dp[i].cend() - 1;
        while (it >= dp[i].cbegin() && (*it < 0 || *it > W)) {
            --it;
        }

        P[i] = distance(dp[i].cbegin(), it);
    }

    int m = *max_element(P.cbegin(), P.cend());
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 80752