akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define pr(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N, X;
ll h[55], p[55];

ll rec(ll lv, ll x) {
    if(lv==0) {
        if(x>0) return 1;
        else return 0;
    }
    
    ll res=0;
    
    if(x>h[lv-1]+1) {
        res+=rec(lv-1, x-h[lv-1]-2)+p[lv-1]+1;
    }else {
        res+=rec(lv-1, x-1);
    }
    
    return res;
}

int main(void) {
    cin >> N >> X;
    ll i;

    h[0]=p[0]=1;
    
    for(i=1; i<=N; i++) {
        h[i]=h[i-1]*2+3;
        p[i]=p[i-1]*2+1;
    }
    
    pr(rec(N, X));
    
    
}

























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

x = A * 12
l = 0
while l == 0:
  if (x * 0.08) // 1 == A:
    if (x * 0.1) // 1 == B:
      print(x)
      quit()
  x += 1
  if (x * 0.08) // 1 > A:
    if (x * 0.1) // 1 > B:
      l = 1
      
print("-1")

Measured memory_bytes: 3060
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=1000023};

int comp[2][2]={1,0,1,1};

il ll lucas(ll n,ll m){
	ll ans = 1;
	while( n && m ){
		ans*=comp[n&1][m&1];
		n>>=1, m>>=1;
		if( ans==0 ) return 0;
	}
	return ans;
}

char a[N];
int f[103][103];

