Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = [int(i) for i in input().split()]
used = [0] * (2 ** n)
used[0] = 1
s.sort(reverse=True)
a = 1
b = [s[0]]
for _ in range(n):
    c = b.copy()
    j = 0
    for i in b:
        while j < 2 ** n:
            if used[j] == 0 and s[j] < i:
                c.append(s[j])
                used[j] = 1
                break
            j += 1
        if j >= 2 ** n:
            print("No")
            exit()
    b = sorted(c, reverse=True)

print("Yes")


Fixed submission:
n = int(input())
s = [int(i) for i in input().split()]
used = [0] * (2 ** n)
used[0] = 1
s.sort(reverse=True)
a = 1
b = [s[0]]
for _ in range(n):
    c = b[:]
    j = 0
    for i in b:
        while j < 2 ** n:
            if used[j] == 0 and s[j] < i:
                c.append(s[j])
                used[j] = 1
                break
            j += 1
        if j >= 2 ** n:
            print("No")
            exit()
    b = sorted(c, reverse=True)

print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append([int(i) - 1 for i in input().split()])

day = 0
ind = [0] * n
while True:
    day += 1
    used = [0] * n
    for i in range(n):
        if ind[i] < n-1 and ind[a[i][ind[i]]] < n-1 and not used[i] and not used[a[i][ind[i]]] and a[a[i][ind[i]]][ind[a[i][ind[i]]]] == i:
            used[i] = 1
            used[a[i][ind[i]]] = 1
            ind[a[i][ind[i]]] += 1
            ind[i] += 1
    if sum(ind) == n*(n-1):
        print(day)
        break
    if sum(used) == 0:
        print(-1)
        break


Fixed submission:
n = int(input())
e = [[] for _ in range(n * n)]
co = [0] * (n * n)
for i in range(n):
    a = [int(i)-1 for i in input().split()]
    for j in range(n - 2):
        aa, bb = min(i, a[j]), max(i, a[j])
        cc, dd = min(i, a[j+1]), max(i, a[j+1])
        e[aa * n + bb].append(cc * n + dd)
        co[cc * n + dd] += 1

x = []
for i in range(n * n):
    if co[i] == 0:
        x.append(i)

ans = 0
while x:
    y = []
    for i in x:
        for j in e[i]:
            co[j] -= 1
            if co[j] == 0:
                y.append(j)
    x = y
    ans += 1
if max(co) > 0:
    print(-1)
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for _ in range(n):
    a.append([int(i) - 1 for i in input().split()])

day = 0
while True:
    day += 1
    used = [0] * n
    for i in range(n):
        if a[i] and a[a[i][0]] and not used[i] and not used[a[i][0]] and a[a[i][0]][0] == i:
            used[i] = 1
            used[a[i][0]] = 1
            del a[a[i][0]][0]
            del a[i][0]
    if sum([len(i) for i in a]) == 0:
        print(day)
        break
    if sum(used) == 0:
        print(-1)
        break


Fixed submission:
n = int(input())
e = [[] for _ in range(n * n)]
co = [0] * (n * n)
for i in range(n):
    a = [int(i)-1 for i in input().split()]
    for j in range(n - 2):
        aa, bb = min(i, a[j]), max(i, a[j])
        cc, dd = min(i, a[j+1]), max(i, a[j+1])
        e[aa * n + bb].append(cc * n + dd)
        co[cc * n + dd] += 1

x = []
for i in range(n * n):
    if co[i] == 0:
        x.append(i)

ans = 0
while x:
    y = []
    for i in x:
        for j in e[i]:
            co[j] -= 1
            if co[j] == 0:
                y.append(j)
    x = y
    ans += 1
if max(co) > 0:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=input().split()
if int(a)>=3200:
  print(b)
else:
  print('red')

Fixed submission:
a=int(input())
b=input()
if int(a)>=3200:
  print(b)
else:
  print('red')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
 
import sys
import math
# 以下を記述しないとTLEになる, 何故？
# ---- ここまで -----------------------

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


