Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = c[0]
jud = []
for i in range(n):
    if i not in jud:
        l = []
        j = p[i] - 1
        while j not in jud:
            jud.append(j)
            l.append(c[p[j]-1])
            j = p[j] - 1
        le = len(l)
        l *= (k//1 + 2)
        # for ii in range(le):
        #     val = l[ii]
        #     ans = max(ans,val)
        #     for cnt in range(ii+1, ii + k):
        #         val += l[cnt]
        #         ans = max(val, ans)

print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = c[0]
jud = []
for i in range(n):
    if i not in jud:
        l = []
        j = p[i] - 1
        while j not in jud:
            jud.append(j)
            l.append(c[p[j]-1])
            j = p[j] - 1
        le = len(l)
        su = sum(l)
        l *= 2
        if su > 0:
            v = (k//le)*su
            ans = max(ans, v)
        for ii in range(le):
            val = 0
            for cnt in range(0, le):
                val += l[ii + cnt]
                if su > 0:
                    v = val + ((k - cnt - 1)//le)*su
                    ans = max(ans, v)
                else:
                    ans = max(ans, val)

print(ans)
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 3 == 0:
            continue
        elif A[i] % 5 == 0:
            continue
        else:
            print('DENIED')
            sys.exit()
print('APPROVED')

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))

for i in range(N):
    if A[i] % 2 == 0:
        if A[i] % 3 == 0:
            continue
        elif A[i] % 5 == 0:
            continue
        else:
            print('DENIED')
            sys.exit()
print('APPROVED')
x, y = int(map, input().split())

if((2*x <= y <= 4*x) and (y%2==0)):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

x, y = map(int, input().split())

if(2*x <= y <= 4*x and y%2==0 and x <= 50):
    print("Yes")
else:
    print("No")
s=input()
if int(s[0])==int(s[1]) or int(s[1])==int(s[2]) or int(s[2])=int(s[3]):
  print("Bad")
else:
  print("Good")

### FIXED CODE ###

s=input()
a=int(s[0])-int(s[1])
b=int(s[1])-int(s[2])
c=int(s[2])-int(s[3])
if a!=0 and b!=0 and c!=0:
  print("Good")
else:
  print("Bad")
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

ans = A[0]
for i in range(1, N - 1):
    ans = math.gcd(ans, A[i])
print(ans)

### FIXED CODE ###

def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

ans = A[0]
for i in range(1, N):
    ans = fractions.gcd(ans, A[i])
print(ans)
H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]
num=0
for i in range(H):
  for j in range(W):
    num+=abs(A[i][j]-B[i][j])
    
#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[[False]*(num) for _ in range(W)] for _ in range(H)]
dp[0][0][0]=True

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for n in range(num):
      if not dp[I][J][n]:
        continue
      if I!=H-1:
        dp[I+1][J][n+sa]=True
        dp[I+1][J][abs(n-sa)]=True
      if J!=W-1:
        dp[I][J+1][n+sa]=True
        dp[I][J+1][abs(n-sa)]=True
    I-=1
    J+=1

sa = abs(A[H-1][W-1] - B[H-1][W-1])
ans=float("inf")
for n in range(num):
  if not dp[-1][-1][n]:
    continue
  ans = min(ans,abs(n-sa),n+sa)
print(ans)

### FIXED CODE ###

H,W=map(int,input().split())

A=[list(map(int,input().split())) for _ in range(H)]
B=[list(map(int,input().split())) for _ in range(H)]

#dp[i][j]=マス(i,j)における可能なポイントのリスト
dp=[[set() for _ in range(W)] for _ in range(H)]
dp[0][0].add(0)

for i in range(W+H-1):
  I,J=0,0
  if i < H:
    I=i
    J=0
  else:
    I=H-1
    J=i-H+1
  while I>=0 and J<W:
    sa = abs(A[I][J] - B[I][J])
    for point in dp[I][J]:
      if I!=H-1:
        dp[I+1][J].add(point+sa)
        dp[I+1][J].add(abs(point-sa))
      if J!=W-1:
        dp[I][J+1].add(point+sa)
        dp[I][J+1].add(abs(point-sa))
    I-=1
    J+=1

