Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
*l, = map(int, input().split())
def has_duplicates(seq):
    return len(seq) != len(set(seq))
S = has_duplicates(l)
if str(S) == 'False':
  print('YES')
elif str(S) == 'True':
  print('NO')



Fixed submission:
S, T = input().split()
A, B = map(int,input().split())
U = input()
if U == S:
  print(A-1, B)
elif U == T:
  print(A, B-1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
*l, = map(int, input().split())
L = sorted(l)
S = 0
for i in range(n):
  for l in range(n):
    if L[i] == L[l]:
      S = 1
if S == 0:
  print('Yes')
elif S == 1:
  print('No')

Fixed submission:
S, T = input().split()
A, B = map(int,input().split())
U = input()
if U == S:
  print(A-1, B)
elif U == T:
  print(A, B-1)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
X = 0
for i in range(len(S)):
  S = S[-1] + S[:-1] 
  print(S)
  if S == T:
    X = 1

if X == 0:
  print('No')
elif X == 1:
  print('Yes')

Fixed submission:
a,b,c = input().split(' ')
A = abs(int(a)-int(b))
B = abs(int(b)-int(c))
C = abs(int(c)-int(a))
N = A + B + C -max(A, B, C)
print(N)
Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
A = sorted(list(map(int, sys.stdin.readline().split())))

count = 0

for i in range(N):
    bool = True
    for j in range(i):
        if A[i] % A[j] == 0:
            bool = False
            break
    if bool:
        count += 1
        
if A[0] == A[1]:
    count -= 1
        
print(count)


Fixed submission:
import sys
N = int(input())
A = sorted(list(map(int, sys.stdin.readline().split())))

d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

A = sorted(set(A))
t = [True] * (10 ** 6 + 1)
for a in A:
    if d[a] > 1:
        t[a] = False
    for i in range(a + a, 10 ** 6 + 1, a):
        t[i] = False
print(sum(1 for a in A if t[a]))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A = list(map(int, sys.stdin.readline().split()))

ans = 1
flag = True
for a in A:
    ans *= a
    if ans > 10 ** 18:
        flag = False
    else:
        flag = True

if flag:
    print(ans)
else:
    print(-1)
        

Fixed submission:
import sys
N = int(input())
A = sorted(list(map(int, sys.stdin.readline().split())))

ans = 1
flag = True
flag_zero = False
for a in A:
    ans *= a
    if ans > 10 ** 18:
        flag = False
        break
    if a == 0:
        flag_zero = True
        break

if flag:
    if not flag_zero:
        print(ans)
    else:
        print(0)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
i = list(map(int, input().split()))
N = i[0]
K = i[1]

p = list(map(int, input().split()))
max_s = 0
s_current = 0

for i in range(N - K + 1):
    if i == 0:
        for j in range(K):
            p_list = [p[k] for k in range(K)]
            max_s = sum(p_list)
            s_current = max_s
    else:
        s_current = s_current - p[i - 1] + p[i + K - 1]
        if s_current > max_s:
            max_s = s_current
    
ans = (max_s + K) / 2.0
print(ans)

Fixed submission:
if __name__ == '__main__':
    import sys
    
    i = list(map(int, input().split()))
    N = i[0]
    K = i[1]
    
    p = list(map(int, sys.stdin.readline().split()))
    max_s = 0
    s_current = 0
    
    for i in range(N - K + 1):
        if i == 0:
            p_list = p[:K]
            max_s = sum(p_list)
            s_current = max_s
        else:
            s_current = s_current - p[i - 1] + p[i + K - 1]
            if s_current > max_s:
                max_s = s_current
        
    ans = (max_s + K) / 2.0
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

N = int(sys.stdin.readline())
L = np.array(list(map(int, sys.stdin.readline().split())))
L = np.sort(L)

count = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        c_cand = L[j + 1:]
        c_num = np.count_nonzero(c_cand < a + b)
        count += c_num
        
print(count)

Fixed submission:
import sys
import bisect

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
L.sort()

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        c = bisect.bisect_left(L, L[i]+L[j])
        if c > j:
            count += c - j - 1
        else:
            pass
        
print(count)

Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np

N = int(sys.stdin.readline())
L = np.array(list(map(int, sys.stdin.readline().split())))
L = np.sort(L)

count = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        c_cand = L[j + 1:]
        c_num = np.count_nonzero(c_cand < a + b)
        count += c_num
        
print(count)

Fixed submission:
import sys
import bisect

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
L.sort()

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        c = bisect.bisect_left(L, L[i]+L[j])
        if c > j:
            count += c - j - 1
        else:
            pass
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

N = int(input())
L = np.array(list(map(int, sys.stdin.readline().split())))
L = np.sort(L)

count = 0

for i in range(N - 2):
    a = L[i]
    for j in range(i + 1, N - 1):
        b = L[j]
        c_cand = L[j + 1:]
        c_num = np.count_nonzero((c_cand < a + b) & (a < b + c_cand) & (b < a + c_cand))
        count += c_num
        
print(count)

Fixed submission:
import sys
import bisect

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
L.sort()

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        c = bisect.bisect_left(L, L[i]+L[j])
        if c > j:
            count += c - j - 1
        else:
            pass
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import itertools

N = int(input())
L = list(map(int, sys.stdin.readline().split()))

c_list = list(itertools.combinations(L, 3))
count = 0

for v in c_list:
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        count += 1
        
print(count)

Fixed submission:
import sys
import bisect

N = int(sys.stdin.readline())
L = list(map(int, sys.stdin.readline().split()))
L.sort()

count = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        c = bisect.bisect_left(L, L[i]+L[j])
        if c > j:
            count += c - j - 1
        else:
            pass
        
print(count)
Buggy python submission (verdict: Runtime Error):
import sympy

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

def fctr1(n): 
    f = {}
    c = 0
    r = int(n ** 0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c != 0:
            f[i] = c
            c = 0
    if n != 1:
        f[n] = 1
    return f


a = fctr1(A)
b = fctr1(B)


cd_dic = {1: 1}
key_list = [1]

for k, v in a.items():
    if k in b:
        key_list.append(k)
        n = min(v, b[k])
        cd_dic[k] = n

print(len(cd_dic))


Fixed submission:
A, B = map(int, input().split())

def fctr1(n): 
    f = {}
    c = 0
    r = int(n ** 0.5)
    for i in range(2, r + 2):
        while n % i == 0:
            c += 1
            n = n // i
        if c != 0:
            f[i] = c
            c = 0
    if n != 1:
        f[n] = 1
    return f


a = fctr1(A)
b = fctr1(B)


cd_dic = {1: 1}
key_list = [1]

for k, v in a.items():
    if k in b:
        key_list.append(k)
        n = min(v, b[k])
        cd_dic[k] = n

print(len(cd_dic))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
    
ans = int(sum(A))

print(ans)

Fixed submission:
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    max = A[N - 1]
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
        if count == M:
            break
    A.sort()
    
ans = int(sum(A))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))

