Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
c = N * A
if c < B:
    print(c)
else:
    print(B)


Fixed submission:
n, a, b = map(int, input().split())
c = n * a
if c < b:
    print(c)
else:
    print(b)
Buggy python submission (verdict: Runtime Error):
s = input()
a = 0
for _ in s:
    a += 1 
if  a != 4:
    print('No')
elif s[0] == s[1] and s[2] == s[3] and s[0] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2] and a[0] != s[1]:
    print('Yes')
else:
    print('No')


Fixed submission:
s = sorted(input())
if (s[0] == s[1]) and (s[2] == s[3]) and (s[0] != s[2]):
        print('Yes')
elif (s[0] == s[2]) and (s[1] == s[3]) and (s[0] != s[1]):
        print('Yse')
elif (s[0] == s[3]) and (s[1] == s[2]) and (s[0] != s[1]):
        print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s = input()
    if s[0] == s[1] ==s[2]:
        print('No')
    elif s[0] == s[2] == s[3]:
        print('No')
    elif s[1] == s[2] == s[3]:
        print('No')
    elif s[0] == s[1] == s[2] == s[3]:
        print('No')
    elif s[0] == s[1]:
        if s[2] == s[3]:
            print('Yes')
        else:
            print('No')
    elif s[0] == s[2]:
        if s[1] == s[3]:
            print('Yse')
        else:
            print('No')
    elif s[0] == s[3]:
        if s[1] == s[2]:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')


Fixed submission:
s = sorted(input())
if (s[0] == s[1]) and (s[2] == s[3]) and (s[0] != s[2]):
        print('Yes')
elif (s[0] == s[2]) and (s[1] == s[3]) and (s[0] != s[1]):
        print('Yse')
elif (s[0] == s[3]) and (s[1] == s[2]) and (s[0] != s[1]):
        print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
s = str(input())
for i in range(1, 5):
    if s[i - 1] == s[i]:
        print('Bad')
        exit()
print('Good')

Fixed submission:
s = str(input())
for i in range(3):
    if s[i] == s[i + 1]:
        print('Bad')
        exit()
print('Good')
Buggy python submission (verdict: Time Limit Exceeded):
a, b, k = map(int, input().split())
for i in range(a, b + 1):
    if i < a + k or i > b - k:
        print(i)

Fixed submission:
a, b, k = map(int, input().split())
if (b - a + 1) <= 2 * k:
  for i in range(a, b + 1):
    print(i)
else:
  for i in range(a, a + k):
    print(i)
  for i in range(b - k + 1, b + 1):
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = 1
for i in range(1, n + 1):
    a *= i
print(a % 1000000007)

Fixed submission:
n = int(input())
a = 1
for i in range(1, n + 1):
    a = (a * i) % (10 ** 9 + 7)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def hyoka(j,p,b_point):
  if j == k:
    point = reduce(mul, A[0:j])
    return point
  else:
    point = b_point/A[j-k-1]*p
    
  if b_point < point:
    print('Yes')
  else:
    print('No')
  return point
b_point = 0
for j,p in enumerate(A[k-1:n+1]):
  i = j+k-1
  result = hyoka(i+1,p,b_point)
  if result > 0:
  	b_point = result


