Harryxun/stf_run huggingface dataset:
from enum import Enum
from queue import Queue
import collections

import sys
import math
import time

t1=time.time()
input = sys.stdin.readline
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


S = str(input())
# S = str('?'*(10**5))
N = 13

dp =[0]*N
dp[0]=1

mul = 1
reversed_S = reversed(S)
for c in reversed_S:
    nextDP = [0]*N
    if c == '?':
        # print('test')
        # print(mul)
        for k in range(10):
            for j in range(N):
                nextDP[(mul*k+j)%N] += dp[j]
                nextDP[(mul*k+j)%N] %= MOD
    else:
        k = int(c)
        for j in range(N):
            nextDP[(mul*k+j)%N] += dp[j]
            nextDP[(mul*k+j)%N] %= MOD

    mul *= 10
    mul %= N
    dp = nextDP[:]
print(dp[5])
#print(time.time()-t1)


### FIXED CODE ###

#from enum import Enum
#from queue import Queue
#import collections

#import sys
#import math
#import time

#t1=time.time()
#input = sys.stdin.readline
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


S = input().strip()
# S = str('?'*(10**5))
N = 13

dp =[0]*N
dp[0]=1

mul = 1
reversed_S = S[::-1]
for c in reversed_S:
    nextDP = [0]*N
    if c == '?':
        # print('test')
        # print(mul)
        for k in range(10):
            for j in range(N):
                nextDP[(mul*k+j)%N] += dp[j]
                nextDP[(mul*k+j)%N] %= MOD
    else:
        k = int(c)
        for j in range(N):
            nextDP[(mul*k+j)%N] += dp[j]
            nextDP[(mul*k+j)%N] %= MOD

    mul *= 10
    mul %= N
    dp = nextDP[:]
print(dp[5])
#print(time.time()-t1)
n = int(input())
s = str(input())
r, g, b = map(s.count, "RGB")
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        k = 2*j - i
        if k<n and len(set([s[i], s[j], s[k]])) == 3:
            ans -= 1
print(ans)

### FIXED CODE ###

if "7" in str(input()):
    print("Yes")
else:
    print("No")
X Y Z = input()
she = 0
she = X
X = Y
Y = she
she = Z
Z = X
X = she
print X, Y, Z

### FIXED CODE ###

X, Y, Z = map(int, input().split(' '))
print(Z, X, Y)
n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = input()
  s = sorted(s)
  hsh[s] += 1

x = 0
for i in hsh:
  x += (hsh[i]*(hsh[i]-1))//2

print(x)

### FIXED CODE ###

n = int(input())
from collections import defaultdict as dd

hsh = dd(int)

for i in range(n):
  s = list(input())
  s = ''.join(sorted(s))
  hsh[s] += 1

x = 0
for i in hsh.keys():
  x += (hsh[i]*(hsh[i]-1))//2

print(x)
import sys
N = int(input())
for i in range(1,3501):
    for j in range(i,3501):
        print(i,j)
        if 4*i*j-N*i-N*j > 0:
            if (N*i*j)%(4*i*j-N*i-N*j) == 0:
            print(i,j,int((N*i*j)/(4*i*j-N*i-N*j)))
            sys.exit()


### FIXED CODE ###

import sys
N=int(input())
for h in range(1,3501):
    for n in range(h,3501):
        if 4*n*h-N*h-N*n >0:
            if (N*h*n)%(4*n*h-N*h-N*n)==0:
                w=int((N*h*n)/(4*n*h-N*h-N*n))
                print(h,n,w)
                sys.exit()
import itertools
import sys


c = list(itertools.product(range(10), repeat=4))

for line in sys.stdin.readlines():
    print sum([l for l in c if int(n) == sum(l)])

### FIXED CODE ###

import sys


for n in sys.stdin:
    ret = 0
    for a in xrange(10):
        for b in xrange(10):
            for c in xrange(10):
                for d in xrange(10):
                    if a+b+c+d == int(n):
                        ret += 1
    print ret
import math
import sys

#n, a, b= map(int, input().split())
n, m  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

a = [""]*m
b = [""]*m
for i in range(m):
  #a[i] = int(input())
  a[i], b[i] = map(int, input().split())

num = [int(i+1) for i in range(5)]
count = [0]*n

