Harryxun/stf_run huggingface dataset:
from collections import deque
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7

p = []
m = []
for i in a:
    if i >= 0:p.append(i)
    elif i < 0:m.append(i)

p.sort(reverse=True)
m.sort()
res = 1

if len(p) == 0 and k % 2 == 1:
    for i in range(k):
        res = (res * m[-(i + 1)]) %mod
    print(res)

else:
    p_ind = 0
    m_ind = 0
    while k:
        
        if p_ind >= len(p):
            temp1 = 0
        else:
            temp = p[p_ind] * p[p_ind + 1] if p_ind + 1 < len(p) else p[p_ind]
            temp1 = p[p_ind]
            
        temp2 = m[m_ind] * m[m_ind + 1] if m_ind + 1 < len(m) else 0
        if temp > temp2 or k == 1:
            res = (res * temp1) %mod
            p_ind += 1
            k -= 1
        else:
            res = (res * temp2) %mod
            m_ind += 2
            k -= 2
    print(res)

### FIXED CODE ###

from collections import deque
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7

p = []
m = []
for i in a:
    if i >= 0:p.append(i)
    elif i < 0:m.append(i)

p.sort(reverse=True)
m.sort()
res = 1
if n == k:
    for i in a:
        res = (res * i) %mod
    print(res)
    exit()
    
if len(p) == 0 and k % 2 == 1:
    for i in range(k):
        res = (res * m[-(i + 1)]) %mod
    print(res)

else:
    p_ind = 0
    m_ind = 0
    while k:
        if k == 1:
            res = (res * p[p_ind]) % mod
            break
        
        temp = p[p_ind] * p[p_ind + 1] if p_ind + 1 < len(p) else 0
        temp1 = m[m_ind] * m[m_ind + 1] if m_ind + 1 < len(m) else 0
        if temp > temp1:
            res = (res * p[p_ind]) %mod
            p_ind += 1
            k -= 1
        else:
            res = (res * temp1) %mod
            m_ind += 2
            k -= 2
    print(res)
n,k = map(int,input().split())



for i in range(k):
    if (!(n-k+2 > i)):
        print(0)

    else:
        total = 1
        total2 = 1
        total3 = 1
        for j in range(i+1):
            total *= n-k+1-j
            total2 *= j+1
            total3 = int(total/total2)
            
        ww = (i+1)**(k-i-1)
        ans = ww * total3

        ans2 = ans % 1000000007

        print(ans2)
    

    

### FIXED CODE ###

n,k = map(int,input().split())
mod = 10**9+7

a = [1 for i in range(2010)]

memo = 1
for i in range(1,2001):
    memo *= i
    a[i] = memo



for i in range(1,k+1):
    if not((n-k+2 > i)):
        print(0)

    else:
        memo1 = a[n-k+1]*a[k-1]
        memo2 = a[i]*a[n-k+1-i]*a[i-1]*a[k-i]

        ans2 = memo1//memo2
        print(ans2%mod)
a = [0 for i in range(26)]
w = []
while 1:
    s = input()
    if s == "-1":
        break

    w.append(s)
for i in w:
    for j in i:
        if j.isalnum():
            c = ord(j.lower())
            a[c-97] += 1
for i in range(26):
    print(chr(i+97) + " : " + str(a[i]))

### FIXED CODE ###

import sys
cnts = {}
for line in sys.stdin:
    for c in list(line.lower()): cnts[c] = cnts.get(c,0) + 1
  
for c in range(ord('a'),ord('z')+1): print(chr(c),':',cnts.get(chr(c),0))
a,b,c,d = input().split()
for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
                if eval(a+i+b+j+c+k+d) == 7:
                    print(a+i+b+j+c+k+d+ "=7")

### FIXED CODE ###

import sys
a,b,c,d = input()
for i in ["+","-"]:
    for j in ["+","-"]:
        for k in ["+","-"]:
                if eval(a+i+b+j+c+k+d) == 7:
                    print(a+i+b+j+c+k+d+ "=7")
                    sys.exit()
def Fib(n, memo={}):
    if n < 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n]