ans=dp[H-1][W-1]
sa = abs(A[H-1][W-1] - B[H-1][W-1])
res=float("inf")
for p in ans:
  res=min(res,abs(p+sa),abs(p-sa))
print(res)
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
A = [i*-1 for i in A]

import heapq
heapq.heapify(A)

while K:
    a = heapq.heappop(A)
    b = heapq.heappop(A)
    a, b = a*-1, b*-1
    c = (b+1)//2
    d = a - c
    heapq.heappush(A, b*-1)
    heapq.heappush(A, c*-1)
    heapq.heappush(A, d*-1)
    K -= 1

print(sorted(A)[0]*-1)


### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

def is_ok(n):
    cnt = 0
    for a in A:
        if n >= a:
            continue
        cnt += a // n
    return cnt <= K

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, 10**9+1))
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = sorted(list(map(int, input().split())))

  not_divisible = [False]*(10**6)
  prev = 0
  for i in range(N):
    if prev == A[i]:
      not_divisible[A[i]] = False
    else:
      not_divisible[A[i]] = True
    prev = A[i]

  for i in range(N):
    if not_divisible[A[i]]:
      j = A[i] + A[i]
      while j <= A[-1]:
        not_divisible[j] = False
        j += A[i]

  cnt = 0
  for i in range(N):
    if not_divisible[A[i]]:
      cnt += 1

  print(cnt)


if(__name__ == '__main__'):
  main()


### FIXED CODE ###

from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  A = sorted(list(map(int, input().split())))

  not_divisible = [False]*(10**6+1)
  for i in range(N):
    not_divisible[A[i]] = True

  prev = 0
  for i in range(N):
    if not_divisible[A[i]]:
      j = A[i] + A[i]
      while j <= A[-1]:
        not_divisible[j] = False
        j += A[i]
    if prev == A[i]:
      not_divisible[A[i]] = False
    prev = A[i]

  cnt = 0
  for i in range(N):
    if not_divisible[A[i]]:
      cnt += 1

  print(cnt)


if(__name__ == '__main__'):
  main()
