Harryxun/stf_run huggingface dataset:
n,x,m = map(int,input().split())

A = [x]
where = {x: 0}
for i in range(1, n):
    a = A[-1]**2 % m
    if a in where:
        break
    where[a] = i
    A.append(a)

perstart = where[a]
res = sum(A)
rem = n - len(A)
per = len(A) - perstart
res += rem//per*sum(A[perstart:perstart+per])
res += sum(A[perstart:perstart + (rem%per)])

print(res)


### FIXED CODE ###

n,x,m = map(int,input().split())

A = [x]
where = {x: 0}
a = x
for i in range(1, n):
    a = A[-1]**2 % m
    if a in where:
        break
    where[a] = i
    A.append(a)

perstart = where[a]
res = sum(A)
rem = n - len(A)
per = len(A) - perstart
res += rem//per*sum(A[perstart:perstart+per])
res += sum(A[perstart:perstart + (rem%per)])

print(res)
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M)-1)  
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)-1)
  if S[j]%3!=0 and S[j]%5!=0:
    T.remove(S[j])
if len(S)==len(T):
  print('APPROVED')
else:
  pritn('DENIED')
    

### FIXED CODE ###

N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M))  :
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)):
  if S[j]%3!=0 and S[j]%5!=0:
      T.remove(S[j])
    
if len(S)==len(T):
  print('APPROVED')
else:
  print('DENIED')
a=int(input())
b=int(input())
if (a+b)%2==1:
  return Odd
else:
  return Even


### FIXED CODE ###

a,b=map(int,input().split())
if (a*b)%2==1:
  print('Odd')
else:
  print('Even')
N=int(input())
 
for N in 10000:
  if N % 1000 == 0：
  print(0)
else:
  sen = N/1000:
  sen2 = sen*1000
  atai = N-sen2
  print(atai)

### FIXED CODE ###

#! /usr/bin/python3

N = int(input())
1 <= N <= 10000

if N % 1000 == 0:
 print(0)
else:
  sen = N//1000
  sen2 = sen*1000
  atai = N-sen2
  atai2 = 1000-atai
  print(atai2)
N,K = map(int, input().split())
counter = 0
K_ = 1
while i=True:
  K_ = K_ * K
  if K > K_:
    print(counter)
    i=False
  counter += 1
  

### FIXED CODE ###

N,K = map(int, input().split())
c = 1
K_ = 1
i=True
while i==True:
  K_ = K_ *K
  if N < K_:
    print(c)
    i=False
  c += 1
import sys
input = sys.stdin.readline
H,W,N = [int(_) for _ in input().split()]
dT={}
if 0 < N  :
    for  _ in range(N):
        x,y = [int(_) - 1 for _ in input().split()]
        if x >= y:
            iDiff = x-y
            if iDiff in dT:
                if x + y < dT[iDiff][2] :
                    dT[iDiff] = (x,y,x+y)
            else:
                dT[iDiff] = (x,y,x+y)
    aG =[]
    aB = sorted(dT.items())
    iL = len(aB)
    if iL == 1:
        print(aB[0][1][2]-1)
    else:
        #入力例2
        #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
        for i in range(1,iL):
            if aB[i][0]-1 == aB[i-1][0]:
                if aB[i][1][2] < aB[i-1][1][2] :
                    aG.append(aB[i][1])
            else:
                aG.append(aB[i][1])
        print(aG)
        print(sorted(aG,key=lambda x:x[2])[0][2]-1)
else:
    print(H)


### FIXED CODE ###