for _ in range(M):
    a = np.max(A)
    n = A.argmax()
    A[n] = int(a / 2)
    
ans = sum(A)

print(ans)

Fixed submission:
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    max = A[N - 1]
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
        if count == M:
            break
    A.sort()
    
ans = int(sum(A))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

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

for _ in range(M):
    a = max(A)
    n = A.index(a)
    A[n] = int(a / 2)
    
ans = sum(A)

print(ans)

Fixed submission:
import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    max = A[N - 1]
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
        if count == M:
            break
    A.sort()
    
ans = int(sum(A))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x

def dfs(v,parent,add):
    value[v] += add
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x,v,value[v])

dfs(1,0,0)

answer = ' '.join(map(str,value[1:]))
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys

N = int(input())
s = [collections.Counter(sys.stdin.readline().rstrip()) for _ in range(N)]

counted = []
count = 0
for s_count in s:
    if s_count not in counted:
        n = s.count(s_count)
        counted.append(s_count)
        count += n * (n - 1) // 2
            
print(count)

Fixed submission:
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


count = 0        
for n in counted.values():
    count += n * (n - 1) // 2
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
s = [input() for _ in range(N)]

s_count_list = [collections.Counter(S) for S in s]

counted = []
count = 0
for s_count in s_count_list:
    if s_count not in counted:
        n = s_count_list.count(s_count)
        counted.append(s_count)
        count += n * (n - 1) // 2
            
print(count)

Fixed submission:
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


count = 0        
for n in counted.values():
    count += n * (n - 1) // 2
            
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