for i in range(m):
  for ii in range(n):
    if(a[i] == num[ii]):
      count[ii] = count[ii] + 1
    if(b[i] == num[ii]):
      count[ii] = count[ii] + 1

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

### FIXED CODE ###

import math
import sys

#n, a, b= map(int, input().split())
n, m  = map(int, input().split())
#s = list(str(input()))
#n = int(input())
#a = list(map(int, input().split()))

a = [""]*m
b = [""]*m
for i in range(m):
  #a[i] = int(input())
  a[i], b[i] = map(int, input().split())

num = [int(i+1) for i in range(n)]
count = [0]*n

for i in range(m):
  for ii in range(n):
    if(a[i] == num[ii]):
      count[ii] = count[ii] + 1
    if(b[i] == num[ii]):
      count[ii] = count[ii] + 1

for i in range(n):
  print(count[i])
from itertools import combinations

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))

idx = range(n)
result = [0, sum(value)-sum(cost)]
index = [idx for idx, v, c in enumerate(zip(value, cost)) if v > c]
comb = [com for i in range(1, len(index)) for com in combinations(index, i)]

for com in comb:
  tmp = 0
  for c in com:
    tmp += value[c]-cost[c]
  result.append(tmp)
    
print(max(result))

### FIXED CODE ###

n = int(input())
value = list(map(int, input().split()))
cost = list(map(int, input().split()))
result = 0
for v, c in zip(value, cost):
  if v > c:
    result += v-c
print(result)
N = int(input())
L = list(map(int, input().split()))

def sort(L):
  if len(L) < 2:
    return(L)
  p = L[0]
  X,Y = divide(p,L[1:])
  return sort(X) + [p] + sort(Y)

def divide(p,L):
  if len(L) < 1:
    return([],[])
  X,Y = divide(p,L[1:])
  l = L[0]
  if l < p:
    return([l] + X,Y)
  else:
    return(X,[l]+Y)
  
L = sort(L)
cut = L[int(N/2)] - L[int((N/2))-1]
print(cut)

### FIXED CODE ###

N = int(input())
L = sorted(list(map(int, input().split())))
  
print(L[int(N/2)] - L[int((N/2))-1])
import sys

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)


### FIXED CODE ###

import sys
sys.setrecursionlimit(2 * 10 ** 5)

N, K = map(int, sys.stdin.readline().strip().split())
A = list(map(int, sys.stdin.readline().strip().split()))

town_line = []
town_set = set()
last_town = None


def search(town=0):
    global last_town
    if town not in town_set:
        town_line.append(town)
        town_set.add(town)
        search(town=A[town]-1)
    else:
        last_town = town
        return


search(0)
town_loop = town_line[town_line.index(last_town):]

if K < len(town_line):
    print(town_line[K] + 1)
else:
    k = K - len(town_line) + 1
    k = k % len(town_loop)
    print(town_loop[k - 1] + 1)
int N = input()
int K = input()
int X = input()
int Y = input()
int fee

if(N <= K):
  fee=N*X
else:
  fee=X*K + Y*(N-K)

print(fee)



### FIXED CODE ###

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if(N <= K):
  fee=N*X
else:
  fee=X*K + Y*(N-K)

print(fee)
N = int(input())
t = list(map(int,input().split()))
v = list(map(int,input().split()))

time = 0
sum_t = sum(t)
velo_cap =[float("inf")]*(2*sum_t+1)
for i in range(N):
  start_t = time
  goal_t = time + 2*t[i]
  for s in range(0,2*sum_t+1):
    if s < start_t:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(start_t-s))
    elif s<goal_t:
      velo_cap[s] = min(velo_cap[s],2*v[i])
    else:
      velo_cap[s] = min(velo_cap[s],2*v[i]+(s-goal_t))
  time += 2*t[i]
for s in range(2*sum_t+1):
  velo_cap[s] = min(velo_cap[s],2*sum_t-s,s)


print(sum(velo_cap)/4-(velo_cap[0]+velo_cap[-1])/8)

### FIXED CODE ###

R=int(input())
G=int(input())
print(2*G-R)
def f(x,y,i):
    if i==N-1:
        return abs(A[N-1]-y)
    b = abs(A[N-1]-y)
    for j in range(i,N-1):
        b = max(b,g(A[j],y,j+1))
    return b