import sys
def 解():
    input = sys.stdin.readline
    H,W,N = [int(_) for _ in input().split()]
    dT={}
    高橋 = H
    if 0 < N  :
        for  _ in range(N):
            x,y = [int(_) - 1 for _ in input().split()]
            if x >= y:
                系列 = x-y
                if 系列 in dT:
                    if x + y < dT[系列][2] :
                        dT[系列] = (x,y,x+y)
                else:
                    dT[系列] = (x,y,x+y)
        aB = sorted(dT.items())
        iL = len(aB)
        if iL == 1:
            高橋,青木,距離 = aB[0][1]
        else:
            #入力例2
            #[(0, (1, 1, 2)), (1, (3, 2, 5)), (2, (5, 3, 8)), (4, (6, 2, 8)), (7, (7, 0, 7))]
            if 0 < len(aB) :
                aG= [aB[0][1]]
                for i in range(1,iL):
                    if aB[i][0]-1 == aB[i-1][0]:
                        if aB[i][1][2] < aB[i-1][1][2] :
                            aG.append(aB[i][1])
                    else:
                        aG.append(aB[i][1])
                if 0 < len(aG) and  aG[0][0] - aG[0][1] == 0 :
                    del aG[0]
                if 0 < len(aG) :
                    高橋,青木,距離 = sorted(aG,key=lambda x:x[0])[0]
    print(高橋)
解()
import math 

h=int(input())
x =math.ceil(math.log2(h))
print( sum([2**y for y in range(x+1)]))



### FIXED CODE ###

import math 
 
h=int(input())
x =math.floor(math.log(h,2))
print( sum([2**y for y in range(x+1)]))
n = int(input())
a =[int(input()) for i in range(n)]
b = []
for i in range(n):
    for j in range(i+1, n+1):
        b.append(a[j]-a[i])
    
b.sort()
b.pop()
        


### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
ma = a[1]-a[0]
mi = a[0]
for i in range(1,n):
    ma = max(ma, a[i] - mi)
    mi = min(mi, a[i])
    
print(ma)
n,m =map(int, input().split())
ac_dic = {}
wa_dic = {}
for _ in range(m):
  p,s = input().split()
  if s == 'AC':
    if p in ac_dic:
      continue
    else:
      ac_dic[p] = 1
  else:
    if p in ac_dic:
      continue
    else:
      if p in wa_dic:
        wa_dic[p] += 1
      else:
        wa_dic[p] = 1

wa_count = 0
for i,c in wa_dic.items():
  if ac_dic[i]:
    wa_count += c

print(f'{sum(ac_dic.values())} {wa_count}')

### FIXED CODE ###

n,m = map(int, input().split())
sub_list = [list(input().split()) for _ in range(m)]

penalty_list = [0]*n #問題ごとのACが出るまでのペナルティ数
result_list = [0]*n #問題ごとの最終的にACが出たかどうかのリスト

for i in range(m):
  if sub_list[i][1] =='AC':
    result_list[int(sub_list[i][0]) -1] = 1
  else:
    if result_list[int(sub_list[i][0]) -1] == 0:
      penalty_list[int(sub_list[i][0]) -1] += 1

ac_count = 0
wa_count = 0
for i in range(n):
  if result_list[i] == 1:
    ac_count += 1
    wa_count += penalty_list[i]

print(f'{ac_count} {wa_count}')
a, b, c = (int, input().split())

if a == b or a == c:
  print ('Yes')
elif b == c:
  print ('Yes')
else:
  print ('No')

### FIXED CODE ###

a, b, c = map(int, input().split())
 
if (a == b and c != a) or (a == c and b != a):
  print ('Yes')
elif b == c and a != b:
  print ('Yes')
else:
  print ('No')
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * r_max
is_prime[0] = False
is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])


### FIXED CODE ###

