stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)

#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)

#define EREP(i,u) for(int i=start[u];i;i=e[i].next)

#define fi first

#define se second

#define mkr(a,b) make_pair(a,b)

#define SZ(A) ((int)A.size())

template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}

template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}

inline int read()

{

	int s=0,f=1; char ch=getchar();

	while(!isdigit(ch) && ch!='-')ch=getchar();

	if(ch=='-')ch=getchar(),f=-1;

	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();

	return ~f?s:-s;

}



const int maxn=5e3+20;



int n,mod;

int dp[maxn];



inline void init()

{

	n=read();mod=read();

}



inline void pls(int &a,int b){ a+=b; a-=a>=mod?mod:0;}



int f[maxn][maxn];



inline void doing()

{

	int len=n-1>>1;

	dp[0]=1;

	REP(i,1,len+(~n&1))

	{

		int w=i;

		for(int j=w;j<=n;j++)

			pls(dp[j],dp[j-w]);

	}

	f[0][0]=1;

	REP(i,1,n)

	{

		REP(j,0,n)f[i][j]=f[i-1][j];

		REP(j,i,n)pls(f[i][j],f[i][j-i]);

	}

	DREP(i,n,1)

	{

		int s=0;

		REP(j,0,n)

		{

			pls(s,f[i-1][j]);

			int nj=j+len+1;

			if(nj<=n)pls(f[i][nj],mod-s);

		}

	}

	int ans=0;

	REP(x,1,n)

	{

		int a=x-1,mx=n-x;

		int suf=0;

		DREP(j,a,0)

		{

			suf=(suf+dp[a-j])%mod;

			ans=(ans+(ll)suf*f[mx][j])%mod;

		}

	}

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

}



int main()

{

	init();

	doing();

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.138127791529655x):
#include<cstdio>

int f[5007];

int min(int a,int b){return a<b? a:b;}

int main()