Fixed submission:
import bisect
s=input()
t=input()
s_set=set([i for i in s])
t_set=set([i for i in t])
if t_set-s_set&t_set:
  print(-1)
  exit()
a={}
for i in t_set:
  a[i]=[]
  for k,j in enumerate(s):
    if j==i:
      a[i].append(k)
  a[i].sort()
ans=0
j=0
for i in t:
  if a[i][-1]<j:
    ans+=len(s)
    j=0
  k=bisect.bisect_left(a[i],j)
  j=a[i][k]+1
print(ans+j)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
s_set=set([i for i in s])
t_set=set([i for i in t])
if t_set-s_set&t_set:
  print(-1)
  exit()
a={}
for i in t_set:
  a[i]=[]
  for k,j in enumerate(s):
    if j==i:
      a[i].append(k)
  a[i].sort()
ans=0
j=0
for i in t:
  if a[i][-1]<j:
    ans+=len(s)
    j=0
  for k in a[i]:
    if k>=j:
      j=k+1
      break
print(ans+j)
      

Fixed submission:
import bisect
s=input()
t=input()
s_set=set([i for i in s])
t_set=set([i for i in t])
if t_set-s_set&t_set:
  print(-1)
  exit()
a={}
for i in t_set:
  a[i]=[]
  for k,j in enumerate(s):
    if j==i:
      a[i].append(k)
  a[i].sort()
ans=0
j=0
for i in t:
  if a[i][-1]<j:
    ans+=len(s)
    j=0
  k=bisect.bisect_left(a[i],j)
  j=a[i][k]+1
print(ans+j)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, p = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for _ in range(m)]

for i in e:
    i[0] -= 1
    i[1] -= 1
    i[2] -= p

d = [-10**18] * n
ok1 = [False] * n
ok2 = [False] * n
d[0] = 0
ok1[0] = True
ok2[-1] = True

for _ in range(n):
    for a, b, c in e:
        if ok1[a]:
            d[b] = max(d[b], d[a] + c)
            ok1[b] = True
        if ok2[b]:
            ok2[a] = True
aa = d[:]

for _ in range(1):
    for a, b, c in e:
        if ok1[a]:
            d[b] = max(d[b], d[a] + c)
            ok1[b] = True
        if ok2[b]:
            ok2[a] = True

bb = d[:]

ok = False
for i in range(n):
    if ok1[i] and ok2[i]:
        if aa[i] != bb[i]:
            ok = True
if ok:
    print("-1")
else:
    print(max(aa[-1], 0))


Fixed submission:
n, m, p = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for _ in range(m)]

for i in e:
    i[0] -= 1
    i[1] -= 1
    i[2] -= p

d = [-10**18] * n
ok1 = [False] * n
ok2 = [False] * n
d[0] = 0
ok1[0] = True
ok2[-1] = True

for _ in range(n):
    for a, b, c in e:
        if ok1[a]:
            d[b] = max(d[b], d[a] + c)
            ok1[b] = True
        if ok2[b]:
            ok2[a] = True
aa = d[:]

for _ in range(n):
    for a, b, c in e:
        if ok1[a]:
            d[b] = max(d[b], d[a] + c)
            ok1[b] = True
        if ok2[b]:
            ok2[a] = True

bb = d[:]

ok = False
for i in range(n):
    if ok1[i] and ok2[i]:
        if aa[i] != bb[i]:
            ok = True
if ok:
    print("-1")
else:
    print(max(aa[-1], 0))
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
a=[0]
for i,j,k in zip(s[:-1],s[1:],range(1,len(s))):
  if i=="R" and j=="L":
    a.append(k)
  else:
    a.append(a[-1])

b=[len(s)-1]
for i,j,k in zip(s[-2::-1],s[:0:-1],range(len(s)-2,-1,-1)):
  if i=="R" and j=="L":
    b=[k]+b
  else:
    b=[b[0]]+b
c=[0]*len(s)
for i,j in enumerate(s):
  if j=="R":
    c[(b[i]-i)%2+b[i]]+=1
  else:
    c[a[i]-(i-a[i])%2]+=1