import math
q = int(input())
l = []
r = []
for i in range(q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

r_max = max(r) + 10
is_prime = [True] * (r_max+1)
is_prime[0] = is_prime[1] = False
for i in range(2, r_max):
    if is_prime[i]:
        for j in range(2, r_max // i + 1):
            is_prime[i*j] = False

# print(is_prime)
a = [0] * r_max
for i in range(3, r_max):
    a[i] = a[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        a[i] += 1
# print(a)

for i in range(q):
    print(a[r[i]] - a[l[i]-1])
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
A,B = input().split()
A = int(A)
B = int(B.replace("."))

ans = (A*B)//100

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

from decimal import Decimal, getcontext
getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()
import math
# slist = "abcdefghijklmnopqrstuvwxyz"
A,B = input().split()
# A = int(A)
# B = float(B)*10000

# B = round(B,-2)
# ans = A*B//10000

A = Decimal(A)
B = Decimal(B)

ans = A*B

# print(A,B,ans)
print(int(ans))
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
r1, c1, r2, c2 = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (10**6 + 1)
for i in range(1, 10**6 + 1):
    f[i] = i * f[i - 1] % mod
fi = {}


def comb(n, r):
    if r not in fi:
        fi[r] = pow(f[r], mod - 2, mod)
    if n - r not in fi:
        fi[n - r] = pow(f[n - r], mod - 2, mod)
    return (f[n] * fi[r] * fi[n - r]) % mod


ans = 0
for x in range(c1, c2 + 1):
    ans += comb(r2 + x + 1, x + 1) - comb(r1 + x, x + 1)
    ans %= mod
print(ans)


### FIXED CODE ###

r, c, R, C = [int(_) for _ in input().split()]
mod = 10**9 + 7

f = [1] * (3 * 10**6 + 10)
for i in range(1, 3 * 10**6 + 10):
    f[i] = i * f[i - 1] % mod
fi = {}


def comb(n, r):
    if r not in fi:
        fi[r] = pow(f[r], mod - 2, mod)
    if n - r not in fi:
        fi[n - r] = pow(f[n - r], mod - 2, mod)
    return (f[n] * fi[r] * fi[n - r]) % mod


a1 = (C + 2) * f[c + 1] * f[C + R + 2] - (c + 1) * f[C + 2] * f[c + R + 1]
a1 *= pow(R + 1, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[R], mod - 2, mod)
a2 = (C + 2) * f[c + 1] * f[C + r + 1] - (c + 1) * f[C + 2] * f[c + r]
a2 *= pow(r, mod - 2, mod) * pow(f[c + 1], mod - 2, mod) * pow(
    f[C + 2], mod - 2, mod) * pow(f[r - 1], mod - 2, mod)
ans = a1 - a2
ans %= mod
print(ans)
class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])
        self.dir = True
        self.vec = None

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
        self.judge = 0
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(N)):
    bridges.append(Bridge(nodes[A], nodes[B]))


### FIXED CODE ###

class Bridge:
    def __init__(self, nodeA, nodeB):
        self.edges = [BridgeEdge(nodeA, self), BridgeEdge(nodeB, self)]
        nodeA.addEdge(self.edges[1])
        nodeB.addEdge(self.edges[0])
        self.dir = True
        self.vec = None
    def __repr__(self):
        return str((self.vec, self.dir))

class BridgeEdge:
    def __init__(self, node, edge):
        self.edge = edge
        self.node = node
    def another(self):
        return self.edge.edges[1 if self.edge.edges[0] == self else 0]

class Node:
    def __init__(self, id):
        self.id = id
        self.bridges = []
        self.parent = None
        self.judge = True
    def addEdge(self, bridgeEdge):
        self.bridges.append(bridgeEdge)
    def __repr__(self):
        return str((self.id, None if self.parent is None else self.parent.node.id, self.judge))

N, M = map(int, input().split())

nodes = [Node(i) for i in range(N+1)]
bridges = []
for A, B in (map(int, input().split()) for _ in range(M)):
    bridges.append(Bridge(nodes[A], nodes[B]))

s = [(0, nodes[1])]
idx = 0
while len(s) > 0:
    level, cur = s.pop()

    nxtlevel = level + 1
    for nxt in cur.bridges:
        if nxt.edge.vec is None:
            cur.judge ^= True
            nxt.edge.vec = (cur.id, nxt.node.id)
            if nxt.node.parent is None:
                nxt.node.parent = nxt.another()
                s.append((nxtlevel, nxt.node))

    if len(s) > 0:
        nl = s[-1][0]
    else:
        nl = 1
    while level >= nl:
        if not cur.judge:
            cur.judge ^= True
            cur.parent.node.judge ^= True
            cur.parent.edge.dir ^= True
        level -= 1
        cur = cur.parent.node
  