N = int(input())
s = [input() for _ in range(N)]

s_count_list = [collections.Counter(S) for S in s]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if s_count_list[i] == s_count_list[j]:
            ans += 1
            
print(ans)

Fixed submission:
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


count = 0        
for n in counted.values():
    count += n * (n - 1) // 2
            
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

mod = 10 ** 9 + 7

# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]  # 後ろから一桁ずつみていく
    if x == "?":
        for k in range(10): # ?が0~9であった時、それぞれのケースについて調べる
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= mod
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])

Fixed submission:
S = input()

mod = 10 ** 9 + 7

# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]  # 後ろから一桁ずつみていく
    if x == "?":
        for k in range(10): # ?が0~9であった時、それぞれのケースについて調べる
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= mod
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= mod
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

import numpy as np
K = np.array([[0] * N for _ in range(N)])
for i in range(N):
    K[i][i] = 1
    if i != N - 1:
        K[i][i + 1] = 1
    else:
        K[i][0] = 1
        
X = np.linalg.solve(K, A)
X = [str(int(2 * x)) for x in X]
ans = " ".join(X)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))

S = sum(A)
A_even_sum = 0
for i in range(1, N - 1, 2):
    A_even_sum += A[i]
X = []
x_1 = (S - 2 * A_even_sum)
X.append(x_1)
for i in range(N - 1):
    x_next = int(2 * A[i] - X[i])
    X.append(x_next)
    X[i] = str(X[i])
X[N - 1] = str(X[N - 1])

ans = " ".join(X)
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

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

C_count = B // C - A // C
if A % C == 0:
    C_count += 1
D_count = B // D - A // D
if A % D == 0:
    D_count += 1
CD_count = B // lcm(C, D) - A // lcm(C, D)
if A % lcm(C, D) == 0:
    CD_count += 1
div_count = C_count + D_count - CD_count
ans = B - A + 1 - div_count
print(ans)

Fixed submission:
from fractions import gcd
A, B, C, D = map(int, input().split())

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

C_count = B // C - A // C
if A % C == 0:
    C_count += 1
D_count = B // D - A // D
if A % D == 0:
    D_count += 1
CD_count = B // lcm(C, D) - A // lcm(C, D)
if A % lcm(C, D) == 0:
    CD_count += 1
div_count = C_count + D_count - CD_count
ans = B - A + 1 - div_count
print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))

x = 0
for i in range(N + 1):
    if i == 0:
        x = 0
    else:
        x += L[i - 1]
        if x > X:
            ans = i
            break

print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
# 行数を取得
import sys
list=[]
for line in sys.stdin:
    list.append(line)

NandX=list[0].split()

N=int(NandX[0])
X=int(NandX[1])

L=list[1].split()
D=0
i=0

if N==1:
    print(1)
else:
    while D<=X and i<=N-1:
        D=D+int(L[i])
        i+=1
        
    if i==N and D<=X:
        print(N+1)
    else:
        print(i)

Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
# 行数を取得
import sys
list=[]
for line in sys.stdin:
    list.append(line)

NandX=list[0].split()
N=int(NandX[0])
X=int(NandX[1])

L=list[1].split()
D=0
i=0
while D<=X:
    D=D+int(L[i])
    i+=1
print(i)


Fixed submission:
# coding: utf-8
# Your code here!
# 行数を取得
import sys
list=[]
for line in sys.stdin:
    list.append(line)

NandX=list[0].split()

N=int(NandX[0])
X=int(NandX[1])

L=list[1].split()
D=0
i=0

if N==1:
    print(1)
else:
    while D<=X and i<=N-1:
        D=D+int(L[i])
        i+=1
        
    if i==N and D<=X:
        print(N+1)
    else:
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
N, M = map(int, sys.stdin.readline().split())
a = [int(sys.stdin.readline()) for _ in range(M)]

MOD = 10 ** 9 + 7

list = [0] * N

for i in range(N):
    if i == 0:
        if (i + 1) in a:
            list[i] = 0
        else:
            list[i] = 1
    elif i == 1:
        if (i + 1) in a:
            list[i] = 0
        elif i in a:
            list[i] = 1
        else:
            list[i] = 2
    else:
        if (i + 1) in a:
            list[i] = 0
        else:
            list[i] = (list[i - 1] + list[i - 2]) % MOD
            