print(" ".join([str(i) for i in c]))

Fixed submission:
s=input()
a=[0]
for i,j,k in zip(s[:-1],s[1:],range(1,len(s))):
  if i=="R" and j=="L":
    a.append(k)
  else:
    a.append(a[-1])

b=[len(s)-1]*len(s)
for i,j,k in zip(s[-2::-1],s[:0:-1],range(len(s)-2,-1,-1)):
  if i=="R" and j=="L":
    b[k]=k
  else:
    b[k]=b[k+1]
c=[0]*len(s)
for i,j in enumerate(s):
  if j=="R":
    c[(b[i]-i)%2+b[i]]+=1
  else:
    c[a[i]-(i-a[i])%2]+=1
print(" ".join([str(i) for i in c]))

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
a=[0]
for i,j,k in zip(s[:-1],s[1:],range(1,len(s))):
  if i=="R" and j=="L":
    a.append(k)
  else:
    a.append(a[-1])

b=[len(s)-1]
for i,j,k in zip(s[-2::-1],s[:0:-1],range(len(s)-2,-1,-1)):
  if i=="R" and j=="L":
    b=[k]+b
  else:
    b=[b[0]]+b
c=[0]*len(s)
for i,j in enumerate(s):
  if j=="R":
    c[(b[i]-i)%2+b[i]]+=1
  else:
    c[a[i]-(i-a[i])%2]+=1
print(" ".join([str(i) for i in c]))

Fixed submission:
s=input()
a=[0]
for i,j,k in zip(s[:-1],s[1:],range(1,len(s))):
  if i=="R" and j=="L":
    a.append(k)
  else:
    a.append(a[-1])

b=[len(s)-1]*len(s)
for i,j,k in zip(s[-2::-1],s[:0:-1],range(len(s)-2,-1,-1)):
  if i=="R" and j=="L":
    b[k]=k
  else:
    b[k]=b[k+1]
c=[0]*len(s)
for i,j in enumerate(s):
  if j=="R":
    c[(b[i]-i)%2+b[i]]+=1
  else:
    c[a[i]-(i-a[i])%2]+=1
print(" ".join([str(i) for i in c]))
Buggy python submission (verdict: Runtime Error):
a,b=[int(i) for i in inpput().split()]
a,b=min(a,b),max(a,b)
c=b-a
if c%2==0:
  print(c//2)
else:
  print("IMPOSSIBLE")

Fixed submission:
a,b=[int(i) for i in input().split()]
a,b=min(a,b),max(a,b)
c=b+a
if c%2==0:
  print(c//2)
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
a=[0]*13
a[0]=1
for i in s:
  b=[0]*13
  for j,k in enumerate(a):
    b[(j*10)%13]+=k
  a=b[:]
  b=[0]*13
  if i=="?":
    for l in range(10):
      for j,k in enumerate(a):
        b[(j+l)%13]+=k
  else:
    for j,k in enumerate(a):
      b[(j+int(i))%13]+=k
  a=[j%(10**9+7) for j in b]
print(a[5]%(10**9+7))

Fixed submission:
s=input()
a=[0]*13
a[0]=1
for i in s:
  b=[0]*13
  for j,k in enumerate(a):
    b[(j*10)%13]+=k
  a=b[:]
  b=[0]*13
  if i=="?":
    for l in range(10):
      for j,k in enumerate(a):
        b[(j+l)%13]+=k
  else:
    for j,k in enumerate(a):
      b[(j+int(i))%13]+=k
  a=[j%(10**9+7) for j in b]
print(a[5]%(10**9+7))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for _ in range(n)]
b = [-1]
c = 1


def bi(a, x):
    i, j = 0, len(a) - 1
    while i != j:
        k = (i + j) // 2+1
        if a[k] < x:
            i = k
        else:
            j = k - 1
    if a[0] >= x:
        i -= 1
    return i


for i in a:
    j = bi(b, i)
    if j == -1:
        b = [i] + b
        c += 1
    else:
        b[j] = i
print(c)


Fixed submission:
n = int(input())
a = [int(input()) for _ in range(n)]
b = [-1]
c = 1


def bi(a, x):
    i, j = 0, len(a) - 1
    while i != j:
        k = (i + j) // 2
        if a[k] >= x:
            i = k+1
        else:
            j = k
    if a[-1] >= x:
        i =-1
    return i


for i in a:
    j = bi(b, i)
    if j == -1:
        b.append(i)
        c += 1
    else:
        b[j] = i
print(c)
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math
n,d=[int(i) for i in inpput().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)

Fixed submission:
import numpy as np
import math
n,d=[int(i) for i in input().split()]
x=[]
for _ in range(n):
  x.append(np.array([int(i) for i in input().split()]))
def dis(x,y):
  return int(np.sum((x-y)**2))
def iss(x):
  a=round(math.sqrt(x))
  return a**2==x
k=0
for i in range(n):
  for j in range(i+1,n):
    if iss(dis(x[i],x[j])):
      k+=1
print(k)
Buggy python submission (verdict: Runtime Error):
from math import factorial as f
n,k=[int(i) for i in input().split()]
d=[0]*n
for j in range(n-1):
  a,b=[int(i)-1 for i in input().split()]
  d[a]+=1
  d[b]+=1
m=1000000007
l=k*int(f(k-1)/f(k-d[0]))%m
for i in d[1:]:
  l=l*int(f(k-2)/f(k-i-1))%m
print(l)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, k = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
ans = 1
mod = 10**9+7


def dfs(i=0, r=-1):
    global ans
    if r == -1:
        ans *= k
        ans %= mod

        p = k-1
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)
    else:
        p = k-2
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)


