Harryxun/stf_run huggingface dataset:
from collections import Counter


from operator import mul
from functools import reduce


def cmbf(n, r):
    if (n < r):
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


cmb = []
for i in range(0, 200001):
    cmb.append(cmbf(i, 2))

N = int(input())
A = list(map(int, input().split()))
c = Counter()
for i in A:
    c.update(str(i))
cmbL = {}
gsum = 0

for i in c.keys():
    tmp1 = cmb[int(c[i])]
    tmp2 = tmp1 - (tmp1 * (1 - 2/c[i]))
    cmbL[i] = [tmp1, tmp2]
    gsum += tmp1

for i in A:
    print(int(gsum - cmbL[str(i)][1]))


### FIXED CODE ###

from collections import Counter


from operator import mul
from functools import reduce


def cmbf(n, r):
    if (n < r):
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


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

for A_i in A:
    c[A_i] += 1

gsum = 0
for i in range(1, N + 1):
    if (c[i] != 0):
        gsum += cmbf(c[i], 2)

for i in A:
    print(gsum-(c[i]-1))
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
l, h =0,0
for i in range(M):
  if A[i]<X:l+=1
  if A[i]>X:h+=1
print(min(l,h))

### FIXED CODE ###

A,B,X=map(int,input().split())
if A<=X<=A+B:print("YES")
else: print("NO")
W, H, N = map(int, input().split())
P = [list(map(int, input().split())) for _ in range(N)]
X1, X2, Y1, Y2 = 0, W, 0, H

for x, y, a in P:
    if a == 1:
        X1 = max(X1, x)
    elif a == 2:
        X2 = min(X2, x)
    elif a == 3:
        Y1 = max(Y1, y)
    elif a == 4:
        Y2 = min(Y2, y)

if X2 <= X1 or Y2 <= Y1:
    S = 0
else:
    S = (X2 - X1) * (Y2 - Y1)

print(S)

### FIXED CODE ###

[a,b,c]=list(map(int,input().split()))
if a+b==c or a+c==b or b+c==a :
    print("Yes")
else:
    print("No")
#??????????????????
import heapq
def SME():
    start = 0
    parameter = 0.99
    ANS = [None]*N
    [end,L] = [int(x) for x in input().split()]
    Whole = [int(x) for x in input().split()]
    A = []
    C = set([i for i in range(N)])
    D = set([])
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        if None not in ANS[a[1]:a[1]+L] : continue
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] : continue
                else :
                    ANS[idx] = a[0]
                    D.add(idx)
                    count += 1
            except IndexError : continue
        if count > N * parameter : break
    for i in C.difference(D):
        if i < L:
            ANS[i] = min(Whole[:i+1])
        else :
            ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

