Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

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

@lru_cache(None)
def f(l, r, xl, xr):
  if l+1 == r:
    return xl * A[l] + xr * A[r]
  tmp = float("inf")
  for m in range(l+1, r):
    v = f(l, m, xl, xl+xr) + f(m, r, xl+xr, xr) - (xl+xr) * A[m]
    tmp = min(tmp, v)
  return tmp

print(f(0, N-1, 1, 1))

Fixed submission:
from functools import lru_cache
 
N = int(input())
A = list(map(int, input().split()))
 
@lru_cache(None)
def f(l, r, xl, xr):
  if l+1 == r:
    return xl * A[l] + xr * A[r]
  tmp = float("inf")
  for m in range(l+1, r):
    v = f(l, m, xl, xl+xr) + f(m, r, xl+xr, xr) - (xl+xr) * A[m]
    tmp = min(tmp, v)
  return tmp
 
print(f(0, N-1, 1, 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

DP = [[{} for _ in range(N)] for _ in range(N)]
DP[0][N-1][(1, 1)] = float("inf")

def initialize(l, r, xl, xr):
  for m in range(l+1, r):
    DP[l][m][(xl, xl+xr)] = float("inf")
    DP[m][r][(xl+xr, xr)] = float("inf")
    initialize(l, m, xl, xl+xr)
    initialize(m, r, xl+xr, xr)
  return

initialize(0, N-1, 1, 1)

for i in range(N-1):
  for xl, xr in DP[i][i+1].keys():
    DP[i][i+1][(xl, xr)] = xl * A[i] + xr * A[i+1]
    
for d in range(2, N):
  for i in range(N-d):
    l = i
    r = i+d
    for xl, xr in DP[l][r].keys():
      tmp = float("inf")
      for m in range(l+1, r):
        v = DP[l][m][(xl, xl+xr)] + DP[m][r][(xl+xr, xr)] - (xl+xr) * A[m]
        if v < tmp:
          tmp = v
      DP[l][r][(xl, xr)] = tmp
print(DP[0][N-1][(1,1)])

Fixed submission:
from functools import lru_cache
 
N = int(input())
A = list(map(int, input().split()))
 
@lru_cache(None)
def f(l, r, xl, xr):
  if l+1 == r:
    return xl * A[l] + xr * A[r]
  tmp = float("inf")
  for m in range(l+1, r):
    v = f(l, m, xl, xl+xr) + f(m, r, xl+xr, xr) - (xl+xr) * A[m]
    tmp = min(tmp, v)
  return tmp
 
print(f(0, N-1, 1, 1))
Buggy python submission (verdict: Runtime Error):
S = int(input()
print(3 * S * S)

Fixed submission:
S = int(input())
print(S * S * 3)
Buggy python submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2 and len(S2) == 2:
    print("Yes")
else :
    print("No")


Fixed submission:
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")

Buggy python submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    ezxt()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2 and len(S2) == 2:
    print("Yes")
else :
    print("No")


Fixed submission:
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")

Buggy python submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2:
    print("Yes")
else :
    print("No")


Fixed submission:
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")

Buggy python submission (verdict: Runtime Error):
A,B,C,D = input()
S = (A+B+C+D)
if len(S.strip(A)) == len(S.strip(B)) and len(S.strip(C)) == len(S.sript(D)):
    print("Yes")
else:
    print("No")

Fixed submission:
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")
Buggy python submission (verdict: Runtime Error):
A , B , C , D = map(int,input().split())
lst = []
list= [i for i in range(A,B) i % C != 0]
for i in list:
    if  i % D != 0:
        lst.append(i)
print(len(lst))


Fixed submission:
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
    else:
        print("Bad")
        exit()
if bool == 1:
    print("Good")

Buggy python submission (verdict: Runtime Error):
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
if bool = 1:
    print("Good")
else:
    print("Bad")


Fixed submission:
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
    else:
        print("Bad")
        exit()
if bool == 1:
    print("Good")

Buggy python submission (verdict: Runtime Error):
N = list(map(int,input()))
for i in len(N - 1):
    if N[i] == N[i+1]:
        print("Good")
    else :
        print("Bad")


Fixed submission:
N = list(map(int,input()))
bool = 0
for i in range(len(N) - 1):
    if N[i] != N[i+1]:
        bool = 1
    else:
        print("Bad")
        exit()
if bool == 1:
    print("Good")
Buggy python submission (verdict: Runtime Error):
N , X =map(int,input().split())
sums = []
i = X
result =[]
for i in range(N):
    sums.append(i+X)
for j in range(N):
    result.append(sum(sums)-sums[j]*2 )
for k in range(N):
    if sum(sums) == result[k]:
        print(result[k])
    else:
        print(abs(min(result[k])))


Fixed submission:
N , X =map(int,input().split())
sums = []
i = X
result =[]
a = []
for i in range(N):
    sums.append(i+X)
for j in range(N):
    a.append(abs(sums[j]))

if sum(sums) ==abs(sum(sums)):
    print(sum(sums) - min(a))
else :
    print(sum(sums) + min(a))
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().sqlit())
if N * A > B :
  print(N*A)
else:
  print(B)
  


Fixed submission:
N,A,B = map(int, input().split())
if N * A < B:
    print(N*A)
else:
    print(B)
Buggy python submission (verdict: Runtime Error):
A = input()
for i in range(A)
	B = int(A)

if A % B == 0 :
  print("Yes")
else:
  print("No")

Fixed submission:
A = int(input())
B = A
list=[]
while B > 0:
    list.append(B%10)
    B //=10
    #print(list)
if A % sum(list) == 0:
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Runtime Error):
at = input().split()
top = input().split()
at_i = 0
top_i = 0
if at =='H':
  at_i = 1

if at == 'D':
  at_i = -1

if top == 'H':
	top_i = 1

if top == 'D':
  top_i = -1

if top_i * at_i == 1:
    print("H")
else :
    print("D")


Fixed submission:
at = list(input())
at_i = 0
top_i = 0
if at[0] =='H':
  at_i = 1

if at[0] == 'D':
  at_i = -1

if at[2] == 'H':
	top_i = 1

if at[2] == 'D':
  top_i = -1

if top_i * at_i == 1:
    print("H")
else :
    print("D")

Buggy python submission (verdict: Runtime Error):
at = input().split()
top = input().split()
if at =='H':
  at_i = 1

if at == 'D':
  at_i = -1
  
if top == 'H':
	top_i = 1

if top == 'D':
  top_i = -1

if top_i * app_i == 1:
  print("H")
else
	print("D")
 

Fixed submission:
at = list(input())
at_i = 0
top_i = 0
if at[0] =='H':
  at_i = 1

if at[0] == 'D':
  at_i = -1

if at[2] == 'H':
	top_i = 1

if at[2] == 'D':
  top_i = -1

if top_i * at_i == 1:
    print("H")
else :
    print("D")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
result = 1
TEISU = 10 **9 + 7
for i in range(N):
    result *= (i + 1)
if result > TEISU:
    print(result % TEISU)
else:
    print(result)


Fixed submission:
N = int(input())
result = 1
TEISU = 10 **9 + 7

for i in range(N):
    result = (i + 1) * result % TEISU
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
a , b , x = map(int,input().split())
cnt = 0
for i in range(a , b+1):
    if i % x == 0:
        cnt += 1
print(cnt)


Fixed submission:
a , b , x = map(int,input().split())
cnt = 0
a = (a - 1 ) // x
b //= x
print(b - a)
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
h = input()
print((a+b)*h/2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
square = (a + b) * h / 2
print(int(square))

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
h = input
print((a+b)*h/2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
square = (a + b) * h / 2
print(int(square))

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
h=input()
print((a+b)*h+/2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
square = (a + b) * h / 2
print(int(square))

Buggy python submission (verdict: Runtime Error):
a=input()
b=input()
h=input
print((a+b)*h+/2)

Fixed submission:
a = int(input())
b = int(input())
h = int(input())
square = (a + b) * h / 2
print(int(square))
Buggy python submission (verdict: Runtime Error):
S = input()
str = []
result = ""
flg = 0
for i in range(len(S)):
    if S[i] == 'B':
        str.pop(i-1)
    else:
        str.append(S[i])
for i in str:
    result += i
print(result)


Fixed submission:
S = input()
str = []
result = ""
flg = 0
for i in range(len(S)):
    if S[i] == 'B':
        result = result[:-1]
    else:
        result += S[i]
print(result)
Buggy python submission (verdict: Runtime Error):
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)
=

Fixed submission:
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())

n, m = mi()
a = [li() for i in range(n)]
a.sort(reverse=True)
rem = m
sm = 0
while a:
    rate, cnt = a.pop()
    take = min(rem, cnt)
    sm += take * rate
    rem -= take
print(sm)
Buggy python submission (verdict: Runtime Error):
import sys
print(len(set(sys.input().read().strip().split())))

Fixed submission:
import sys
input(), print(len(set(sys.stdin.read().strip().split())))
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))