dfs()
print(ans)

Buggy python submission (verdict: Runtime Error):
from math import factorial as f
n,k=[int(i) for i in input().split()]
d=[0]*n
for j in range(n-1):
  a,b=[int(i)-1 for i in input().split()]
  d[a]+=1
  d[b]+=1
m=1000000007
l=k*(f(k-1)//f(k-d[0]))%m
for i in d[1:]:
  l=l*(f(k-2)//f(k-i-1))%m
print(l)


Fixed submission:
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, k = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
ans = 1
mod = 10**9+7


def dfs(i=0, r=-1):
    global ans
    if r == -1:
        ans *= k
        ans %= mod

        p = k-1
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)
    else:
        p = k-2
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)


dfs()
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
if k > (n - 1)*(n - 2) // 2:
    print(-1)
else:
    ed = []
    for i in range(1, n):
        ed.append(" ".join(map(str, [1, i + 1])))
    kk = (n - 1)*(n - 2) - k
    if not kk:
        print(len(ed))
        print("\n".join(ed))
        exit()
    for i in range(1, n):
        for j in range(1, n):
            ed.append(" ".join(map(str, [i + 1, j + 1])))
            kk -= 1
            if not kk:
                print(len(ed))
                print("\n".join(ed))
                exit()


Fixed submission:
n, k = [int(i) for i in input().split()]
if k > (n - 1)*(n - 2) // 2:
    print(-1)
else:
    ed = []
    for i in range(1, n):
        ed.append(" ".join(map(str, [1, i + 1])))
    kk = (n - 1)*(n - 2)//2 - k
    if not kk:
        print(len(ed))
        print("\n".join(ed))
        exit()
    for i in range(1, n):
        for j in range(i+1, n):
            ed.append(" ".join(map(str, [i + 1, j + 1])))
            kk -= 1
            if not kk:
                print(len(ed))
                print("\n".join(ed))
                exit()
Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy as de
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for i,b in enumerate(s):
  d=de(a)
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=de(d)
print(a[-1]%1000000007)
    


Fixed submission:
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy as de
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for i,b in enumerate(s):
  d=de(a)
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=de(d)
print(a[-1]%1000000007)
    


