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

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

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

if n == 0:
    print(1 if A[0] == 1 else -1)
else:

    ans = 1
    b = 0
    L = [[0,0] for i in range(n)]
    # L[-1][0] = A[-1]
    # L[-1][1] = A[-1]
    l = A[-1]
    r = A[-1]
    for i in range(n-1,-1,-1):

        L[i][0] = (l+1)//2 + A[i]
        L[i][1] = r + A[i]
        l = L[i][0]
        r = L[i][1]

    if L[0][0] != 1:
        print(-1)
    else:
        ans = 1
        now = 1
        for i in range(1, n):
            now = min(L[i][1], now*2)
            # print(i,now)
            ans += now
            now -= A[i]
        print(ans + A[-1])

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

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

ans = 1
b = 0
L = [[0,0] for i in range(n)]
# L[-1][0] = A[-1]
# L[-1][1] = A[-1]
l = A[-1]
r = A[-1]
for i in range(n-1,-1,-1):

    L[i][0] = (l+1)//2 + A[i]
    L[i][1] = r + A[i]
    l = L[i][0]
    r = L[i][1]

if L[0][0] != 1:
    print(-1)
else:
    ans = 1
    now = 1
    for i in range(1, n):
        now = min(L[i][1], now*2)
        # print(i,now)
        ans += now
        now -= A[i]
    print(ans + A[-1])
Problem p02787 (python)

Fixed submission:
import sys
input = sys.stdin.readline
h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

D = [float("inf")] * (h+10**4+3)
D[0] = 0
for j in range(n):
    for i in range(len(D)):
        D[i] = min(D[i],D[i-A[j][0]] + A[j][1])
    # print(D[:20])
# print(D[:20])
print(min(D[h:]))

# a = float("inf")
# for i in range(n):
#     for j in range(n):
#         for k in range(h//A[i][0]+1):
#             b = A[i][1] * k + A[j][1] * max(0,-((-h+k*A[i][0])//A[j][0]))
#             a = min(a,b)
#             print(A[i][1] , k , A[j][1] , max(0,-((-h+k*A[i][0])//A[j][0])))
#             print(i,j,k,a)
        
# print(a)

# for i in range(n):
#     A[i].append(A[i][0]/ A[i][1])
# A.sort(reverse=True)
# A.sort(key=lambda x:x[2], reverse=True)
# print(A)
# a = 0
# while h > 0:
#     i=0
#     k = h//A[i][0]
#     h -= k * A[i][0]
#     a += k * A[i][1]
#     print(h)
#     if h > 0:
#         for i in range(n):
#             A[i][0] = min(A[i][0], h)
#             A[i][2] = A[i][0] / A[i][1]
#         A.sort(reverse=True)
#         A.sort(key=lambda x:x[2], reverse=True)
#     print(A)
# print(a)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
h,n = map(int,input().split())
A = [list(map(int,input().split())) for i in range(n)]

D = [float("inf")] * (h+10**4+3)
D[0] = 0
for j in range(n):
    for i in range(len(D)//A[j][0] + 1):
        D[i] = min(D[i],D[i-A[j][0]] + A[j][1])
    # print(D[:20])
# print(D[:20])
print(min(D[h:]))

# a = float("inf")
# for i in range(n):
#     for j in range(n):
#         for k in range(h//A[i][0]+1):
#             b = A[i][1] * k + A[j][1] * max(0,-((-h+k*A[i][0])//A[j][0]))
#             a = min(a,b)
#             print(A[i][1] , k , A[j][1] , max(0,-((-h+k*A[i][0])//A[j][0])))
#             print(i,j,k,a)
        
# print(a)

# for i in range(n):
#     A[i].append(A[i][0]/ A[i][1])
# A.sort(reverse=True)
# A.sort(key=lambda x:x[2], reverse=True)
# print(A)
# a = 0
# while h > 0:
#     i=0
#     k = h//A[i][0]
#     h -= k * A[i][0]
#     a += k * A[i][1]
#     print(h)
#     if h > 0:
#         for i in range(n):
#             A[i][0] = min(A[i][0], h)
#             A[i][2] = A[i][0] / A[i][1]
#         A.sort(reverse=True)
#         A.sort(key=lambda x:x[2], reverse=True)
#     print(A)
# print(a)
Problem p02802 (python)

Fixed submission:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])-1

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)
Problem p02803 (python)

Fixed submission:
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=w*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][w*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [input() for i in range(h)]

import numpy as np
from scipy.sparse.csgraph import floyd_warshall

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=h*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][h*ni+nj] = 1