D = 0
num = 1

while num <= N+1:
  if D >= X:
    print(num)
    break
  D = D + L[num-1]
  num += 1
else:
  print(N)

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

D = 0
num = 1

while num <= N:
  D = D + L[num-1]
  if D > X:
    print(num)
    break
  num += 1
else:
  print(N+1)
Buggy python submission (verdict: Runtime Error):
n = input()
m = input()
l = input()
n = n - m
print(n)
if n >= l
 n = n - l
  print(n)
else:
  print(n)

Fixed submission:
n = input()
m = input()
l = input()

n = int(n)
m = int(m)
l = int(l)

n = n - m
while n >= l :
  n = n - l
else: 
  print(n)
Buggy python submission (verdict: Runtime Error):
x = map(int,raw_input().split())
print(max([x[0]+x[1],x[0]-x[1],x[0]*x[1]]))

Fixed submission:
x = list(map(int,input().split()))
print(max([x[0]+x[1],x[0]-x[1],x[0]*x[1]]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [sorted(list(input())) for i in range(n)]
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if A[i] == A[j]:
            ans += 1
            
print(ans)

Fixed submission:
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
 
N = int(input())
 
A = []
for i in range(N):
    a = input()
    a_counter = Counter(a)
    A.append(a_counter)
    
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            cnt += 1
            
print(cnt)

Fixed submission:
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for i in range(N):
    a = sorted(list(input()))
    A.append(a)
    
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            cnt += 1
            
print(cnt)

Fixed submission:
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)

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

N = int(input())

A = []
for i in range(N):
    a = input()
    a_counter = Counter(a).most_common()
    a_counter.sort(key = lambda x: x[1])
    a_counter.sort(key = lambda x: x[0])
    A.append(a_counter)
    
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            cnt += 1
            
print(cnt)

Fixed submission:
N = int(input())
 
D = {}
for i in range(N):
    s = ''.join(sorted(input()))
    D.setdefault(s, 0)
    D[s] += 1
    
ans = 0
for v in D.values():
    if v > 1:
        for i in range(v):
            ans += i
    
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, D = map(int, input().split())

X = [[int(i) for i in input().split()] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)

Fixed submission:
import numpy as np
N, D = map(int, input().split())

X = [[int(i) for i in input().split()] for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i + 1 , N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k]) ** 2
        if np.sqrt(tmp) % 1 == 0:
            ans += 1
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