Fixed submission:
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy as de
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for i,b in enumerate(s):
  d=de(a)
  k=0
  for j,c in enumerate(t):
    d[j]+=k
    if b==c:
      k+=a[j]
  d[-1]+=k
  a=de(d)
print(a[-1]%1000000007)
    


Fixed submission:
n,m =[int(i) for i in input().split()]
s=[int(i) for i in input().split()]
t=[int(i) for i in input().split()]
a=[1]*(m+1)
for b in s:
  d=a[:]
  k=0
  for j,c in enumerate(t):
    d[j]=(k+d[j])%1000000007
    if b==c:
      k=(k+a[j])%1000000007
  d[-1]=(k+d[-1])%1000000007
  a=d[:]
print(a[-1])
Buggy python submission (verdict: Runtime Error):
a,b=[int(i) for i in input().split()]
if b=1:
  print(0)
else:
  print(a-b)


Fixed submission:
a,b=[int(i) for i in input().split()]
if b==1:
  print(0)
else:
  print(a-b)
Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
b = [0] * n
b[0], b[1] = 1, 2
c = [0]*n
a = [int(input()) for _ in range(m)]
for i in a:
    c[i - 1] = 1
    b[i - 1] = 0
for i in range(2, n):
    if c[i] == 0:
        b[i] = b[i - 1] + b[i - 2]
print(b[-1])


Fixed submission:
n, m = [int(i) for i in input().split()]
b = [0] * (n+1)
b[0],b[1]=1,1
c = [0]*(n+1)
a = [int(input()) for _ in range(m)]
for i in a:
    c[i] = 1
    b[i]=0
for i in range(2, n+1):
    if c[i] == 0:
        b[i] = b[i - 1] + b[i - 2]
print(b[-1]%(10**9+7))

Buggy python submission (verdict: Runtime Error):
n, m = [int(i) for i in input().split()]
b = [0] * n
b[0], b[1] = 1, 2
c = [0]*n
a = [int(input()) for _ in range(m)]
for i in a:
    c[i - 1] = 1
    b[i - 1] = 0
for i in range(2, n):
    if c[i] == 0:
        b[i] = b[i - 1] + b[i - 2]
print(b[-1])


Fixed submission:
n, m = [int(i) for i in input().split()]
b = [0] * (n+1)
b[0],b[1]=1,1
c = [0]*(n+1)
a = [int(input()) for _ in range(m)]
for i in a:
    c[i] = 1
    b[i]=0
for i in range(2, n+1):
    if c[i] == 0:
        b[i] = b[i - 1] + b[i - 2]
print(b[-1]%(10**9+7))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  s, p = list(map(int, input().split()))
  a.append([s,-p,i])
a.sort()
for i in a:
  print(i[-1])


Fixed submission:
n = int(input())
a = []
for i in range(n):
  s, p = input().split()
  a.append([s,-int(p),i])