def resolve():
    N, M = [int(i) for i in input().split()]
    aa = []
    for _ in range(M):
        aa.append(int(input()))
    # fib_l = list(Fib(i) for i in range(N + 1))

    ans = 1
    now = 0
    for a in aa:
        if now == a:
            ans = 0
            break
        tmp = a - now - 1
        # ans = ans * fib_l[tmp]
        ans = ans * Fib(tmp)
        now = a + 1
    else:
        # ans = ans * fib_l[N - now]
        ans = ans * Fib(N - now)
    print(ans % (10**9 + 7))


resolve()


### FIXED CODE ###

def Fib(n, memo={}):
    if n < 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n]


def resolve():
    N, M = [int(i) for i in input().split()]
    aa = []
    for _ in range(M):
        aa.append(int(input()))
    fib_l = list(Fib(i) for i in range(N + 1))

    ans = 1
    now = 0
    for a in aa:
        if now == a:
            ans = 0
            break
        tmp = a - now - 1
        ans = ans * fib_l[tmp]
        now = a + 1
    else:
        ans = ans * fib_l[N - now]
    print(ans % (10**9 + 7))


resolve()
# utf-8:

def main():
    X, Y = map(str, raw_input().split())
    d = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "E": 15}
    if d[X] < d[Y]:
        print("<")
    elif d[X] > d[Y]:
        print(">")
    elif d[X] == d[Y]:
        print("=")


if __name__ == '__main__':
    main()


### FIXED CODE ###

# utf-8:

def main():
    X, Y = map(str, raw_input().split())
    d = {"A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15}
    if d[X] < d[Y]:
        print("<")
    elif d[X] > d[Y]:
        print(">")
    elif d[X] == d[Y]:
        print("=")


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

a, b = x.split()
a = list(a)
b = int(b)

a[b] = a[b].lower()

print("".join(a))



### FIXED CODE ###

x = input()
s = input()

n, k = x.split()
k = int(k)
s = list(s)

s[k-1] = s[k-1].lower()

print("".join(s))
if A >= 9 or B >= 9:
    print(":(")
else:
    print("Yay!")

### FIXED CODE ###

A,B = map(int,input().split())
if A >= 9 or B >= 9:
    print(":(")
else:
    print("Yay!")
n = int(input())
al = [0 for _ in range(n)]
for i in range(n):
    al[i] = int(input())

def check(al,bl,i):
    bl.append(i)
    i = al[i]-1
    if i in bl:
        print("-1")
    elif i == 1:
        print(len(bl))
    else:
        check(al,bl,i)

bl = []
check(al,bl,0)

### FIXED CODE ###

n = int(input())
al = [int(input()) for i in range(n)]

i = 0
for j in range(n):
    i = al[i]-1
    if i == 1:
        print(j+1)
        exit()
print(-1)
def main():
    import math
    n = int(input())
    inlis = []
    for _ in range(n):
        a = int(input())
        inlis.append(a)

    ans = inlis[0]
    for i in range(1, n):
        ans = ans * inlis[i] // math.gcd(ans, inlis[i])

    print(ans)

    



    
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    import fractions
    n = int(input())
    inlis = []
    for _ in range(n):
        a = int(input())
        inlis.append(a)
    
    ans = inlis[0]
    for i in range(1, n):
        ans = ans * inlis[i] // fractions.gcd(ans, inlis[i])

    print(ans)

    
    
if __name__ == "__main__":
    main()
N = int(input())
A = list(map(int, input().split()))
seen = [0]*(200+1)
A.sort()
ans = 0
for a in A:
    if seen[a] == 0:
        ans += 1
        x = a
        j = 1
        while x <= 200:
            seen[x] = 1
            j += 1
            x = a*j
print(ans)

### FIXED CODE ###

from collections import Counter
 
N = int(input())
A_raw = Counter(list(map(int, input().split())))
A = [x[0] for x in A_raw.items() if x[1] == 1]
A.sort()
B = [x[0] for x in A_raw.items() if x[1] > 1]
B.sort()
seen = [0]*(1000000+1)
for b in B:
    if seen[b] == 0:
        x = b
        j = 1
        while x <= 1000000:
            seen[x] = 1
            j += 1
            x = b*j
ans = 0
for a in A:
    if seen[a] == 0:
        ans += 1
        x = a
        j = 1
        while x <= 1000000:
            seen[x] = 1
            j += 1
            x = a*j
print(ans)
N=input()
c=0
flag = 0
for i in N:
    if i=='C' and  c==0 :c+=1
    if i=='F' and c==1: flag=1
if flag:print("Yes")
else flag:print("No")

### FIXED CODE ###

N=input()
c=0
flag = 0
for i in N:
    if i=='C' and  c==0 :c+=1
    if i=='F' and c==1: flag=1
if flag==1:print("Yes")
else :print("No")
from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *l = nf()
    al = list(l)
    for i in range(n):
        ma = max([*al[:i], *al[i+1:]])
        print(ma)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin

readline = stdin.readline


def nf():
    """
    入力全て(EOFまで)を`int iter`に変換
    """
    return map(int, open(0).read().split())


def main():
    n, *al = nf()
    s, f = sorted(al)[-2:]
    if s == f:
        for _ in range(n):
            print(f)
        return
    for a in al:
        if a == f:
            print(s)
            continue
        print(f)


if __name__ == "__main__":
    main()
S = list(input())
sum = 700
for s in S:
  if s = "o":
    sum += 100
print(sum)

### FIXED CODE ###

S = list(input())
sum = 700
for s in S:
  if s == "o":
    sum += 100
print(sum)
def ans(n, AA, x):
    tmp = n + AA[0]
    if len(AA) == 1:
        try: x[tmp] = 1
        except: pass
    else:
        f3(n, AA[1:], x)
        try:
            x[tmp] = 1
            f3(tmp, AA[1:],x)
        except:
            pass
    return
 
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
M = map(int, raw_input().split())
 
x = [0 for i in range(max(M)+1)]
f3(0, A, x)
 
for e in M:
    if x[e] == 1:
        print 'yes'
    else:
        print 'no'

### FIXED CODE ###

def ans(n, AA, x):
    tmp = n + AA[0]
    if len(AA) == 1:
        try: x[tmp] = 1
        except: pass
    else:
        ans(n, AA[1:], x)
        try:
            x[tmp] = 1
            ans(tmp, AA[1:],x)
        except:
            pass
    return
 
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
M = map(int, raw_input().split())
 
x = [0 for i in range(max(M)+1)]
ans(0, A, x)
 
for e in M:
    if x[e] == 1:
        print 'yes'
    else:
        print 'no'
L = list(map(int(),input().split()))
if sum(L)==17:
  print('YES')
else:
  pritn('NO')
 

### FIXED CODE ###

L = [int(i) for i in input().split()]

S = sum(L)
S2 = S - L[0]
S1 = S2 - L[1]

if S != 17:
    print('NO')
else:
    if S2==10 and S1==5:
        print('YES')
    elif S2==12 and (S1==5 or S1==7):
        print('YES')
    else:
        print('NO')
n =int(input())
nl = list(map(int,input().split()))
result = 0
for i in range(n):
    for k in range(i+1,n):
        result += nl[i] * nl[k]
        
print(result)

### FIXED CODE ###

a, b = map(int,input().split())
result = max(a - 2* b, 0)
print(result)
H, A = map(int, input.split())
ans = H // A
if H % A != 0:
  ans = ans + 1
print(ans)

### FIXED CODE ###

H, A = map(int, input().split())
ans = H // A
if H % A != 0:
  ans = ans + 1
print(ans)
n, m = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
match = 0
ans = 0
mini = min(a)

for j in range(n):
    for k in range(b[a.index(mini)]):
        if m <= match:
            break
        ans += mini
        match += 1
    
    b.pop(a.index(mini))
    a.remove(mini)
    mini = min(a)
print(ans)

### FIXED CODE ###

# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ab = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a,b))
ab = sorted(ab)
for c, d in ab:
    if m >= d:
        ans += c*d
        m -= d
    else:
        ans += c*m
        break
print(ans)
import math
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
# output LCM(T1,T2... Tn)=LCM(Tn,LCM(Tn-1,LCM(...)))
def lcm(a,b):
  g = math.gcd(a,b)
  #print(g)
  return int(a*b/g)
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)