N,X = map(int, input().split())
L = [map(int,input().split())]
accumL = []
for n in range(len(L)):
  accumL.append(sum(L[:n+1])
s = [x < 4 for x in accumL]
print(str(s.index(False) + 1))

### FIXED CODE ###

N,X = map(int, input().split())
L = [x for x in map(int, input().split())]
accumL = [sum(L[:x]) <= X for x in range(len(L)+1)]
if accumL[-1] == True:
  print(N + 1)
else:
  print(accumL.index(False))
a = list(map(int,input().split()))
if 500 * a[0] >= a[1] :
  print(Yes)
else :
  print(No)

### FIXED CODE ###

a = list(map(int,input().split()))
if 500*a[0] >= a[1] :
  print('Yes')
else :
  print('No')
N,M,K=map(int,input().split())
A=[int(x) for x in input().split()]+[10**9]
B=[int(x) for x in input().split()]+[10**9]

c,i,j=0,0,0
while K>0 and (i<N or j<M):
  if K==min(K,A[i],B[i]):
    break
  c+=1
  if A[i]<B[j]:
    K-=A[i]
    i+=1
  elif B[j]<A[i]:
    K-=B[j]
    j+=1
  else:
    if A[i+1]<=B[j+1]:
      K-=A[i]
      i+=1
    else:
      K-=B[j]
      j+=1

print(c)


### FIXED CODE ###

from bisect import bisect_right
from itertools import accumulate

N,M,K=map(int,input().split())
A=list(accumulate([0]+[int(x) for x in input().split()]))
B=list(accumulate([0]+[int(x) for x in input().split()]))

m=0
for i in range(0,N+1):
  if K<A[i]:
    break
  m=max(m,i+bisect_right(B,K-A[i])-1)

print(m)
#include <bits/stdc++.h>
using namespace std;
long long a,b,x,ans,temp;
int main()
{
    cin>>a>>b>>x;
    if(a%x==0) ans=a/x;
    else	ans=a/x+1;
    temp=b/x;
    cout<<temp-ans+1;
    return 0; 
}

### FIXED CODE ###

s=input().split()
a=int(s[0])
b=int(s[1])
c=int(s[2])
print(b//c-(a-1)//c)
n,k = map(int, input().split())
a = list(map(int, input().split()))
number = [0]*n
for i in range(n):
    number[a[i]-1]+=1
number.remove(0)
number.sort()
ans = 0

if len(number)<=k:
    print(0)
else:
    for i in range(len(number)-k):
        ans += number[i]
    print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
a = list(map(int, input().split()))
number = [0]*n
for i in range(n):
    number[a[i]-1]+=1
number.sort(reverse=True)
ans = 0

for i in range(k):
    ans += number[i]
ans = n-ans
print(ans)
D,G= map(int,input().split())
pc=[]
for i in range(D):
  p,c= map(int,input().split())
  pc.append([p,c])
i=D
minN=100000
while i>0:
  #t=pc[i][0]*100*(i+1)+pc[i][1]
  t=pc[i-1][0]*100*(i)+pc[i-1][1]
  if t>=G:
    
    n=pc[i-1][0]
    minN=min(n,minN)
    while n-1>0:
      t1=(n-1)*100*(i)
      if t1>G:
        n=n-1
        continue
      else:
        minN=minN(minN,n+1)
      n=n-1
    
  i=i-1
print(minN)

### FIXED CODE ###

rate=int(input())
result=""
if rate<1200:
  result="ABC"
elif rate<2800:
  result="ARC"
else:
  result="AGC"
print(result)
import math

print(2 * pi * input())

### FIXED CODE ###

import math

R = input()

print(2 * float(R) * math.pi)
end = [1,1,1,1,1]
while True:
  n = int(input())
  if n == 0:
    break
  mp = [[0] * 5 for _ in range(4000)]
  height = [0] * 5
  cnt = 0
  for i in range(n):
    d, p, q = map(int, input().split())
    q -= 1
    cnt += p
    if d == 1:
      pos = max(height[q:q + p])
      mp[pos][q:q + p] = [1] * p
      if mp[pos] == end:
        cnt -= 5
        mp.pop(pos)
        mp.append([0] * 5)
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q:q + p] = [pos + 1] * p

    if d == 2:
      pop_flag = False
      pos = height[q]
      for y in range(pos, pos + p):
        mp[y][q] = 1
      for y in range(pos + p - 1, pos - 1, -1):
        if mp[y] == end:
          cnt -= 5
          mp.pop(y)
          mp.append([0] * 5)
          pop_flag = True
      
      if pop_flag:
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q] += p
  
  print(cnt)


### FIXED CODE ###

end = [1,1,1,1,1]
while True:
  n = int(input())
  if n == 0:
    break
  mp = [[0] * 5 for _ in range(6000)]
  height = [0] * 5
  cnt = 0
  for i in range(n):
    d, p, q = map(int, input().split())
    q -= 1
    cnt += p
    if d == 1:
      pos = max(height[q:q + p])
      mp[pos][q:q + p] = [1] * p
      if mp[pos] == end:
        cnt -= 5
        mp.pop(pos)
        mp.append([0] * 5)
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q:q + p] = [pos + 1] * p

    if d == 2:
      pop_flag = False
      pos = height[q]
      for y in range(pos, pos + p):
        mp[y][q] = 1
      for y in range(pos + p - 1, pos - 1, -1):
        if mp[y] == end:
          cnt -= 5
          mp.pop(y)
          mp.append([0] * 5)
          pop_flag = True
      
      if pop_flag:
        for x in range(5):
          for y in range(i * 5 - 1, -1, -1):
            if mp[y][x] == 1:
              height[x] = y + 1
              break
          else:
            height[x] = 0
      else:
        height[q] += p
  
  print(cnt)