# print(N)

# for k in range(m):
#     for i in range(m):
#         for j in range(m):
#             N[i][j] = min(N[i][j], N[i][k]+N[k][j])

N = floyd_warshall(N)


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(int(ans))

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split())
S = [input() for i in range(h)]

m = h*w

N = [[float("inf")]* m for i in range(m)]

for i in range(m):
    N[i][i] = 0

for i in range(h):
    for j in range(w):
        t=h*i+j
        if S[i][j] != "#":
            for dt in [[-1,0],[1,0],[0,1],[0,-1]]:
                di = dt[0]
                dj=dt[1]
                ni = i+di
                nj = j+dj
                if 0 <= ni < h and 0 <= nj < w and S[ni][nj] == ".":
                    N[t][h*ni+nj] = 1

# print(N)

for k in range(m):
    for i in range(m):
        for j in range(m):
            N[i][j] = min(N[i][j], N[i][k]+N[k][j])


for i in range(m):
    for j in range(m):
        if N[i][j] == float("inf"):
            N[i][j] = -1
ans = 0
# print(N)
for i in range(m):
    ans = max(ans, max(N[i]))
print(ans)
Problem p02814 (python)

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

# import numpy as np

# def gcd(x, y):
#     while x != 0 and y != 0:
#         x, y = max(x, y), min(x, y)
#         x %= y
#     return y

from fractions import gcd

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

import sys

a = 0

B = [0] * n
C = A[:]

for i in range(n):
    while A[i] % 2 == 0:
        A[i] //= 2
        B[i] += 1

if len(set(B)) != 1:
    print("0")
