stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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]);











    

}

// Optimized solution to the same problem (faster):
/*** 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]);

    



}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

    }

}


// Optimized solution to the same problem (faster):
#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;

        }

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
/*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;

}


// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<utility>

#include<vector>



using namespace std;



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









int ans[100000];

int n;

struct edge { int to, cost; };

vector<edge> G[100000];

void func(int e){

    rep(i, G[e-1].size()){

        if (ans[G[e-1][i].to-1] == -1) {

            if (G[e-1][i].cost % 2 == 0) {

                ans[G[e-1][i].to-1] = ans[e-1];

            }else{

                ans[G[e-1][i].to-1] = ans[e-1]^1;

            }

            func(G[e-1][i].to);

        }

    } 

}



int main(){

    // int n;

    cin >> n;

    int u[n-1], v[n-1], w[n-1];

    rep(i, n-1){

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

        edge g;

        g.cost = w[i];

        g.to = v[i];

        G[u[i]-1].push_back(g);

        g.to = u[i];

        G[v[i]-1].push_back(g);

    }



    // rep(j, n){

    //     cout << j + 1 << ";";

    //     rep(i, G[j].size()) cout << "<" << G[j][i].to << ' ' << G[j][i].cost << ">";

    //     cout << endl;

    // }

    rep(i, n) ans[i] = -1;    

    ans[0] = 0;

    func(1);



    rep(i, n) cout << ans[i] << endl;

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<algorithm>

#include<string>

#include<vector>

#include<cstdlib>

#include<queue>

#include<cstdio>



using namespace std;



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

#define P pair<long int, long int>





int main(){

    long int n;

    cin >> n;

    long int u, v, w;

    vector<P> p[n];

    rep(i, n - 1) {

        cin >> u >> v >> w;

        u--; v--;

        p[u].push_back(P(v, w));

        p[v].push_back(P(u, w));

    }

    long int col[n];

    rep(i, n) col[i] = 0;

    col[0] = 1;

    queue<P> que;

    que.push(P(0, 0));

    while(!que.empty()){

        P g = que.front();

        que.pop();

        long int e = g.first;

        long int dis = g.second;

        for (int i = 0; i < p[e].size(); i++){

            if(col[p[e][i].first] == 0){

                long int disn = dis + p[e][i].second;

                if(disn % 2 == 0) col[p[e][i].first] = 1;

                else col[p[e][i].first] = 2;

                // cout << e << " " << p[e][i].first << " " << disn << endl;

                que.push(P(p[e][i].first, disn));

            }

        }

    }

    rep(i, n) cout << col[i] - 1 << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<vector>

#include <bitset>

#include<math.h>

using namespace std;

#define INF 110000000000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,int> P;



int N;

vector<P> V[110000];

int color[110000];



void dfs(int x){

  for(int i=0;i<(int)V[x].size();i++){

    if(color[V[x][i].first]==-1){

      if(V[x][i].second==0){

        color[V[x][i].first]=color[x];

        dfs(V[x][i].first);

      }else{

        color[V[x][i].first]=color[x]^1;

        dfs(V[x][i].first);

      }

    } 

  }

}



int main(){

  for(int i=0;i<110000;i++) color[i]=-1;

  cin>>N;

  int u,v;

  ll w;

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

    cin>>u>>v>>w;

    V[u].push_back(P(v,w%2));

    V[v].push_back(P(u,w%2));

  }

  color[1]=0;

  dfs(1);

  for(int i=1;i<=N;i++) cout<<color[i]<<endl;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<iostream>

#include<queue>

#include<vector>

#include <bitset>

#include<math.h>

using namespace std;

#define INF 110000000000000000

#define MOD 1000000007

typedef long long ll;

typedef pair<int,ll> P;



vector<P> V[110000];

ll d[110000];

int N,u,v;





void bfs(){

  queue<P> que;



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

    d[i]=INF;

  }



  que.push(P(0,0));



  d[0]=0;



  while(que.size()){

    P p=que.front(); que.pop();

    for(int i=0;i<V[p.first].size();i++){

        P x=V[p.first][i];

      if(d[x.first]==INF){

        que.push(P(x.first,x.second+p.second));

        d[x.first]=x.second+p.second;

      }

    }

  }



  return;

}





int main(){

    cin>>N;

    ll w;

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

        cin>>u>>v>>w;

        u--; v--;

        V[u].push_back(P(v,w));

        V[v].push_back(P(u,w));

    }



    bfs();

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

        if(d[i]%2==0) cout<<0<<endl;

        else cout<<1<<endl;

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

using namespace std;



int N;

int ans[100010] = {};

struct edge{int to, len;};

vector<vector<edge>> v(100010);



void dfs(int n,int m,int c){

    ans[n] = c;

    for(auto x:v[n]){

        if(x.to==m) continue;

        if(x.len==0) dfs(x.to,n,c);

        else dfs(x.to,n,1-c);

    }

}





int main(){

    cin >> N;

    int a,b,w;

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

        cin >> a >> b >> w;

        w %= 2;

        v[a].push_back({b,w});

        v[b].push_back({a,w});

    }

    dfs(1,0,0);

    for(int i=1;i<=N;i++) cout << ans[i] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template <class T, class U> using Pa = pair<T, U>;

template <class T> using vec = vector<T>;

template <class T> using vvec = vector<vec<T>>;



struct edge{

    int to;

    int d;

};



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int N;

    cin >> N;

    vvec<edge> g(N);

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

        int a,b,w;

        cin >> a >> b >> w;

        a--; b--;

        g[a].push_back({b,w});

        g[b].push_back({a,w});

    }

    vec<int> ans(N);

    auto dfs = [&](auto&& self,int cur,int par,int col)->void{

        ans[cur] = col;

        for(auto& e:g[cur]) if(e.to!=par){

            self(self,e.to,cur,e.d%2==0? col:1-col);

        }

    };

    dfs(dfs,0,-1,0);

    for(int i=0;i<N;i++) cout << ans[i] << "\n";

}

// Fastest known solution for this problem: