akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
map<int,long long> a,b;
long long ans=999999999999999;
int main(){
	long long amin=99999999999,bmin=999999999,an,bn,m,dis,x,y,temp;
	cin>>an>>bn>>m;
	for(int i=0;i<an;i++)
		cin>>a[i],amin=min(amin,a[i]);
	for(int i=0;i<bn;i++)
		cin>>b[i],bmin=min(bmin,b[i]);
	for(int i=0;i<m;i++){
		cin>>x>>y>>dis;
		temp=a[x-1]+b[y-1]-dis;
		if(temp<ans)
			ans=temp;
	}
	if(amin+bmin<ans)
		cout<<amin+bmin;
	else
		cout<<ans;
	return 0;
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a.at(i);

    if (n == 1) {
        cout << 1 << endl;
        return;
    }

    sort(ALL(a));
    int amax = a.at(n-1);

    vector<bool> dp(amax + 1, true);

    REP(i,n-1) {
        if (a.at(i) == a.at(i + 1)) dp.at(a.at(i)) = false;
        for(int j = 2; a.at(i) * j <= amax; j++) {
            dp.at(a.at(i) * j) = false;
        }
    }

    int ans = 0;

    REP(i,n) {
        if (dp.at(a.at(i))) {
            ans++;
        }
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 4300
//************************
//*  Date: 2018.11.2     *
//*  Problem:            *
//*  Author: xuziyuan    * 
//************************

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++)
#define LL long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int x,y;

int main()
{
	cin>>x>>y;
	cout<<x+y/2<<endl;
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e18;
int si[] = {-1, 0, 1, 0};
int sj[] = {0, -1, 0, 1};

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

  int count = 0;
  rep(i,n) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) count++;
    else count = 0;
    if(count >= 3){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n; cin >> n;
    int minv = 1000000009;
    int maxv = 0;

    for(int i=0; i<n; i++){
        int a; cin >> a;
        maxv = max(maxv, a);
        minv = min(minv, a);
    }

    cout << maxv - minv << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
using namespace std;
int main(){
	int a, b;
    cin>> a >> b;
    if (a==1){
        a = 14;
    }
    if (b==1){
        b=14;
    }
    if (a>b){
        cout << "Alice";
    }
    else if (b>a){
       cout << "Bob";
    }
    else if (b==a){
        cout<< "Draw";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(100000,0);
    for(int i = 0;i < n;i++){
        int b;
        cin >> b;
        if(b != 0)a[b-1]++;
        a[b]++;
        a[b+1]++;
    }
    sort(a.begin(),a.end(),greater<int>());
    cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
a = input().split()
a = [int(i) for i in a]
drink = []


for i in range(a[0]):
    b = input().split()
    b = [int(i) for i in b]
    drink.append(b)

count = 0
drink = sorted(drink, key=lambda x: x[0])

while (a[1] > 0):
    if drink[0][1] > a[1]:
        count += drink[0][0] * a[1]
        a[1] = 0
    else:
        count += drink[0][0] * drink[0][1]
        a[1] -= drink[0][1]
    drink.pop(0)

print(count)

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

using ll = long long;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <int> a[n+1], dp[n+1];
	a[0].assign(m+1, 0);
	dp[0].assign(m+1, 1e9);
	for (int i=1; i<=n; i++) {
		a[i].assign(m+1, 0);
		dp[i].assign(m+1, 1e9);
		for (int j=1; j<=m; j++) {
			char s;
			cin >> s;
			a[i][j] = (s == '#' ? 1 : 0);
		}
	}
	dp[1][0] = dp[0][1] = 0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++) {
			if (a[i][j]) {
				dp[i][j] = min(dp[i-1][j]+(a[i-1][j]?0:1), dp[i][j-1]+(a[i][j-1]?0:1));
			} else {
				dp[i][j] = min(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	cout << dp[n][m];
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef long long ll;

map<ll, int>m;
ll ans[10];
ll h, w, n;

int main() {
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		ll a, b, c, d;
		cin >> a >> b;
		for (int j = 1; j <= 3; j++) {//一つのマスにつき9つの四角に使用される。
			c = (a - j)*(w - 2);
			for (int k = 1; k <= 3; k++) {
				d = b - k;
				//cout << "c:" << c << "\t" << "d:" << d << endl;
				if (c >= 0 && d >= 0 && c+d < (w-2)*(h-2) && d < (w - 2)) {//
					if (m.find(c + d) != m.end()) {
						//cout << "out" << "\n" << m[c+d] <<endl;
						m[c + d]++;
					}else {
						m[c + d] = 1;
					}
				}
			}
		}
	}

	for (auto i = m.begin(); i != m.end(); i++) {
		//cout << i->first << "\t" << m[i->first] << endl;
		ans[int(i->second)]++;
	}
	ans[0] = (w - 2)*(h - 2)-m.size();
	for (int i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 56448
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int n, m, x;
	cin >> n >> m >> x;

	vector<int> a(n);

	int i;
	rep(i, m)
	{
		int val;
		cin >> val;
		a[val]++;
	}
	
	//for (int i = 0; i < n; i++) cout << a[i] << " ";

	int cost1 = 0, cost2 = 0;

	for (int i = x; i < n; i++)
	{
		cost1 += a[i];
	}
	for (int i = x; i >= 0; i--)
	{
		cost2 += a[i];
	}

	cout << min(cost1, cost2) << endl;
}


Measured memory_bytes: 256
N = int(input())
Zahyou = set()
L = []
R = []
for n in range(N):
    A,B = [int(hoge) for hoge in input().split()]
    L.append(A)
    R.append(B)
L.sort()
R.sort(reverse=True)
if N%2:
    Mid = N//2 + 1
    print(R[Mid-1] - L[Mid-1] + 1)
else:
    ll = N//2
    rr = N//2 + 1
    MidMin = (L[ll-1] + L[rr-1]) /2
    MidMax = (R[ll-1] + R[rr-1]) /2
    print(int((MidMax - MidMin)// 0.5 + 1))

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

int main(){
    int N,X,Y; cin >> N >> X >> Y; --X; --Y;
    vector <int> ans(N);
    rep(i,N){
        vector <int> dist(N,INF);
        queue <int> q;
        q.push(i);
        dist[i]=0;
        
        while(!q.empty()){
            int v=q.front(); q.pop();
            if (v+1<N && dist[v+1]==INF){
                q.push(v+1);
                dist[v+1]=dist[v]+1;
            }
            if (v-1>=0 && dist[v-1]==INF){
                q.push(v-1);
                dist[v-1]=dist[v]+1;
            }
            if (v==X && dist[Y]==INF){
                q.push(Y);
                dist[Y]=dist[v]+1;
            }
            if (v==Y && dist[X]==INF){
                q.push(X);
                dist[X]=dist[v]+1;
            }
        }
        rep(i,N) ans[dist[i]]++;
    }
    rep(i,N) ans[i]/=2;
    for (int i=1; i<=N-1; i++) cout << ans[i] << endl;
    return 0;
}

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

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

	int * K = new int [M];
	int **S = new int*[M];
	for (int i = 0; i < M; i++) {
		S[i] = new int[N];
	}

	int *P = new int [M];

	for (int m = 0; m < M; m++) {
		cin >> K[m];
		for (int s = 0; s < K[m]; s++) {
			cin >> S[m][s];
		}
	}
	for (int m = 0; m < M; m++) {
		cin >> P[m];
	}

	int finalcombcnt = 0;

	int maxcombs = std::pow(2, N);
	for (int comb = 0; comb < maxcombs; comb++) {
		int onbulbCnt = 0;
		for (int bulb = 0; bulb < M; bulb++) {
			int oncnt = 0;
			for (int bulb_switch = 0; bulb_switch < K[bulb]; bulb_switch++) {
				if ((comb >> (S[bulb][bulb_switch]-1)) & 0x01) { /* if bulb is on */
					oncnt++;
				}
			}
			if (P[bulb] == 0) { /* even */
				if (oncnt % 2 == 0) {
					onbulbCnt++;
				}
				else {
					break;
				}
			}
			else if (P[bulb] == 1) {  /* odd */
				if (oncnt % 2 == 1) {
					onbulbCnt++;
				}
				else {
					break;
				}
			}
		}
		if (onbulbCnt >= M)
			finalcombcnt++;
	}
	cout << finalcombcnt;
	//	for(int m=0;m<M;m++){
	//		cout << K[m] << "\t";
	//		for(int s=0;s<K[m];s++){
	//			cout  << S[m][s] << "\t";
	//		}
	//		cout << endl;
	//	}
	//	
	//	for(int m=0;m<M;m++){
	//		cout << P[m]  << "\t";
	//	}
	//	cout << endl;

}


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

int main(){
    int n;
    while(cin>>n,n){
        int ma=0,id;
        while(n--){
            int p,a,b;
            cin>>p>>a>>b;
            if(a+b>ma){
                ma=a+b;
                id=p;
            }
        }
        cout<<id<<" "<<ma<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

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

int main(){
    int h, w; cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    REP(i, h) REP(j, w) cin >> a[i][j];
    int cnt = 0;
    vector<tuple<int, int, int, int>> d;
    REP(idx, h*w-1){
        int ii = idx / w;
        int jj = idx % w;
        if(ii % 2) jj = w - 1 - jj;
        if(a[ii][jj] % 2){
            ++cnt;
            --a[ii][jj];
            int ni = (idx+1) / w;
            int nj = (idx+1) % w;
            if(ni % 2) nj = w - 1 - nj;
            ++a[ni][nj];
            d.PB(MT(ii+1, jj+1, ni+1, nj+1));
        }
    }
    cout << cnt << "\n";
    REP(i, cnt){
        cout << get<0>(d[i]) << " " << get<1>(d[i]) << " ";
        cout << get<2>(d[i]) << " " << get<3>(d[i]) << "\n";
    }
    return 0;
}


Measured memory_bytes: 5232
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    long long N, K, i, j, count;
    double ans=0;

    cin >> N >> K;

    for(i=1; i<=N; i++){
        count = 0;

        j = i;

        while(j < K){
            j *= 2;

            count++;
        }

        ans += pow(0.5, count);
    }

    ans /= N;

    cout << setprecision(15) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,p[505*505],a[505*505];
int q[505*505],qb,qn;
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)
	{
		int x;
		geti(x);
		p[x]=i;
	}
	qb=0;
	for(int i=1;i<=n*n;i++)
	{
		if(!p[i])
		{
			q[qn++]=i;
			continue;
		}
		a[i]=p[i];
		int times=p[i]-1;
		while(times--)
		{
			if(qb==qn)
			{
				puts("No");
				return 0;
			}
			a[q[qb++]]=p[i];
		}
	}
	qb=qn=0;
	for(int i=n*n;i>=1;i--)
	{
		if(!p[i])
		{
			if(!a[i])q[qn++]=i;
			continue;
		}
		a[i]=p[i];
		int times=n-p[i];
		while(times--)
		{
			if(qb==qn)
			{
				puts("No");
				return 0;
			}
			a[q[qb++]]=p[i];
		}
	}
	puts("Yes");
	for(int i=1;i<=n*n;i++)
	{
		puti(a[i]);
	}
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    dou a,b,c;
    dou d=0.0;
    std::cin >> a>>b>>c;
    if(c>2*sqrtl(a*b)+a+b)std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
}


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

int N, M;
vector<vector<int>> info;

int is_valid(vector<int> P, vector<int> state) {
  // P: how to turn on the lights
  map<int, int> search;
  for (int i = 0; i < state.size(); i++) {
    if (state[i] == 1) search[i] = 1;
  }

  vector<int> P_copy;
  copy(P.begin(), P.end(), back_inserter(P_copy));

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < info[i].size(); j++) {
      if (search[info[i][j]]) P_copy[i] = !P_copy[i];
    }
  }

  int count = 0;
  for (int i = 0; i < P_copy.size(); i++) {
    if (P_copy[i] == 0) count++;
  }

  return count == P.size();
}

int calc(int now_idx, vector<int> P, vector<int> now_state) {
  if (now_idx == N) {
    return is_valid(P, now_state);
  }

  vector<int> new_state;
  for (int i = 0; i < now_state.size(); i++) {
    if(i == now_idx) new_state.push_back(1);
    else new_state.push_back(now_state[i]);
  }

  return calc(now_idx + 1, P, now_state) + calc(now_idx + 1, P, new_state);
}

int main() {
  // N: switch
  // M: light
  cin >> N >> M;
  vector<int> P(M);

  for (int i = 0; i < M; i++) {
    int k; cin >> k;
    vector<int> tmp(k);
    for (int j = 0; j < k; j++) {
      int a; cin >> a;
      tmp[j] = a - 1;
    }

    info.push_back(tmp);
  }
  for (int i = 0; i < M; i++) {
    cin >> P[i];
  }
  vector<int> init_state(N, 0); // present state of switches
  int res = calc(0, P, init_state);

  cout << res << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNiINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
long long inv(long long a) {
	long long now = 1;
	long long cnt = MOD - 2;
	while (cnt != 0) {
		if (cnt % 2 == 1) {
			now *= a;
			now %= MOD;
		}
		a *= a;
		a %= MOD;
		cnt /= 2;
	}
	return now;
}
long long geko[500000] = {};
int main() {
#define int long long
	long long n, a, b, k;
	cin >> n >> a >> b >> k;
	geko[0] = 1;
	for (int i = 1; i <= n; ++i) {
		geko[i] = geko[i - 1] * inv(i);
		geko[i] %= MOD;
		geko[i] *= (n - (long long)i + 1LL);
		geko[i] %= MOD;
	}
	long long ans = 0;
	for (long long i = 0; i <= n; ++i) {
		long long remaining = k - a * i;
		if (remaining < 0) break;
		if (remaining % b == 0) {
			long long go = remaining / b;
			if (go <= n) {
				long long tmp = geko[i] * geko[go];
				tmp %= MOD;
				ans += tmp;
				ans %= MOD;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll max=0;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
        max+=(a[i]-1);
    }
    cout << max << endl;
}

Measured memory_bytes: 3572
#include <stdio.h>

int main(){
  int H,W,i,j;

  while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0) {
      break;
    }
    for(j=1; j<=H; j++) {
      for(i=1; i<=W; i++) {
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
using namespace std;
const int M = 400005 ;
inline int read() {
	char c = getchar() ; int x = 0 , w = 1 ;
	while(c>'9'||c<'0') { if(c=='-') w = -1 ; c = getchar() ; }
	while(c>='0'&&c<='9') { x = x*10+c-'0' ; c = getchar() ; }
	return x*w ;
}
int n, a[M] ;
vector<std::pair<int, int> > K;

bool check(int d) {
	K.clear();
	K.push_back(std::make_pair(0, 0));
	for (int i = 1; i <= n; ++i)
		if (a[i] <= a[i - 1])
		{
			while (K.back().first > a[i]) K.pop_back();
			for (int j = a[i]; ; --j)
			{
				if (j < 1) return false;
				int t = 1;
				if (K.back().first == j) t = 1 + K.back().second, K.pop_back();
				if (t < d) {
					K.push_back(make_pair(j, t));
					break;
				}
			}
		}
	return true;
}

int main() {
	n = read() ;
	for (int i = 1; i <= n; ++i) a[i] = read() ;
	int l = 1, r = n;
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", l);
}

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

typedef pair<long long, long long> data_t;

int main(){
  int N,L;
  cin>>N>>L;
  vector<string> s(N);
  for(int i=0;i<N;i++)
    cin>>s[i];
  sort(s.begin(),s.end());
  string ans;
  for(int i=0;i<N;i++)
    cout<<s[i];
  cout<<endl;
}


Measured memory_bytes: 256
import itertools
a,b,c,d = map(int,input().split())
x = [a,b]
y = [c,d]
comb = list(itertools.product(x,y))
ans = x[0]*y[0]

for i in range(len(comb)):
    seki = comb[i][0] * comb[i][1]
    if seki > ans:
        ans = seki
print(ans)



Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
// #define int long long int 

void solve()
{
    int n;cin >> n;
    n--;

    int sum = 0;
    for(int i=1;i<=n;++i)
    {
        int curr = (n/i);
        // cout << " THIS IS THE I : " << i << ' ' << " THIS IS THE CURRENT VALUE : " << curr << '\n';
        sum += curr;
    }

    cout << sum << '\n';
}
 
signed main()
{
     int test_cases;test_cases=1;
     //cin >> test_cases;
     while(test_cases --> 0) solve();
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
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 * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    int a, b, c, x, ans=0;
    R a>>b>>c>>x;
    rep(i, a+1){
        rep(j, b+1){
            rep(k, c+1){
                if(500*i+100*j+50*k==x)ans+=1;
            }
        }
    }
    co(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N,Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> A(N+1); // A[i]:= i 文字目まで見たときのAC の数の合計
    rep(i,N){
        A[i+1] = A[i];
        if(S[i]=='C' && S[i-1]=='A' && i-1>=0){
            A[i+1]++;
        }
    }
    rep(i,Q){
        int l,r;
        cin >> l >> r;
        cout << A[r] - A[l] << endl;
    }
}

Measured memory_bytes: 1488
n,m = map(int,input().split())
s,c = [],[]
for i in range(n):
    a = list(map(int,input().split()))
    s.append(a)
for i in range(m):
    a = list(map(int,input().split()))
    c.append(a)


for i in range(n):
    tmp = 10**16
    ans = 0
    for j in range(m):
        b = (abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]))
        if tmp > b:
            tmp = b
            ans = j+1
    print(ans)

Measured memory_bytes: 68296
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	f=(double)a/b;
	r=a-b*d;
	printf("%d %d %f",d,r,f);
	return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#include <functional>
#include<stdio.h>
using namespace std;
#define ll       	long long int
#define dd      	long double
#define pb          push_back
#define pf          push_front
#define pi         pair<ll,ll>
#define vi          vector<ll>
#define vpi        vector<pi>
#define mi          map<ll,ll>
#define vvi         vector<vector<ll>>
#define mpi         map<pi,ll>
#define pipi        pair<ll,pair<ll,ll> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x         first
#define y         second
#define sz(x)       (ll)x.size()
#define u        	'\n'
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define rf(s)       for(auto &c : s)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++) //use Iterator
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define ef          else if
#define yes       cout<<"Yes"<<'\n';
#define no        cout<<"No"<<'\n';
#define C         continue;
#define wa(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<'\n'
#define debugp(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i.x<<","<<i.y<<" | "; cout<<'\n'
#include <ext/pb_ds/tree_policy.hpp>     
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>     
using namespace __gnu_pbds;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define fbo find_by_order
#define ook order_of_key
const ll N = 350;
 
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); } 
/*
ll power(ll x, ll y) 
{ 
    ll res = 1;  
	x=x%M; 
    while (y > 0) 
    { 
        if (y & 1) 
        res = (res*x)%M; 
        y = y>>1; 
        x = (x*x)%M;  
    } 
    return res; 
}
*/
signed main()
{
	tezz
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,i;
		cin>>n;
		vi a(n),b(n);
		fo(i,0,n)
		{
			
			cin>>a[i]>>b[i];
		}
		ll flag=0;
		fo(i,0,n-2)
		{
			if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
			{
				yes
				flag=1;
				break;
			}
		}
		if(flag==0)
		no
	}
	return 0;
} 

Measured memory_bytes: 3640
n,m=map(int,input().split())
a=[input() for _ in[0]*n]
b=[input() for _ in[0]*m]
for i in range(n-m+1):
  for j in range(n-m+1):
    f=1
    for s in range(m):
      for t in range(m):
        if(a[i+s][j+t]!=b[s][t]):f=0
    if(f):break
  if(f):break
print(["No","Yes"][f])

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

#define 	ll 						long long int
#define 	pb 						push_back
#define 	mp 						make_pair
#define 	fast 					ios_base::sync_with_stdio(false);cin.tie(NULL);
#define 	ff 						first
#define 	ss 						second
#define 	nil 					-10e+9
#define 	initial 				0
#define 	waiting 				1
#define 	visit 					2
#define 	inf  					10e+9
#define 	mx   					200005
#define 	mxx  					1000005
#define 	mod  					1000000007
#define 	pr   					pair<ll,ll>
#define 	pp_queue 			priority_queue<pr,vector<pr>, greater<pr> >
#define 	dp_queue 			priority_queue<int,vector<int>, greater<int> >
#define 	sp_queue 			priority_queue<int>
#define 	fr(i,p,q)			for(int i=p;i<q;++i)
#define 	frr(i,p,q) 		for(int i=p;i<=q;++i)
#define 	mem(a,b) 			memset(a,b,sizeof(a))
#define 	len(a)   			(int)a.size()
#define 	input  				freopen("input.txt", "r", stdin);
#define 	output 				freopen("output.txt", "w", stdout);
#define 	debug(arr,j,n) fr(i,j,n) cout<<arr[i]<<" ";

ll power(ll a,ll b){ll aa=1;while(b){if(b&1){aa=aa*a;aa%=mod;}a=a*a;a%=mod;b/=2;}return aa;}

using namespace std;

int main()
{
  string s;
	cin>>s;

	if(s=="Sunny") cout<<"Cloudy";
	if(s=="Cloudy") cout<<"Rainy";
	if(s=="Rainy") cout<<"Sunny";
	//if(s=="Sunny") cout<<"Cloudy";
  return 0;
}


Measured memory_bytes: 256
import sys
from heapq import*
r=sys.stdin.readline
def g(s,g):
 F=[1e7]*-~n;F[s]=0
 H=[(0,s)]
 while H:
  c,u=heappop(H)
  if u==g:return c
  for f,v in E[u]:
   t=c+f
   if t<F[v]:
    F[v]=t
    heappush(H,(t,v))
 return-1
for e in iter(input,'0 0'):
 n,k=map(int,e.split())
 E=[[]for _ in[0]*-~n]
 for _ in[0]*k:
  f=[*map(int,r().split())]
  if f[0]:
   c,d,e=f[1:]
   E[c]+=[(e,d)]
   E[d]+=[(e,c)]
  else:print(g(*f[1:]))


Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		String b = sc.nextLine();
		String ans = null;
		if(a.length() < b.length()) {
			ans = "LESS";
		}
		else if(a.length() > b.length()) {
			ans = "GREATER";
		}
		else {
			for(int i = 0; i < a.length() ; i++) {
				if(a.charAt(i)>b.charAt(i)) {
					ans = "GREATER";
					break;
				}
				else if(a.charAt(i) < b.charAt(i)) {
					ans ="LESS";
					break;
				}
				else if(a.charAt(i) == b.charAt(i) && i == a.length()-1) {
					ans = "EQUAL";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
int f[200001],c[200001],pos[200001],nxt[200001];
int main()
{
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		if(pos[c[i]])
			nxt[pos[c[i]]]=i;
		pos[c[i]]=i;
	}
	f[1]=1;
	for(i=1;i<=n;i++)
	{
		if(nxt[i]>i+1)
			f[nxt[i]]=(f[nxt[i]]+f[i])%1000000007;
		f[i+1]=(f[i+1]+f[i])%1000000007;
	}
	printf("%d",f[n]);
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[200010];
int M=0;

bool check(int m){
	int sum=0;
	REP(i,N){
		int c=ceil2(A[i],m);
		sum+=c;
	}
	if(sum<=K+N){
		return true;
	}
	return false;
}

signed main(){
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
		M=max(M,A[i]);
	}
	int ok=M,ng=0;
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		if(check(mid)){
			ok=mid;
		}
		else{
			ng=mid;
		}
	}
	cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 5064
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), acc(N+1, 0);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        acc[i+1] = acc[i] + A[i];
    }

    ll ans = 1LL << 60;
    for(int j = 1; j < N; j++) {
        int i1 = lower_bound(acc.begin(), acc.end(), acc[j]/2) - acc.begin();
        int k1 = lower_bound(acc.begin(), acc.end(), acc[j] + (acc[N] - acc[j]) / 2) - acc.begin();

        vector<int> I = {i1};
        vector<int> K = {k1};
        if(i1 - 1 > 0) I.push_back(i1-1);
        if(k1 - 1 > j) K.push_back(k1-1);
        for(auto i : I) {
            for(auto k : K) {
                vector<ll> area = {
                    acc[i],
                    acc[j] - acc[i],
                    acc[k] - acc[j],
                    acc[N] - acc[k]
                };
                sort(area.begin(), area.end());
                ans = min(ans, area.back() - area[0]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n;
	cin >> n;
	int cnt[3] = { 0,0,0 };
	int ans = 1;
	rep(i, n) {
		int a;
		cin >> a;
		int pl = 0;
		rep(j, 3) {
			if (cnt[j] == a) pl++;
		}
		ans *= pl;
		ans %= MOD;
		rep(j, 3) {
			if (cnt[j] == a) {
				cnt[j]++;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
a,v = ma()
b,w = ma()
t = ni()
if w>=v:
    print("NO")
    exit()
d = abs(a-b)
if d + w*t <=v*t:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9472
#include <cstdio>
#include <cstdlib>

#include <vector>
#include <cassert>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

struct Edge {
   int to, weight;
};

int N;
vector< vector<Edge> > adj;

VI color;
void dfs(int u, int col) {
   color[u] = col;
   for (Edge e : adj[u]) {
      int v = e.to;
      if (color[v] < 0) {
         dfs(v, e.weight & 1 ? col^1 : col);
      }
      else {
         assert(((e.weight & 1) != 0) == (color[u] != color[v]));
      }
   }
}

int main() {
   scanf("%d", &N);
   adj = vector< vector<Edge> >(N);
   for (int j = 1; j < N; ++j) {
      int u, v, w;
      scanf("%d %d %d", &u, &v, &w);
      --u, --v;
      adj[u].push_back({v, w});
      adj[v].push_back({u, w});
   }

   color = VI(N, -1);
   dfs(0, 0);

   for (int u = 0; u < N; ++u)
      printf("%d\n", color[u]);

   return 0;
}


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

using namespace std;

const int INF = numeric_limits<int>::max() / 2;
typedef long long ll;

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

  int n;cin>>n;
  int odd=0;
  for(int i=0;i<n;i++){
      ll a;cin>>a;
      if(a%2) odd++;
  }
  if(odd%2) cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


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

int main() {
  int N, user[10], field;
  char mountain;
  vector<string> ans;

  for (cin >> N; N != 0; cin >> N) {
    for (int i = 0; i < 10; i++) {
      user[i] = 0;
    }
    for (int i = 0; i < 100; i++) {
      cin >> mountain;
      switch (mountain) {
        case 'M':
          user[i % N]++;
          break;
        case 'S':
          field += user[i % N] + 1;
          user[i % N] = 0;
          break;
        case 'L':
          user[i % N] += field + 1;
          field = 0;
      }
    }

    sort(user, user + N);
    ostringstream stream;
    stream << user[0];
    for (int i = 1; i < N; i++) {
      stream << " " << user[i];
    }
    stream << " " << field;
    ans.push_back(stream.str());

    field = 0;
  }

  for (auto it = ans.begin(); it != ans.end(); it++) {
    cout << *it << endl;
  }
  return 0;
}


Measured memory_bytes: 3208
#include <cstdio>
using namespace std;

char map[8][9];

int main(void)
{
    int x, y;
    
    while (scanf("%s", map[0]) != EOF){
        if (!(map[0][0] == '0' || map[0][0] == '1')){
            continue;
        }
        
        for (int i = 1; i < 8; i++){
            scanf("%s", map[i]);
        }
        
        for (int i = 0; i < 64; i++){
			if(map[i / 8][i % 8] == '1'){
				x = i % 8;
				y = i / 8;
				break;
			}
		}
		if((map[y + 1][x] == '1') && (map[y][x + 1] == '1') && (map[y + 1][x + 1] == '1'))
        {
			printf("A\n");
		}
        else if((map[y + 1][x] == '1') && (map[y + 2][x] == '1') && (map[y + 3][x] == '1'))
        {
			printf("B\n");
		}
        else if((map[y][x + 1] == '1') && (map[y][x + 2] == '1') && (map[y][x + 3] == '1'))
        {
			printf("C\n");
		}
        else if((map[y][x + 1] == '1') && (map[y + 1][x + 1] == '1') && (map[y + 1][x + 2] == '1'))
        {
			printf("E\n");
		}
        else if((map[y + 1][x] == '1') && (map[y + 1][x + 1] == '1') && (map[y + 2][x + 1] == '1'))
        {
			printf("F\n");
		}
        else if((map[y][x + 1] == '1') && (map[y + 1][x] == '1') && (map[y + 1][x - 1] == '1'))
        {
			printf("G\n");
		}
        else if((map[y + 2][x - 1] == '1') && (map[y + 1][x] == '1') && (map[y + 1][x - 1] == '1'))
        {
			printf("D\n");
		}
        
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a, b;
    cin>>a>>b;
    for(int i=0; i<a.length();++i)
    {
        cout<<a[i];
        if(i<b.length()) cout<<b[i];
    }
    cout<<endl;
}

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

#define mkp make_pair


pair<string,int> makeEdge(string a,string b){
    if(a.size()>b.size()) swap(a,b);
    if(b.substr(0,a.size())==a) return mkp(b.substr(a.size()),a.size());
    else return mkp("",-1);
}

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;i++) cin>>S[i];

  map<string,int> dist;
  priority_queue<pair<int,string>,vector<pair<int,string>>,greater<pair<int,string>>> PQ;
  for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
          auto e=makeEdge(S[i],S[j]);
          if(e.second!=-1){
              dist[e.first]=e.second;
              PQ.push(mkp(e.second,e.first));
          }
      }
  }

  while(!PQ.empty()){
    auto f=PQ.top();
    PQ.pop();
    int cost=f.first;
    string now=f.second;
    if(dist[now]<cost) continue;
    
    if(now==""){
        cout<<cost<<endl;
        return 0;
    }

    for(int i=0;i<N;i++){
      auto e=makeEdge(now,S[i]);
      if(e.second==-1) continue;
      string nex=e.first;
      int neco=e.second;
      if(dist.count(nex)==false||dist[nex]>dist[now]+neco){
        dist[nex]=dist[now]+neco;
        PQ.push(mkp(dist[nex],nex));
      }
    }
  }

  cout<<0<<endl;

  return 0;
}



Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    map<ll,ll> A{};
    int n; cin >> n;
    rep(i,n){
        int a; cin >> a;
        int b = a + 1;
        int c = a - 1;
        A[a]++;
        A[b]++;
        A[c]++;
    }
    
    ll Ans = -100;
    for (auto it = A.begin(); it != A.end(); it++) {
        Ans = max(Ans,it->second);
    }
    
    cout << Ans << endl;
    
}



Measured memory_bytes: 6144
//HOW YOU DOI'N........................JT
//Could this code be more bad..........CB
//I know...............................MG
//Hii..................................RG
//Noooooooo............................RG
//I wish I could but I don't want to...PB

//That's what she said.................MS


#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (ll i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vvl vector<vector<ll>>
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;

ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll min(ll a,ll b){if(a>=b)return b;return a;}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}

#define MAX_SIZE 100005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
			for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
	for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}


vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};





// Lets start ...

vvl l(200005);
ll vis[200005];

void dfs(ll x,ll &tot){
    vis[x]=1;
    for(ll z:l[x]){
        if(vis[z]==0){
            tot++;
            dfs(z,tot);
        }
    }
}

void solve(){
    ll n,m;
    cin>>n>>m;
    map<pll,ll>mp;
    fi(i,0,m){
        ll x,y;
        cin>>x>>y;
        if(mp[{x,y}]||mp[{y,x}])continue;
        else{
            mp[{x,y}]++;
            l[x].pb(y);
            l[y].pb(x);
        }
    }

fi(i,1,n+1)vis[i]=0;
ll mx=0;
fi(i,1,n+1){
    if(vis[i]==0){
        ll tot=1;
        dfs(i,tot);
        mx=max(tot,mx);
    }
}
cout<<mx;
}


int main(){
    //vector<int> primes;
    //Sieve(primes);
    
    fast
    ll tests=1,cnt=0;
    //cin>>tests;
    while(tests--){
        solve();
    }
    

    return 0;
    }

// Done:)




Measured memory_bytes: 50136