if all(node.judge for node in nodes[1:]):
    for br in bridges:
        if br.dir:
            print("{} {}".format(br.vec[0], br.vec[1]))
        else:
            print("{} {}".format(br.vec[1], br.vec[0]))
else:
    print("-1")
#C
import bisect
alphabet = "abcdefghijklmnopqrstuvwxyz"
n = int(input())
cnt = 0
amari = []

#下処理
niroku = [1]
for i in range(1,15):
    a = niroku[-1]
    niroku.append(a + 26**i)

idx = bisect.bisect_left(niroku, n)

n = n - niroku[idx-1] + 1
z_cnt = idx-1
#print(n)
while n // 26 > 0:
    n_before = n
    amari.append(str(n%26))
    a = n % 26
    n = n // 26
    cnt += 1
#print(a)
#print(n)
#print(cnt)

if int("".join(amari)) != 0: 
    amari.append(str(n))
amari.reverse()
#print(amari)
result = []

for i in range(len(amari)):
    result.append(alphabet[int(amari[i])-1])

for i in range(z_cnt):
    result[i] = "z"

print("".join(result))


### FIXED CODE ###

n = int(input())
ans = ""
while n > 0:
    n -= 1
    ans += chr(ord('a') + n%26)
    #print(ans)
    n = n // 26
print(ans[::-1])
dat =list(input().split())

for i in dat:
	i = int(i)

dat.sort()
dat.reverse()

asum = 0
bsum = 0

for i in range(len(dat)):
     bsum = bsum + dat[i]
		
print(bsum)

### FIXED CODE ###

n = int(input())
dat = list(input().split())

dat = list(map(int,dat))

dat.sort(reverse=True)

asum = 0
bsum = 0

for i in range(n):
	if i % 2 == 0:
		asum = asum + dat[i]
	else:
		bsum = bsum + dat[i]
		
print(asum-bsum)
N = int(input())
A = [0] + list(map(int, input().split()))

for i in range(N-1, 0, -1):
    tmp = 0
    for t in range(i, N+1, i):
        tmp += A[t]
    if tmp == i % 2:
        break

print(tmp)
for i in range(1, tmp+1):
    if i % tmp == 0:
        print(i)


### FIXED CODE ###

N = int(input())
A = [0] + list(map(int, input().split()))