{

    int n,p,ans=0;

    scanf("%d%d",&n,&p),f[0]=1;

    for(int i=1;i<n;++i) for(int k=min(i,n-i+1),j=k;j<n;++j) (f[j]+=f[j-k])%=p;

    for(int i=0;i<n;++i) (ans+=1ll*(n-i)*f[i]%p)%=p;

    printf("%d",ans);

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

using namespace std;

int D[5010][5010], n, Mod, C[5010];

void Make(int t) {

	int i, j;

	for (i = 0; i <= n / (t+1); i++) {

		for (j = t * i; j <= n-t; j++) {

			D[i + 1][j + t] = (D[i + 1][j + t] + D[i][j]) % Mod;

		}

	}

}

int main() {

	int i, j;

	scanf("%d%d", &n, &Mod);

	D[0][0] = 1;

	for (i = 2; i <= n; i++) {

		C[min(i - 2, n + 1 - i)]++;

	}

	for (i = n / 2; i >= 0; i--) {

		for (j = 0; j < C[i]; j++) {

			Make(i);

		}

	}

	int res = 0;

	for (i = 0; i < n; i++) {

		for (j = 0; j <= n; j++) {

			res = (res + (long long)max(n - i - j, 0) * D[i][j]) % Mod;

		}

	}

	printf("%d\n", res);

}

// Faster C++ solution for the same problem (measured speedup: 1.196104910606279x):
#include<cstdio>

#include<algorithm>

using namespace std;

int D[5010], n, Mod, C[5010];

void Make(int t) {

	int i;

	for (i = 0; i <= n - t; i++) {

		D[i+t] = (D[i+t] + D[i]) % Mod;

	}

}

int main() {

	int i;

	scanf("%d%d", &n, &Mod);

	D[0] = 1;

	for (i = 2; i <= n; i++) {

		Make(min(i - 1, n + 2 - i));

	}

	int res = 0;

	for (i = 0; i < n; i++) {

		res = (res + 1ll * (n - i)*D[i]) % Mod;

	}

	printf("%d\n", res);

}
// Slower C++ solution:
#include<iostream>

using namespace std;

struct node{

    int x,y;

    int len;

    node(){};

    node(int xx,int yy){x=xx;y=yy;len=x*x+y*y;}

    bool judge(node t)

    {

        if(t.len==len&&(x*t.y-y*t.x)>0&&(t.x*x+t.y*y)==0)return 1;

        else return 0;

    };

};

int main()

{

    node p1,p2,p3,p4,tt,t;

    int x,y;

    cin>>x>>y;

    p1=node(x,y);

    cin>>x>>y;

    p2=node(x,y);

    tt=node(p2.x-p1.x,p2.y-p1.y);

    for(int i=-400;i<=400;++i)

    {

        for(int j=-400;j<=400;++j)

        {

            t=node(i,j);

            t=node(t.x-p2.x,t.y-p2.y);

            if(tt.judge(t))p3=node(i,j);

            t=node(i,j);

            t=node(p1.x-t.x,p1.y-t.y);

            if(t.judge(tt))p4=node(i,j);

        }

    }

    cout<<p3.x<<" "<<p3.y<<" "<<p4.x<<" "<<p4.y<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 17.687006595470866x):
#include<stdio.h>



int main()

{

    int x1,y1,y2,x2,x3,y3,y4,x4,x,y;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    x = x2-x1;

    y = y2-y1;

    x3 = x2-y;

    x4 = x1-y;

    y3 = y2+x;

    y4 = y1+x;

    printf("%d %d %d %d\n", x3,y3,x4,y4);

    return 0;



}
// Slower C++ solution:
#include<iostream>

using namespace std;

struct node{

    int x,y;

    int len;

    node(){};

    node(int xx,int yy){x=xx;y=yy;len=x*x+y*y;}

    bool judge(node t)

    {

        if(t.len==len&&(x*t.y-y*t.x)>0&&(t.x*x+t.y*y)==0)return 1;

        else return 0;

    };

};

int main()

{

    node p1,p2,p3,p4,tt,t;

    int x,y;

    cin>>x>>y;

    p1=node(x,y);

    cin>>x>>y;

    p2=node(x,y);

    tt=node(p2.x-p1.x,p2.y-p1.y);

    for(int i=-400;i<=400;++i)

    {

        for(int j=-400;j<=400;++j)

        {

            t=node(i,j);

            t=node(t.x-p2.x,t.y-p2.y);

            if(tt.judge(t))p3=node(i,j);

            t=node(i,j);

            t=node(p1.x-t.x,p1.y-t.y);

            if(t.judge(tt))p4=node(i,j);

        }

    }

    cout<<p3.x<<" "<<p3.y<<" "<<p4.x<<" "<<p4.y<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 17.68789056198233x):
#include <stdio.h>



int main()

{

    int x1,y1,x2,y2,x3,y3,x4,y4,d1,d2;

    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);

    d1=x2-x1;

    d2=y1-y2;

    x3=x2+d2;

    y3=y2+d1;

    x4=x1+d2;

    y4=y1+d1;

    

    printf("%d %d %d %d\n",x3,y3,x4,y4);

    



    return 0;

}
// Slower C++ solution:
#include<iostream>

using namespace std;

struct node{

    int x,y;

    int len;

    node(){};

    node(int xx,int yy){x=xx;y=yy;len=x*x+y*y;}

    bool judge(node t)

    {

        if(t.len==len&&(x*t.y-y*t.x)>0&&(t.x*x+t.y*y)==0)return 1;

        else return 0;

    };

};

int main()

{

    node p1,p2,p3,p4,tt,t;

    int x,y;

    cin>>x>>y;

    p1=node(x,y);

    cin>>x>>y;

    p2=node(x,y);

    tt=node(p2.x-p1.x,p2.y-p1.y);

    for(int i=-400;i<=400;++i)

    {

        for(int j=-400;j<=400;++j)

        {

            t=node(i,j);

            t=node(t.x-p2.x,t.y-p2.y);

            if(tt.judge(t))p3=node(i,j);

            t=node(i,j);

            t=node(p1.x-t.x,p1.y-t.y);

            if(t.judge(tt))p4=node(i,j);

        }

    }

    cout<<p3.x<<" "<<p3.y<<" "<<p4.x<<" "<<p4.y<<endl;

}

// Faster C++ solution for the same problem (measured speedup: 17.99322636612303x):
#include <cstdio>

#define rg register

using namespace std;

typedef long long ll;

template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}

template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}

template <typename Tp> inline void read(Tp &x)

{

	x=0;int f=0;char ch=getchar();

	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();

	if(ch=='-') f=1,ch=getchar();

	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();

	if(f) x=-x;

}

int x1,y1,x2,y2,a,b;

int main()

{

	read(x1);read(y1);read(x2);read(y2);

	a=x2-x1;b=y2-y1;

	printf("%d %d %d %d\n",x2-b,y2+a,x2-a-b,y2+a-b);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<bits/stdc++.h>

#include <stdio.h>

#include<unordered_map>

#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define ll long long

#define ld long double

#define pll pair<ll,ll>

#define vll vector<ll>

#define vvll vector<vector<ll> >

#define vpll vector<pair<ll,ll> >

#define P complex<ld>

#define X real()

#define Y imag()

#define all(v) v.begin(),v.end()

#define rall(v) v.rbegin(),v.rend()

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

#define repp(i,s,n)   for(int i=s;i<=n;i++)

#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}

#define mkp make_pair

#define clr(ar,v) memset(ar,v,sizeof(ar));

#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)

#define popcnt(x) __builtin_popcount(x)

#define EPS 1e-9

#define INF 1000000000000000009

using namespace std;

//freopen("output.txt", "w", stdout);

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

const int mod = 1000000007;

const int N = 2 * 100000 + 9;

const double pi = acos(-1);

class cmp{

public:

	bool operator() (ll &A, ll &B){

		return A > B;

	}

};

bool by_sec(const pll &a, const pll &b){

	if ((abs(a.first) == abs(b.first)))

		return (abs(a.second) < abs(b.second));

	return (abs(a.first) < abs(b.first));

}

bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){

	return (get<2>(a) < get<2>(b));

}

ld dist(P a, P b){

	return (ld)abs(a - b);

}

ll fact[1000009], inv[1000009];

ll fp(ll a, ll b){

	if (b == 0)

		return 1;

	ll ans = fp(a, b / 2);

	ans = (ans * ans) % mod;

	if (b % 2 != 0)

		ans = (ans * (a % mod)) % mod;

	return ans;

}

void FacInv(ll n){

	fact[0] = inv[0] = 1;

	for (ll i = 1; i <= n; i++)

	{

		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;

		inv[i] = fp(fact[i], mod - 2);

	}

}

ll ncr(ll n, ll r){

	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;

}

ll gcd(ll a, ll b){

	if (b == 0)return a;

	return gcd(b, a%b);

}

ll max(ll a, ll b){

	if (a >= b)return a;

	else return b;

}

ll min(ll a, ll b){

	if (a <= b)return a;

	else return b;

}



vvll gr(N);

bool vis[N][4];

vll en;

void dfs(ll n, ll c){

	vis[n][c] = 1;

	if (c == 0){

		if (!vis[n][3]){

			vis[n][3] = 1;

			en.push_back(n);

		}

		return;

	}

	for (auto i : gr[n]){

		if (!vis[i][c-1])

		dfs(i, c - 1);

	}

}



int main()

{

	Amr_Abdelazim



		ll x, y, a, b;

	cin >> x >> y >> a >> b;

	ll dx = a - x, dy = b - y;

	cout << a - dy << " " << b + dx << " ";

	cout << x - dy << " " << y + dx << "\n";

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 6.5006905137271875x):
#include <bits/stdc++.h>

#include<iostream>

using namespace std;

typedef long long ll;

const int N=1e5+5;

ll u[N],m[N],b[N];

vector<vector<int> > adj;

bool visited[N][10]={};

int nodesNum;

int s,t;





int main(){

   ios_base::sync_with_stdio(false);

    cin.tie(0);

    cout.tie(0);



int x1,y1,x2,y2,x3,y3,x4,y4;

cin>>x1>>y1>>x2>>y2;

int x=x2-x1;

int y=y2-y1;

x3=x2-y;

y3=y2+x;

x4=x1-y;

y4=y1+x;

cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4;



    return 0;

}
// Slower C++ solution:
#include <vector>

#include <bitset>

#include <iostream>



using B = std::bitset<32>;



int main()