ans = list[N - 1]
print(ans)

Fixed submission:
import sys
N, M = map(int, sys.stdin.readline().split())
a = [int(sys.stdin.readline()) for _ in range(M)]

MOD = 10 ** 9 + 7

list = [0] * N

if M > 0:
    j = 0
    for i in range(N):
        if i == 0:
            if a[j] == 1:
                list[i] = 0
            else:
                list[i] = 1
        elif i == 1:
            if a[j] == 2:
                list[i] = 0
            elif a[0] == 1:
                list[i] = 1
            else:
                list[i] = 2
        else:
            if a[j] == i + 1:
                list[i] = 0
            else:
                list[i] = (list[i - 1] + list[i - 2]) % MOD
        if i + 1 == a[j] and j < M - 1:
            j += 1

else:
    for i in range(N):
        if i == 0:
            list[i] = 1
        elif i == 1:
            list[i] = 2
        else:
            list[i] = (list[i - 1] + list[i - 2]) % MOD
            
ans = list[N - 1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]

MOD = 10 ** 9 + 7

list = [0] * N

for i in range(N):
    if i == 0:
        if (i + 1) in a:
            list[i] = 0
        else:
            list[i] = 1
    elif i == 1:
        if (i + 1) in a:
            list[i] = 0
        elif i in a:
            list[i] = 1
        else:
            list[i] = 2
    else:
        if (i + 1) in a:
            list[i] = 0
        else:
            list[i] = (list[i - 1] + list[i - 2]) % MOD
            
ans = list[N - 1]
print(ans)

Fixed submission:
import sys
N, M = map(int, sys.stdin.readline().split())
a = [int(sys.stdin.readline()) for _ in range(M)]

MOD = 10 ** 9 + 7

list = [0] * N

if M > 0:
    j = 0
    for i in range(N):
        if i == 0:
            if a[j] == 1:
                list[i] = 0
            else:
                list[i] = 1
        elif i == 1:
            if a[j] == 2:
                list[i] = 0
            elif a[0] == 1:
                list[i] = 1
            else:
                list[i] = 2
        else:
            if a[j] == i + 1:
                list[i] = 0
            else:
                list[i] = (list[i - 1] + list[i - 2]) % MOD
        if i + 1 == a[j] and j < M - 1:
            j += 1

else:
    for i in range(N):
        if i == 0:
            list[i] = 1
        elif i == 1:
            list[i] = 2
        else:
            list[i] = (list[i - 1] + list[i - 2]) % MOD
            
ans = list[N - 1]
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
S = input()
if S[K - 1] == 'A':
  S[K - 1] = 'a'
elif S[K - 1] == 'B':
  S[K - 1] = 'b'
else:
  S[K - 1] = 'c'
print(S)

Fixed submission:
N, K = map(int, input().split())
S = list(input())

if S[K - 1] == 'A':
    S[K - 1] = 'a'
elif S[K - 1] == 'B':
    S[K - 1] = 'b'
else:
    S[K - 1] = 'c'

ans = ''.join(S)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
N = int(sys.stdin.readline())
edges = [list(map(int,sys.stdin.readline().split())) for _ in range(N - 1)]
A = [[] for _ in range(N + 1)]
 
for edge in edges:
    A[edge[0]].append([edge[1],edge[2]])
    A[edge[1]].append([edge[0],edge[2]])
 
depth = [-1] * (N + 1)
depth[1] = 0
 
def dfs(A,s):
    for v in A[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(A,v[0])    
dfs(A,1)
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)
N = int(sys.stdin.readline())
edges = [list(map(int,sys.stdin.readline().split())) for _ in range(N - 1)]
A = [[] for _ in range(N + 1)]
 
for edge in edges:
    A[edge[0]].append([edge[1],edge[2]])
    A[edge[1]].append([edge[0],edge[2]])
 
depth = [-1] * (N + 1)
depth[1] = 0
 
def dfs(A,s):
    for v in A[s]:
        if depth[v[0]] == -1:
            depth[v[0]] = depth[s] + v[1]
            dfs(A,v[0])    
dfs(A,1)
for d in depth[1:]:
    if d % 2 == 0:
        print(0)
    else:
        print(1)