else:
    for i in range(n):
        C[i] //= 2
    A = C
    b = A[0]
    for i in range(1,n):
        b = lcm(A[i], b)
        if b > m:
            print(0)
            sys.exit()
        # b = np.lcm(A[i],b)
    # print("b", b)

    # b=np.lcm.reduce(A)

    ans = (m//b + 1) // 2
    # if (m//(b*2))*(b*2)+b<=m:
    #     ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

import numpy as np

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return y

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

a = 0
for i in range(n):
    if A[i]%2==1:
        a = 1
if a==1:
    print(0)
else:
    for i in range(n):
        A[i] //= 2
    b = A[0]
    for i in range(1,n):
        b = np.lcm(A[i],b)
    # print(b)

    # b=np.lcm.reduce(A)

    ans = m//(b*2)
    if (m//(b*2))*(b*2)+b<=m:
        ans += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

import numpy as np

def gcd(x, y):
    while x != 0 and y != 0:
        x, y = max(x, y), min(x, y)
        x %= y
    return y

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

a = 0
for i in range(n):
    if A[i]%2==1:
        a = 1
if a==1:
    print(0)
else:
    for i in range(n):
        A[i] //= 2
    # b = A[0]
    # for i in range(1,n):
    #     b = lcm(b,A[i])
    # print(b)

    b=np.lcm.reduce(A)

    ans = m//(b*2)
    if (m//(b*2))*(b*2)+b<=m:
        ans += 1
    print(ans)
Problem p02846 (python)

Fixed submission:
t1,t2 = map(int,input().split())

a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
c1 = b1-a1
c2 = b2-a2

s = t1*c1
t = s + t2*c2
# print(c1,c2,s,t)
ans = -1
if s * t > 0:
    ans = 0
elif t == 0:
    ans=-10
else:
    if s > t:
        tt = abs(t)
        ans = -((-s / tt)//1)*2 - 1
        if s / tt - s//tt < 10**-25:
            ans += 1
    else:
        ss = abs(s)
        ans = -((-ss / t)//1)*2 - 1
        if ss / t -ss//t < 10**-25:
            ans += 1
if ans == -10:
    print("infinity")
else:
    print(int(ans))

Buggy submission (verdict: Runtime Error):
t1,t2 = map(int,input().split())

a1,a2 = map(int,input().split())
b1,b2 = map(int,input().split())
c1 = b1-a1
c2 = b2-a2

s = t1*c1
t = s + t2*c2
print(c1,c2,s,t)
ans = -1
if s * t > 0:
    ans = 0
elif t == 0:
    ans="infinity"
else:
    if s > t:
        tt = abs(t)
        ans = -((-s / tt)//1)*2 - 1
        if s / tt - s//tt < 10**-25:
            ans += 1
    else:
        ss = abs(s)
        ans = -((-ss / t)//1)*2 - 1
        if ss / t -ss//t < 10**-25:
            ans += 1
print(int(ans))
Problem p02901 (python)

Fixed submission:
n, m = map(int,input().split())
A = []
C = []
for i in range(m):
    ab = list(map(int,input().split()))
    A.append(ab)
    cc = list(map(int,input().split()))
    C.append(cc)
T = []
for i in range(m):
    t = 0
    for j in C[i]:
        t += 2**(j-1)
    T.append(t)


n2 = 2**n

DP = [[float("inf") for i in range(n2)] for j in range(m+1)]
for i in range(m+1):
    DP[i][0] = 0

for i in range(1,m+1):
    t = T[i-1]
    for j in range(n2):
        # print(i,j,t)
        # print(DP[i][j|t], DP[i-1][j|t], DP[i-1][j] + A[i-1][0])
        DP[i][j|t] = min(DP[i][j|t], DP[i-1][j|t], DP[i-1][j] + A[i-1][0])
        DP[i][j] = min(DP[i][j], DP[i-1][j])
        # print(DP[i][j|t])

ans = DP[-1][-1]
if ans == float("inf"):
    ans = -1
print(int(ans))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra

n, m = map(int,input().split())
A = []
C = []
for i in range(m):
    ab = list(map(int,input().split()))
    A.append(ab)
    cc = list(map(int,input().split()))
    C.append(cc)

M = [[float("inf")] * 2**n for i in range(2**n)]

for i in range(2**n):
    M[i][i] = 0

for i in range(m):
    t = 0
    for j in C[i]:
        t += 2**(j-1)
    for j in range(2**n):
        for k in range(2**n):
            if (t-(k-j)) ^ (k-j) == t:
                # print(t,j)
                M[j][k] = min(M[j][k], A[i][0])
# print(M)

d = dijkstra(M, indices = 0)

ans = d[-1]
if ans == float("inf"):
    ans = -1
print(int(ans))
Problem p02926 (python)

Fixed submission:
import math

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

X2 = []
for i in range(n):
    if X[i] != [0, 0]:
        X2.append(X[i][:])

X = X2[:]

n = len(X)

if n == 0:
    print(0)
else:

    for i in range(n):
        X[i].append(math.atan2(X[i][1], X[i][0]))

    X.sort(key=lambda x:x[2])

    X += X[:]
    #print(X)
    ans = 0

    X_sum = [[X[0][0], X[0][1]]]
    for i in range(1, 2*n):
        #print(i)
        X_sum.append([X_sum[i-1][0] + X[i][0], X_sum[i-1][1] + X[i][1]])

    #print(len(X_sum))

    for st in range(0, n):
        for en in range(st+1, st+n+1):
            dis = [0, 0]
            for i in range(st, en):
                #print(i)
                dis[0] = X_sum[en][0] - X_sum[st][0]
                dis[1] = X_sum[en][1] - X_sum[st][1]
            #print(st,en,(dis[0]**2 + dis[1]**2)**0.5)
            ans = max(ans, (dis[0]**2 + dis[1]**2))


    print(ans ** 0.5)

Buggy submission (verdict: Runtime Error):
import math

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

X2 = []
for i in range(n):
    if X[i] != [0, 0]:
        X2.append(X[i][:])

X = X2[:]

n = len(X)

for i in range(n):
    X[i].append(math.atan2(X[i][1], X[i][0]))

X.sort(key=lambda x:x[2])

X += X[:]
#print(X)
ans = 0

X_sum = [[X[0][0], X[0][1]]]
for i in range(1, 2*n):
    #print(i)
    X_sum.append([X_sum[i-1][0] + X[i][0], X_sum[i-1][1] + X[i][1]])

#print(len(X_sum))

for st in range(0, n):
    for en in range(st+1, st+n+1):
        dis = [0, 0]
        for i in range(st, en):
            #print(i)
            dis[0] = X_sum[en][0] - X_sum[st][0]
            dis[1] = X_sum[en][1] - X_sum[st][1]
        #print(st,en,(dis[0]**2 + dis[1]**2)**0.5)
        ans = max(ans, (dis[0]**2 + dis[1]**2))


print(ans ** 0.5)
Problem p02949 (python)

Fixed submission:
n, m, p = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    A[i][2] = - (A[i][2]-p)

#import numpy as np
# A = np.full(np.inf, (n+1, n+1))

# scipy.sparse.csgraph.bellman_ford


S = [10**13 for i in range(n+1)]

S[1]=0
for i in range(m):
    if A[i][0] == 1:
        S[A[i][1]]=A[i][2]

for j in range(n-1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])

#print(S)
ans1 = -S[n]

for j in range(n):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])
#print(S)
ans2 = -S[n]

if ans1 != ans2:
    print(-1)
else:
    print(max(0, ans1))

Buggy submission (verdict: Runtime Error):
n, m, p = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

for i in range(m):
    A[i][2] = - (A[i][2]-p)


import numpy as np
S = [np.inf for i in range(n+1)]

S[1]=0
for i in range(m):
    if A[i][0] == 1:
        S[A[i][1]]=A[i][2]

for j in range(n-1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])

#print(S)
ans1 = -S[n]

for j in range(1):
    for i in range(m):
        S[A[i][1]] = min(S[A[i][1]], S[A[i][0]]+A[i][2])
#print(S)
ans2 = -S[n]

if ans1 != ans2:
    print(-1)
else:
    print(max(0, ans1))
Problem p02973 (python)

Fixed submission:
n = int(input())
A = [int(input()) for i in range(n)]

Q = [-float("inf"), A[0]] + [float("inf")] * (n+1)
le = 2
for i in range(1, n):
    if Q[le-1] >= A[i]:
        Q[le] = A[i]
        le += 1
    else:
        l = 0
        r = le
        m = (l+r)//2
        while r-l > 1:
            if Q[m] >= A[i]:
                l = m
            else:
                r = m
            m = (l+r)//2
        Q[l+1] = A[i]
    # print(Q[:10])

print(le-1)

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

AA=[]
for i in range(n):
    AA.append([A[i],i])

A = AA[:]
A.sort(key=lambda x:x[0])

mm = 10**5+10
B=[0 for i in range(mm)]
for i in range(n):
    if A[i]<=mm:
        B[A[i]]+=1
        mm=A[i]
    else:
        t=A[i]
        while B[t]==0:
            t-=1
        B[t]-=1
        B[A[i]]+=1
        #print(B)
        if mm==t and B[t]==0:
            while B[mm]==0:
                mm+=1
print(sum(B))
Problem p02995 (python)

Fixed submission:


def gcd(x,y):
    x, y = max(x,y), min(x,y)
    while x!=0 :
        x, y = max(x,y), min(x,y)
        x %= y
    return y
#print(gcd(4,8))

a,b,c,d = map(int,input().split())
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d

cd = int(c*d/gcd(c,d))
cd_ok = b//cd - (a-1)//cd

print(int(b-a+1-c_ok-d_ok+cd_ok))

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d

cd = int(c*d/math.gcd(c,d))
cd_ok = b//cd - (a-1)//cd

print(int(b-a+1-c_ok-d_ok+cd_ok))

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d = map(int,input().split())
c_ok = b//c - (a-1)//c
d_ok = b//d - (a-1)//d

cd = int(c*d/math.gcd(c,d))
cd_ok = b//cd - (a-1)//cd

print(int(b-a+1-c_ok-d_ok+cd_ok))
Problem p03006 (python)

Fixed submission:
n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

# B = [[[0, 0] for i in range(n)] for j in range(n)]
if n == 1:
    print(1)
else:

    D = {}
    for i in range(n):
        for j in range(n):
            if i != j:
                dy = A[i][1] - A[j][1]
                dx = A[i][0] - A[j][0]
                try:
                    D[(dx, dy)] += 1
                except:
                    D[(dx, dy)] = 1
    # print(D)
    ans = n - max(list(D.values()))
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [list(map(int,input().split())) for i in range(n)]

# B = [[[0, 0] for i in range(n)] for j in range(n)]
D = {}
for i in range(n):
    for j in range(i+1, n):
        dy = A[i][1] - A[j][1]
        dx = A[i][0] - A[j][0]
        try:
            D[(dx, dy)] += 1
        except:
            D[(dx, dy)] = 1

ans = n - max(list(D.values()))
print(ans)
Problem p03007 (python)

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

a, b = max(A), min(A)
for t in [a, b]:
    for i in range(len(A)):
        if A[i] == t:
            A.pop(i)
            break

ans = a-b
for i in range(n-2):
    ans += abs(A[i])
print(ans)

for i in range(n-2):
    if A[i] > 0:
        print(b, A[i])
        b -= A[i]
    else:
        print(a, A[i])
        a -= A[i]
print(a, b)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))

a, b = max(A), min(A)
for t in [a, b]:
    for i in range(len(A)):
        if A[i] == t:
            A.pop(i)

ans = a-b
for i in range(n-2):
    ans += abs(A[i])
print(ans)

for i in range(n-2):
    if A[i] > 0:
        print(b, A[i])
        b -= A[i]
    else:
        print(a, A[i])
        a -= A[i]
print(a, b)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))