{

  int N;

  std::cin >> N;

  int S[500000];

  for(int i = 0; i < N; ++i) {

    char c;

    std::cin >> c;

    S[i] = 1 << (c - 'a');

  }

  int Q;

  std::cin >> Q;

  while (Q--) {

    int q;

    std::cin >> q;

    if (q == 1) {

      int i;

      char c;

      std::cin >> i >> c;

      S[i - 1] = 1 << (c - 'a');

    } else {

      int r, l;

      std::cin >> r >> l;

      --r;

      int res{};

      for (int i = r; i < l; ++i) {

          res |= S[i];

      }

      B ans(res);

      std::cout << ans.count() << '\n';

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.089594867473232x):
#include <vector>

#include <bitset>

#include <cstdio>



using B = std::bitset<32>;



int main()

{

  int N;

  scanf("%d\n", &N);

  int S[500000];

  for(int i = 0; i < N; ++i) {

    char c;

    scanf("%c", &c);

    S[i] = 1 << (c - 'a');

  }

  int Q;

  scanf("\n%d\n", &Q);

  while (Q--) {

    int q;

    scanf("%d ", &q);

    if (q == 1) {

      int i;

      char c;

      scanf("%d %c\n", &i, &c);

      S[i - 1] = 1 << (c - 'a');

    } else {

      int r, l;

      scanf("%d %d\n", &r, &l);

      --r;

      int res{};

      for (int i = r; i < l; ++i) {

          res |= S[i];

      }

      B ans(res);

      printf("%d\n", ans.count());

    }

  }

  return 0;

}
// Slower C++ solution:
#include <vector>

#include <bitset>

#include <iostream>



constexpr char ALPHA = 'a';

constexpr int ONE = 1;



int main()

{

  int N;

  std::cin >> N;

  std::vector<int> S(N);

  for(auto& s : S) {

    char c;

    std::cin >> c;

    s = ONE << (c - ALPHA);

  }

  int Q;

  std::cin >> Q;

  while (Q--) {

    int q;

    std::cin >> q;

    if (q == ONE) {

      int i;

      char c;

      std::cin >> i >> c;

      S[i - 1] = 1 << (c - ALPHA);

    } else {

      int r, l;

      std::cin >> r >> l;

      --r;

      int res{};

      for (int i = r; i < l; ++i) {

          res |= S[i];

      }

      std::bitset<32> ans(res);

      std::cout << ans.count() << '\n';

    }

  }

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.951773710916313x):
#include <vector>

#include <bitset>

#include <cstdio>



using B = std::bitset<32>;



int main()

{

  int N;

  scanf("%d\n", &N);

  int S[500000];

  for(int i = 0; i < N; ++i) {

    char c;

    scanf("%c", &c);

    S[i] = 1 << (c - 'a');

  }

  int Q;

  scanf("\n%d\n", &Q);

  while (Q--) {

    int q;

    scanf("%d ", &q);

    if (q == 1) {

      int i;

      char c;

      scanf("%d %c\n", &i, &c);

      S[i - 1] = 1 << (c - 'a');

    } else {

      int r, l;

      scanf("%d %d\n", &r, &l);

      --r;

      int res{};

      for (int i = r; i < l; ++i) {

          res |= S[i];

      }

      B ans(res);

      printf("%d\n", ans.count());

    }

  }

  return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

#define ll long long

#define For(i,x,y) for(int i=x;i<=y;i++)

#define Rep(i,x,y) for(int i=x;i>=y;i--)

#define Forn(i,x,y) for(int i=x;i<y;i++)

#define oo 1000000

#define zyy 1000000007

#define M 100

#define N 200005

using namespace std;

inline int read(){int x=0,f=0;char ch=getchar();for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1;for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-48;return f?-x:x;}

inline void write(ll x){if(x<10) putchar(x+48);else write(x/10),putchar(x%10+48);}

inline void writeln(ll x){if(x<0) putchar('-'),x=-x;write(x);putchar('\n');}

int n,a[N],ans;

int main(){

	n=read();For(i,1,n) a[i]=read(),ans+=a[i];

	sort(a+1,a+1+n);

	if(ans%10!=0) return writeln(ans),0;

	For(i,1,n) if(a[i]%10!=0){

		ans-=a[i];

		return writeln(ans),0;

	}

	puts("0");

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.276118891393462x):
#include<cstdio>

#include<cstring>

#include<algorithm>

#define ll int

#define N 200005

#define mod 1000000007

#define rep(i,j,k) for (ll i=j;i<=k;++i)

#define per(i,j,k) for (ll i=j;i>=k;--i)

using namespace std;

inline ll read(){

	char ch=getchar(); ll x=0,f=1;

	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }

	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }

	return x*f;

}

ll n,x,sum,tmp=mod;

int main(){

	n=read();

	rep(i,1,n){

		sum+=x=read();

		if (x%10) tmp=min(tmp,x);

	}

	if (sum%10) printf("%d",sum);

	else if (tmp!=mod) printf("%d",sum-tmp);

	else printf("%d",0);

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> lpair;

const ll MOD = 1e9 + 7;

const ll INF = 1e18;

#define rep(i,m,n) for(ll i = (m); i < (n); i++)

#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)

#define print(x) cout << (x) << endl;

#define print2(x,y) cout << (x) << " " << (y) << endl;

#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

ll N;

ll u[100010], v[100010], w[100010];

vector<lpair> tree[100010];

ll d[100010] = {};



void dfs(ll cur, ll par, ll v){

    d[cur] = v;

    for(auto &e: tree[cur]){

        if(e.first == par) continue;

        if(v == 0){

            if(e.second == 0){

                dfs(e.first, cur, 0);

            }else{

                dfs(e.first, cur, 1);

            }

            

        }else{

            if(e.second == 0){

                dfs(e.first, cur, 1);

            }else{

                dfs(e.first, cur, 0);

            }



        }







    }

}



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    cin >> N;

    rep(i,0,N-1){

        cin >> u[i] >> v[i] >> w[i];

        u[i]--; v[i]--;

        tree[u[i]].push_back(make_pair(v[i], w[i] % 2));

        tree[v[i]].push_back(make_pair(u[i], w[i] % 2));

    }

    memset(d, -1, sizeof(d));

    dfs(0,-1, 0);

    rep(i,0,N) print(d[i]);











    

}

// Faster C++ solution for the same problem (measured speedup: 1.2125204722270502x):
/*** author: yuji9511 ***/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using lpair = pair<ll, ll>;

const ll MOD = 1e9+7;

const ll INF = 1e18;

#define rep(i,m,n) for(ll i=(m);i<(n);i++)

#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)

#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

void print() {}

template <class H,class... T>

void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

vector<lpair> tree[100010];

ll color[100010] = {};



void dfs(ll cur, ll par, ll d){

    if(d % 2 == 0){

        color[cur] = 0;

    }else{

        color[cur] = 1;

    }

    for(auto &e: tree[cur]){

        if(e.first == par) continue;

        dfs(e.first, cur, d + e.second);

    }

}

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll N;

    cin >> N;

    ll u[100010], v[100010], w[100010];

    rep(i,0,N-1){

        cin >> u[i] >> v[i] >> w[i];

        u[i]--; v[i]--;

        tree[u[i]].push_back({v[i], w[i]});

        tree[v[i]].push_back({u[i], w[i]});

    }

    dfs(0, -1, 0);

    rep(i,0,N) print(color[i]);

    



}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<cmath>