int main(){
	int n=ci();
	scanf("%s",a+1);
	int cnt1=0, cnt2=0, cnt3=0;
	rep(i,1,n){
		if( a[i]=='1' ) cnt1++;
		if( a[i]=='2' ) cnt2++;
		if( a[i]=='3' ) cnt3++;
	}
	if( n<=100 ){
		rep(i,1,n) f[1][i] = a[i]-'0';
		rep(i,2,n){
			rep(j,1,n-i+1) f[i][j] = abs(f[i-1][j]-f[i-1][j+1]);
		}
		printf("%d\n",f[n][1]);
		return 0;
	}
	if( cnt2==0 ){
		rep(i,1,n) if( a[i]=='3' ) a[i]='2';
	}
	int ans = 0;
	rep(i,0,n-1){
		if( lucas(n-1,i) ) ans ^= (a[i+1]&1);
	}
	if( cnt2==0 ) ans*=2;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define LL long long
#define P 1000000007
#define M 1000005
using namespace std; 
int main(){
	int n,K;
	cin>>n>>K;
	int mx=(n-1)*(n-2)/2;
	if(K>mx){
		puts("-1");return 0;
	}
	int m=n-1+(mx-K);
	printf("%d\n",m);
	int p=mx-K;
	for(int i=2;i<=n;i++)printf("%d %d\n",1,i);
	for(int i=2;i<=n&&p;i++)
		for(int j=i+1;j<=n&&p;j++){
			printf("%d %d\n",i,j);p--;
		}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

int main() {
  int i, j;
  int n;
  char S[55][55];
  int num_alphabet[55][26] = {};
  int least_alphabet[26];
  for(i = 0; i < 26; i++) {
    least_alphabet[i] = 100;
  }
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s", S[i]);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < strlen(S[i]); j++) {
      int d = (int)S[i][j] - 97;
      num_alphabet[i][d] += 1;
    }
  }
  for (j = 0; j < 26; j++) {
    for (i = 0; i < n; i++) {
      if (least_alphabet[j] > num_alphabet[i][j]) {
	least_alphabet[j] = num_alphabet[i][j];
      }
    }
  }
  //for (i = 0; i < 26; i++) {
  //  printf("%d ", least_alphabet[i]);
  //}
  char ans[55];
  int p = 0;
  for (i = 0; i < 26; i++) {
    for (j = 0; j < least_alphabet[i]; j++) {
      ans[p+j] = (char)(97+i);
    }
    p += least_alphabet[i];
  }
  for (i = 0; i < p; i++) {
    printf("%c", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 128
import Foundation
 
let inputs = readLine()!.components(separatedBy: " ")
let x = Int(inputs[0])!
let y = Int(inputs[1])!

let b = (y - 2 * x) / 2
let a = (4 * x - y) / 2

if a < 0 || b < 0 {
    print("No")
    exit(0)
} 

if a + b == x && 2 * a + 4 * b == y {
    print("Yes")
} else {
    print("No")
}


    


Measured memory_bytes: 14072
#include<iostream>

int data[101];

int main(){
	int n,max=0;
	while(std::cin>>n){
		data[n]++;
		if(max<data[n])max=data[n];
	}
	for(int i=1;i<=100;i++){
		if(data[i]==max)std::cout<<i<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int h,w;
char c[100][100];
int dp[100][100];
int z[100][100],s[100][100],dz[100][100],ds[100][100];
int main(){
	ios::sync_with_stdio(0);
	cin>>h>>w;
	rep(i,h)
	rep(j,w){
		cin>>c[i][j];
	}
	int now=0;
	rep(i,h){
		now=0;
		rep(j,w){
			if(c[i][j]=='#')
			now++;
			else
			now=0;
			z[i][j]=now;
		}
	}
	rep(i,w){
		now=0;
		rep(j,h){
			if(c[j][i]=='#')
			now++;
			else
			now=0;
			s[j][i]=now;
		}
	}
	now=0;
	if(c[0][0]=='#')
	now++,dp[0][0]=1,dz[0][0]=1,ds[0][0]=1;
	forn(i,1,w){
		if(c[0][i]=='#')
		now++;
		else
		now=0;
		dz[0][i]=now;
		dp[0][i]=dp[0][i-1];
		if(now==1){
			dp[0][i]++;
			ds[0][i]=1;
		}
	}
	now=0;
	if(c[0][0]=='#')
	now++;
	forn(i,1,h){
		if(c[i][0]=='#')
		now++;
		else
		now=0;
		ds[i][0]=now;
		dp[i][0]=dp[i-1][0];
		if(now==1){
			dp[i][0]++;
			dz[i][0]=1;
		}
	}
	
	forn(i,1,h)
	forn(j,1,w){
		int ans1=dp[i-1][j],ans2=dp[i][j-1];
		if(c[i][j]=='.'){
			dp[i][j]=min(ans1,ans2);
			continue;
		}
		if(c[i-1][j]!='#')
		ans1++;
		if(c[i][j-1]!='#')
		ans2++;
		dp[i][j]=min(ans1,ans2);
	}
	cout<<dp[h-1][w-1]; 
	re 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

int main(){FIN;
  ll n,m; cin >> n >> m;
  ll ans=0;
  vector<ii> v(n);
  fore(i,0,n) cin >> v[i].fst >> v[i].snd;
  sort(ALL(v));
  fore(i,0,n){
    ans+=min(v[i].snd,m)*v[i].fst;
    m-=min(v[i].snd,m);
  }
  cout << ans << endl;
}

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

int	main() {
	int N, K, Q;
	cin >>N >>K >>Q;
	vector<int> A(N, 0);
	int AA;
	for (int i=0; i<Q; i++) {
		cin >>AA;
		AA--;
		A.at(AA)++;
	}
	for (int i=0; i<N; i++) 
		if (K-Q+A.at(i)>0)
			cout <<"Yes" <<endl;
		else
			cout <<"No" <<endl;
	return 0;
};


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

const char *table = "abcdefghijklmnopqrstuvwxyz";

inline char shift(char c, int n)
{
    return table[(c - 'a' - n) % 26];
}

void shift(std::string &s, int n)
{
    for (unsigned i = 0; i < s.size(); ++i) {
        if (s[i] != ' ' && s[i] != '.') s[i] = shift(s[i], n);
    }
}

int search_number(const std::string &s)
{
    for (unsigned i = 0; i < s.size() - 3; ++i) {
        int n = s[i] - 't';
        if (shift(s[i + 1], n) == 'h') {
            if (shift(s[i + 2], n) == 'e'
                    || (i < s.size() - 3 && shift(s[i + 2], n) == 'i' && shift(s[i + 3], n) == 's')
                    || (i < s.size() - 3 && shift(s[i + 2], n) == 'a' && shift(s[i + 3], n) == 't'))
                return n;
        }
    }
    return s[s.size() - 3] - 't';
}

int main()
{
    std::string s;
    while (getline(std::cin, s)) {
        shift(s, search_number(s));
        std::cout << s << std::endl;
    }
}

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

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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	
	ll sum = 0;
	REP(i, n) {
		int in;
		scanf("%d", &in);
		sum += in;
	}
	cout << sum / n << endl;
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <string.h>
int main(void){
    int N,X[101];
    int max=-1,min=101,Smin=1000000000,S;
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        scanf("%d",&X[i]);
        if(X[i]>max){
            max=X[i];
        }
        if(min>X[i]){
            min=X[i];
        }
    }
    for (int i=min; i<=max; i++) {
        S=0;
        for (int j=0 ; j < N ; j++) {
            S+=(X[j]-i)*(X[j]-i);
        }
        if(S<Smin){
            Smin=S;
        }
    }
    printf("%d\n",Smin);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[55];
ll s[55][55];
int num[55];
int cmp(ll A,ll B)
{
	return A>B;
}
void init()
{
	s[1][1]=1;
	s[1][0]=1;
	for(int i=2;i<=50;i++)
	{
		s[i][0]=1;
		s[i][i]=1;
		for(int j=1;j<i;j++)
		{
			s[i][j]=s[i-1][j-1]+s[i-1][j];
		}
	}
}
int main()
{
	int n,l,r;
	scanf("%d%d%d",&n,&l,&r);
	init();
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1,cmp);
	ll sum=0;
	int k=0;
	num[0]=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1])
		{
			num[k]++;
		}
		else
		{
			k++;
			num[k]++;	
		}
	}
	ll ans=0;
	for(int i=1;i<=l;i++)
	{
		sum+=a[i];
	}
	printf("%.6lf\n",sum/(double)l);
	if(num[0]>=l)
	{
		for(int i=l;i<=min(num[0],r);i++)
		{
			ans+=s[num[0]][i];
		}
	}
	else
	{
		int nums=0;
		int keys;
		int keys2;
		for(int i=0;i<=k;i++)
		{
			if(nums+num[i]>=l)
			{
				keys=num[i];
				keys2=l-nums;
				break;
			}
			nums+=num[i];
		}
		ans+=s[keys][keys2];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[100005];
int main()
{
	scanf("%s",s);
	int n=strlen(s)-1,cnt=1;
	for(int i=0;i<n;i++)
	{
		if(s[i]!=s[i+1]) cnt++;
	}
	cout<<cnt-1<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d,x,y,z,w,t;
  cin >> a >> b >> c >> d;
  x = a*c;
  y = b*c;
  z = a*d;
  w = b*d;
  t = max(max(x,y),max(z,w));
  cout << t << endl;
}


Measured memory_bytes: 3632
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node{int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].left != NIL)
        h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1>h2 ? h1 : h2);
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ",getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if(T[u].parent == NIL)
        printf("root\n");
    else if( T[u].left == NIL && T[u].right == NIL)
        printf("leaf\n");
    else
        printf("internal node\n");
}

int main(){
    int v,l,r,root = 0;
    scanf("%d",&n);

    for(int i=0;i<n;i++) T[i].parent = NIL;

    for(int i=0;i<n;i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }

    for(int i = 0; i<n; i++) if(T[i].parent == NIL ) root = i;

    setDepth(root, 0);
    setHeight(root);

    for(int i = 0;i<n;i++) print(i);

    return 0;
}


Measured memory_bytes: 2768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a));

    vector<ll> s(a);
    FOR(i, 1, n) s[i] += s[i-1];

    auto check = [&](ll mid) {
        ll cnt = 0;
        REP(i, n) {
            // a[i] + a[j] >= mid となるようなjが何個あるか？
            ll num = lower_bound(ALL(a), mid-a[i]) - a.begin();
            cnt += n-num;
        }
        return cnt >= m;
    };

    ll lb=0, ub=INF;
    while(ub-lb>1) {
        ll mid=(lb+ub)/2;
        if(check(mid)) lb = mid;
        else ub = mid;
    }

    ll ret = 0, cnt = 0;
    REP(i, n) {
        // a[i] + a[j] >= lb (j>=num)
        ll num = lower_bound(ALL(a), lb-a[i]) - a.begin();
        ll tmp = (s[n-1] - (num==0?0:s[num-1])) + a[i] * (n-num);
        ret += tmp;
        cnt += n-num;
    }
    while(cnt > m) cnt--, ret -= lb;
    cout << ret << endl;

    return 0;
}

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