Fixed submission:
[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

for i in range(k,n):
  if A[i-k]<A[i]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def hyoka(j,p,b_point):
  if j == k:
    point = reduce(mul, A[0:j])
    return point
  else:
    point = b_point/A[j-k-1]*p
    
  if b_point < point:
    print('Yes')
  else:
    print('No')
  return point
b_point = 0
for i,p in enumerate(A):
  if i+1 < k:
    continue
  result = hyoka(i+1,p,b_point)
  if result > 0:
  	b_point = result


Fixed submission:
[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

for i in range(k,n):
  if A[i-k]<A[i]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def hyoka(j,p,b_point):
  point = reduce(mul, A[j-k:j])
  if j == k:
    return point
  if b_point < point:
    print('Yes')
  else:
    print('No')
  return point
b_point = 0
for i,p in enumerate(A):
  if i+1 < k:
    continue
  result = hyoka(i+1,p,b_point)
  if result > 0:
  	b_point = result


Fixed submission:
[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

for i in range(k,n):
  if A[i-k]<A[i]:
    print('Yes')
  else:
    print('No')

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

def hyoka(j,p,b_point):
  if j < k:
    return 0
  point = reduce(mul, A[j-k:j])
  if j == k:
    return point
  if b_point < point:
    print('Yes')
  else:
    print('No')
  return point
b_point = 0
for i,p in enumerate(A):
  result = hyoka(i+1,p,b_point)
  if result > 0:
  	b_point = result


Fixed submission:
[n,k] = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

for i in range(k,n):
  if A[i-k]<A[i]:
    print('Yes')
  else:
    print('No')
Buggy python submission (verdict: Runtime Error):
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,K = read_int_map()
An = read_int_list()
memo = [0]*(N+1)
memo_indx = [0]*(N+1)
memo[1] = 1
memo_indx[1] = 0
seq_an = [1]
next_place = An[0]
for i in range(len(An)):
    if memo[next_place] == 0:
        seq_an.append(next_place)
        memo[next_place] = 1
        memo_indx[next_place] = i + 1
        next_place = An[next_place-1]
    else:
        break
loop_idx = memo_indx[next_place]
loop_list = seq_an[loop_idx:]
if K <= len(seq_an):
    print(seq_an[K])
else:
    num = (K - len(seq_an)) % len(loop_list)
    print(loop_list[num])

Fixed submission:
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,K = read_int_map()
An = read_int_list()
memo = [0]*(N+1)
memo_indx = [0]*(N+1)
memo[1] = 1
memo_indx[1] = 0
seq_an = [1]
next_place = An[0]
for i in range(len(An)):
    if memo[next_place] == 0:
        seq_an.append(next_place)
        memo[next_place] = 1
        memo_indx[next_place] = i + 1
        next_place = An[next_place-1]
    else:
        break
loop_idx = memo_indx[next_place]
loop_list = seq_an[loop_idx:]
if K <= len(seq_an)-1:
    print(seq_an[K])
else:
    num = (K - len(seq_an)) % len(loop_list)
    print(loop_list[num])
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
output = 0
for i1 in range(1,K+1):
    for i2 in range(1,K+1):
        for i3 in range(1,K+1):
            output += gcd(i1,i2,i3)
print(output)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
output = 0
for i1 in range(1,K+1):
    for i2 in range(1,K+1):
        for i3 in range(1,K+1):
            output += gcd(i1,i2,i3)
print(output)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

srt_n = str(N)
keta = len(srt_n)

#ans = [0] * ( keta + 1 )
N_list = [0] * (keta+1)
ans_num = 0

for i in reversed(range(keta)):
    N_list[keta-i-1] = int(srt_n[i])

for i in range(keta+1):
    if N_list[i] == 5 and N_list[i+1] >= 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    elif N_list[i] > 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    else:
        #ans[i] =  N_list[i]
        ans_num += N_list[i]
#print(ans)
print(ans_num)

Fixed submission:
N = input()

keta = len(N)

#ans = [0] * ( keta + 1 )
N_list = [0] * (keta+1)
ans_num = 0

for i in reversed(range(keta)):
    N_list[keta-i-1] = int(N[i])

for i in range(keta+1):
    if N_list[i] == 5 and N_list[i+1] >= 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    elif N_list[i] > 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    else:
        #ans[i] =  N_list[i]
        ans_num += N_list[i]
#print(ans)
print(ans_num)

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

srt_n = str(N)
keta = len(srt_n)

ans = [0] * ( keta + 1 )
N_list = [0] * (keta+1)
ans_num = 0

for i in reversed(range(keta)):
    N_list[keta-i-1] = int(srt_n[i])

for i in range(keta+1):
    if N_list[i] == 5 and N_list[i+1] >= 5:
        ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    elif N_list[i] > 5:
        ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    else:
        ans[i] =  N_list[i]
        ans_num += N_list[i]
#print(ans)
print(ans_num)

Fixed submission:
N = input()

keta = len(N)

#ans = [0] * ( keta + 1 )
N_list = [0] * (keta+1)
ans_num = 0

for i in reversed(range(keta)):
    N_list[keta-i-1] = int(N[i])

for i in range(keta+1):
    if N_list[i] == 5 and N_list[i+1] >= 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    elif N_list[i] > 5:
        #ans[i] = 0
        N_list[i+1] += 1
        ans_num += 10 - N_list[i]
    else:
        #ans[i] =  N_list[i]
        ans_num += N_list[i]
#print(ans)
print(ans_num)
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    kakuritsu[i] =  num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    max_sn[i] = sum(kakuritsu[i:i+K]) * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))

Fixed submission:
import heapq

N,K = map(int,input().split(' '))
pn = list(map(int,input().split(' ')))
#Sn = [0] * N
#Sn[0] = pn[0]
#for i in range(1,len(pn)):
#    Sn[i] = Sn[i-1] + pn[i]
kakuritsu = [0] * N 
num_list = [0] * 1001
num_list[0] = 0
for i in range(1,1001):
    num_list[i] = num_list[i-1] + i

for i in range(N):
    if i != 0:
        kakuritsu[i] = kakuritsu[i-1] + ( num_list[pn[i]] / pn[i] )
    else:
        kakuritsu[i] = num_list[pn[i]] / pn[i]

max_sn = [0] * N

for i in range(N-K+1):
    if i != 0:
        max_sn[i] = ( kakuritsu[i-1+K] - kakuritsu[i-1]   ) * (-1)
    else:
        max_sn[i] = kakuritsu[i-1+K] * (-1)

heapq.heapify(max_sn)
print(heapq.heappop(max_sn) * (-1))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N,D,A = map(int,input().split(' '))
XHn = [ list(map(int,input().split(' '))) for _ in range(N)]
ans = 0
XHn.sort()
for i  in range(N):
    x = XHn[i][0]
    h = XHn[i][1]
    need_bom = 0
    distance_bom = x + D*2
    if h > 0:
        need_bom = math.ceil(h/A)
        for i2 in range(i,N):
            x2 = XHn[i2][0]
            if x2 <= distance_bom:
                XHn[i2][1] -= A*need_bom
            else:
                break
        ans += need_bom
print(ans)

Fixed submission:
import math
from collections import deque
N,D,A = map(int,input().split(' '))
XHn = [ list(map(int,input().split(' '))) for _ in range(N)]
ans = 0
XHn.sort()
attacks = deque([]) # (区間,攻撃回数)
attack = 0
ans = 0
for i  in range(N):
    x = XHn[i][0]
    h = XHn[i][1]
    while len(attacks) > 0 and x > attacks[0][0]:
        distance,attack_num = attacks.popleft()
        attack -= attack_num*A
    if h > attack:
        diff = h - attack 
        distance_attack = x + D*2
        need_attack = math.ceil(diff/A)
        attacks.append((distance_attack,need_attack))
        attack += A*need_attack
        ans += need_attack
print(ans)
Buggy python submission (verdict: Runtime Error):
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)
'''

Fixed submission:
M = int(input())
keta = 0
count_sum = 0
for _ in range(M):
    d,c= map(int,input().split(' '))
    keta += c
    count_sum += d*c
additional = count_sum//10
if 9 < count_sum:
    print(keta-1 + (count_sum-1)//9)
else:
    print(keta-1)
Buggy python submission (verdict: Time Limit Exceeded):
NKQ = input().split(' ')
N = int(NKQ[0])
K = int(NKQ[1])
Q = int(NKQ[2])

An = [K] * N

for _ in range(Q):
    A = int(input()) 
    for i in range(N):
        An[i] -= 1
    An[A-1] += 1

for i in range(N):
    if An[i] > 0:
        print('Yes')
    else:
        print('No')

Fixed submission:
NKQ = input().split(' ')
N = int(NKQ[0])
K = int(NKQ[1])
Q = int(NKQ[2])

Bn = [0] * N
for _ in range(Q):
    A = int(input()) 
    Bn[A-1] += 1

for i in range(N):
    if K - Q + Bn[i]  > 0:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
sorted_lists = []
count_list = []

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
    inserted_flag = True
    input_sorted = sorted(input()) 
    for i in range(len(sorted_lists)): 
        if input_sorted == sorted_lists[i]:
            count_list[i] = count_list[i] + 1
            inserted_flag = False
    if inserted_flag:
        sorted_lists.append(input_sorted)
        count_list.append(1)

count = 0
for count_num in count_list:
    if count_num == 1:
        continue
    count = count + combinations_count(count_num, 2)
print(count)

Fixed submission:
import math
N = int(input())
sorted_map = {}

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(N):
    inserted_flag = True
    input_sorted = ''.join(sorted(input()))
    if input_sorted in sorted_map.keys():
        sorted_map[input_sorted] += 1
        inserted_flag = False
    if inserted_flag:
        sorted_map[input_sorted] = 1

count = 0
for count_num in sorted_map.values():
    if count_num == 1:
        continue
    count += combinations_count(count_num, 2)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
An = input().split(' ')
ball_list = [0] * N
output_list = []
count = 0
for i in range(N):
    sum_amari = sum(ball_list[(N - i -1)::(N - i)])
    if sum_amari % 2 != int(An[N - i -1]): 
        ball_list[N - i -1] = 1
        output_list.insert(0,str(N - i))

print(len(output_list))
if len(output_list) > 0:
    print(' '.join(output_list))

Fixed submission:
N = int(input())
An = input().split(' ')
ball_list = [0] * N
output_list = []
count = 0
for i in range(N):
    sum_amari = sum(ball_list[(N - i -1)::(N - i)])
    if sum_amari % 2 != int(An[N - i -1]): 
        ball_list[N - i -1] = 1
        output_list.append(str(N - i))
output_list.reverse()
print(len(output_list))
if len(output_list) > 0:
    print(' '.join(output_list))
Buggy python submission (verdict: Runtime Error):
import itertools
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
store = [0,0]
num_list = range(L,R+1)
combination_list = list(itertools.combinations(num_list,2))

for comb in combination_list:
    mod = (comb[0]% 2019) * (comb[1]% 2019 ) 
    if mod < min_num:
        min_num = mod
        if mod == 0:
            break

print(min_num)

Fixed submission:
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
flag = False
for l in range(L,R):
    for r in range(l+1,R+1):
        mod = (l*r) %2019
        if mod < min_num:
            min_num = mod
            if mod == 0:
                flag =True
                break
    if flag:
        break

print(min_num)

Buggy python submission (verdict: Runtime Error):
import itertools
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
store = [0,0]
num_list = range(L,R+1)
combination_list = list(itertools.combinations(num_list,2))

for comb in combination_list:
    mod = (comb[0] * comb[1] ) % 2019
    if mod < min_num:
        min_num = mod
        if mod == 0:
            break

print(min_num)

Fixed submission:
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
flag = False
for l in range(L,R):
    for r in range(l+1,R+1):
        mod = (l*r) %2019
        if mod < min_num:
            min_num = mod
            if mod == 0:
                flag =True
                break
    if flag:
        break

print(min_num)

Buggy python submission (verdict: Runtime Error):
import itertools
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
store = [0,0]
num_list = range(L,R+1)
combination_list = list(itertools.combinations(num_list,2))

for comb in combination_list:
    mod = (comb[0] * comb[1] ) % 2019
    if mod < min_num:
        min_num = mod
        store[0] = comb[0]
        store[1] = comb[1]

print(' '.join(map(str,store)))

Fixed submission:
LR = input().split(' ')
L = int(LR[0])
R = int(LR[1])

min_num = 2000000001
flag = False
for l in range(L,R):
    for r in range(l+1,R+1):
        mod = (l*r) %2019
        if mod < min_num:
            min_num = mod
            if mod == 0:
                flag =True
                break
    if flag:
        break

print(min_num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
Pn = list(input().split(' '))

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] <= Pn[i] and Pn[i] < Pn[i+1] ) or ( Pn[i+1] <= Pn[i] and Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)


S = list(input())
S.sort()

if S[0] == S[1] and S[2] == S[3] and S[1] != S[2]:
    print('Yes')
else:
    print('No')

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

count_pn = 0
for i in range(1,N-1):
    if ( Pn[i-1] < Pn[i] < Pn[i+1] ) or ( Pn[i+1] < Pn[i] < Pn[i-1] ):
        count_pn += 1
print(count_pn)
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split(' '))

def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret

base_num = N-K+1
for i in range(K):
    select_num = nCk(base_num,i+1)
    seq_num = nCk(K-1,i)
    count_n = select_num*seq_num%(10**9 + 7)
    print(count_n)


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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
max_N = 2000 #階乗の制限どれだけ
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, max_N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

base_num = N-K+1
for i in range(K):
    select_num = cmb(base_num,i+1,mod)
    seq_num = cmb(K-1,i,mod)
    count_n = (select_num*seq_num)%mod
    print(count_n)
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_num = (B//C - (A-1)//C)
d_num = (B//D - (A-1)//D)
cd_num = (B//lcm(C, D) - (A-1)//lcm(C, D))
print((B-A+1) - (c_num+d_num-cd_num))

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

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

c_num = (B//C - (A-1)//C)
d_num = (B//D - (A-1)//D)
cd_num = (B//lcm(C, D) - (A-1)//lcm(C, D))
print((B-A+1) - (c_num+d_num-cd_num))
Buggy python submission (verdict: Runtime Error):
N = int(input())
ABn = [ list(map(int,input().split(' '))) for _ in range(N) ]
ABn.sort(key=lambda x: x[1])

count_time = 0
for AB in ABn:
    count_time += AB[0]
    if count_time <= AB[1]:
        continue
    else:
        print('No')
        exit(1)
print('Yes')

Fixed submission:
N = int(input())
ABn = [ list(map(int,input().split(' '))) for _ in range(N) ]
ABn.sort(key=lambda x: x[1])

count_time = 0
for AB in ABn:
    count_time += AB[0]
    if count_time <= AB[1]:
        continue
    else:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    u,v,w = map(int,input().split(' '))
    graph[u].append((v,w))
    graph[v].append((u,w))

color_list = [-1]*(N+1)
color_list[1] = 0
'''
for i in range(1,N+1):
    for node in graph[i]:
        if node[1]%2 ==0:
            num =  color_list[i]
        else:
            num =  0 if color_list[i] == 1 else 1
        if color_list[node[0]] == -1:
            color_list[node[0]] = num