L, R = map(int, input().split())

L_list = []
for i in range(L, R):
    L_list.append(i)

R_list = []
for i in range(L + 1, R + 1):
    R_list.append(i)

ans = []
for l in np.array(L_list):
    ans.append((l * np.array(R_list) % 2019).min())
    
print(min(ans))

Fixed submission:
l, r = map(int, input().split())

ans = float('inf')
for i in range(l, min(r, l + 2019)):
    for j in range(i + 1, min(r + 1, l + 2019 + 1)):
        x = i * j % 2019
        ans = min(ans, x)
        
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
mod = 1000000007

B = ['.'] * (n + 1)
for a in A:
    B[a] = '#'
    
dp = [0] * (n + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, n + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(1 if n == 1 else dp[-1])

Fixed submission:
import sys
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

if N == 1:
    print(1)
    sys.exit()

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Fixed submission:
import sys
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

if N == 1:
    print(1)
    sys.exit()

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
dp[1] = 1
dp[2] = 2
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])

Fixed submission:
import sys
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
mod = 10 ** 9 + 7

if N == 1:
    print(1)
    sys.exit()

B = ['.'] * (N + 1) 
for a in A:
    B[a] = '#'
    
dp = [0] * (N + 1)
if B[1] == '.' and B[2] == '.':
    dp[1] = 1
    dp[2] = 2
elif B[1] == '#' and B[2] == '.':
    dp[2] = 1
elif B[1] == '.' and B[2] == '#':
    dp[1] = 1
    
for i in range(3, N + 1):
    if B[i] == '.':
        dp[i] = (dp[i - 2] + dp[i - 1]) % mod
    
print(dp[N])
Buggy python submission (verdict: Runtime Error):
import itertools
 
N, M = map(int, input().split())
 
S = []
for i in range(M):
    k, *s = map(int, input().split())
    S.append([s])
    
P = [int(i) for i in input().split()]
 
A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Fixed submission:
import itertools

N, M = map(int, input().split())

S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())

S = []
for i in range(M):
    k, *s = map(int, input().split())
    S.append([*s])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)

Fixed submission:
import itertools

N, M = map(int, input().split())

S = []
for i in range(M):
    s = list(map(int, input().split()))
    S.append(s[1:])
    
P = [int(i) for i in input().split()]

A = [0, 1]
ans = 0
for i in itertools.product(A, repeat = N):
    flag = 0
    for j in range(M):
        cnt = 0
        for s in S[j]:
            if i[s - 1] == 1:
                cnt += 1
        if cnt % 2 != P[j]:
            flag = 1
    if flag == 0:
        ans += 1
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

n, m = map(int, input().split())
A = []
for i in range(m):
    l, r = map(int, input().split())
    A.extend(list(range(l, r + 1)))
    
cnt = 0
for v in Counter(A).values():
    if v == m:
        cnt += 1
        
print(cnt)

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

l = -1
r = N + 1
for i in range(M):
    L, R = map(int, input().split())
    l = max(l, L)
    r = min(r, R)
    
if l > r:
    print(0)
else:
    print(r - l + 1)
Buggy python submission (verdict: Runtime Error):
from collections import deque

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [-1] * N
color[0] = 0
Q = deque()
Q = [0]

while len(Q) != 0:
    cur = Q.popleft()
    for to, dist in G[cur]:
        if color[to] == -1:
            color[to] = (color[cur] + dist) % 2
            Q.append(to)
            
for i in range(N):
    print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 8)

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)

Buggy python submission (verdict: Runtime Error):
N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 8)

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)