### FIXED CODE ###

#import math
N = int(input())
T = []
for i in range(N):
  T.append(int(input()))
# output LCM(T1,T2... Tn)=LCM(Tn,LCM(Tn-1,LCM(...)))
def gcd(a,b): #Recusion!!
  if min(a,b) == 0:
    return max(a,b)
  else:
    return gcd(min(a,b),max(a,b)%min(a,b))
    
"""
  mi = min(a,b)
  ma = max(a,b)
  ans = 1
  '''for i in range(2,mi+1):
    if (mi%i)+(ma%i) == 0:
      mi /= i
      ma /= i
      ans *= i
      i -= 1'''
  while True:
    #print(ma,mi)
    if (ma % mi) == 0:
      ans = mi
      break
    else:
      mi = ma%mi
      ma = mi
      
  return ans"""


def lcm(a,b):
  #g = math.gcd(a,b)
  g = gcd(a,b)
  #print(g)
  return int(a*b//g)
ans = T[0]
for i in range(1,len(T)):
  ans = lcm(ans,T[i])
print(ans)
N=int(input())
c=list(map(int,input().split()))

for i in range(N):

    if c[i]%2==0:
        if c[i]%3==0 or c[i]%5==0:
        else:
            print("DENIED")
            exit(0)

print("APPROVED")


### FIXED CODE ###

N=int(input())
c=list(map(int,input().split()))

for i in range(N):

    if c[i]%2==0:
        if c[i]%3==0 or c[i]%5==0:
            continue

        else:
            print("DENIED")
            exit(0)

print("APPROVED")
import numpy as np

N = int(input())
price = []

for i in range(N):
    price.append(int(input()))

price = np.array(price)
max_index = np.argmax(price)

print(int(np.sum(price) - price[max_index] / 2))

### FIXED CODE ###

day = int(input())

difference = int(25 - day)

if difference > 0:
    answer = "Christmas " + "Eve " * (difference - 1) + "Eve"
else:
    answer = "Christmas"

print(answer)
from itertools 
n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

cnt=0
for v in itertools.permutations(range(1,N+1), N):
    cnt +=1
    if(p==v):
        a = cnt
    if(q==v):
        b = cnt

print(abs(a-b))

### FIXED CODE ###

import itertools
n = int(input())
p = tuple(((map(int,input().split()))))
q = tuple(((map(int,input().split()))))

num = []
for i in range(1,n+1):
    num.append(i)
ans = []
for i in itertools.permutations(num,n):
    ans.append(i)

print(abs(ans.index(p)-ans.index(q)))
H=int(input())
A=int(input())

ans=0
while True:
   H -= A
   ans += 1
   if H<=0:
      break
        
print(ans)  

### FIXED CODE ###

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


ans=0
while True:
   H -= A
   ans += 1
   if H<=0:
      break
        
print(ans)
n,k = map(int,input().split())
print(min(n%k),k - (n%k))

### FIXED CODE ###

n,k = map(int,input().split())
print(min(n%k,k - n%k))
from collections import *
mod=10**6+3
fac=[0 for i in range(mod-1)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    D=pow(d,mod-2,mod)
    a,b=x*D%mod,(x+(n-1)*d)*D%mod
    if a>0 and a<b and b<mod:
        value=fac[b]*pow(fac[a-1],mod-2,mod)*pow(d,n,mod)
        print(value%mod)
    else:
        print(0)


### FIXED CODE ###

from collections import *
mod=10**6+3
fac=[0 for i in range(mod)]
fac[0]=1
for i in range(0,len(fac)-1):
    fac[i+1]=(fac[i]*(i+1))%mod
fac[0]=0
Q=int(input())
for q in range(Q):
    x,d,n=map(int,input().split())
    if d>0:
        D=pow(d,mod-2,mod)
        a=(x-d%mod)*D%mod
        b=(a+n)%mod
        if a<b and a+n<mod:
            if a>0:
                value=fac[b]*pow(fac[a],mod-2,mod)*pow(d,n,mod)
            else:
                value=fac[b]*pow(d,n,mod)
            print(value%mod)
        else:
            print(0)
    else:
        print(pow(x,n,mod))
n = int(input())
li = [input().split() for i in range(n)]
ans = 0
for a,b in lis:
    if b =='JPY':
        ans += float(a)
    else:
        ans += float(a)*380000
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(n):
    x, u = input().split()
    x =float(x)
    ans += x if u == 'JPY' else 380000*x
print(ans)
while True:
　　try:
        l = map(int, raw_input().split(","))
        v1 = l.pop(10)
        v2 = l.pop(10)
        p = v1*float(sum(l))/(v1+v2)
        for i in range(10):
            p -= l[i]
            if p <= 0:
                print i+1
                break
　　except:
      　break


### FIXED CODE ###

while True:
    try:
        l = map(int, raw_input().split(","))
        v1 = l.pop(10)
        v2 = l.pop(10)
        p = v1*float(sum(l))/(v1+v2)
        for i in range(10):
            p -= l[i]
            if p <= 0:
                print i+1
                break
    except:
        break
import bisect

N=int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

count=0
for i in range(N):
    a_cand = bisect.bisect_right(A,B[i]-1)
    c_cand = N-bisect.bisect_right(C,B[i])
    count += a_cand*c_cand
print(count)


### FIXED CODE ###

a,b=map(int,input().split())
print((a+b)%24)
N,K=map(int,input().split())
if(N>=(2*(K-1)))
  print("YES")
else:
  print("NO")

### FIXED CODE ###

N,K=map(int,input().split())
if(N>(2*(K-1))):
  print("YES")
else:
  print("NO")
def gcd(a,b):
    if b > 0:
        return gcd(b,a%b)
    elif b == 0:
        return a

N,X = map(int,input().split())
x = list(map(int,input().split()))
xlen = [abs(x[0]-X)]
for i in range(N-1):
    xlen.append(x[i+1]- x[i])
ans = xlen[0]
for i in range(N-2):
    ans = gcd(ans,xlen[i+1])
    #print(ans)
print(ans)

### FIXED CODE ###

def gcd(a,b) :
    if b>0 :
        return gcd(b,a % b)
    elif b == 0:
        return a


N,X = map(int,input().split())
x = list(map(int,input().split()))
if N == 1:
    print(abs(x[0] - X))
else:
    xlen = []
    for i in range(N):
        xlen.append(abs(x[i] - X))
        #print(xlen[i])
    ans = xlen[0]
    for i in range(1,N):
        ans = gcd(ans,xlen[i])
        #print(ans)
    print(ans)
A = list(map(int, input().split()))
if max(A)=7 and mean(A)=5 and min(A)=5:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

A = list(map(int, input().split()))
A =sorted(A)
if A[0]==5 and A[1]==5 and A[2]==7:
  print("YES")
else:
  print("NO")
import sys
import numpy as np
import heapq

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]


n, k = reatIntN()
ss = sys.stdin.readline().strip()


class Node:
    def __init__(self, p, n, v):
        self.prev = p
        self.next = n
        self.value = v


r = Node(None, None, None)
r.next = r
r.prev = r

def append(n, value):
    nn = Node(n, n.next, value)
    n.next.prev = nn
    n.next = nn

def remove(n):
    pn = n.prev
    nn = n.next
    nn.prev = pn
    pn.next = nn
    n.next = None
    n.prev = None
    n.value = None


i = 0
while i < len(ss):
    b = i
    c = ss[i]
    while (i < len(ss)) and (c == ss[i]):
        i += 1
    append(r, (int(c), b, i))


def _calc(p):
    d = 0
    if (p is not r) and (p.value[0] == 0):
        lh = p.value[1]
        rh = p.value[2]
        if p.next is not r:
            lh = min(lh, p.next.value[1])
        if p.prev is not r:
            rh = max(rh, p.prev.value[2])
        d = rh - lh
    return d
 


p = r.next
pq = []
while p is not r:
    d = _calc(p)
    if 0 < d:
        heapq.heappush(pq, (-d, p.value[2], p))
    p = p.next


for i in range(k):
    if len(pq) == 0:
        break
    _, _, p = heapq.heappop(pq)
    if (p.value is not None) and (p.value[0] == 0):
        lh = p.value[1]
        rh = p.value[2]

        if p.next is not r:
            lh = min(lh, p.next.value[1])
            remove(p.next)
        if p.prev is not r:
            rh = max(rh, p.prev.value[2])
            remove(p.prev)
        p.value = (1, lh, rh)

        dp = _calc(p.prev)
        if 0 <= dp:
            heapq.heappush(pq, (-dp, p.prev.value[2], p.prev))
        dn = _calc(p.next)
        if 0 <= dn:
            heapq.heappush(pq, (-dn, p.next.value[2], p.next))

ret = 0
p = r.next
while p is not r:
    if p.value[0] == 1:
        ret = max(ret, p.value[2] - p.value[1])
    p = p.next
print(ret)

### FIXED CODE ###

import sys
import numpy as np

reatInt = lambda: int(sys.stdin.readline())
reatIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]