def g(x,y,i):
    if i==N-1:
        return abs(x-A[N-1])
    b = abs(x-A[N-1])
    for j in range(i,N-1):
        b = min(b,f(x,A[j],j+1))
    return b
N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
print(f(Z,W,0))

### FIXED CODE ###

N,Z,W = map(int,input().split())
A = list(map(int,input().split()))
if N>=2:
    print(max(abs(A[-1]-A[-2]),abs(A[-1]-W)))
else:
    print(abs(A[0]-W))
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,M = map(int,input().split())
    shirube = [None]*(N+1)
    shirube[1] = (1,0)
    mmap = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int,input().split())
        mmap[a].append(b)
        mmap[b].append(a)
    queue = deque()
    queue.appendleft((1,0))
    while queue:
        current_node, distance = queue.pop()
        for next_node in mmap[current_node]:
            new_distance = distance+1
            if shirube[next_node] is None:
                shirube[next_node] = (current_node, new_distance)
                queue.appendleft((next_node, new_distance))
            elif shirube[next_node][1] > new_distance:
                shirube[next_node] = (current_node, new_distance)
                queue.appendleft((next_node, new_distance))
    shirube = shirube[1::]
    if None in shirube:
        print("No")
        return
    print("Yes")
    for s in shirube[1::]:
        print(s[0])


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

### FIXED CODE ###

import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,M = map(int,input().split())
    shirube = [None]*(N+1)
    shirube[1] = (1,0)
    mmap = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = map(int,input().split())
        mmap[a].append(b)
        mmap[b].append(a)
    queue = deque()
    queue.appendleft((1,0))
    while queue:
        current_node, distance = queue.pop()
        for next_node in mmap[current_node]:
            new_distance = distance+1
            if shirube[next_node] is None:
                shirube[next_node] = (current_node, new_distance)
                queue.appendleft((next_node, new_distance))
            elif shirube[next_node][1] > new_distance:
                shirube[next_node] = (current_node, new_distance)
                queue.appendleft((next_node, new_distance))
    shirube = shirube[1::]
    if None in shirube:
        print("No")
        return
    print("Yes")
    for s in shirube[1::]:
        print(s[0])


if __name__ == '__main__':
    main()