#include<iomanip>

#include<map>

#include<cstring>



using namespace std;



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

using ll = long long;

using P = pair<int, int>;

const int INF = 1e9;

const ll LLINF = 1LL<<60;

/* -- template -- */



vector<int>color(100000, -1);

vector<vector<P>> G;

void dfs(int i){

    for(pair<int, int> next : G[i]){

        if(color[next.first] == -1){

            if(next.second % 2){

                color[next.first] = !color[i];

            }else{

                color[next.first] = color[i];

            }

            dfs(next.first);

        }

    }

}

int main(){

    int N; cin >> N;

    G.resize(N);

    rep(i, N - 1){

        int u, v, w; cin >> u >> v >> w;

        --u;--v;

        G[u].push_back(make_pair(v, w));

        G[v].push_back(make_pair(u, w));

    }

    color[0] = 0;

    dfs(0);

    rep(i, N){

        cout << color[i] << endl;

    }

}


// Faster C++ solution for the same problem (measured speedup: 1.3912264207344978x):
#include<iostream>

#include<vector>

#include<algorithm>

#include<queue>

#include<deque>

#include<cmath>

#include<map>

#include<cstring>

#include<iomanip> //cout << fixed << setprecision(15) << x << endl;



using namespace std;

typedef long long ll;

const int INF = 1e9 + 6;

const ll MOD = 1e9 + 7;

const ll LLINF = 1LL<<60;

#define P pair<int, int>

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

#define pb push_back

#define mp make_pair

#define all(x) (x).begin(),(x).end()

/* -- template -- */



int main() {

    int N; cin >> N;

    vector<vector<P>> G(N);

    rep(i, N - 1) {

        int u, v, w; cin >> u >> v >> w; --u, --v;

        G[u].pb(mp(v, w));

        G[v].pb(mp(u, w));

    }

    vector<int> dist(N, INF);

    dist[0] = 0;

    queue<int>Q;

    Q.push(0);

    while(!Q.empty()) {

        int q = Q.front(); Q.pop();

        for(P next : G[q]) {

            if(dist[next.first] == INF) {

                dist[next.first] = dist[q] + next.second;

                Q.push(next.first);

            }

        }

    }

    rep(i, N) {

        if(dist[i] % 2) {

            cout << 1 << endl;

        } else {

            cout << 0 << endl;

        }

    }

}
// Slower C++ solution:
/*In the name of Allah*/