k = int(input())
s = list(input())
l=[]
if(len(s)<=k):
  word = "".join(s)
  print(word)
else:
  for i in range(k):
    l.append(s[i])
    name = "".join(l)
print(name + "...")


### FIXED CODE ###

k = int(input())
s = list(input())

l=[]
if(len(s)<=k):
  word = "".join(s)
  print(word)
else:
  for i in range(k):
    l.append(s[i])
    name = "".join(l)

  print(name + "...")
# 0<=a<=bのときの攻め方 ... 進むしかないね
# 0<=b<=a   ... 一回だけ符号をかえたらあとは進むしかないね
# a<=0<=b   ... abs(a)<abs(b)なら符号をかえたらショートカットできるね ちがったらすすむしかないね
# b<=0<=a   ... abs(a)<abs(b)ならすすんでから符号かえればいいね ちがったら符号かえてからすすめばいいね これは同じことだよ
# a<=b<=0   ... 進むしかないね
# b<=a<=0   ... 符号変えてすすんで符号かえればいいね
a, b = map(int, input().split())
if 0 <= a <= b:
    print(b - a)
elif 0 <= b <= a:
    print(1 + a + b)
elif a <= 0 <= b:
    if abs(a) <= abs(b):
        print(1 + b - abs(a))
        raise "????????????????????????"
    else:
        print(abs(b) + abs(a))
elif b <= 0 <= a:
    print(1 + abs(abs(b) - abs(a)))
elif a <= b <= 0:
    print(abs(b - a))
elif b <= a <= 0:
    print(2 + abs(abs(b) - abs(a)))
else:
    raise "fuck"


### FIXED CODE ###

# 0<x<yだとインクリメント、などのような分岐

x, y = map(int, input().split())
if 0<=x<y:
  print(y-x)
elif y<x:
  print(min(2+abs(x-y), 1+abs(-x-y)))
else:
  print(min(abs(y-x), 1+abs(-y-x)))
a = int(input())
b = int(input())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

### FIXED CODE ###

a,b = map(int,input().split())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')
n = input("east_west road:")
m =input("north_south road:")
block =(int(n)-1) * (int(m)-1)
print(block) 


### FIXED CODE ###

n,m = list(map(int,input().split()))
print((n-1)*(m-1))
a = []
b = {}
n = int(input())
for _ in range(n):
    s, i = input().split()
    a += [(s, int(i))]
    b.setdefault(int(i), []).append(s)
b = {val: iter(s).__next__ for val, s in D.items()}

def partition(a, left, right):
    standard = a[right][1]
    cnt = left
    for i in range(left, right):
        if a[i][1] <= standard:
            a[cnt],a[i] = a[i], a[cnt]
            cnt += 1
    a[cnt],a[i] = a[i], a[cnt]
    return cnt

def quickSort(a, left = 0, right = len(a) - 1):
    if 1 <= right - left:
        cnt_ = partition(a, left, right)
        quickSort(a,left, cnt_ - 1)
        quickSort(a,cnt_ + 1, right)

quickSort(a, 0 , len(a)-1)

ok = 1
for v, d in A:
    if D[d]() != v:
        ok = 0
print(['Not stable','Stable'][ok])


for i in range(n):
    print(*a[i])


### FIXED CODE ###

a = []
b = {}
n = int(input())
for _ in range(n):
    s, i = input().split()
    a += [(s, int(i))]
    b.setdefault(int(i), []).append(s)
b = {val: iter(s).__next__ for val, s in b.items()}

def partition(a, left, right):
    standard = a[right][1]
    cnt = left
    for i in range(left, right):
        if a[i][1] <= standard:
            a[cnt],a[i] = a[i], a[cnt]
            cnt += 1
    a[cnt],a[right] = a[right], a[cnt]
    return cnt