int H, W;
int rightOrDown(vector<vector<int>> &dp, vector<vector<int>> &data, int h, int w, int cnt) {
  if(dp.at(h).at(w) <= cnt || dp.at(H-1).at(W-1) <= cnt) {
    return 0;
  }
  
  dp.at(h).at(w) = cnt;
  if(w < W-1) {
    int add = 0;
    if(data.at(h).at(w) == 0 && data.at(h).at(w+1) == 1) add = 1;
    rightOrDown(dp, data, h, w+1, cnt + add);
  }
  if(h < H-1) {
    int add = 0;
    if(data.at(h).at(w) == 0 && data.at(h+1).at(w) == 1) add = 1;
    rightOrDown(dp, data, h+1, w, cnt + add);
  }
  
  return 0;
}

int main() {
  cin >> H >> W;

  vector<vector<int>> data(H, vector<int>(W));
  for(int i = 0; i < H; ++i){
    string line;
    cin >> line;
    for(int j = 0; j < W; ++j){
      char t = line.at(j);
      if(t == '#'){
        data.at(i).at(j) = 1;
      }
    }
  }
  vector<vector<int>> dp(H, vector<int>(W,1000));
  if(data.at(0).at(0) == 0){
    rightOrDown(dp, data, 0, 0, 0);
  } else {
    rightOrDown(dp, data, 0, 0, 1);
  }

  cout << dp.at(H-1).at(W-1) << endl;
}


