Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03196 (python)

Fixed submission:
from functools import reduce
from operator import mul
def prime_factorize_dict(n, N):
    d = {1: 1}
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N, P = map(int, input().split())
print(reduce(mul, (factor ** (power // N) for factor, power in prime_factorize_dict(P, N).items())))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import mul
def prime_factorize_dict(n, N):
    d = {1: 50}
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N, P = map(int, input().split())
factors, powers = zip(*((factor, power) for factor, power in prime_factorize_dict(P, N).items() if power >= N))
print(reduce(mul, (factor ** (min(powers) // N) for factor in factors)))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from operator import mul
def prime_factorize_dict(n):
    if n == 1:
        return {1: 1}
    d = dict()
    while not n & 1:
        d[2] = d.get(2, 0) + 1
        n >>= 1
    f = 3
    while f * f <= n:
        if not n % f:
            d[f] = d.get(f, 0) + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = d.get(n, 0) + 1
    return d

N, P = map(int, input().split())
factors, powers = zip(*((factor, power) for factor, power in prime_factorize_dict(P).items() if power >= N))
print(reduce(mul, (factor ** (min(powers) // N) for factor in factors)))
Problem p03220 (python)

Fixed submission:
from numpy import array, argmin

input()
temp_on_sea, oracle = map(int, input().rstrip("\n").split())
heights = list(map(int , input().rstrip("\n").split()))
temp_diff = [abs(temp_on_sea - height * 0.006 - oracle) for height in heights]

print(array(temp_diff).argmin() + 1)

Buggy submission (verdict: Runtime Error):
from numpy import ndarray, argmin

input()
temp_on_sea, oracle = map(int, input().rstrip("\n").split())
heights = ndarray(list(map(lambda x: abs(int(x) - oracle) , input().rstrip("\n").split())))

print(heights.argmin() + 1)
Problem p03241 (python)

Fixed submission:
N, M = map(int, input().split())
divisors = sorted(sum((list({n, M // n}) for n in range(1, int(M ** 0.5) + 1) if not M % n), []), reverse=True)

for d in divisors:
    if M // d >= N:
        print(d)
        break

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
divisors = sorted(sum(([*{n, M // n}] for n in range(1, int(M ** 0.5) + 1) if not M % n), []), reverse=True)

for d in divisors:
    if M // d >= N:
        print(d)
        break
Problem p03292 (python)

Fixed submission:
import numpy as np
A = np.array(sorted(map(int, input().split())))
print((A[1:] - A[:-1]).sum())

Buggy submission (verdict: Runtime Error):
s1 = input()
print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")
Problem p03293 (python)

Fixed submission:
s1 = input()
print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")

Buggy submission (verdict: Runtime Error):
print("Yes" if input() in tuple(s1[i:] + s1[:i] for i in range(len(s1))) else "No")
Problem p03294 (python)

Fixed submission:
N = int(input())
print(sum(map(int, input().split())) - N)

Buggy submission (verdict: Runtime Error):
N = int(input())
print(eval(input().replace(" ", "+")) - N)
Problem p03331 (python)

Fixed submission:
n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2 + 1)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2)]))

Buggy submission (verdict: Runtime Error):
n = int(input())
print(min([sum(map(int, str(i) + str(n - i))) for i in range(1, n // 2)]))
Problem p03386 (python)

Fixed submission:
A, B, K = map(int, input().split())
for n in sorted(filter(lambda n: A <= n <= B , set(range(A, A + K)) | set(range(B - K + 1, B + 1)))):
    print(n)

Buggy submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
for n in sorted({*range(A, A + K), *range(B - K + 1, B + 1)}):
    print(n)
Problem p03408 (python)

Fixed submission:
nblues = int(input())
profits = dict()
for _ in range(nblues):
    word = input().rstrip("\n")
    profits[word] = profits.get(word, 0) + 1

nreds = int(input())
for _ in range(nreds):
    word = input().rstrip("\n")
    profits[word] = profits.get(word, 0) - 1

print(max(0, max(profits.items(), key=lambda t: t[1])[1]))

Buggy submission (verdict: Runtime Error):
dict_ = dict()
[exec("dict_['{0}'] = dict_.get('{0}', 0) + 1".format(input())) for _ in range(int(input()))]
[exec("dict_['{0}'] = dict_.get('{0}', 0) - 1".format(input())) for _ in range(int(input()))]
print(max(*dict_.values(), 0))
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
print("Odd" if (a * b) % 2 else "Even")

Buggy submission (verdict: Runtime Error):
manhattan = lambda x,y: abs(x[0] - y[0]) + abs(x[1] - y[1])

def solve():
    n = int(input())
    table = [[0, 0, 0]] + list(map(int, input().rstrip("\n").split()) for i in range(n))

    for i in range(1, len(table)):
        t = (table[i][0] - table[i - 1][0] - manhattan(table[i - 1][1:], table[i][1:]))
        if t < 0 or t % 2 != 0:
            return "No"
    return "Yes"

print(solve())
Problem p03457 (python)

Fixed submission:
manhattan = lambda x,y: abs(x[0] - y[0]) + abs(x[1] - y[1])

def solve():
    n = int(input())
    table = [[0, 0, 0]] + [list(map(int, input().rstrip("\n").split())) for i in range(n)]

    for i in range(1, len(table)):
        t = (table[i][0] - table[i - 1][0] - manhattan(table[i - 1][1:], table[i][1:]))
        if t < 0 or t % 2 != 0:
            return "No"
    return "Yes"

print(solve())

Buggy submission (verdict: Runtime Error):
manhattan = lambda x,y: abs(x[0] - y[0]) + abs(x[1] - y[1])

def solve():
    n = int(input())
    table = [[0, 0, 0]] + list(map(int, input().rstrip("\n").split()) for i in range(n))

    for i in range(1, len(table)):
        t = (table[i][0] - table[i - 1][0] - manhattan(table[i - 1][1:], table[i][1:]))
        if t < 0 or t % 2 != 0:
            return "No"
    return "Yes"

print(solve())

Buggy submission (verdict: Runtime Error):
manhattan = lambda x,y: abs(x[0] - y[0]) + abs(x[1] - y[1])

def solve():
    n = int(input())
    table = [[0, 0, 0]] + list(map(int, input().rstrip("\n").split()) for i in range(n))

    for i in range(1, len(table)):
        t = (table[i][0] - table[i - 1][0] - manhattan(table[i - 1][1:], table[i][1:]))
        if t < 0 or t % 2 != 0:
            return "No"
    return "Yes"

print(solve())
Problem p03472 (python)

Fixed submission:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

try:
    while H > 0:
        H -= next(C)
        count += 1
except StopIteration:
    Q, R = divmod(H, m)
    print(count + Q + bool(R))
else:
    print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
C = B > m
Q, R = np.divmod(H - B[C].sum(), m)

print(C.sum() + Q + bool(R))
Problem p03477 (python)

Fixed submission:
A, B, C, D = map(int, input().split())
left, right = A + B, C + D
print((
    "Left" if left > right else
    "Balanced" if left == right else
    "Right"
    ))

Buggy submission (verdict: Runtime Error):
line = input()
A, B, C, D = map(int, input().split())
left, right = A + B, C + D
print((
    "Left" if left > right else
    "Balanced" if left == right else
    "Right"
    ))

Buggy submission (verdict: Runtime Error):
line = input()
left, right = eval(line[:3].replace(" ", "+")), eval(line[-4:].replace(" ", "+"))
print((
    "Left" if left > right else
    "Balanced" if left == right else
    "Right"
    ))
Problem p03478 (python)

Fixed submission:
n, lo, hi = map(int, input().rstrip("\n").split())
print(sum([i if lo <= sum(map(int, str(i))) <= hi else 0 for i in range(n + 1)]))

Buggy submission (verdict: Runtime Error):

k, s = map(int, input().rstrip("\n").split())
count = 0

for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            count += (x + y + z == s)

print(count)
Problem p03557 (python)

Fixed submission:
from bisect import bisect
from itertools import accumulate

n = int(input())
a_list = sorted(map(int, input().split()))
b_list = sorted(map(int, input().split()))
c_list = sorted(map(int, input().split()))

b_c_table_ = list(accumulate(reversed(tuple(n - bisect(c_list, b) for b in b_list))))
b_c_table_.reverse()
b_c_table_ += [0]

print(sum(b_c_table_[bisect(b_list, a)] for a in a_list))

Buggy submission (verdict: Runtime Error):
from functools import lru_cache as cache
from bisect import bisect

n = int(input())
a_list = sorted(map(int, input().split()))
b_list = sorted(map(int, input().split()))
c_list = sorted(map(int, input().split()))

b_c_table = [n - bisect(c_list, b) for b in b_list]

@cache(maxsize=None)
def sum_(*list_):
    return sum([*list_])

ans = 0
for a in a_list:
    i = bisect(b_list, a)
    ans += sum_(*b_c_table[i:n])
print(ans)
Problem p03574 (python)

Fixed submission:

import numpy as np
h, w = map(int, input().rstrip("\n").split())

array = np.array([[" "] * (w + 2)] + [list(" " + input().rstrip("\n") + " ") for _ in range(h)] + [[" "] * (w + 2)])

list_ = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if array[i][j] == "#":
            list_.append("#")
        else:
            list_.append(str(sum(sum(array[i - 1:i + 2, j - 1:j + 2] == "#"))))
    list_.append("\n")
list_.pop()

print("".join(list_))

Buggy submission (verdict: Runtime Error):
import numpy as np
h, w = map(int, input().rstrip("\n").split())

array = np.array([[" "] * (w + 2)] + [list(" " + input().rstrip("\n") + " ") for _ in range(h)] + [[" "] * (w + 2)])

list_ = []

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if array[i][j] == "#":
            list_.append("#")
        else:
            list_.append(str(sum(sum(array[i - 1:i + 2, j - 1:j + 2] == "#"))))
    list_.append("\n")
list_.pop()

print("".join(list_))
Problem p03575 (python)

Fixed submission:
from scipy.sparse import coo_matrix, csgraph
N, M = map(int, input().split())
points = tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(M))
matrix = coo_matrix(([1] * M, tuple(zip(*points))), shape=(N, N)).toarray()
total = 0
for point in points:
    matrix[point] = 0
    total += csgraph.connected_components(matrix, directed=False, return_labels=False) != 1
    matrix[point] = 1
print(total)

Buggy submission (verdict: Runtime Error):
from scipy.sparse import coo_matrix, csgraph
N, M = map(int, input().split())
points = tuple(tuple(map(lambda n: int(n) - 1, input().split())) for _ in range(M))
matrix = coo_matrix(([1] * M, zip(*points)), shape=(N, N)).toarray()
total = 0
for point in points:
    matrix[point] = 0
    total += csgraph.connected_components(matrix, directed=False, return_labels=False) != 1
    matrix[point] = 1
print(total)
Problem p03599 (python)

Fixed submission:
A, B, C, D, E, limit = map(int, input().rstrip("\n").split())

target_concent = E * 100 / (100 + E)
water_vars = {(i * A + j * B) * 100 for i in range(limit // (100 * A) + 1) for j in range(limit // (100 * B) + 1) if (i * A + j * B) * 100 <= limit}
water_vars = sorted(water_vars)[1:]

ans_solution = 0
ans_sugar = 0
max_concent = 0

break_all = False

for water in water_vars:
    sugar_limit = limit - water
    sugar_vars = {i * C + j * D for i in range(sugar_limit // C + 1) for j in range(sugar_limit // D + 1) if i * C + j * D <= sugar_limit}
    sugar_vars = sorted(sugar_vars)
    for sugar in sugar_vars:
        concent = sugar * 100 / (sugar + water)
        if concent == target_concent:
            ans_solution = water + sugar
            ans_sugar = sugar
            break_all = True
            break
        elif max_concent <= concent < target_concent:
            ans_solution = water + sugar
            ans_sugar = sugar
            max_concent = concent
        elif concent > target_concent:
            break
    if break_all:
        break

print(ans_solution, ans_sugar)

Buggy submission (verdict: Runtime Error):
A, B, C, D, E, limit = map(int, input().rstrip("\n").split())

target_rate = E * 100 / (100 + E)
water_vars = {(i * A + j * B) * 100 for i in range(limit // (100 * A) + 1) for j in range(limit // (100 * B) + 1) if (i * A + j * B) * 100 <= limit}
water_vars = sorted(water_vars)
ans_solution = 0
ans_sugar = 0
min_rate_dest = 100

for water in water_vars:
    sugar_limit = limit - water
    sugar_vars = {i * C + j * D for i in range(sugar_limit // C + 1) for j in range(sugar_limit // D + 1) if i * C + j * D <= sugar_limit}
    sugar_vars = sorted(sugar_vars)
    for sugar in sugar_vars:
        rate = sugar * 100 / (sugar + water)
        if target_rate - rate == 0:
            ans_solution = water + sugar
            ans_sugar = sugar
            break
        elif 0 < target_rate - rate < min_rate_dest:
            ans_solution = water + sugar
            ans_sugar = sugar
            min_rate_dest = target_rate - rate
        else:
            break

print(ans_solution, ans_sugar)
Problem p03607 (python)

Fixed submission:
n = int(input())
list_ = [int(input()) for _ in range(n)]

dict_ = dict()
for key in list_:
    dict_[key] = dict_.get(key, 0) + 1
print(sum(num % 2 for num in dict_.values()))

Buggy submission (verdict: Runtime Error):
n = int(input())
list_ = [int(input()) for _ in range(n)]

dict_ = dict()
for key in set(list_):
    dict_[key] += dict_.get(key, 0) + 1
print(sum(num % 2 for num in dict_.values()))
Problem p03813 (python)

Fixed submission:
print("ARC" if int(input()) >= 1200 else "ABC")

Buggy submission (verdict: Runtime Error):
print("ARC" if int(input) > 1200 else "ABC")
Problem p04001 (python)

Fixed submission:
nums = list(input().strip())
N = len(nums)
head = nums.pop(0)
print(sum(eval(head + "".join([('' if (j >> i) % 2 else '+') + str(n) for i, n in enumerate(nums)])) for j in range(2 ** (N - 1))))

Buggy submission (verdict: Runtime Error):
nums = list(input().strip())
N = len(nums)
head = nums.pop(0)
print(sum(eval(head + "".join([f"{'' if (j >> i) % 2 else '+'}{n}" for i, n in enumerate(nums)])) for j in range(2 ** (N - 1))))
Problem p04044 (python)

Fixed submission:
n, l = map(int, input().rstrip("\n").split())
strings = sorted([input().rstrip() for _ in range(n)])

print("".join(strings))

Buggy submission (verdict: Runtime Error):
[print("".join(sorted(input() for _ in range(l)))) for n, l in [map(int, input().split())]]
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
ans = 'Yes' if 500 * k >= x else 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
import math

def gcd(a, b):
	if  b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return (a * b) // gcd(a, b)

n, m = map(int, input().split())
a = [int(x) for x in input().split()]
g = a[0]
for i in range(n):
	g = lcm(g, a[i])
while g % 2 == 0:
	g //= 2

rb = m // g
if rb % 2 == 0:
	print(rb // 2)
else:
	print(rb // 2 + 1)
Problem p02646 (python)

Fixed submission:
a, v = map(int, input().split()) 
b, w = map(int, input().split())
t = int(input()) 
if v <= w:
  print('NO') 
else:
  q = abs(a-b) / abs(v - w) 
  if abs(a-b) <= abs(v - w) * t:
    print('YES') 
  else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input()) 
b, w = map(int, input())
t = int(input()) 
if v <= w:
  print('NO') 
else:
  q = abs(a-b) / abs(v - w) 
  if abs(a-b) * t <= abs(v - w):
    print('YES') 
  else:
    print('NO')
Problem p03597 (python)

Fixed submission:
N = int(input())
A = int(input())
print(N**2-A)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
length = 0
Khalf = K//2
for i in range(N):
	if x[i] <= Khalf:
		length += 2*x[i]
	else:
		length += 2*(K-x[i])
print(length)

Buggy submission (verdict: Runtime Error):
N = int(input())
K = int(input())
x = list(map(int,input().split()))
length = 0
Khalf = K//2
for i in range(N):
	if x[i] <= Khalf:
		length += 2*x[i]
	else:
		length += 2*(K-x[i])
print(length)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
now = 1
used = [-228] * (n + 191)
used[1] = -1
cn = -292
ahah = 1
for _ in range(k):
    now = A[now]
    if used[now] != -228:
        cn = _ + 1 - used[now] - 1
        break
    used[now] = _
    ahah += 1
if cn == -292:
    print(now)
    exit(0)
for i in range((k - ahah) % cn):
    now = A[now]
print(now)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = [0] + list(map(int, input().split()))
now = 1
used = [0] * (n + 191)
used[1] = 1
for _ in range(k):
    now = A[now]
    if used[now] != 0:
        cn = _+1-used[now]+1
        break
    used[now] = _ + 1
for i in range(k % cn):
    now = A[now]
print(now)
Problem p02976 (python)

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

n, m = map(int,input().split())
A = [[int(i) for i in input().split()] for i in range(m)]

if m&1:
    print(-1)
    exit()

E = [[] for i in range(n + 1)]
used_e = [False] * m
ans = []

for i, (a, b) in enumerate(A):
    E[a].append((b, i))
    E[b].append((a, i))

used = [False] * (n + 1)

def dfs(prev, v):
    if used[v]:
        return
    used[v] = True
    cnt = 0

    for to, i in E[v]:
        dfs(v, to)
        if not used_e[i]:
            cnt += 1

    for to, i in E[v]:
        if cnt % 2 == 1 and to == prev:
            continue
        if not used_e[i]:
            ans.append((v, to))
            used_e[i] = True

dfs(0, 1)

for a in ans:
    print(*a)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
edge = [[-1] for _ in range(n+1)]
for i in range(m):
    a,b = [int(i) for i in input().split()]
    edge[a].append(b)
    edge[b].append(a)
if(m&1==1):
    print(-1)
    exit()
print(edge)
for i in range(n+1):
    if len(edge[i])==2:
        l = edge[i][1]
        print(l,i)
        edge[l][0] -= 1
        edge[l].remove(i)
        edge[i].clear()
for i in range(n+1):
    if edge[i][0]%2==0:
        for e in edge[i][1:]:
            if edge[e][0]%2==1:
                print(i,e)
                edge[i][0] -= 1
                edge[i].remove(e)
                edge[e].remove(i)
for i in range(n+1):
    if len(edge[i])==2:
        l = edge[i][1]
        print(l,i)
        edge[l][0] -= 1
        edge[l].remove(i)
        edge[i].clear()
    for e in edge[i][1:]:
        if len(edge[e])==2:
            continue
        print(i,e)
        edge[i][0] -= 1
        edge[i].remove(e)
        edge[e].remove(i)
print(edge)
Problem p02993 (python)

Fixed submission:
s = input()
for i in range(1,4):
    if s[i]==s[i-1]:
        print("Bad")
        exit()
print("Good")

Buggy submission (verdict: Runtime Error):
s = input()
if s[0]==s[1] or s[1]==s[2] or s[2]==-s[3]:
    print("Good")
else:
    print("Bad")
Problem p03030 (python)

Fixed submission:
n = int(input())
SQ  = []
for i in range(n):
    s,q = input().split()
    SQ.append([s,q,i+1])
SQ.append(['zzzzzzzzzzzzzz',0,i+2])
X = sorted(SQ)
res = []
city = X[0][0]
for i in range(n+1):
    if X[i][0] == city:
        res.append([int(X[i][1]),X[i][2]])
    else:
        res.sort(reverse=True)
        for r in res:
            print(r[1])
        res = [[int(X[i][1]),X[i][2]]]
        city = X[i][0]

Buggy submission (verdict: Runtime Error):
n = int(input())
SPN = []
for i in range(n):
    s,p = input().split()
    SPN.append([s,int(p),i+1])
SPN = sorted(sorted(SPN, key=lambda x:x[1], reverse=1), lambda x:x[0])
for s,p,n in SPN:
    print(n)
Problem p03032 (python)

Fixed submission:
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = []
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for p in range(min(len(Q),k-len(Q))):
            if Q[p] < 0:
                s -= Q[p]   
        res.append(s)
        Q = []
print(max(res))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = 0
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for k in range(min(i+j+1,m-i-j)):
            if Q[k] < 0:
                s -= Q[k]   
        res = max(res,s)
        Q = []
print(res)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
V = list(map(int,input().split()))
rV = V[::-1]
Q = []
m = min(n,k)
res = 0
for i in range(m+1):
    for j in range(m-i+1):
        Q.extend(V[:i])
        Q.extend(rV[:j])
        if not Q:
            continue
        s = sum(Q)
        Q.sort()
        for k in range(min(i+j+1,m-i-j+1)):
            if Q[k] < 0:
                s -= Q[k]   
        res = max(res,s)
        Q = []
print(res)
Problem p03044 (python)

Fixed submission:
n = int(input())
edges = [set() for _ in range(n)]
for i in range(n-1):
    u,v,w = [int(i)-1 for i in input().split()] 
    edges[u].add((v,w+1))
    edges[v].add((u,w+1))
ans = [-1]*n
q = [(0,0,-1)]
while q:
    v,d,p = q.pop()
    if d%2 == 0:
        ans[v] = 0
    else:
        ans[v] = 1
    for u,w in edges[v]:
        if u == p:
            continue
        q.append((u,d+w,v))
for i in range(n):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
	a,b,x = map(int,input().split())
	a -= 1
	b -= 1
	x = x%2
	d[a].append([b,x])
	d[b].append([a,x])
color = [0]*n
used = set()
def dfs(v):
	for e,l in d[v]:
		if e not in used:
			used.add(e)
			if l == 1:
				color[e] = 1
			dfs(e)
dfs(0)
for c in color:
	print(c)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = [[] for i in range(n)]
for i in range(n-1):
	a,b,x = map(int,input().split())
	a -= 1
	b -= 1
	x = x%2
	d[a].append([b,x])
	d[b].append([a,x])
print(d)
color = [0]*n
used = set()
def dfs(v):
	for e,l in d[v]:
		#print(e)
		if e not in used:
			used.add(e)
			if l == 1:
				color[e] = 1
			dfs(e)
dfs(0)
for c in color:
	print(c)