'''
def search(n):
    for node in graph[n]:
        if node[1]%2 ==0:
            num =  color_list[n]
        else:
            num =  0 if color_list[n] == 1 else 1
        if color_list[node[0]] == -1:
            color_list[node[0]] = num
            search(node[0]) 
search(1)
print(color_list)
for i in range(1,N+1):
    print(color_list[i])

Fixed submission:
import sys

sys.setrecursionlimit(4100000)
N = int(input())
graph = [[] for _ in range(N+1)]
for _ in range(N-1):
    u,v,w = map(int,input().split(' '))
    graph[u].append((v,w))
    graph[v].append((u,w))

color_list = [-1]*(N+1)
color_list[1] = 0
'''
for i in range(1,N+1):
    for node in graph[i]:
        if node[1]%2 ==0:
            num =  color_list[i]
        else:
            num =  0 if color_list[i] == 1 else 1
        if color_list[node[0]] == -1:
            color_list[node[0]] = num
'''
def search(n):
    for node in graph[n]:
        if node[1]%2 ==0:
            num =  color_list[n]
        else:
            num =  0 if color_list[n] == 1 else 1
        if color_list[node[0]] == -1:
            color_list[node[0]] = num
            search(node[0]) 
search(1)
#print(color_list)
for i in range(1,N+1):
    print(color_list[i])
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

X,Y,Z,K = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))
output = []

for a in An:
    for b in Bn:
        for c in Cn:
            heapq.heappush(output,(a+b+c)*(-1))

for _ in range(K):
    print(heapq.heappop(output) * (-1))


Fixed submission:
import heapq
 
X,Y,Z,K = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))
output = []
ABn = [0] * (X*Y)
count = 0
for a in An:
    for b in Bn:
        ABn[count] = a + b
        count += 1
ABn.sort(reverse=True)
ABn = ABn[0:K]

for ab in ABn:
    for c in Cn:
        heapq.heappush(output,(ab+c)*(-1))
 
for _ in range(K):
    print(heapq.heappop(output) * (-1))

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

X,Y,Z,K = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))
output = []

for a in An:
    for b in Bn:
        for c in Cn:
            heapq.heappush(output,(a+b+c)*(-1))

for _ in range(K):
    print(heapq.heappop(output) * (-1))


Fixed submission:
import heapq
 
X,Y,Z,K = map(int,input().split(' '))
An = list(map(int,input().split(' ')))
Bn = list(map(int,input().split(' ')))
Cn = list(map(int,input().split(' ')))
output = []
ABn = [0] * (X*Y)
count = 0
for a in An:
    for b in Bn:
        ABn[count] = a + b
        count += 1
ABn.sort(reverse=True)
ABn = ABn[0:K]

for ab in ABn:
    for c in Cn:
        heapq.heappush(output,(ab+c)*(-1))
 
for _ in range(K):
    print(heapq.heappop(output) * (-1))