Measured memory_bytes: 384
// Author : Abhisar Singhal
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string>    
#include <sstream>
#include <utility>   
#include <ctime>
#include <cassert>
#include <fstream>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> II;
typedef vector<long long> VLL;
typedef vector<bool> VB;

#define SZ(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define MS(A) memset(A, 0, sizeof(A))
#define MSV(A,a) memset(A, a, sizeof(A))
#define MAX(a,b) ((a >= b) ? (a) : (b))
#define MIN(a,b) ((a >= b) ? (b) : (a))
#define ABS(a) (((a) > 0) ? (a) : (-a))
#define MP make_pair
#define X first
#define Y second
#define PB push_back
#define FOUND(A, x) (A.find(x) != A.end())
#define getcx getchar_unlocked
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12

#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define clrbit(s, b) (s &= ~(1<<b))

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REV(i, a, n) for(int i = a; i > n; i--)
#define FORALL(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define ALL(A) A.begin(), A.end()
#define LLA(A) A.rbegin(), A.rend()
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 1, 0, 0, -1, -1, -1}, dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
inline void inp( int &n ) {
	n=0; int ch = getcx(); int sign = 1;
	while(ch < '0' || ch > '9') { if(ch == '-') sign=-1; ch = getcx(); }
	while(ch >= '0' && ch <= '9') { n = (n << 3) + (n << 1) + ch - '0', ch = getcx(); }
	n = n * sign;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, t;
	cin >> n >> t;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ending = 0;
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		if (ending > a[i]) {
			ans -= ending - a[i];
		}
		ans += t;
		ending = a[i] + t;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define maxn 4000
#define int long long
#define N 3500
int n, P, f[maxn][maxn];
int fac[maxn], ans, inv[maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k;
}

void init()
{
	inv[1] = inv[0] = 1;
	for(int i = 2; i <= N; i ++)
		inv[i] = (P - P / i) * inv[P % i] % P;
	fac[0] = 1;
	for(int i = 1; i <= N; i ++)
		fac[i] = fac[i - 1] * i % P,
		inv[i] = inv[i - 1] * inv[i] % P;
}

void update(int &x, int y) { x = (x + y) % P; }

int C(int n, int m)
{
	if(m > n) return 0;
	return fac[n] * inv[m] % P * inv[n - m] % P;
}

int Qpow(int x, int times, int P)
{
	int base = 1;
	for(int i = times; i; x = x * x % P, i >>= 1)
		if(i & 1) base = base * x % P;
	return base;
}

void Get_DP()
{
	f[0][0] = 1;
	for(int i = 1; i <= n; i ++)
		for(int j = 0; j <= i; j ++)
		{
			if(j) f[i][j] = f[i][j] + f[i - 1][j - 1] % P;
			f[i][j] = (f[i][j] + (j + 1) * f[i - 1][j] % P) % P;
		}
}

int DP(int i)
{
	int ret = 0;
	for(int j = 0; j <= i; j ++)
		update(ret, f[i][j] * Qpow(2, (n - i) * j % P, P));
	return ret;
}

signed main()
{
	n = read(), P = read();
	init(); Get_DP();
	for(int i = 0; i <= n; i ++)
	{
		int Mul = Qpow(2, Qpow(2, n - i, P - 1), P);
		if(i & 1) update(ans, (P - (Mul * C(n, i) % P * DP(i) % P)) % P);
		else update(ans, (Mul * C(n, i) % P * DP(i) % P) % P);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 92800
#include<stdio.h>
int main()
{
    int a,b;
a,b=1,2,3;
a!=b;
scanf("%d %d",&a,&b);
if(a==1&&b==2)
    printf("3\n",a,b);
    else if(a==2&&b==1)
        printf("3\n",a,b);
    else if(a==1&&b==3)
        printf("2\n",a,b);
    else if(a==3&&b==1)
        printf("2\n",a,b);
    else if(a==2&&b==3)
        printf("1\n",a,b);
    else
        printf("1\n",a,b);

    return 0;
}


Measured memory_bytes: 128
L,R=map(int,input().split())
ans=float('inf')
for i in range(L,R):
  for j in range(L+1,R+1):
    s=(i*j)%2019
    
    if s==0:
      print(0)
      exit()
    else:
      ans=min(s,ans)
      
print(ans)
    

Measured memory_bytes: 9164
S=input()
So=S[0::2]
Se=S[1::2]
if So.count('0')+Se.count('1')>So.count('1')+Se.count('0'):
    print(len(S)-So.count('0')-Se.count('1'))
else:
    print(len(S)-So.count('1')-Se.count('0'))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();

    bool ok = true;
    rep(i, n){
        if(i % 2){
            ok &= (in[i] != 'R');
        }
        else {
            ok &= (in[i] != 'L');
        }
    }

    cout << (ok ? "Yes":"No") << endl;

    return 0;
}


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


ll sum_of_divisors(ll max_n){
	ll sum;
	sum = (max_n+1)*max_n/2;
	for(ll i = 2; i <= max_n; i++){
		ll term_num = max_n/i;
		ll divd_max = term_num*i;
		ll product_sum = term_num*(i+divd_max)/2;
		sum += product_sum;
	}
	return sum;
}


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

	cout << sum_of_divisors(N) << endl;
 
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	string S;
	cin>>S;
	if(S[0]==S[1] && S[1]==S[2] && S[2]==S[3]){
		cout<<"No";
	}else if((S[0]==S[1] && S[2]==S[3]) || (S[1]==S[2] && S[0]==S[3]) || (S[1]==S[3] && S[0]==S[2])){
		cout<<"Yes";
	}else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <cstdlib>
#include <algorithm>
#define roop(start,end,inc) for(int i = start;i < end;i+=inc)

using namespace std;

int main(){
	int a[9] = {};
	int val[3] = {};
	for(int i=0;i<9;++i){
		cin >> a[i];
	}
	val[0] = min(a[0],min(a[1],a[2]));
	val[1] = min(a[3],min(a[4],a[5]));
	val[2] = min(a[6],min(a[7],a[8]));
	roop(0,3,1) a[i] -= val[0];
	roop(3,6,1) a[i] -= val[1];
	roop(6,9,1) a[i] -= val[2];
	cout << ((a[0] == a[3] && a[3] == a[6] && a[1] == a[4] && a[4] == a[7] && a[2] == a[5] && a[5] == a[8]) ? "Yes" : "No") << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, l;
int par1[N], par2[N];
struct kaka {
    int fi, se, value;
} a[N];

bool cmp(kaka x, kaka y) {
    return (x.fi < y.fi) || (x.fi == y.fi && x.se < y.se);
}

int anc(int p, int par[]) {
    if (p == par[p]) return p;
    return par[p] = anc(par[p], par);
}

int join(int p, int q, int par[]) {
    par[anc(p, par)] = anc(q, par);
}

int main() {
    //freopen("065D.txt", "r", stdin);
    cin >> n >> k >> l;
    for (int i = 1; i <= n; i++) par1[i] = par2[i] = i;
    while (k--) {
        int x, y; scanf("%d %d", &x, &y);
        join(y, x, par1);
    }
    while (l--) {
        int x, y; scanf("%d %d", &x, &y);
        join(y, x, par2);
    }
    for (int i = 1; i <= n; i++) {
        par1[i] = anc(i, par1);
        par2[i] = anc(i, par2);
    }

    for (int i = 1; i <= n; i++) {
        a[i].fi = par1[i];
        a[i].se = par2[i];
        a[i].value = i;
    }
    sort(a + 1, a + n + 1, cmp);
    //for (int i = 1; i <= n; i++) cout << a[i].fi << " " << a[i].se << " " << a[i].value << endl;

    map <pair<int, int>, int> M;
    for (int i = 1; i <= n; i++) M[{a[i].fi, a[i].se}]++;

    int res[N];
    for (int i = 1; i <= n; i++) res[a[i].value] = M[{a[i].fi, a[i].se}];
    for (int i = 1; i <= n; i++) cout << res[i] << " ";
}






















Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> 	pii;
typedef long long 		ll;
typedef vector<int> 	vi;
#define PI 				3.14159265
#define int				long long
#define f 				first
#define s 				second
#define pb 				push_back
#define mtup 			make_tuple
#define nl 				'\n'
#define FLASH 			ios_base::sync_with_stdio(false);cin.tie(NULL);
#define maxheap 		priority_queue<ll>
#define minheap 		priority_queue<ll,vector<ll> ,greater<ll>>
const ll inf = 1e18 + 1;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 55;
ll modpow(ll a,ll b,int mod = LLONG_MAX) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) {return __gcd(a,b);}

signed main(){
	FLASH
	string s = "";int n, k;char c;
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> c;
		if (i != k) s += c;
		else {
			if (c == 'A') s+='a';
			if (c=='B') s+='b';
			if (c=='C') s+='c';
		}
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    string T; cin >> T;
    int cnt=0;
    for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3844
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    cout<<fixed<<setprecision(15);
    ll a,c; cin>>a;
    ld b; cin>>b;
    c=(ll)(b*100+0.1);
    cout<<(a*c)/100<<endl;
}

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

int main(){
    int n,i;
    while(cin>>n&&n){
        int x,y,h,w,b;
        int mo=0,big,wei,max;
        for(i=0;i<n;i++){
        cin>>x>>y>>h>>w;
        b=x+y+h;
        if(b<=60) big=1;
        else if(b<=80) big=2;
        else if(b<=100) big=3;
        else if(b<=120) big=4;
        else if(b<=140) big=5;
        else if(b<=160) big=6;
        else big=7;

        if(w<=2) wei=1;
        else if(w<=5) wei=2;
        else if(w<=10) wei=3;
        else if(w<=15) wei=4;
        else if(w<=20) wei=5;
        else if(w<=25) wei=6;
        else wei=7;

        if(big<=wei) max=wei;
        else max=big;
        switch(max){
            case 1:
            mo+=600;
            break;
            case 2:
            mo+=800;
            break;
            case 3:
            mo+=1000;
            break;
            case 4:
            mo+=1200;
            break;
            case 5:
            mo+=1400;
            break;
            case 6:
            mo+=1600;
            break;
            case 0:
            mo+=0;
            break;
            default:
            mo+=0;
            break;
        }
        }
        cout<<mo<<endl;
    }
    return 0;
}


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

int main(){
	int N,K,Q;
	cin >> N >> K >> Q;
	vector<int> point(N,K-Q);
	vector<int> a(Q);
	for(int i=0;i<Q;i++){
		cin >> a.at(i);
	}
	for(int i=0;i<Q;i++){
		point.at(a.at(i)-1) +=1;
	}
	for(int i=0;i<N;i++){
		if(point.at(i)>0){
			cout << "Yes" <<endl;
		}else{
			cout << "No" << endl;
		}
	}
}

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

using namespace std;
using lint = long long;
#define MOD 1000000007

int main(void)
{
    int H, W;
    cin >> H >> W;
    vector<vector<char> > s(H, vector<char>(W));

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            char c;
            cin >> c;
            s[i][j] = c;
        }
    }

    vector<vector<int> > h_a(H, vector<int>(W));
    vector<vector<int> > w_a(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        lint cnt = 0;
        for(int j = 0; j < W; j++){
            if(s[i][j] == '.'){
                cnt++;
            }else{
                cnt = 0;
            }
            w_a[i][j] = cnt;
        }
    }
    for(int i = 0; i < H; i++){
        lint cnt = 0;
        for(int j = W-1; j >= 0; j--){
            if(w_a[i][j] != 0){
                if(cnt < w_a[i][j]){
                    cnt = w_a[i][j];
                }else{
                    w_a[i][j] = cnt;
                }
            }else{
                cnt = 0;
            }
        }
    }

    for(int j = 0; j < W; j++){
        lint cnt = 0;
        for(int i = 0; i < H; i++){
            if(s[i][j] == '.'){
                cnt++;
            }else{
                cnt = 0;
            }
            h_a[i][j] = cnt;
        }
    }
    for(int j = 0; j < W; j++){
        lint cnt = 0;
        for(int i = H-1; i >= 0; i--){
            if(h_a[i][j] != 0){
                if(cnt < h_a[i][j]){
                    cnt = h_a[i][j];
                }else{
                    h_a[i][j] = cnt;
                }
            }else{
                cnt = 0;
            }
        }
    }

    lint max = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            lint light = h_a[i][j] + w_a[i][j] - 1;
            if(max < light){
                max = light;
            }
        }
    }
    /*
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << w_a[i][j];
        }
        cout << endl;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << h_a[i][j];
        }
        cout << endl;
    }
    */
    

    cout << max << endl;
    return 0;
}

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