a = max(A)
b = min(A)
A.pop(a)
A.pop(b)

ans = a-b
for i in range(n-2):
    ans += abs(A[i])
print(ans)

for i in range(n-2):
    if A[i] > 0:
        print(b, A[i])
        b -= A[i]
    else:
        print(a, A[i])
        a -= A[i]
print(a, b)
Problem p03044 (python)

Fixed submission:
n = int(input())
A = [list(map(int,input().split())) for i in range(n-1)]

B = [[] for i in range(n+1)]

for i in range(len(A)):
    B[A[i][0]].append([A[i][1],A[i][2]])
    B[A[i][1]].append([A[i][0],A[i][2]])

root = 0
for i in range(len(B)):
    root = max(root, len(B[i]))

ANS = [-1 for i in range(n+1)]
ANS[root]=0
#print(B)
nurulist = [root]
t = 0
while t < len(nurulist):
    k = nurulist[t]
    col = ANS[k]
    for j in range(len(B[k])):
        if ANS[B[k][j][0]] == -1:
            ANS[B[k][j][0]] = (col + B[k][j][1])%2
            nurulist.append(B[k][j][0])
    t += 1


#print(ANS)

for i in range(n):
    print(ANS[i+1])

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [list(map(int,input().split())) for i in range(n-1)]