n, k = reatIntN()
ss = sys.stdin.readline().strip()

l = []
i = 0
if ss[0] == '0':
    l.append((1, 0))
else:
    l.append((0, 0))
while i < len(ss):
    c = ss[i]
    while (i < len(ss)) and (c == ss[i]):
        i += 1
    l.append((int(c), i))

i = 1
ret = 0
while i < len(l):
    q = 1 if  l[i][0] == 0 else 0
    b = i - 1
    e = min(i + 2 * k - q, len(l) - 1)
    ret = max(ret, l[e][1] - l[b][1])
    i += 1
print(ret)
# -*- coding: utf-8 -*-
A=int(input())
B=int(input())
C=(A-1)*(B-1)
print(C)

### FIXED CODE ###

A,B=list(map(int,input().split()))
C=(A-1)*(B-1)
print(C)
import numpy as np

N = int(input())
tmp = input().split(' ')

A = []
for i in range(N):
    A.append(int(tmp[i]))

A = np.asarray(A)

z = np.asarray([x for x in range(N)])
A = A - z

b = np.median(A)
A = A - b
A = np.abs(A)
print(A.sum().astype(np.uint8))


### FIXED CODE ###

N = int(input())
if N % 2 == 0:
    print(N)
else:
    print(N * 2)
n = int(input())
graph = {i: [] for i in range(1, n + 1)}
for _ in range(n - 1):
    u, v, ww = map(int, input().split())
    graph[u].append([v,ww])
    graph[v].append([u,ww])