int main() {
	int b, r, g, c, s, t;
	while(cin >> b >> r >> g >> c >> s >> t, b+r+g+c+s+t) {
		int res = 0;
		res += 15*b + 15*(5*b) + 5*b;
		res += 15*r + 15*(3*r) + 3*r;
		res += 7*g;
		res += 2*c;
		res -= 3*(t-s);
		cout << res + 100 << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;



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


    ll r;
    cin>>r;
    long double ans=6.2831853071795*r;
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;

signed main() {
  int N;
  cin >> N;
  
  vector<int> cnt(100010);
  cnt.at(0) = 3;
  int ans = 1;
  for( int i = 0; i < N; i++ ){
    int A;
    cin >> A;
    ans *= cnt.at(A);
    ans %= MOD;
    cnt.at(A)--;
    cnt.at(A+1)++;
  }
  if( ans >= 0 ) cout << ans << endl;
  else cout << 0 << endl;
  
}

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

int main(){
	int n,t,p;
	string name;
	queue<pair<string,int> >q;
	cin>>n>>p;
	for(int i=0;i<n;i++){
		cin>>name>>t;
		q.push(make_pair(name,t));
	}
	
	pair<string,int> temp;
	int els=0,a;
	
	while(!q.empty()){
		temp = q.front();
		q.pop();
		a = min(temp.second,p);
		temp.second-=a;
		els+=a;
		if(temp.second>0){
			q.push(temp);
		}else{
			cout<<temp.first<<" "<<els<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 6344
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 ll MOD = 1e9 + 7;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }

int main() {
   int N, X;
   cin >> N >> X;
   vector<int> S(N);
   for (int i = 0; i < N; i++) cin >> S[i];
   sort(S.begin(), S.end());

   vector<vector<ll> > dp(N + 1, vector<ll>(X + 1, 0));

   for (int x = 0; x <= X; x++) dp[0][x] = x;
   for (int i = 0; i < N; i++) {
      for (int x = 0; x <= X; x++) {
         dp[i + 1][x] += dp[i][x % S[i]];
         dp[i + 1][x] %= MOD;
         dp[i + 1][x] += dp[i][x] * i % MOD;
         dp[i + 1][x] %= MOD;
      }
   }
   cout << dp[N][X] << endl;
   return 0;
}


Measured memory_bytes: 158592
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
static const lint MOD9 = (lint)1e9+7;
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}

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

    map<lint, int> lunlun;
    queue<string> que;
    for (char c = '1'; c <= '9'; ++c)
    {
        string s; s += c;
        lunlun[atoll(s.c_str())] = 1;
        que.push(s);
    }

    while (!que.empty())
    {
        string now = que.front(); que.pop();
        lunlun[atoll(now.c_str())] = 1;
        if (len(now) == 10)
        {
            continue;
        }
        char top = now[len(now) - 1];
        if (top == '0')
        {
            que.push(now + '0');
            que.push(now + '1');
        }
        else if (top == '9')
        {
            que.push(now + '8');
            que.push(now + '9');
        }
        else
        {
            for (char i = top - 1; i <= top + 1; ++i)
            {
                que.push(now + i);
            }
        }
    }

    int cnt = 1;
    for (cauto p : lunlun)
    {
        if (cnt == K)
        {
            cout << p.first << endl;
            break;
        }
        cnt++;
    }

    return 0;
}
















Measured memory_bytes: 14080
from collections import deque

n = int(input())
L = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    L[u-1].append((v-1, w))
    L[v-1].append((u-1, w))
d = [-1] * n
d[0] = 0
c = [0] * n
c[0] = 0
q = deque([0])
while q:
    t = q.popleft()
    dist = d[t]
    for v, w in L[t]:
        if d[v] < 0:
            d[v] = dist + w
            if d[v] % 2:
                c[v] = 1
            q.append(v)
for x in c:
    print(x)


Measured memory_bytes: 43896
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

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

  int n, m;
  cin >> n >> m;

  vector<pair<int, int>> paths(m);

  for (auto &p : paths)
  {
    cin >> p.first >> p.second;
  }

  vector<int> g, s;

  for (auto &p : paths)
  {
    if (p.first == 1)
    {
      g.push_back(p.second);
    }
    if (p.second == n)
    {
      s.push_back(p.first);
    }
  }

  if (g.empty() || s.empty())
  {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  sort(g.begin(), g.end());
  sort(s.begin(), s.end());

  auto ge = g.begin();
  auto se = s.begin();

  bool possible = false;
  while (ge != g.end() && se != s.end()) {
    while (*ge < *se && ge != g.end()) {
      ++ge;
    }
    while (*se < *ge && se != s.end()) {
      ++se;
    }
    if (*ge == *se) {
      possible = true;
      break;
    }
  }

  if (possible) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
#define pb push_back
int main(void){
    ll n,m,x;
    cin>>n>>m>>x;
    ll a[n][m],c[n];
    rep(0,i,n){
        cin>>c[i];
        rep(0,j,m)cin>>a[i][j];
    }
    ll ans=1e8;
    rep(0,bit,(1<<n)){
        ll tmp[m];
        ll ans0=0;
        rep(0,i,m)tmp[i]=0;
        vector<ll>s;
        rep(0,i,n){
            if(bit&(1<<i)){
                s.pb(i);
            }
        }
        rep(0,i,s.size()){
            ll x0=s[i];
            rep(0,j,m)tmp[j]+=a[x0][j];
            ans0+=c[x0];
        }
        bool t=true;
        rep(0,i,m)if(tmp[i]<x)t=false;
        if(t)ans=min(ans,ans0);
    }
    if(ans==(ll)1e8)ans=-1;
    cout<<ans;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,x,y,s;
  cin>>n>>k>>x>>y;
  if(n<=k)s=x*n;
  if(n>k)s=k*x+(n-k)*y;
  cout << s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for (int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EB emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;

int main(void) {
    int N, A, B;
    cin >> N >> A >> B;
    VI t(N);
    REP(i, N) cin >> t[i];
    int cnt = 0;
    REP(i, N) {
        if (A <= t[i] && t[i] < B) continue;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int comp(const void* a, const void* b) 
{
	return *(int*)a - *(int*)b; // 升序
}

bool IsArrayRepeat(int* arr, int len)
{
	if (!arr || len <= 1)
		return false;


	qsort(arr, len, sizeof(int), comp);

	for (int i = 0; i < len - 1; i++)
	{
		if (arr[i] == arr[i + 1])
			return true;
	}

	return false;
}


int main() {
	
	int n;
	scanf("%d", &n);
	int i;
	int a[200006];
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a+n);
	if (IsArrayRepeat(a, n) ) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 1404
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define ss second
#define mod 998244353
#define pb push_back
#define mp make_pair
#define int long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
//int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<int,int> &a, 
              const pair<int,int> &b) 
{   
    if(a.ff == b.ff){
        return (b.ss < a.ss);
    }
    return (a.ff<b.ff); 
}
int l[100003], r[100003];

int32_t main()
{
    // IOS;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
    // #endif
    /********************* From here ***********************/
    int n;
    cin >>  n;
    int a[100004];

    rep(i, 0, n){
        cin >> a[i];
    }
    
    l[0] = a[0];
    r[n-1] = a[n-1];
    cerr<<"HI\n";
    rep(i, 1, n){
        l[i] = __gcd(l[i-1], a[i]);
    }
    for(int i = n-2;i>= 0;i--){
        r[i] = __gcd(r[i+1], a[i]);
    }
    // rep(i, 0, n){
    //     cout << l[i] << " ";
    // }
    // cout << endl;
    // rep(i, 0, n){
    //     cout << r[i] << " ";
    // }

    int ans = r[1];
    rep(i, 1, n-1){
        ans = max(__gcd(l[i-1], r[i+1]), ans);
    }

    ans = max(ans, l[n-2]);

    cout << ans;
}


Measured memory_bytes: 2560
<?php
    ini_set('error_reporting', E_ALL & ~E_NOTICE);

    fscanf(STDIN, "%d %d", $N, $K);
    $A = explode(" ", trim(fgets(STDIN)));
    
    $arr = array();
    
    foreach ($A as $v) {
        $arr[$v]++;
    }
    $cnt = count($arr);
    
    rsort($arr);

    $ans = 0;
    
    for ($i = $K; $i < $cnt; $i++) {
        $ans += $arr[$i];
    }
    
    echo $ans . PHP_EOL;


Measured memory_bytes: 35312
n, y = map(int, input().split())
y //= 1000
yen = [10, 5, 1]


def bs(n10):
    high = y // 5 + 1
    low = 0
    while high - low > 1:
        mid = (high + low) // 2
        if mid + n10 > n or mid * 5 > y - n10 * 10 - (n - n10 - mid):
            high = mid
        else:
            low = mid
    return low


try:
    for i in range(n + 1):
        for j in range(n + 1 - i):
            if i * yen[0] + j * yen[1] + (n - i - j) * yen[2] == y:
                print("{} {} {}".format(i, j, n - i - j))
                raise Exception
    print("-1 -1 -1")
except Exception:
    pass


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
int gcd(int x, int y) { return (y ? gcd(y, x % y) : x); }
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    int ans = a[0];
    for (int i = 0; i < N; i++) ans = gcd(ans, a[i]);
    cout << ans << '\n';
}


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,n,m,s,k,ans;
  while(cin >> d && d != 0){
    cin >> n >> m;
    vector<int> vec;
    vec.push_back(0);
    ans = 0;
    n--;
    while(n--){
      cin >> s;
      vec.push_back(s);
    }
    sort(vec.begin(),vec.end());
    vec.push_back(d);
    while(m--){
      cin >> k;
      ans += min(*lower_bound(vec.begin(),vec.end(),k)-k,k-vec[lower_bound(vec.begin(),vec.end(),k)-vec.begin()-1]);
    }
    cout << ans << endl;
  }
  return (0);
}

Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int grid[3][3];

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> grid[i][j];
        }
    }

    bool right = false;
    for (int i = 0; i <= grid[0][0]; i++) {
        
        int b[3] = {};

        for (int j = 0; j < 3; j++) {
            b[j] = grid[0][j] - i;
        }

        int a[3] = {};

        for (int m = 1; m < 3; m++) {
            a[m] = grid[m][0] - b[0];
        }

        for (int k = 0; k < 3; k++) {
            for (int l = 0; l < 3; l++) {
                if (grid[k][l] != a[k] + b[l]) goto fail;
            }
        }

        right = true;

        break;

    fail:;
    }

    out(right ? "Yes" : "No");

    int aaa;
    cin >> aaa;
}

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


int main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string str;
    int s,ds,i;
       cin>>str;
    s=0;
    for (i=0; str[i]!='\0'; i++)
    {
        s+=str[i]-'0';
    }
    if (s%9==0)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 3760