def quickSort(a, left = 0, right = len(a) - 1):
    if 1 <= right - left:
        cnt_ = partition(a, left, right)
        quickSort(a,left, cnt_ - 1)
        quickSort(a,cnt_ + 1, right)

quickSort(a, 0 , len(a)-1)

ok = 1
for s, i in a:
    if b[i]() != s:
        ok = 0
print(['Not stable','Stable'][ok])


for i in range(n):
    print(*a[i])
from fractions import gcd
def swap(a,b):
  c=a
  a=b
  b=c
  return(a,b)
n,m=map(int,input().split())
s=input()
t=input()
o=n*m//gcd(n,m)
if m>n:
  s,t=swap(s,t)
  n,m=swap(n,m)
if not n%m:
  for i in range(m):
    if s[n//m*i]!=t[i]:
      print(-1)
      break
  else:
    print(n)
  exit()
for i in range(1,10**7):
  g=o*i
  x=['.']*g
  for j in range(n):
    x[j*(g//n)]=s[j]
  for j in range(m):
    if x[j*(g//m)]!='.'and x[j*(g//m)]!=t[j]:break
  else:
    print(len(x))
    break
else:print(-1)

### FIXED CODE ###

from fractions import gcd
n,m=map(int,input().split())
s=input()
t=input()
g=gcd(n,m)
a=n//g
b=m//g
for i in range(g):
  if s[a*i]!=t[b*i]:
    print(-1)
    break
else:
  print(n*m//g)
"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from math import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = int(round(val*lcm_ongoing/gcd(val, lcm_ongoing)))
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(int(round(lcm_of_A/value)) for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))


### FIXED CODE ###

"""
the condition is straightforward.
each element of A and B must multiply to the same value.
to minimise the total of B, simply make that value as small
as possible (since A is fixed).

lcm(2, 3, 4) = 12
therefore B is
12/2, 12/3, 12/4
and the sum of B is
12/2 + 12/3 + 12/4

lcd of a list is loop: lcd(partial, new_value)
lcd(a, b) = ab / gcd(a, b)
"""

from fractions import gcd


def lcm(list_ints):
    lcm_ongoing = 1
    for val in list_ints:
        lcm_ongoing = val*lcm_ongoing//gcd(val, lcm_ongoing)
    return lcm_ongoing


def flatten(N, A):
    # get lcm
    lcm_of_A = lcm(A)
    # get sum of lcm/values
    ans = sum(lcm_of_A//value for value in A)
    modulo_value = int(int(10e8)+7)
    return ans % modulo_value


if __name__ == "__main__":
    test1 = \
"""3
2 3 4"""
    test2 = \
"""5
12 12 12 12 12"""
    test3 = \
"""3
1000000 999999 999998"""
    test = test3
    # N = int(test.split("\n")[0])
    # A = list(map(int, test.split("\n")[1].split()))
    N = int(input())
    A = list(map(int, input().split()))
    print(flatten(N, A))
n, y = map(int, input().split())

for i in range(n+1):
    for j in range(n-i+1):
        if 10000 * a + 5000 + b + 1000 * (n-(a+b)) == y:
            print(a, b, n-(a+b))
            exit()

print(-1, -1, -1)

### FIXED CODE ###

n, y = map(int, input().split())

for a in range(0, n+1):
    for b in range(0, n-a+1):
        if 10000 * a + 5000 * b + 1000 * (n-(a+b)) == y:
            print(a, b, n-(a+b))
            exit()

print("-1 -1 -1")
a, v = list(map(long, input().split()))
b, w = list(map(long, input().split()))
t = long(input())

if a == b:
    print('NO')
    exit()
elif b > a:
    if v <= w:
        print('NO')
        exit()

    if b - a <= t * (v-w):
        print('YES')
    else:
        print('NO')
else:
    if w <= v:
        print('NO')
        exit()

    if a - b <= t * (w-v):
        print('YES')
    else:
        print('NO')


### FIXED CODE ###

a, v = list(map(float, input().split()))
b, w = list(map(float, input().split()))
t = float(input())

if v <= w:
    print('NO')
    exit()

if abs(v-w)*t >= abs(a-b):
    print('YES')
else:
    print('NO')
a, b, k = map(int, input().split())
for x in range(a,b):
  if x < a + k  or x > b - k:
    print(x)
  else:
    continue

### FIXED CODE ###

s = input()
if s.count("a") == 1 and s.count("b") == 1 and s.count("c") == 1:
  print("Yes")
else:
  print("No")
import sys,collections as cl,bisect as bs
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

def on(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if not x[n][i][0] == nn:
			if (k + x[n][i][1]) % 2 == 0:
				a[x[n][i][0]] = 0
				on(x,x[n][i][0],n,k + x[n][i][1] % 2)
			else:
				on(x,x[n][i][0],n,k + x[n][i][1] % 2)


n = int(input())

a = [1 for i in range(n)]
a[0] = 0
b = [[] for i in range(n)]

for i in range(n-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

on(b,0,0,0)

for i in range(n):
	print(a[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)
nnn = int(input())

a = [-2 for i in range(nnn)]
a[0] = 0

def m():
	return map(int,input().split())


def oon(x,n,nn,k):
	global a
	for i in range(len(x[n])):
		if x[n][i][0] != nn and a[nn] != -2:
			p = (k + x[n][i][1]) % 2
			if p == 0:
				a[x[n][i][0]] = 0
			else:
				a[x[n][i][0]] = 1
			oon(x,x[n][i][0],n,p)



b = [[] for i in range(nnn)]

for i in range(nnn-1):
	z,x,c = m();
	b[z-1].append([x-1,c])
	b[x-1].append([z-1,c])

oon(b,0,0,0)

for i in range(nnn):
	print(a[i])
x,y = map(int,input.split())

print(x+(y//2))

### FIXED CODE ###

X,Y = map(int,input().split())
 
print( X + (Y // 2))
n = int(input())
s = input()
x=0
max=0
for i in range(n):
    if s[i]=="I":
        x += 1
    else:
        x -= 1
    max = max(max,x)
print(max)

### FIXED CODE ###

a, b, c, d = map(int, input().split())
if a*b==c*d:
    print(a*b)
else:
    print(max(a*b, c*d))
n = int(input())
a = 0
b = n
total = []

def digitSum(number):
    sum = 0
    while number > 0:
        sum += number % 10
        number //= 10
    return sum

for i in range(2, n + 1):
    a = i
    b = n - a
    if b < a:
        break
    total.append(digitSum(a) + digitSum(b))
print(min(total))

### FIXED CODE ###

n = int(input())
a = 0
b = n
total = []

def digitSum(number):
    sum = 0
    while number > 0:
        sum += number % 10
        number //= 10
    return sum

for i in range(1, n + 1):
    a = i
    b = n - a
    if b < a:
        break
    total.append(digitSum(a) + digitSum(b))
print(min(total))
import math
A, B = map(int, input().split())

def lcm(x, y):
    return x * y // math.gcd(x, y)

print(lcm(A, B))

### FIXED CODE ###

from fractions import gcd

A, B = map(int, input().split())

print(A * B // gcd(A, B))
n,m=map(int,input().split())
a=[list(input())for i in range(n)]
b=[list(input())for j in range(m)]
for i in range(n-m):
    for x in range(n-m):
        if a[i][x:x+m]==b[i]:
            flag=1
            for j in range(1,m):
                if a[i+j][x:x+m]!=b[i+j]:
                    flag=0
            if flag:
                print("Yes")
                exit()
print("No")
               


### FIXED CODE ###

n,m=map(int,input().split())
a=[list(input())for i in range(n)]
b=[list(input())for j in range(m)]
for i in range(n-m+1):
    for x in range(n-m+1):
        if a[i][x:x+m]==b[0]:
            flag=1
            for j in range(0,m):
                if a[i+j][x:x+m]!=b[j]:
                    flag=0
            if flag:
                print("Yes")
                exit()
print("No")