#include <bits/stdc++.h>

using namespace std;

#define inf 1000000001

#define MAX 200005

#define mod 1000000007

#define ll long long

#define fr first

#define sc second

bool c[MAX];

vector< pair<int,int> > g[MAX];

void dfs(int u,int par ){

	for(auto v : g[u]){

		if(v.fr != par){

			if(v.sc&1)c[v.fr] = 1 - c[u];

			else c[v.fr] = c[u];

			dfs(v.fr,u);

		}

	}

}



int main(){

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

	int n,x,y,w;

	cin>>n;

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

		cin>>x>>y>>w;

		g[x].push_back({y,w});

		g[y].push_back({x,w});

	}

	dfs(1,0);

	for(int i = 1; i <= n ;i++)cout<<c[i]<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.407782435913854x):
#include <bits/stdc++.h>



using namespace std;





int confere[10000000];





vector<vector<pair<int,int>>>v;





void dfs(int i,int j,int peso){



	if(confere[i]!=-1) return;



	if(peso%2==0) confere[i]=j;

	else confere[i]= (j+1)%2;





	for(int s=0;s<v[i].size();s++){



		dfs(v[i][s].first, confere[i],v[i][s].second);

	}



}



int main(){



	int n;

	int u,u2,w;

	cin >> n;



	for(int i=0;i<n+10;i++){

		vector<pair<int,int>>s;

		v.push_back(s);

	}



	for(int i=0;i<n+10;i++){

		confere[i]=-1;

	}

	n--;



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

		cin >> u >> u2 >> w;

		v[u].push_back(make_pair(u2,w));

		v[u2].push_back(make_pair(u,w));

	}

	dfs(1,0,0);



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

		cout << confere[i] << endl;

	return 0;

}
// Slower C++ solution:
/*In the name of Allah*/

#include <bits/stdc++.h>

using namespace std;

#define inf 1000000001

#define MAX 200005

#define mod 1000000007

#define ll long long

#define fr first

#define sc second

bool c[MAX];

vector< pair<int,int> > g[MAX];

void dfs(int u,int par ){

	for(auto v : g[u]){

		if(v.fr != par){

			if(v.sc&1)c[v.fr] = 1 - c[u];

			else c[v.fr] = c[u];

			dfs(v.fr,u);

		}

	}

}



int main(){

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

	int n,x,y,w;

	cin>>n;

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

		cin>>x>>y>>w;

		g[x].push_back({y,w});

		g[y].push_back({x,w});

	}

	dfs(1,0);

	for(int i = 1; i <= n ;i++)cout<<c[i]<<endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.4242008078816961x):
#include <bits/stdc++.h>

#define ll long long

#define ull unsigned long long

#define pii pair<int,int>

#define piii pair<int,pii>

#define pll pair<ll,ll>

#define plii pair<ll,pii>

#define vi vector<int>

#define ff first

#define ss second

#define mp make_pair

#define pb push_back

#define SORT(x) sort(x.begin(), x.end())

#define GSORT(x) sort(x.begin(), x.end(), greater<int>())

#define mx 100001

#define eps 0.00000000001

#define mod 1000000007

#define pi acos(-1)

#define inf 100000000

#define loop(i,b,n) for(int i=b;i<n;++i)

#define rev_loop(i,b,n) for(int i=b;i>=n;--i)

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

const int N_MAX=1e5;

vector<vector<pll> >g(N_MAX);

vector<ll>color(N_MAX,0);





void dfs(ll u,ll p=-1){

    for(auto v:g[u]){

        if(v.ff==p)continue;

        if(v.ss%2)

            color[v.ff]=1-color[u];

        else

        color[v.ff]=color[u];

        dfs(v.ff,u);

    }

}

int main(){

    fio;

    ll n;

    cin >>n;

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

        ll u,v,w;

    cin >>u>>v>>w;

    u--;

    v--;

        g[u].pb({v,w});

        g[v].pb({u,w});

    }

    dfs(0);

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

        cout <<color[i]<<endl;

    }

    return 0;

}