ANS = SME()
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
N = input(int())
kisuu = -(-N // 2)
print(kisuu / N)

### FIXED CODE ###

N = int(input())
kisuu = -(-N // 2)
print(kisuu / N)
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

dist = [0] * (M-1)
for i in range(M-1):
    dist[i] = X[i+1] -X[i]

dist.sort()

if N >= M:
    print(0)
else:
    ans = sum(dist[:M-N])

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()

dist = [0] * (M-1)
for i in range(M-1):
    dist[i] = X[i+1] -X[i]

dist.sort()

if N >= M:
    ans = 0
else:
    ans = sum(dist[:M-N])

print(ans)
n,k=map(int,input().split())
List=list(map(int,input().split()))


li = []

for i in range(n):
    count=0
    for j in range(n):
        if List[i]>List[j]:
            count += 1
    li.append(count)

count2=0

for i in range(1,n):
    for j in range(i+1,n+1):
        if int(List[i-1]) > int(List[j-1]):
            count2 += 1

counted = k*count2 + sum(li)*k*(k-1)/2

ans = counted % 1000000007
print(int(ans))

### FIXED CODE ###

m,d=map(int,input().split())
count = 0

if d >= 22:

    for mm in range(1,m+1,1):
        
        for dd in range (22,d+1):
            dd = str(dd)
            d10 = int(dd[0])
            d1 = int(dd[1])
            
            if d1>=2 and mm == d1*d10 :
                count +=1
print(count)
def z(x):
  if x == 0:
  	return 10
  else:
    return x

menu = [int(input()) for i in range(5)]
dist = list(map(lambda x: x%10, menu))
dist2 = list(map(lambda x: z(x), dist))
idx = dist.index(min(dist2))
dist2.pop(idx)
inv = list(map(lambda x: 10-x, dist2))
cost = sum(menu) + sum(inv)
print(cost)

### FIXED CODE ###

dish = [0]*5
inv = [0]*5

for i in range(5):
  dish[i] = int(input())
  inv[i] = (10-dish[i]%10)%10
  
cost = sum(dish) + sum(inv) - max(inv)
print(cost)
import sys
sys.setrecursionlimit(200000)
 
n, k = map(int, input().split())
 
h = [int(i) for i in input().split()]
 
d = {}
 
def dp(p):
  if p in d:
    return d[p]
  if p == n-1:
    return 0
  m = min([dp(p+i)+abs(h[p]-h[p+i]) for i in reversed(range(1, min(n-p, k+1)))])
  d[p] = m
  return m

print(dp(0))

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[1]-h[0])
for i in range(2, n):
  a = [0] * min(i,k)
  for j in range(1, min(i,k)+1): 
    a[j-1] = dp[i-j]+abs(h[i]-h[i-j])
  dp[i] = min(a)

print(dp[-1])
n=int(input())
#d = [list(map(int,input().split())) for _ in range(s)]

def p(val):
    print(val)

count = 0

#cは1以上で、問題文からN-1 a*b <=N-1のものをもとめる
#aを1からふやしてく、cはaとbが決まれば自動歴に決まるので、
for i in range(1,n):
    

    

        
p(count)

### FIXED CODE ###


n=int(input())
#d = [list(map(int,input().split())) for _ in range(s)]

def p(val):
    print(val)

count = 0

#cは1以上で、問題文からN-1 a*b <=N-1のものをもとめる
#aを1からふやしてく、cはaとbが決まれば自動歴に決まるので、
for i in range(1,n):
    count +=(n-1)//i

    

        
p(count)
r,p=int(input()),3.141592653589
print(p*(r**2),p*r*2)


### FIXED CODE ###

import math;r=float(input());print(math.pi*(r**2),math.pi*r*2)
A=sorted(list(map(int,input().split())))

r = (A[0]+A[1])/2
for i in range(2,len(A)):
    r=(r+A[i])/2
    
print(r)

### FIXED CODE ###

N=int(input()) #not needed for Python, but needed for competition
A=sorted(list(map(int,input().split())))

r = (A[0]+A[1])/2
for i in range(2,len(A)):
    r=(r+A[i])/2
    
print(r)
A,B,C,D = map(int, input().split())

if (A+B) > (C+D):
    print('Left')
elif (A+B) == (C+D:
    print('Balanced')
else:
    print('Right')

### FIXED CODE ###

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

if (A+B) > (C+D):
    print('Left')
elif (A+B) == (C+D):
    print('Balanced')
else:
    print('Right')
h,w=map(int,input().split())
l=[]
for i in range(h):
    l.append(list(input()))
for i in range(h):
    for j in range(w):
        if l[i][j]=='.':
            s=[i,j]
v=[[0 for i in range(w)] for j in range(h)]       
v[s[0]][s[1]]=1
mc=0
ms=s
q=[[s,0]]
while q:
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            if mc<c+1:
                mc=c+1
                ms=[nx,ny]
v=[[0 for i in range(w)] for j in range(h)]       
v[ms[0]][ms[1]]=1
ans=0
q=[[ms,0]]
while q:
    p=q.pop(0)
    x=p[0][0]
    y=p[0][1]
    c=p[1]
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    for j in k:
        nx=x+j[0]
        ny=y+j[1]
        if 0<=nx<h and 0<=ny<w and l[nx][ny]=='.' and v[nx][ny]==0:
            v[nx][ny]=1
            q.append([[nx,ny],c+1])
            ans=max(ans,c+1)
                #ms=[nx,ny]
print(ans)

### FIXED CODE ###

al=list('abcdefghijklmnopqrstuvwxyz')
a=input()
print(al[al.index(a)+1])
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  	return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)


  

### FIXED CODE ###

def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  return ansc

a,b,c,d=map(int , input().strip().split() )
tl=b-a+1

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
#print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)
W, H, x, y, r = [int(i) for i input().split()]
if x < 0 or y < 0:
    print("No")
elif x+y <= W and y+r <= H:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

W, H, x, y, r = [int(i) for i in input().split()]
if x < 0 or y < 0:
    print("No")
elif x+r <= W and y+r <= H:
    print("Yes")
else:
    print("No")
S = input()

if S ='ABC':
  print('ARC')
else:
  print('ABC')

### FIXED CODE ###

S = input()

if S =='ABC':
  print('ARC')
else:
  print('ABC')
import itertools

N, M, Q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(Q)]