for i in range(N//2, 0, -1):
    # tmp = 0
    # j = i
    # while j < N+1:
    #     tmp += A[j]
    #     j += j
    # A[i] = tmp % 2
    A[i] = sum(A[i::i]) % 2
ans = [i for i, j in enumerate(A) if j == 1]

print(len(ans))
print(*ans)
n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = sum(ac)
no_wa = sum(wa)

print(str(no_acc) + ' ' + str(no_wa))

### FIXED CODE ###

n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = 0
no_wa = 0

for i in range(n):
    if ac[i] == 1:
        no_ac += 1
        no_wa += wa[i]

print(str(no_ac) + ' ' + str(no_wa))
s=input()
if s =='ABC' :
  print('ARC')
else if s=='ARC':
  prinr('ABC')

### FIXED CODE ###

s=input()
if s =='ABC' :print('ARC')
elif s=='ARC':print('ABC')
W,H,X,Y = map(int,input().split())
if W/2 == X and H/2 == Y:
    f = 1
else:
    f = 0
print(W*H/2, f)


### FIXED CODE ###

X,Y = map(int,input().split())
if X < Y:
    print(0)
else:
    print(10)
#ABC057.B
N,M = map(int,input().split())
L1 = []
L2 = []

for i in range(N):
    a,b = map(int,input().split())
    L1.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    L2.append([c,d])

for j in range(N):
    L3 = []
    for l in range(M):
        L3.append(abs(L1[j][0]-L2[l][0]) + abs(L1[j][1]-L2[l][1]))
    print(L3.index(min(L3)+1)

### FIXED CODE ###

#ABC057.B
N,M = map(int,input().split())
L1 = []
L2 = []

for i in range(N):
    a,b = map(int,input().split())
    L1.append([a,b])
for m in range(M):
    c,d = map(int,input().split())
    L2.append([c,d])

for j in range(N):
    L3 = []
    for l in range(M):
        L3.append(abs(L1[j][0]-L2[l][0]) + abs(L1[j][1]-L2[l][1]))
    print(L3.index(min(L3))+1)
n = int(input())
s = sorted(map,int,input().split())
M = 10 ** 18
ans = 1
for ss in s:
	ans *= ss
	if ans > M:
		ans = -1
		break
	elif ans == 0:
		break

### FIXED CODE ###

n = int(input())
s = sorted(map(int,input().split()))
M = 10 ** 18
ans = 1
for ss in s:
	ans *= ss
	if ans > M:
		ans = -1
		break
	elif ans == 0:
		break
print(ans)
import sys
input = sys.stdin.readline
import numpy as np
import time



"""
def make_table_min(n, m):
    Table = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    c = 10
    for i in range(n):
        rem = np.random.randint(1,m+1)
        Table.remove(rem)
    return Table

"""

def make_table(n, m):
    Table = [None]*n
    for i in range(n):
        rem = np.random.randint(1,m+1)
        Table[i] = rem
    return Table

t0 = time.time()
n, m, q = map(int, input().split())
Lis = [[int(e) for e in input().split()] for _ in range(q)]

Sum_cor = []
for i in range(10000000000):
    if m >=6:
        Table = make_table(n,m)
    else:
        Table = make_table(n,m)
    Table.sort()
    d_sum = 0
    for l in Lis:
        if Table[l[1]-1]-Table[l[0]-1] == l[2]:
            d_sum+=l[3]
    Sum_cor.append(d_sum)
    t1 = time.time()
    if t1-t0 >1.8:
        print(max(Sum_cor))
        break


### FIXED CODE ###

import sys
input = sys.stdin.readline


a, b, c= map(int, input().split())


#f_table = [a*t//b for t in range(b)]

if c >= b:
    print((a * (b-1)) // b)

else:
    x = c
    c_amari = c%b
    c_sho = c//b
    ans =(a * c_amari) //b
    print(ans)
N, A, B = map(int, input().split())

tmp_init = [1]*A + [0]*B
#len_add = len(tmp)
sum_tmp_init = sum(tmp_init)
len_tmp = len(tmp_init)
sum_b = 0
len0 = 0
tmp = []
while len(tmp) < N:
    sum_b += sum_tmp_init
    len0 += len_tmp
    tmp += [1]*A + [0]*B

ans = sum_b -sum_tmp_init  + sum(tmp_init[:N-len0+len_tmp])

print(ans)

### FIXED CODE ###

N, A, B = map(int, input().split())
if N >= (A+B):
    ans = A * (N//(A+B)) + min((N - ((A + B) * (N//(A+B)))), A)
elif N > A:
    ans = A
elif A >= N:
    ans = N
print(ans)
n = int(raw_input())
for i in range(n):
    x0, y0, x1, y1, x2, y2, x3, y3 = raw_input().split()
    if float(y1-y0)/(x1-x0) == float(y3-y2)/(x3-x2):
        print 'YES'
    else:
        print 'NO'    

### FIXED CODE ###

n = int(raw_input())
for i in range(n):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(float, raw_input().split(' '))
    if x0==x1 or x2==x3:
        if x0==x1 and x2==x3:
            print 'YES'
        else:
            print 'NO'
    elif abs(float(y1-y0)/(x1-x0) - float(y3-y2)/(x3-x2)) < 1e-10:
        print 'YES'
    else:
        print 'NO'
a=int(input().replace(" ",""))
print("YNeos"[(a**0.5)*2!=floor(a)::2])

### FIXED CODE ###

a=int(input().replace(" ",""))
print("No"if a**0.5%1 else "Yes")
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = float('inf')

for i in range(1, 101)[::-1]:
    if abs(x - i) <= min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)


### FIXED CODE ###

x, n = map(int, input().split())
p = list(map(int, input().split()))
min = float('inf')

for i in range(0, 102)[::-1]:
    if abs(x - i) <= min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)
import sys
sys.setrecursionlimit(1000000)

global color 
global adlist
color = [0 for _ in range(100001)] 

def make_adlist(N, uvw):
  global adlist
  adlist = [[] for _ in range(N)]
  for u, v, w in uvw:
    adlist[u-1] += [[v-1, w]]
  return adlist 

def dfs(v, c, dis):
  global color
  color[v] = c
  for next_v, w in adlist[v]:
    if color[next_v] == c:
      return False
    if color[next_v] == 0 and (dis+w) % 2 != 0:
      return dfs(next_v, -c, dis+w)
    elif color[next_v] == 0 and (dis+w) % 2 == 0:
      return dfs(next_v, c, dis+w)
    elif color[next_v] == -c and (dis+w) % 2 == 0:
      return True 
    else:
      return False

  return True


def main():
  N = int(input())
  uvw = [list(map(int, input().split())) for _ in range(N-1)]
  for i in range(N):
    if color[i] == 0:
      dfs(i, 1, 0)
  for c in color[:N]:
    if c == 1:
      print(1)
    else:
      print(0)


if __name__ == "__main__":
  main()




### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)

global color 
global adlist
color = [0 for _ in range(100001)] 

def make_adlist(N, uvw):
  global adlist
  adlist = [[] for _ in range(N)]
  for u, v, w in uvw:
    adlist[u-1] += [[v-1, w%2]]
    adlist[v-1] += [[u-1, w%2]]
  return adlist 

def dfs(v, c):
  global color
  global adlist
  color[v] = c
  for next_v, w in adlist[v]:
    if color[next_v] != 0:
      continue
    if color[next_v] == 0 and w % 2 != 0:
      dfs(next_v, -c)
    elif color[next_v] == 0 and w % 2 == 0:
      dfs(next_v, c)

  return 


def main():
  N = int(input())
  uvw = [list(map(int, input().split())) for _ in range(N-1)]
  adlist = make_adlist(N, uvw)
  dfs(0, 1)
  for c in color[:N]:
    if c == 1:
      print(1)
    else:
      print(0)


if __name__ == "__main__":
  main()
def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)

def size(x):
  return-par[find(x)]
  
n,m,k=map(int,input().split())

par=[-1]*n

F=[]
B=[]

f=[set() for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    F.append([a,b])
    
for i in range(k):
    c,d=map(int,input().split())
    B.append([c,d])

for a,b in F:
    a-=1
    b-=1
    unite(a,b)
    f[a].add(b)
    f[b].add[a]

a=[size(i)-len(f[i])-1 for i in range(n)]

for c,d in B:
    c-=1
    d-=1
    if same(c,d):
        a[c]-=1
        a[d]-=1
print(*a)

### FIXED CODE ###

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]

def unite(x,y):
  x,y=find(x),find(y)
  if x!=y:
    if x>y:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
    
def same(x,y):
  return find(x)==find(y)

def size(x):
  return-par[find(x)]
  
n,m,k=map(int,input().split())

par=[-1]*n

F=[]
B=[]

f=[set() for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    F.append([a,b])
    
for i in range(k):
    c,d=map(int,input().split())
    B.append([c,d])

for a,b in F:
    a-=1
    b-=1
    unite(a,b)
    f[a].add(b)
    f[b].add(a)

a=[size(i)-len(f[i])-1 for i in range(n)]

for c,d in B:
    c-=1
    d-=1
    if same(c,d):
        a[c]-=1
        a[d]-=1
print(*a)