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

A = [a for i, a in enumerate(A) if a <= i+1]
k = 0

while k < len(A):
    if A[k] != k+1:
        A.pop(k)
    else:
        k += 1

if len(A) == 0:
    print(-1)
else:
    print(N - len(A))

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

A = [a for i, a in enumerate(A) if a <= i+1]

k = 0
for a in A:
    if a == k+1:
        k += 1
    

if k == 0:
    print(-1)
else:
    print(N - k)

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

A = [a for i, a in enumerate(A) if a <= i+1]
A = [a for i, a in enumerate(A) if a <= i+1]
k = 0

while k < len(A):
    if A[k] != k+1:
        A.pop(k)
    else:
        k += 1

if len(A) == 0:
    print(-1)
else:
    print(N - len(A))

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

A = [a for i, a in enumerate(A) if a <= i+1]

k = 0
for a in A:
    if a == k+1:
        k += 1
    

if k == 0:
    print(-1)
else:
    print(N - k)

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

A = [a for i, a in enumerate(A) if a <= i+1]
k = 0

while k < len(A):
    if A[k] != k+1:
        A.pop(k)
    else:
        k += 1

if len(A) == 0:
    print(-1)
else:
    print(N - len(A))

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

A = [a for i, a in enumerate(A) if a <= i+1]

k = 0
for a in A:
    if a == k+1:
        k += 1
    

if k == 0:
    print(-1)
else:
    print(N - k)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        bin_a = bin(a)[2:].zfill(max_bin_digits)
        for i, b in enumerate(bin_a):
            if int(b):
                cnts[-i-1] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        for i in range(max_bin_digits):
            if 1 << i & a:
                cnts[i] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [[0, 0] for _ in range(max_bin_digits)]

    for a in A:
        bin_a = bin(a)[2:].zfill(max_bin_digits)
        for i, b in enumerate(bin_a):
            cnts[-i-1][int(b)] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i][0] * cnts[i][1] * 2 ** i
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        for i in range(max_bin_digits):
            if 1 << i & a:
                cnts[i] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10 ** 9 + 7

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

    max_bin_digits = len(bin(max(A))[2:])
    cnts = [[0, 0] for _ in range(max_bin_digits)]

    for a in A:
        bin_a = bin(a)[2:].zfill(max_bin_digits)
        bin_a = bin_a[::-1]
        for i, b in enumerate(bin_a):
            cnts[i][int(b)] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i][0] * cnts[i][1] * 2 ** i
        ans %= MOD

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    max_bin_digits = len(bin(max(A))[2:])
    cnts = [0] * max_bin_digits

    for a in A:
        for i in range(max_bin_digits):
            if 1 << i & a:
                cnts[i] += 1

    ans = 0
    for i in range(max_bin_digits):
        ans += cnts[i] * (N - cnts[i]) * 2 ** i
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ans = []
for i in range(N, len(S)):
    ans.append(S[i])

for i in range(N):
    ans.append(S[i])

print(''.join(ans))

Fixed submission:
N = int(input())
S = input()

alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
di = {}
for i in range(len(alp)):
    di[alp[i]] = i
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
# N = N % len(S)

ans = []
for s in S:
    ans.append(alp[di[s]+N])