ans = 0
P = [[i for i in range(1, M+1)] for _ in range(N)]

# print(R)
for comb in itertools.product(*P):
    flag = True
    p = comb[0]
    for i in comb:
        if i < p:
            flag = False
            break
        p = i

    if not flag:
        continue

    # print(comb)

    temp = 0
    for abcd in ABCD:
        a, b, c, d = abcd
        if comb[b-1] - comb[a-1] == c:
            temp += d
    if temp >= ans:
        ans = temp

print(ans)


### FIXED CODE ###

import math

DEBUG = False

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

if DEBUG:
    ans = 0
    for x in range(1, N+1):
        term1 = math.floor(A*x/B)
        term2 = A * math.floor(x/B)
        temp = term1 - term2
        print("x: {}, temp: {}, term1: {}, term2: {}".format(x, temp, term1, term2))
        ans = max(ans, temp)
    print(ans)

print(math.floor(A*min(B-1, N)/B)-A*math.floor(min(B-1, N)/B))
a, b = input().split()

x = (a+b)/2

if x % 2 == 0:
  print(x)
else:
  print(1+(a+b)//2)

### FIXED CODE ###

a, b = (int(x) for x in input().split())
 
x = (a+b)/2
 
if (a+b) % 2 == 0:
  print(int(x))
else:
  print(int(1+(a+b)//2))
n, q = map(int, input().split())
s_list = list(input())
l_r_list = [list(map(int, input().split())) for _ in range(q)]
c_sum= [0]
su = 0
for i in range(n):
    if s_list[i] == "A" and s_list[i + 1] == "C":
        su += 1
    c_sum.append(su)
for l, r in l_r_list:
    print(c_sum[r - 1] - c_sum[l - 1])

### FIXED CODE ###

n, q = map(int, input().split())
s_list = list(input())
l_r_list = [list(map(int, input().split())) for _ in range(q)]
c_sum = [0]
su = 0
for i in range(n - 1):
    if s_list[i] == "A" and s_list[i + 1] == "C":
        su += 1
    c_sum.append(su)
for l, r in l_r_list:
    print(c_sum[r - 1] - c_sum[l - 1])
while 1:
????????T,U,N,E,W,S=1,6,5,3,4,2
????????n=int(raw_input())
????????if n==0: break
????????ans=T
????????for i in range(n):
????????????????di=raw_input()
????????????????if di=="North":
????????????????????????N,T,S,U=T,S,U,N
????????????????elif di=="East":
????????????????????????E,U,W,T=T,E,U,W
????????????????elif di=="South":
????????????????????????T,S,U,N=N,T,S,U
????????????????elif di=="West":
????????????????????????T,E,U,W=E,U,W,T
????????????????elif di=="Left":
????????????????????????E,S,W,N=S,W,N,E
????????????????elif di=="Right":
????????????????????????S,W,N,E=E,S,W,N
????????????????else:
????????????????????????print '[*] Error ->',di
????????????????????????raise IOError
????????????????ans+=T
????????print ans

### FIXED CODE ###

while(1):
    num=int(raw_input())
    if num==0:
        break
    else:
        d=[0,1,2,3,4,5,6]
        sum=1
        for i in range(num):
            dir=num=raw_input()
            if dir=="North":
                d=[0,d[2],d[6],d[3],d[4],d[1],d[5]]
            elif dir=="East":
                d=[0,d[4],d[2],d[1],d[6],d[5],d[3]]
            elif dir=="West":
                d=[0,d[3],d[2],d[6],d[1],d[5],d[4]]
            elif dir=="South":
                d=[0,d[5],d[1],d[3],d[4],d[6],d[2]]
            elif dir=="Right":
                d=[0,d[1],d[3],d[5],d[2],d[4],d[6]]
            else:
                d=[0,d[1],d[4],d[2],d[5],d[3],d[6]]
            sum=sum+d[1]
        print sum
n,k=[int(i) for i in input().split()]
l=[int(i) for i in input().split()]
l.sort()
a=0
for i in range(k):
  a+=l[n-1-i]
print(a)

### FIXED CODE ###

l=[int(i) for i in input().split()]
if (l[0]%3)==0 or (l[1]%3)==0 or (l[0]+l[1])%3==0:
  print ("Possible")
else:
  print ("Impossible")
n,x = map(int, input().split())
l = list(map(int, input().split()))
cnt = 1

for i in range(2,n+2):
  if sum(l[:i-1]) <= x:
    cnt += 1
    
print(cnt)

### FIXED CODE ###

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

if x < a:
  print(0)
else:
  print(10)
N = int(raw_input())

numbers = map(int, raw_input().split())

min_num = min(numbers)
max_num = max(numbers)
min_cost = None 


for result in xrange(min_num, max_num+1):
    cost = 0 
    for number in numbers:
        cost += (number - result)**2
    if min_cost:
        if min_cost >= cost:
            min_cost = cost 
    else:
        min_cost = cost
print min_cost


### FIXED CODE ###

N = int(raw_input())

sum = 0

for i in xrange(N+1):
     sum += i

print sum
K = int(input())
S = input()
if len(S) >= K:
  print(S[:K], '...', sep='')
else:
  print(S)

### FIXED CODE ###

hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = 3
N = input()
r = int(N[-1])
if r in hon:
  print('hon')
elif r in pon:
  print('pon')
else:
  print('bon')
N, L = int(input()), int(input())

flavors = [x + L - 1 for x in range(1, N + 1)]
planned_pie = sum(flavors)
eat = min(flavors)
eat_abs = -min([abs(x) for x in flavors])
print([planned_pie - max(eat, eat_abs) if planned_pie <
       0 else planned_pie - max(eat, eat_abs)][0])

### FIXED CODE ###

N, L = map(int, input().split())
flavors = [x + L - 1 for x in range(1, N + 1)]
flavors.remove(min(flavors, key=abs))
# flavors.pop(flavors.index(min(flavors, key=abs)))
print(sum(flavors))
import sys
from functools import reduce
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
c = [gcd_list(a[:i] + a[i+1:]) for i in range(n%10)]
c.sort()
if n == 2:
    print(c[1])
else:
    print(c[2])

### FIXED CODE ###

import sys
def gcd(m, n):
    if n == 0:
        n, m = m, n
    r = m % n
    return gcd(n, r) if r else n

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
l, r = [0]*(n+1), [0]*(n+1)
for i in range(1, n+1):
    l[i] = gcd(l[i-1], a[i-1])
    r[n-i] = gcd(r[n-i+1], a[n-i])
ans = 0
for i in range(n):
    m = gcd(l[i], r[i+1])
    if ans < m:
        ans = m
print(ans)
def check(x, y, flag):
	farm[x][y] = "$"
	if farm[x + 1][y] != "$" and farm[x + 1][y] == flag : check(x + 1, y, flag)
	if farm[x - 1][y] != "$" and farm[x - 1][y] == flag : check(x - 1, y, flag)
	if farm[x][y + 1] != "$" and farm[x][y + 1] == flag : check(x, y + 1, flag)
	if farm[x][y - 1] != "$" and farm[x][y - 1] == flag : check(x, y - 1, flag)

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	farm = []
	farm.append(list("$" * (w + 2)))
	for i in range(0, h):
		farm.append(list("$" + raw_input() + "$"))
	farm.append(list("$" * (w + 2)))
	
	count = 0
	for i in range(0, h):
		for j in range(0, w):
			if farm[i + 1][j + 1] != "$":
				check(i + 1, j + 1, farm[i + 1][j + 1])
				count += 1
				
	print count

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

def check(x, y, flag):
	farm[x][y] = "$"
	if farm[x + 1][y] == flag : check(x + 1, y, flag)
	if farm[x - 1][y] == flag : check(x - 1, y, flag)
	if farm[x][y + 1] == flag : check(x, y + 1, flag)
	if farm[x][y - 1] == flag : check(x, y - 1, flag)
	return 1

while True:
	h,w = map(int, raw_input().split())
	if h == 0 and w == 0 : break

	farm = []
	farm.append(list("$" * (w + 2)))
	for i in range(0, h):
		farm.append(list("$" + raw_input() + "$"))
	farm.append(list("$" * (w + 2)))
	
	count = 0
	for i in range(0, h):
		for j in range(0, w):
			if farm[i + 1][j + 1] != "$":
				count += check(i + 1, j + 1, farm[i + 1][j + 1])
				
	print count
import math

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

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

x = b//c - (a - 1)//c 

y = b//d - (a - 1)//d

cd = lcm(c, d)

z = b//cd - (a - 1)//cd

ans = b - a + 1 - x - y + z
print(ans)


### FIXED CODE ###

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

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)
x = b//c - (a - 1)//c

y = b//d - (a - 1)//d

cd = lcm(c, d)

z = b//cd - (a - 1)//cd

ans = b - a + 1 - x - y + z
print(ans)
n = int(input())
S = map(int, input().split())
q = int(input())
T = map(int, input().split())

def binary_search(A, key):
    left = 0
    right = n
    while left < right:
        mid = (left + right)/2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

cnt = 0
for i in T:
    if binary_search(S, i):
        cnt += 1

print(cnt)

### FIXED CODE ###

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))