N,M=map(int,input.split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
  
for i in range(N-M):
    if B[0] in A[i]:
      for j in range(1,M):
        if B[j] in A[i+j]:
          if j = M - 1:
            print("Yes")
            exit(0)
          else:
            continue
        else:
          break
          
print("No")

### FIXED CODE ###

N,M=map(int,input().split())
A=[""]*N
B=[""]*M
for i in range(N):
  A[i]=input()
for i in range(M):
  B[i]=input()
  
A_tmp=[""]*M
for i in range(N-M+1):
  for j in range(N-M+1):
    for k in range(M):
      A_tmp[k]=A[j+k][i:i+M]
    if A_tmp==B:
      print("Yes")
      exit(0)

print("No")
S=input()
t=len(S)
m=t//2
S1=""
S2=""
for x1 in range(m):
  S1 += S[x1]
for x2 in range(m+1,2*m+1):
  S2 += S[x2]
S2=S2[::-1]
if S1==S2:
  t1=len(S1)
  t2=len(S2)
  m1=t1//2
  m2=t2//2
  R11=""
  R12=""
  for y1 in range(m1):
    R11 += S1[y1]
  for y2 in range(m1+1,2*m1+1):
    R12 += S1[y2]
  R12=R12[::-1]
  if R11==R12:
    R21=""
    R22=""
    for z1 in range(m2):
      R21 += S2[z1]
    for z2 in range(m2+1,2*m2+1):
      R22 += S2[z2]
    R22=R22[::-1]
    if R21==R22:
      print('Yes')
    else:
      print('No')
  else:
    print('No')
else:
  print('No')
  
  

### FIXED CODE ###

import sys
S=input()
N=len(S)
if S[:N//2]==S[N//2+1:][::-1]:
  if N==3:
    print("Yes")
  elif (N//2)%2==1:
    if S[:(N//2)//2]==S[(N//2)//2+1:N//2][::-1] and S[N//2+1:-(N//2)//2]==S[-(N//2)//2+1:][::-1]:
      print("Yes")
    else:
#      sys.stderr.write("2\n")
      print("No")
  else:
    if S[:(N//2)//2]==S[(N//2)//2:N//2][::-1] and S[N//2+1:-(N//2)//2]==S[-(N//2)//2:][::-1]:
      print("Yes")
    else:
      print("No")
else:
#  sys.stderr.write("1\n")
  print("No")
r,c=map(int,input().split())
mod=10**9+7
g=[]
for _ in range(r):
  g.append(input())
dp=[[0 for j in range(c)] for i in range(r)]
dp[0][0]=1
for i in range(r):
  for j in range(c):
    if g[i][j]=='.':
        if i>0:
            dp[i][j]+=dp[i-1][j]%mod
        if j>0:
            dp[i][j]+=dp[i][j-1]%mod


print(dp[-1][-1])
      


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
res=[-1]*n
res[0]=0
res[1]=abs(h[0]-h[1])
for i in range(2,n):
  res[i]=min(abs(h[i-1]-h[i])+res[i-1],abs(h[i-2]-h[i])+res[i-2])

print(res[-1])
n,a,b=map(int,input().split())
bet=abs(b-a)
if bet%2==0:
  winner='ALice'
  else:
    winner='Borys'
    
print(winner)

### FIXED CODE ###

n,a,b=map(int,input().split())
bet=abs(b-a)
if bet%2==0:
  winner='Alice'
else:
    winner='Borys'
    
print(winner)
a = raw_input() . split()

print a[0] * a[1]
print 2 * (a[0] + a[1])

### FIXED CODE ###

a , b= map(int,raw_input(). split())
S = a * b
O = 2 * a + 2 * b

print str(S) + ' ' +  str(O)
from heapq import *
def main():
    N=int(input())
    line = list(input())
    ans=[]

    for i in range(N+1):
        a=line[:i].count("#")
        b=line[i:].count(".")
        heappush(ans,a+b)
    
    return peappop(ans)

print(main())

### FIXED CODE ###

n = int(input())
s = input()
ans = s.count('.')
num = ans
for c in s:
  if c == '.':
    num -= 1
  else:
    num += 1
  
  ans = min(ans,num)

print(ans)
# encoding:utf-8
import sys

def main():
	n = int(input())
	vers = [list(map(int, input().split())) for _ in range(n - 1)]
	q, k = list(map(int, input().split()))
	queries = [list(map(int, input().split())) for _ in range(q)]

	#n = 10 ** 5
	#vers = [[i + 1, i + 2, 10 ** 9] for i in range(n - 1)]

	new_vers = mapping(n, vers)
	dist = calcMinDist(n, new_vers, k, queries)
	calcQueries(dist, queries, k)
	
def mapping(n, vers):
	new_vers = {i :[] for i in range(n)}
	for ver in vers:
		new_vers[ver[0] - 1].append((ver[1], ver[2]))
		new_vers[ver[1] - 1].append((ver[0], ver[2]))
	return new_vers

def calcMinDist(n, new_vers, k, queries):
	dist = [- 1 for _ in range(n)]
	flag = [False for _ in range(n)]
	dist[k - 1] = 0
	flag[k - 1] = True
	dfs(new_vers, dist, flag, k)
	return dist

def dfs(new_vers, dist, flag, frm):
	flag[frm - 1] = True
	vs = new_vers[frm - 1]
	for v in vs:
		if flag[v[0] - 1] == False:
			dist[v[0] - 1] = dist[frm - 1] + v[1]
			new_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0])

	return [new_vers, dist, flag, frm]

def calcQuery(dist, query, k):
	print(dist[query[0] - 1] + dist[query[1] - 1])

def calcQueries(dist, queries, k):
	for query in queries:
		calcQuery(dist, query, k)

if __name__ == '__main__':
	sys.setrecursionlimit(100000)
	main()

### FIXED CODE ###

# encoding:utf-8
import sys
 
def main():
	n = int(input())
	vers = [list(map(int, input().split())) for _ in range(n - 1)]
	q, k = list(map(int, input().split()))
	queries = [list(map(int, input().split())) for _ in range(q)]
 
	#n = 10 ** 5
	#vers = [[i + 1, i + 2, 10 ** 9] for i in range(n - 1)]
 
	new_vers = mapping(n, vers)
	dist = calcMinDist(n, new_vers, k, queries)
	calcQueries(dist, queries, k)
	
def mapping(n, vers):
	new_vers = {i :[] for i in range(n)}
	for ver in vers:
		new_vers[ver[0] - 1].append((ver[1], ver[2]))
		new_vers[ver[1] - 1].append((ver[0], ver[2]))
	return new_vers
 
def calcMinDist(n, new_vers, k, queries):
	dist = [- 1 for _ in range(n)]
	flag = [False for _ in range(n)]
	dist[k - 1] = 0
	flag[k - 1] = True
	dfs(new_vers, dist, flag, k)
	return dist
 
def dfs(new_vers, dist, flag, frm):
	flag[frm - 1] = True
	vs = new_vers[frm - 1]
	for v in vs:
		if flag[v[0] - 1] == False:
			dist[v[0] - 1] = dist[frm - 1] + v[1]
			new_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0])
 
	return [new_vers, dist, flag, frm]
 
def calcQuery(dist, query, k):
	print(dist[query[0] - 1] + dist[query[1] - 1])
 
def calcQueries(dist, queries, k):
	for query in queries:
		calcQuery(dist, query, k)
 
if __name__ == '__main__':
	sys.setrecursionlimit(1000000)
	main()
a,b=map(int,input().split)
if a>b:
  print(a-1)
else:
  print(a)

### FIXED CODE ###

a,b=map(int,input().split( ))
if a>b:
  print(a-1)
else:
  print(a)
m = []
f = []
r = []
while(True):
    M,F,R=map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    else:
        m.append(M)
        f.append(F)
        r.append(R)
for i in range(len(m)):
    score = m[i]+f[i]
    if (m[i] == -1 or f[i] ==-1) or score<30:
        print("F")
    elif score>=80:
        print("A")
    elif 65<=score<80:
        print("B")
    elif 50<=score<65:
        print("C")
    elif 30<=score<50 and r>50:
        print("C")
    elif 30<=score<50:
        print("D")


### FIXED CODE ###

m = []
f = []
r = []
while(True):
    M,F,R=map(int,input().split())
    if M == -1 and F == -1 and R == -1:
        break
    else:
        m.append(M)
        f.append(F)
        r.append(R)
for i in range(len(m)):
    score = m[i]+f[i]
    if (m[i] == -1 or f[i] ==-1) or score<30:
        print("F")
    elif score>=80:
        print("A")
    elif 65<=score<80:
        print("B")
    elif 50<=score<65:
        print("C")
    elif 30<=score<50 and r[i]>=50:
        print("C")
    elif 30<=score<50:
        print("D")
import math
s = input()
k = int(input())

i = 0
while i < k:
    if s[i] != '1':
        break
    i += 1
print(s[i])


### FIXED CODE ###

s = input()
k = int(input())
if len(s) == 1 or k == 1:
    print(s[0])
else:
    i = 0
    while i < k - 1 and i < len(s):
        if s[i] != '1':
            break
        i += 1
    print(s[i])
print('Odd' if input()%2!=0 and input()%2!=0 else 'Even')

### FIXED CODE ###

a,b = map(int,input().split())
print('Odd' if a%2!=0 and b%2!=0 else 'Even')
N, M = list(map(int, input().split(' ')))
r = [ None for i in range(N) ]
duplicated = False
for i in range(M):
  s, c = list(map(int, input().split(' ')))
  if r[s-1] is not None:
	duplicated = True
    break
  r[s-1] = c

v = -1
if not duplicated:
  for i in range(N):
    if r[i] is None:
      r[i] = 0
  v = sum(r[i] * 10**i for i in range(N))
  if v < 100:
    v = -1

print(v)


### FIXED CODE ###

N, M = list(map(int, input().split(' ')))
r = [ None for i in range(N) ]

illegal = False
for i in range(M):
  s, c = list(map(int, input().split(' ')))
  if r[s-1] is not None and r[s-1] != c:
    illegal = True
    break
  r[s-1] = c

v = -1
if not illegal:
  for i in range(N):
    if r[i] is None:
      if i == 0 and N != 1:
        r[i] = 1
      else:
        r[i] = 0
  v = sum(r[i] * 10**(N-1-i) for i in range(N))
  if v < 10**(N-1) and not (N == 1 and v == 0):
    v = -1

print(v)
from functools import reduce
from operator import mul
N = int(input())
divide = []
for i in range(2,int( (10**12) / 2 ) + 1):
    while( N % i == 0):
        divide.append(i)
        N = int( N/i )
    if N ==1:
        break

i = 0
check = []
while(i < len(divide)-1):
    a = divide[:i+1]
    x = reduce(mul,a)
    b = divide[i+1:]
    y = reduce(mul,b)
    check.append(x + y)
    i += 1
    
ans = min(check) - 2
print(ans)

### FIXED CODE ###

N = int ( input() )
check_list = []
for i in range( 1, int( N**( 1/2 )+1 ) ):
    check = 0
    if N % i == 0:
        check = i + int( N / i ) - 2
        check_list.append(check)

print( min(check_list) )
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, q = map(int, input().split())
counter = [0]*n
edges = {}

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[b] = a

for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

for i in range(1, n):
    counter[i] += counter[edges[i+1]-1]

print(*counter)

### FIXED CODE ###

from collections import deque
n, Q = map(int, input().split())
edges = [[] for _ in range(n+1)]
count = [0]*(n+1)
q = deque()
q.append((1, 0))

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)
for _ in range(Q):
    p, x = map(int, input().split())
    count[p] += x

while(q):
    k = q.popleft()
    count[k[0]] += count[k[1]]
    for i in edges[k[0]]:
        if not i == k[1]:
            q.append((i, k[0]))

print(*count[1:])
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        for i in range(H):
            print(W*"#")
    print("")


### FIXED CODE ###

while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
            print(W*"#")
    print("")
A = [int(input()) for _ in range(5)]
ans = 0

for i in range(5):
    if A[i] % 10 == 0:
        ans += A[i]
    else:
        temp = (A//10)*10
        ans += temp

print(ans)  

### FIXED CODE ###

A = [int(input()) for _ in range(5)]
ans = 0
temp2 = 10

for i in range(5):
    if A[i] % 10 == 0:
        ans += A[i]
    else:
        temp = (A[i]//10)*10 + 10
        ans += temp
        if temp2 > A[i] % 10:
            temp2 = A[i] % 10


temp2 = 10 - temp2
ans = ans - temp2
print(ans)
a = int(input())
b = int(input())

if a + b = 3:
    print(3)
elif a + b = 4:
    print(2)
else:
    print(1)


### FIXED CODE ###

a = int(input())
b = int(input())

if a + b == 3:
    print(3)
elif a + b == 4:
    print(2)
else:
    print(1)
from math import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 1
for i in a:
    ans = lcm(ans,i)
for i in a:
    if (ans//i) % 2 == 0:
        print(0)
        exit()
print(((m//(ans//2))+1)//2)

### FIXED CODE ###

from fractions import gcd
def lcm(a,b):
    return (a*b)//gcd(a,b)
n,m = map(int,input().split())
a = list(map(int,input().split()))
ans = 1
for i in a:
    ans = lcm(ans,i)
for i in a:
    if (ans//i) % 2 == 0:
        print(0)
        exit()
print(((m//(ans//2))+1)//2)
n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    tree[u-1].append((v-1, w))
    tree[v-1].append((u-1, w))

visited = [False for _ in range(n)]
visited[0] = True
ans = [0 for _ in range(n)]

def journey(next, bit):
    for pos in next:
        v, w = pos
        if visited[v]: continue
        visited[v] = True
        if w % 2 == 0: 
            ans[v] = bit
            journey(tree[v], bit)
        else: 
            ans[v] = 1-bit
            journey(tree[v], 1-bit)
    
journey(tree[0], 0)
[print(x) for x in ans]

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n = int(input())
tree = [[] for _ in range(n)]
for _ in range(n-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    tree[u].append((v, w))
    tree[v].append((u, w))

ans = [0 for _ in range(n)]

def journey(u, p, bit):
    ans[u] = bit
    for v, w in tree[u]:
        if v == p: continue
        if w % 2 == 0: journey(v, u, bit)
        else: journey(v, u, 1-bit)
    
journey(0, -1, 0)
[print(x) for x in ans]