print(''.join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import math
X, Y = map(int, input().split())
MOD = 10**9 + 7

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

def solve():
    a = (2*Y-X) / 3
    b = (2*X-Y) / 3
    if a.is_integer() and b.is_integer() and a >= 0 and b >= 0:
        ans = combinations_count(a+b, min(a, b))
        print(ans%MOD)
    else:
        print(0)

if __name__ == '__main__':
    solve()

Fixed submission:
from math import factorial
X, Y = map(int, input().split())
MOD = 10**9 + 7

def comb(n, r, p):
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % p

def solve():
    a = (2*Y-X) / 3
    b = (2*X-Y) / 3
    if a.is_integer() and b.is_integer() and a >= 0 and b >= 0:
        ans = comb(int(a+b), int(min(a, b)), MOD)
        print(ans)
    else:
        print(0)

if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

def main():
    N = int(input())
    L = list(map(int, input().split()))

    L = sorted(L)
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_left

def main():
    N = int(input())
    L = list(map(int, input().split()))
    
    L = sorted(L)
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    L = list(map(int, input().split()))

    L = sorted(L)
    ans = 0
    comb = [p for p in combinations(L, 3)]
    for a, b, c in comb:
        if c < a + b:
            ans += 1

    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
from bisect import bisect_left

def main():
    N = int(input())
    L = list(map(int, input().split()))
    
    L = sorted(L)
    ans = 0
    for i in range(N-2):
        a = L[i]
        for j in range(i+1, N-1):
            k = bisect_left(L[j+1:], a + L[j])
            ans += k

    print(ans)

    
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
S = input()

def solve():
    global K, S
    concat_S = S[:]
    while 'LL' in concat_S:
        concat_S = concat_S.replace('LL', 'L', 1)
    while 'RR' in concat_S:
        concat_S = concat_S.replace('RR', 'R', 1)

    ans = len(S) - len(concat_S)
    if len(concat_S) >= 4:
        # 2個ずつ消す
        num_rm = min(K, (len(concat_S)-2)//2)
        K -= num_rm
        ans += num_rm * 2
        len_concat_S = len(S) - ans

        if K:
            if len_concat_S == 3:
                ans += 2
            elif len_concat_S == 2:
                ans += 1
        print(ans)
        return
    if K:
        if len(concat_S) == 3:
            ans += 2
        elif len(concat_S) == 2:
            ans += 1
        
    print(ans)
    return

if __name__ == "__main__":
    solve()

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

def solve():
    global K, S
    concat_S = S[:]
    while 'LL' in concat_S:
        concat_S = concat_S.replace('LL', 'L')
    while 'RR' in concat_S:
        concat_S = concat_S.replace('RR', 'R')

    ans = len(S) - len(concat_S)
    if len(concat_S) >= 4:
        # 2個ずつ消す
        num_rm = min(K, (len(concat_S)-2)//2)
        K -= num_rm
        ans += num_rm * 2
        len_concat_S = len(S) - ans

        if K:
            if len_concat_S == 3:
                ans += 2
            elif len_concat_S == 2:
                ans += 1
        print(ans)
        return
    if K:
        if len(concat_S) == 3:
            ans += 2
        elif len(concat_S) == 2:
            ans += 1
        
    print(ans)
    return

if __name__ == "__main__":
    solve()

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

def solve():
    global K, S
    concat_S = S[:]
    while 'LL' in concat_S:
        concat_S = concat_S.replace('LL', 'L', 1)
    while 'RR' in concat_S:
        concat_S = concat_S.replace('RR', 'R', 1)

    ans = len(S) - len(concat_S)
    S = concat_S
    while K and len(S) > 3:
        S = ''.join([S[0], S[3:]])
        ans += 2
        K -= 1

    if K:
        if len(S) == 3:
            ans += 2
        elif len(S) == 2:
            ans += 1
        
    print(ans)

if __name__ == "__main__":
    solve()

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

def solve():
    global K, S
    concat_S = S[:]
    while 'LL' in concat_S:
        concat_S = concat_S.replace('LL', 'L')
    while 'RR' in concat_S:
        concat_S = concat_S.replace('RR', 'R')

    ans = len(S) - len(concat_S)
    if len(concat_S) >= 4:
        # 2個ずつ消す
        num_rm = min(K, (len(concat_S)-2)//2)
        K -= num_rm
        ans += num_rm * 2
        len_concat_S = len(S) - ans

        if K:
            if len_concat_S == 3:
                ans += 2
            elif len_concat_S == 2:
                ans += 1
        print(ans)
        return
    if K:
        if len(concat_S) == 3:
            ans += 2
        elif len(concat_S) == 2:
            ans += 1
        
    print(ans)
    return

if __name__ == "__main__":
    solve()
Buggy python submission (verdict: Runtime Error):
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  print(sum([combinations_count(t, 2) for t in  c.values()]))
 
if __name__ == '__main__':
  main()

Fixed submission:
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys 
inpurt = sys.stdin.readline
N = int(input())
cnt = 0
texts = [sorted(list(input().rstrip())) for _ in range(N)]
for i in range(N):
  for j in range(i+1, N):
    if texts[i] == texts[j]:
      cnt += 1
print(cnt)

Fixed submission:
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    S = readline().rstrip()
    N = 13
    dp = [0] * 13  # dp[k]: 13で割った余りがkのパターン数
    dp[0] = 1
    
    mul = 1
    for i in range(len(S)-1, -1, -1):
        next_dp = [0] * N
        s = S[i]
        if s == '?':
            for k in range(10):
                for j in range(N):
                    next_dp[(k * mul + j) % N] += dp[j]
                    next_dp[(k * mul + j) % N] %= MOD
        else:
            k = int(s)
            for j in range(N):
                next_dp[(k * mul + j) % N] += dp[j]
                next_dp[(k * mul + j) % N] %= MOD
        mul *= 10
        mul %= N
        dp = next_dp

    print(dp[5])

if __name__ == '__main__':
    main()

Fixed submission:
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7

def main():
    S = readline().rstrip()
    N = 13
    dp = [0] * 13  # dp[k]: 13で割った余りがkのパターン数
    dp[0] = 1
    
    mul = 1
    for s in S[::-1]:
        next_dp = [0] * N
        if s == '?':
            for k in range(10):
                for j in range(N):
                    next_dp[(k * mul + j) % N] += dp[j]
                    next_dp[(k * mul + j) % N] %= MOD
        else:
            k = int(s)
            for j in range(N):
                next_dp[(k * mul + j) % N] += dp[j]
                next_dp[(k * mul + j) % N] %= MOD
        mul *= 10
        mul %= N
        dp = next_dp

    print(dp[5])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    for i in range(len(A)):
        a = A[:]
        a.pop(i)
        print(max(a))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    max_val = max(A)
    AA = A[:]
    AA.remove(max_val)
    second_max_val = max(AA)
    for a in A:
        if a != max_val:
            print(max_val)
        else:
            print(second_max_val)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))

    for i in range(N//2, 0, -1):
        sum_m = sum([A[j] for j in range(i*2, N+1) if j%i==0])
        if A[i] == 0:
            if sum_m % 2 == 1:
                A[i] = 1
        else:
            if sum_m % 2 == 1:
                A[i] = 0

    sum_b = sum(A)
    print(sum_b)
    if sum_b:
        for i in range(N+1):
            if A[i] == 1:
                print(i)


if __name__ == "__main__":
    main()

Fixed submission:
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    b = [None]*N
    
    for i in range(N, math.ceil(N/2), -1):
        b[i-1] = A[i-1]
    
    for i in range(math.ceil(N/2), 0, -1):
        s = sum([b[j-1] for j in range(2*i, N+1, i)])
        b[i-1] = (A[i-1] + s) % 2
        
    b_out = [str(i+1) for i in range(N) if b[i] == 1]
    print(sum(b))
    print(' '.join(b_out))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    L, R = map(int, input().split())
    start = time.time()
    if R // 2019 > L // 2019:
        print(0)
        return
    retval = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            retval = min(retval, (i % 2019 * j % 2019) % 2019)
            if retval == 0:
                print(0)
                return
            
    print(retval)
    return
    
if __name__ == '__main__':
    main()

Fixed submission:
def main():
    L, R = map(int, input().split())
    if R // 2019 > L // 2019:
        print(0)
        return
    retval = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            retval = min(retval, (i % 2019 * j % 2019) % 2019)
    print(retval)
    return
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
from math import factorial
MOD = 10 ** 9 + 7

def main():
    N, K = map(int, readline().rstrip().split())
    f1 = factorial(N-K+1)
    f2 = factorial(K-1)
    f3 = 1
    for i in range(1, K+1):
        ans = f2 // (f3 * factorial(K-i))
        f3 *= i
        ans *= f1 // (f3 * factorial(N-K+1-i))
        print(ans % MOD)

if __name__ == '__main__':
    main()

Fixed submission:
from math import factorial

N, K = map(int, input().split())
n_blue, n_red = K, N-K

for k in range(1, K+1):
    if k-1 > n_red:
        print(0)
        continue
    retval = (factorial(n_red+1) // (factorial(n_red-k+1) * factorial(k))) * (factorial(n_blue-1) // (factorial(n_blue-k) * factorial(k-1)))
    print(retval % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
from math import factorial

N, K = map(int, input().split())
n_blue, n_red = K, N-K

for k in range(1, K+1):
    retval = (factorial(n_red+1) // (factorial(n_red-k+1) * factorial(k))) * (factorial(n_blue-1) // (factorial(n_blue-k) * factorial(k-1)))
    print(retval % (10**9 + 7))

Fixed submission:
from math import factorial

N, K = map(int, input().split())
n_blue, n_red = K, N-K

for k in range(1, K+1):
    if k-1 > n_red:
        print(0)
        continue
    retval = (factorial(n_red+1) // (factorial(n_red-k+1) * factorial(k))) * (factorial(n_blue-1) // (factorial(n_blue-k) * factorial(k-1)))
    print(retval % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = 0
i = 0
while D <= X:
    D += L[i]
    i += 1
print(i)

Fixed submission:
def main():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    D = 0
    i = 0
    while True:
        D += L[i]
        i += 1
        if D > X:
            print(i)
            return
        if i == N:
            print(i+1)
            return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())

divide_x = (x * H, (W-x) * H)
divide_y = (W * y, W * (H-y))
max_value = max(min(divide_x), min(divide_y))
if min(divide_x) == min(divide_y):
    is_mullt_ans = 1
else:
     is_mullt_ans = 0

print(max_value, is_mult_ans)

Fixed submission:
W, H, x, y = map(int, input().split())

if W % 2 == 0 and H % 2 == 0 and x == W // 2 and y == H // 2:
    is_mullt_ans = 1
else:
    is_mullt_ans = 0

print(W * H / 2, is_mullt_ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
broken_floors = [int(input()) for _ in range(M)]
dp = [0]*(N+2)
dp[1] = 1

for i in range(1, N+1):
    if i not in broken_floors:
        dp[i+1] = (dp[i] + dp[i-1]) % MOD

print(dp[-1])

Fixed submission:
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
broken_floors = set(int(input()) for _ in range(M))
dp = [0]*(N+2)
dp[1] = 1

for i in range(1, N+1):
    if i not in broken_floors:
        dp[i+1] = (dp[i] + dp[i-1]) % MOD

print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

def main():
    N, K = map(int, readline().rstrip().split())
    V = list(map(int, readline().rstrip().split()))
    V_rev = V[::-1]
    res = 0
    for x in range(K+1):
        for y in range(K-x+1):
            z = K - x - y
            if z > x + y:
                continue
            temp = V[:x] + V_rev[:y]
            heapify(temp)
            for _ in range(z):
                heappop(temp)

            res = max(res, sum(temp))
    
    print(res)


if __name__ == '__main__':
    main()

Fixed submission:
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

def main():
    N, K = map(int, readline().rstrip().split())
    V = list(map(int, readline().rstrip().split()))
    V_rev = V[::-1]
    res = 0
    for x in range(min(N, K)+1):
        for y in range(min(N, K)-x+1):
            z = K - x - y
            temp = V[:x] + V_rev[:y]
            heapify(temp)
            for _ in range(z):
                if temp:
                    m = heappop(temp)
                    if m >= 0:
                        heappush(temp, m)
                        break
                else:
                    break

            res = max(res, sum(temp))
    
    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline
from scipy.sparse.csgraph import dijkstra

def main():
    N = int(input())
    path = [[False] * N for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map(int, readline().rstrip().split())
        path[u-1][v-1] = w
        path[v-1][u-1] = w
    
    G = dijkstra(path, indices=0)
    for i in range(N):
        if G[i] % 2 == 0:
            print(0)
        else:
            print(1)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
readline = sys.stdin.readline
from heapq import heapify, heappush, heappop

def dijkstra(path, N, a):
    visited = [False] * N
    que = [(0, a)]
    heapify(que)  # 始点aから各頂点への(距離, 頂点ID)
    dist = [-1] * N  # 始点aから各頂点への距離
    dist[a] = 0  # 始点aからaへの距離は0
    while que:
        d, v = heappop(que)  # 始点から最短距離の頂点を(確定ノード)を取り出す
        visited[v] = True  # 確定フラグを立てる
        # 接続先ノードの情報を更新する
        for d, to in path[v]:
            cost = dist[v] + d
            if dist[to] < 0 or cost < dist[to]:
                dist[to] = cost
                if not visited[to]:
                    heappush(que, (cost, to))

    return dist

def main():
    N = int(input())
    path = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = map(int, readline().rstrip().split())
        path[u-1].append((w, v-1))
        path[v-1].append((w, u-1))
    
    G = dijkstra(path, N, 0)
    for i in range(N):
        if G[i] % 2 == 0:
            print(0)
        else:
            print(1)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0

for i in range(1, 2**N):
    comb = list(map(int, bin(i)[2:].zfill(N)))
    X, Y = 0, 0
    for i, c in enumerate(comb):
        if c == 1:
            X += V[i]
            Y += C[i]
    ans = max(ans, X-Y)

print(ans)

Fixed submission:
N = int(input())
values = list(map(int, input().split()))
costs = list(map(int, input().split()))
gains = [values[i] - costs[i] for i in range(N) if values[i] - costs[i] > 0]
print(max(sum(gains), 0))