color = [-1] * n

def dfs(x):
    for sub in graph[x]:
        next = sub[0]
        lon = sub[1]
        if color[next - 1] != -1:
            continue
        if lon % 2 == 0:
            color[next - 1] = color[x - 1]
        else:
            if color[x-1] == 1:
                color[next - 1] = 0
            else:
                color[next - 1] = 1
        dfs(next)

color[0] = 0
dfs(1)
for i in color:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
n = int(input())
graph = {i: [] for i in range(1, n + 1)}
for _ in range(n - 1):
    u, v, ww = map(int, input().split())
    graph[u].append([v,ww])
    graph[v].append([u,ww])
color = [-1] * n

def dfs(x):
    for sub in graph[x]:
        next = sub[0]
        lon = sub[1]
        if color[next - 1] != -1:
            continue
        if lon % 2 == 0:
            color[next - 1] = color[x - 1]
        else:
            if color[x - 1] == 1:
                color[next - 1] = 0
            else:
                color[next - 1] = 1
        dfs(next)

color[0] = 0
dfs(1)
for i in color:
    print(i)
perint("TEST")

### FIXED CODE ###

import sys
a = []
for l in sys.stdin:
    a.append(l)
count = 0
for i in range(3):
  if a[0][i] == a[1][i]:
    count += 1
print(count)