def binary_search(A, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right)/2)
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid + 1
    return False

cnt = 0
for i in T:
    if binary_search(S, i):
        cnt += 1

print(cnt)
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a-A)+abs(b-B)+abs(c-C)-30
        else:
            return INF
    ret1 = dfs(cur+1, a, b, c)
    ret2 = dfs(cur+1, a+L[cur], b, c) + 10
    ret3 = dfs(cur+1, a, b+L[cur], c) + 10
    ret4 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret1 + ret2 + ret3 + ret4)

print(dfs(0,0,0,0))


### FIXED CODE ###

N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

ans = 10 ** 10

# 4bit search
for i in range(4**N):
    mask = i
    NowCost = 0
    Group0 = []
    Group1 = []
    Group2 = []
    NonGroup = []
    for j in range(N-1, -1, -1):
        if mask % 4 == 0:
            Group0.append(L[j])
            mask //= 4
        elif mask % 4 == 1:
            Group1.append(L[j])
            mask //= 4
        elif mask % 4 == 2:
            Group2.append(L[j])
            mask //= 4
        else:
            NonGroup.append(L[j])
            mask //= 4
    if len(Group0) == 0 or len(Group1) == 0 or len(Group2) == 0:
        continue
    NowCost += 10 * (len(Group0) - 1)
    LengthGroup0 = sum(Group0)
    NowCost += 10 * (len(Group1) - 1)
    LengthGroup1 = sum(Group1)
    NowCost += 10 * (len(Group2) - 1)
    LengthGroup2 = sum(Group2)
    NowCost += abs(A - LengthGroup0)
    NowCost += abs(B - LengthGroup1)
    NowCost += abs(C - LengthGroup2)
    ans = min(ans, NowCost)