B = [[] for i in range(n+1)]

for i in range(len(A)):
    B[A[i][0]].append([A[i][1],A[i][2]])
    B[A[i][1]].append([A[i][0],A[i][2]])

root = 0
for i in range(len(B)):
    root = max(root, len(B[i]))

ANS = [-1 for i in range(n+1)]
ANS[root]=0
#print(B)
def nuru(k):
    col = ANS[k]
    for j in range(len(B[k])):
        if ANS[B[k][j][0]] == -1:
            ANS[B[k][j][0]] = (col + B[k][j][1])%2
            nuru(B[k][j][0])

nuru(root)

#print(ANS)

for i in range(n):
    print(ANS[i+1])

Buggy submission (verdict: Runtime Error):
n = int(input())
A = [list(map(int,input().split())) for i in range(n-1)]

B = [[] for i in range(n+1)]

for i in range(len(A)):
    B[A[i][0]].append([A[i][1],A[i][2]])
    B[A[i][1]].append([A[i][0],A[i][2]])

root = 0
for i in range(len(B)):
    root = max(root, len(B[i]))

ANS = [0 for i in range(n+1)]

def nuru(k):
    col = ANS[k]
    for j in range(len(B[k])):
        ANS[B[k][j][0]] = (col + B[k][j][1])%2
        nuru(j)

nuru(root)

#print(ANS)

for i in range(n):
    print(ANS[i+1])
Problem p03096 (python)

Fixed submission:
n = int(input())
C = [int(input()) for i in range(n)]
nc = 2 * 10 ** 5 + 3
mod = 10**9+7

A = [0] * n
B = [-1] * nc

A[-1] = 1
B[C[-1]] = n-1
# print(B)

for i in range(n-2, -1, -1):
    if B[C[i]] != -1 and B[C[i]] != i+1:
        A[i] = (A[i+1] + A[B[C[i]]]) % mod
    else:
        A[i] = A[i+1]
    B[C[i]] = i
    # print(A,B)

# print(A)
# print(B)
print(A[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
C = [int(input()) for i in range(n)]
nc = 10 ** 5 + 3
mod = 10**9+7

A = [0] * n
B = [-1] * nc

A[-1] = 1
B[C[-1]] = n-1
# print(B)

for i in range(n-2, -1, -1):
    if B[C[i]] != -1 and B[C[i]] != i+1:
        A[i] = (A[i+1] + A[B[C[i]]]) % mod
    else:
        A[i] = A[i+1]
    B[C[i]] = i
    # print(A,B)

# print(A)
# print(B)
print(A[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
C = [int(input()) for i in range(n)]
mod = 10**9+7

A = [0] * n
B = [-1] * (n+1)

A[-1] = 1
B[C[-1]] = n-1
# print(B)

for i in range(n-2, -1, -1):
    if B[C[i]] != -1 and B[C[i]] != i+1:
        A[i] = (A[i+1] + A[B[C[i]]]) % mod
    else:
        A[i] = A[i+1]
    B[C[i]] = i
    # print(A,B)

# print(A)
# print(B)
print(A[0])