a.sort()
for i in a:
  print(i[-1]+1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
  s, p = map(int, input().split())
  a.append([s,-p,i])
a.sort()
for i in a:
  print(i[-1])

Fixed submission:
n = int(input())
a = []
for i in range(n):
  s, p = input().split()
  a.append([s,-int(p),i])
a.sort()
for i in a:
  print(i[-1]+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
u = [-1] * n
u[0] = 0
a = []
for i in range(n-1):
    u1, u2, w = [int(j) for j in input().split()]
    u1, u2 = u1 - 1, u2 - 1
    a.append((u1, u2, w))
a.sort()
i=0
while a:
    j=a[i]
    if u[j[0]] != -1:
        u[j[1]] = (u[j[0]] + j[2]) % 2
        del a[i]
        i=0
    elif u[j[1]] != -1:
        u[j[0]] = (u[j[1]] + j[2]) % 2
        del a[i]
        i = 0
    else:
        i+=1

for i in u:
    print(i)
    


Fixed submission:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(i) - 1 for i in input().split()]
    c += 1
    e[a].append([b, c])
    e[b].append([a, c])

c = [0] * n


def dfs(i=0, r=-1, co=0):
    c[i] = co
    for j, k in e[i]:
        if j != r:
            dfs(j, i, (co+k) % 2)


dfs()
print("\n".join(map(str, c)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
u = [-1] * n
u[0] = 0
a = []
for i in range(n-1):
    u1, u2, w = [int(j) for j in input().split()]
    u1, u2 = u1 - 1, u2 - 1
    a.append((u1, u2, w))
i=0
while a:
    j=a[i]
    if u[j[0]] != -1:
        u[j[1]] = (u[j[0]] + j[2]) % 2
        del a[i]
        i=0
    elif u[j[1]] != -1:
        u[j[0]] = (u[j[1]] + j[2]) % 2
        del a[i]
        i = 0
    else:
        i+=1

for i in u:
    print(i)
    


Fixed submission:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(i) - 1 for i in input().split()]
    c += 1
    e[a].append([b, c])
    e[b].append([a, c])

c = [0] * n


def dfs(i=0, r=-1, co=0):
    c[i] = co
    for j, k in e[i]:
        if j != r:
            dfs(j, i, (co+k) % 2)


dfs()
print("\n".join(map(str, c)))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
u = [-1] * n
u[0] = 0
a = []
for i in range(n-1):
    u1, u2, w = [int(j) for j in input().split()]
    u1, u2 = u1 - 1, u2 - 1
    a.append((u1, u2, w))
i=0
while a:
    j=a[i]
    if u[j[0]] != -1:
        u[j[1]] = (u[j[0]] + j[2]) % 2
        del a[i]
        i=-1
    elif u[j[1]] != -1:
        u[j[0]] = (u[j[1]] + j[2]) % 2
        del a[i]
        i = -1
    i+=1

for i in u:
    print(i)
    


Fixed submission:
import sys
sys.setrecursionlimit(1000000)


def input():
    return sys.stdin.readline()


n = int(input())
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = [int(i) - 1 for i in input().split()]
    c += 1
    e[a].append([b, c])
    e[b].append([a, c])

c = [0] * n


def dfs(i=0, r=-1, co=0):
    c[i] = co
    for j, k in e[i]:
        if j != r:
            dfs(j, i, (co+k) % 2)


dfs()
print("\n".join(map(str, c)))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input())
print(n-k+1)

Fixed submission:
n,k = map(int,input().split())
print(n-k+1)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

mx = 0
for i in range(n):
    l = 0
    r = 0
    for j in range(i): l = gcd(l, a[j])
    for j in range(i+1, n): r = gcd(r, a[j])
    mx = max(mx, gcd(l, r))

print(mx)


Fixed submission:
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

b = [0] * n
c = [0] * n

j = 0
for i, k in enumerate(a):
    b[i] = j
    j = gcd(j, k)

j = 0
for i, k in reversed(list(enumerate(a))):
    c[i] = j
    j = gcd(j, k)

ma = 0
for i in range(n):
    ma = max(ma, gcd(b[i], c[i]))
print(ma)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
c=[a,b,a-1,b-1];c.sort()
print(sum(c[-2:]))

Fixed submission:
a,b=map(int,input().split());c=[a,b,a-1,b-1];c.sort();print(sum(c[-2:]))
Buggy python submission (verdict: Runtime Error):
a=[]
for i invrangr(6):
  a.append(int(input()))
if a[4]-a[0]>a[5]:
  print(":(")
else:
  print("Yay!")

Fixed submission:
a=[]
for i in range(6):
  a.append(int(input()))
if a[4]-a[0]>a[5]:
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
a=[]
for i in range(5):
  a.append(int(input()))
a.sort(key=x:lambda (x-1)%10)
b=0
for i in range(5):
  if i==1:
    b+=a[i]
  else:
    c=(a[i]+1)//10+1
    b+=c*10
print(b)

Fixed submission:
a=[]
for i in range(5):
  a.append(int(input()))
a.sort(key=lambda x:(x-1)%10)
b=0
for i in range(5):
  if i==0:
    b+=a[i]
  else:
    c=(a[i]-1)//10+1
    b+=c*10
print(b)