print(ans)
n=int(input())
t, a=map(int, input().split())
h=list(int(i) for i input().split())
temp=[abs(a-(t-k*0.006)) for k in h]
print(temp.index(min(temp))+1)



### FIXED CODE ###

n=int(input())
t, a=map(int, input().split())
h=list(int(i) for i in input().split())
temp=[abs(a-(t-k*0.006)) for k in h]
print(temp.index(min(temp))+1)
A,B=map(int,input().split())
if A-2*B>=0:
  print(A-2B)
else:
  print('0')

### FIXED CODE ###

A,B=map(int,input().split())
if A-2*B>=0:
  print(A-2*B)
else:
  print(0)
# input data
n=int(input())
u=[]
v=[]
w=[]
for i in range(0,n-1):
	ui,vi,wi = map(int, input().split())
	u.append(ui)
	v.append(vi)
	w.append(wi%2)


# solve
ans=[]
for i in range(0,n+1):
	ans.append(-1)

_neighbors=[]
for i in range(0,n+1):
	_neighbors.append([])

for i in range(0,n-1):
	_neighbors[u[i]].append([v[i], w[i]])
	_neighbors[v[i]].append([u[i], w[i]])

# paint v with c=0,1 and its neighbors
def bfs(u,c):
	if ans[u] != -1:
		return

	ans[u] = c

	for vw in _neighbors[u]:
		if vw[1] == 0:
			bfs(vw[0],c)
		else:
			bfs(vw[0],1-c)

bfs(1,0)

for i in range(1,n+1):
	print(ans[i])


### FIXED CODE ###

import sys

sys.setrecursionlimit(100000)

# input data
n=int(input())
u=[]
v=[]
w=[]
for i in range(0,n-1):
	ui,vi,wi = map(int, input().split())
	u.append(ui)
	v.append(vi)
	w.append(wi%2)


# solve
ans=[]
for i in range(0,n+1):
	ans.append(-1)

_neighbors=[]
for i in range(0,n+1):
	_neighbors.append([])

for i in range(0,n-1):
	_neighbors[u[i]].append([v[i], w[i]])
	_neighbors[v[i]].append([u[i], w[i]])

# paint v with c=0,1 and its neighbors
def bfs(u,c):
	if ans[u] != -1:
		return

	ans[u] = c

	for vw in _neighbors[u]:
		if vw[1] == 0:
			bfs(vw[0],c)
		else:
			bfs(vw[0],1-c)

bfs(1,0)

for i in range(1,n+1):
	print(ans[i])