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

Fixed submission:
S = input()
A = [0 for i in range(2019)]
x = 0
q = 1
for i in range(len(S)):
    p = i + 1
    a = (int(S[-p]))
    b = a*q%2019
    x = (x+b) % 2019
    A[x] += 1
    q = q*10%2019
ans = A[0]
for i in range(2019):
    ans += A[i]*(A[i]-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
A = [0 for i in range(2019)]
x = 0
for i in range(len(S)):
    p = i + 1
    a = (int(S[-p]))10**i % 2019
    x = (x+a) % 2019
    A[x] += 1
ans += A[i]
for i in range(2019):
    ans += A[i]*(A[i]-1)//2
print(ans)
Problem p02783 (python)

Fixed submission:
import math
H,A = map(int,input().split())
print(math.ceil(H/A))

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
h = 2*10**4
dp = [10**9 for i in range(h+1)]
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(h+1):
        if j < a:
            continue
        dp[j] = min(dp[j-a]+b,dp[j])
ans = 10**9
for i in range(H,h+1):
    ans = min(ans,dp[i])
print(ans)
Problem p02787 (python)

Fixed submission:
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
x = max(A)
dp = [10**9 for i in range(H+x+1)]
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(H+x+1):
        if j < a:
            continue
        dp[j] = min(dp[j-a]+b,dp[j])
ans = 10**9
for i in range(H,H+x+1):
    ans = min(ans,dp[i])
print(ans)

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
x = max(A)
dp = [10**9 for i in range(H+x+1)]
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(H+x+1):
        if j < a:
            continue
        dp[j] = min(dp[j-a]+b,dp[j])
ans = 10**9
for i in range(H,H+X+1):
    ans = min(ans,dp[i])
print(ans)

Buggy submission (verdict: Runtime Error):
H,N = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
h = 2*10**4
dp = [10**9 for i in range(x+1)]
dp[0] = 0
for i in range(N):
    a = A[i]
    b = B[i]
    for j in range(x+1):
        if j < a:
            continue
        dp[j] = min(dp[j-a]+b,dp[j])
ans = 10**9
for i in range(H,x+1):
    ans = min(ans,dp[i])
print(ans)
Problem p02788 (python)

Fixed submission:
N,D,A = map(int,input().split())
attack_number = {}
Enemy = []
import math
for i in range(N):
    x,h = map(int,input().split())
    n = math.ceil(h/A)
    attack_number[x] = n
    Enemy.append(x)
Enemy.sort()
bomb_number = [0 for i in range(N+1)]
F = {}
import bisect
for i in range(N):
    x = Enemy[i]
    y = bisect.bisect_right(Enemy,x+2*D)
    F[i] = y
ans = 0
for i in range(N):
    if i > 0:
        bomb_number[i] += bomb_number[i-1]
    x = attack_number[Enemy[i]] - bomb_number[i]
    if x <= 0:
        continue
    y = F[i]
    bomb_number[i] += x
    bomb_number[y] -= x
    ans += x
print(ans)

Buggy submission (verdict: Runtime Error):
N,D,A = map(int,input().split())
d = {}
E = []
for i in range(N):
    x,h = map(int,input().split())
    d[x] = h
    E.append(x)
E.sort()
ans = 0
import bisect
for i in range(N):
    x = E[i]
    if d[x] <= 0:
        continue
    y = bisect.bisect_right(E,x+2*D)
    ans += d[x]
    for j in range(i,y):
        d[j] -= d[x]
print(ans)
Problem p02802 (python)

Fixed submission:
N,M = map(int,input().split())
d = {}
P = {}
for i in range(1,N+1):
    d[i] = 0
    P[i] = 0
for i in range(M):
    p,s = map(str,input().split())
    q = int(p)
    if d[q] == 1:
        continue
    else:
        if s == 'AC':
            d[q] = 1
        else:
            P[q] += 1
ans1 = 0
ans2 = 0
for i in range(1,N+1):
    if d[i] == 1:
        ans1 += 1
        ans2 += P[i]
print(ans1,ans2)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
S = []
P = 0
for i in range(M):
    p,s = map(str,input().split())
    q = int(p)
    if q in S:
        continue
    if s == 'AC':
        S.append(q)
    else:
        P += 1
ans = len(s)
print(ans,P)
Problem p02817 (python)

Fixed submission:
S,T = map(str,input().split())
ans = T + S
print(ans)

Buggy submission (verdict: Runtime Error):
X =int(input())
def f(n):
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
    return True
for i in range(X,100004):
    if f(i):
        return(i)
        break
Problem p02821 (python)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [0 for i in range(10**5+1)]
S = [0]
s = 0
for i in range(N):
    B[A[i]] += 1
    s += A[i]
    S.append(s)
for i in range(2,10**5+2):
    B[-i] += B[-i+1]
d = 0
u = 2*10**5
for i in range(30):
    x = (u+d)//2
    if i == 28:
        x += 1
    m = 0
    for i in range(N):
        a = A[i]
        y = max(x - a,0)
        if y <= 10**5:
            m += B[y]
    if m >= M:
        d = x
    else:
        u = x
ans = 0
for i in range(N):
    a = A[i]
    x = max(d - a,0)
    if x <= 10**5:
        y = B[x]
    else:
        y = 0
    ans += (S[N] - S[N-y]) + a*y
ans -= (m-M)*d
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [0 for i in range(10**5+1)]
S = [0]
s = 0
for i in range(N):
    B[A[i]] += 1
    s += A[i]
    S.append(s)
for i in range(2,10**5+2):
    B[-i] += B[-i+1]
d = 0
u = 2*10**5
for i in range(30):
    x = (u+d)//2
    if i == 30:
        x += 1
    m = 0
    for i in range(N):
        a = A[i]
        y = max(x - a,0)
        if y <= 10**5:
            m += B[y]
    if m >= M:
        d = x
    else:
        u = x
ans = 0
for i in range(N):
    a = A[i]
    x = max(d - a,0)
    if x <= 10**15:
        y = B[x]
    else:
        y = 0
    ans += (S[N] - S[N-y]) + a*y
ans -= (m-M)*d
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [0 for i in range(10**5+1)]
S = [0]
s = 0
for i in range(N):
    B[A[i]] += 1
    s += A[i]
    S.append(s)
for i in range(2,10**5+2):
    B[-i] += B[-i+1]
d = 0
u = 2*10**5
for i in range(30):
    x = (u+d)//2
    m = 0
    for i in range(N):
        a = A[i]
        y = max(x - a,0)
        if y <= 10**5:
            m += B[y]
    if m >= M:
        d = x
    else:
        u = x
ans = 0
for i in range(N):
    a = A[i]
    x = max(d - a,0)
    if x <= 10**15:
        y = B[x]
    else:
        y = 0
    ans += (S[N] - S[N-y]) + a*y
ans -= (m-M)*d
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
B = [0 for i in range(10**5+1)]
S = [0]
s = 0
for i in range(N):
    B[A[i]] += 1
    s += A[i]
    S.append(s)
for i in range(2,10**5+2):
    B[-i] += B[-i+1]
d = 0
u = 2*10**5
for i in range(30):
    x = (u+d)//2
    m = 0
    for i in range(N):
        a = A[i]
        y = max(x - a,0)
        if y <= 10**5:
            m += B[y]
    if m >= M:
        d = x
    else:
        u = x
ans = 0
for i in range(N):
    a = A[i]
    x = max(d - a,0)
    y = B[x]
    ans += (S[N] - S[N-y]) + a*y
ans -= (m-M)*d
print(ans)
Problem p02824 (python)

Fixed submission:
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if i == N - P:
        ans = P
    else:
        if (a+M) >= A[-1]:
            if T >= total_score:
                ans = kazu + P
                break
print(ans)

Buggy submission (verdict: Runtime Error):
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if (a+M) > A[-1]:
        if T >= total_score:
            ans = kazu + P
            break
print(ans)
Problem p02848 (python)

Fixed submission:
N = int(input())
S = input()
n = len(S)
ans = ''
for i in range(n):
    a = (ord(S[i])-65+N)%26
    a += 65
    b = chr(a)
    ans += b
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
ans = ''
for i in range(N):
    a = ord(S[i])-97+N
    if a >= 26:
        a = a - 26
    a += 97
    b = chr(a)
    ans += b
print(ans)
Problem p02850 (python)

Fixed submission:
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
d = {}
D = {}
D[1] = 1
k = 1
H = []
list = [1]
sumi = []
while list:
    x = list.pop(0)
    sumi.append(x)
    Y = G[x]
    k = D[x] + 1
    while Y:
        y = Y.pop(0)
        if x in G[y]:
            G[y].remove(x)
        if k > K:
            k -= K
        list.append(y)
        d[(x,y)] = k
        D[y] = k 
        k += 1
        if k > K:
            k -= K
                
for i in range(N-1):
    a,b = W[i]
    print(d[(a,b)])

Buggy submission (verdict: Runtime Error):
N = int(input())
W = []
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    W.append((a,b))
    G[a].append(b)
    G[b].append(a)
K = 0
for i in range(1,N+1):
    n = len(G[i])
    K = max(K,n)
print(K)
C = [[i for i in range(1,K+1)] for j in range(N+1)]

for i in range(N-1):
    a,b = W[i]
    x = C[a].pop(0)
    C[b].remove(x)
    print(x)
Problem p02882 (python)

Fixed submission:
import math
a, b, x = map(int,input().split())
V = (a**2)*b
v = V*0.5
if x >= v:
    U = V - x
    c = (U*2) / (a**3)
    z = math.atan(c)
    print(math.degrees(z))
else:
    c = (a*(b**2)) / (x*2)
    z = math.atan(c)
    print(math.degrees(z))

Buggy submission (verdict: Runtime Error):
import math
a, b, x = map(int,input().split())
V = (a**2)*b
v = V*0.5
if x > v:
    U = V - x
    c = U / (a**3)
    z = math.atan(c)
    print(z)
elif x = v:
    z = math.atan(1)
    print(z)
else:
    c = (a*(b**2)) / x
    z = math.atan(c)
    print(z)
Problem p02885 (python)

Fixed submission:
A,B = map(int,input().split())
ans = A-B*2
if ans < 0:
    ans = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int,input().split()))
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum += d[i] + d[j]
print(sum)
Problem p02886 (python)

Fixed submission:
N = int(input())
d = list(map(int,input().split()))
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum += d[i]*d[j]
print(sum)

Buggy submission (verdict: Runtime Error):
N = int(input())
d = list(map(int,input().split()))
sum = 0
for i in range(N-1):
    for j in range(i+1,N):
        sum += d[i] + d[j]
print(ans)
Problem p02899 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
for i in range(N):
    x = A[i]
    B[x-1] = str(i+1)
B = " ".join(B)
print(B)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = [0]*N
for i in range(n):
    x = A[i]
    B[x] = str(i+1)
B = " ".join(B)
print(B)
Problem p02901 (python)

Fixed submission:
N,M = map(int,input().split())
A = [0]
C = [0] 
for i in range(M):
    a,b = map(int,input().split())
    A.append(a)
    c = list(map(int,input().split()))
    x = 0
    for j in range(1,N+1):
        if j in c:
            x += 2**(j-1)
    C.append(x)
inf = 10**9
dp = [inf for i in range(2**N)]
dp[0] = 0
for i in range(1,M+1):
    dp[C[i]] = min(dp[C[i]],A[i])
    for j in range(2**N):
        k =  j|C[i]
        dp[k] = min(dp[k],dp[j]+A[i])
if dp[2**N-1] == inf:
    dp[2**N-1] = -1
print(dp[2**N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [[]]
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a)
ans = 0
n = 0
while n < ((N-1)*N)//2:
    f = []
    ans += 1
    t = 0
    for i in range(1,N+1):
        if i in f:
            continue
        if len(A[i]) > 0:
            a = A[i][0]
        else:
            continue
        if (A[a][0] == i):
            if a not in f:
                A[i].pop(0)
                A[a].pop(0)
                f.append(i)
                f.append(a)
                n += 1
                t = 1
    if t == 0:
        print(-1)
        quit()
print(ans)
Problem p02910 (python)

Fixed submission:
S = input()
N = len(S)
n = N // 2
ans = 'Yes'
for i in range(n):
    p = S[2*i]
    q = S[2*i+1]
    if p == 'L':
        ans = 'No'
    if q == 'R':
        ans = 'No'
if N % 2 == 1:
    if S[N-1] == 'L':
        ans = 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
S = int()
N = len(S)
n = N // 2
ans = 'tes'
for i in range(n):
    p = S[2*i]
    q = S[2*i+1]
    if p == 'L':
        ans = 'No'
    if q == 'R':
        ans = 'No'
if N % 2 == 1:
    if S[N-1] == 'L':
        ans = 'No'
print(ans)
Problem p02911 (python)

Fixed submission:
N,K,Q = map(int,input().split())
A = [0]*N
for i in range(Q):
    a = int(input())
    A[a-1] += 1
for i in range(N):
    x = K+A[i]-Q
    if x > 0:
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
N,K,Q = map(int,input().split())
A = [0]*N
for i in range(N):
    a = int(input())
    A[a-1] += 1
for i in range(N):
    x = K+A[i]-Q
    if X > 0:
        print('Yes')
    else:
        print('No')
Problem p02918 (python)

Fixed submission:
N,K = map(int,input().split())
S = input()
ans = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += 1
ans += 2*K
if ans > N-1:
    ans = N-1
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
S = input()
ans = 0
for i in range(N):
    if S[i] == S[i+1]:
        ans += 1
ans += 2*K
if ans > N-1:
    ans = N-1
print(ans)
Problem p02936 (python)

Fixed submission:
N,Q = map(int,input().split())
G = [[]for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
C = [0]*(N)
for i in range(Q):
    p,x = map(int,input().split())
    C[p-1] += x
from collections import deque
d=deque()
d.append(0)
t = [False]*(N)
t[0] = True
while d:
    a = d.popleft()
    for b in G[a]:
        if not t[b]:
            t[b] = True
            d.append(b)
            C[b] += C[a]
print(*C)

Buggy submission (verdict: Runtime Error):
N,Q = map(int,input().split())
P = [1]*(N+1)
for i in range(N):
    a,b = map(int,input().split())
    P[b] = a
C = [0]*(N+1)
for i in range(Q):
    p,x = map(int,input().split())
    C[p] = x
for i in range(2,N):
    q = P[i]
    C[i] += C[q]
C.pop(0)
print(*C)
Problem p02960 (python)

Fixed submission:
S = input()
n = len(S)
mod = 10**9 + 7
pow10 = [1]
for i in range(1,n):
    x = pow10[-1]
    y = 10*x%13
    pow10.append(y)
dp = [[0 for i in range(13)]for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    d = S[-i-1]
    if d == '?':
        for j in range(10):
            s = (pow10[i]*j)%13
            for t in range(13):
                r = (s+t)%13
                dp[i+1][r] = (dp[i+1][r] + dp[i][t])%mod
    else:
        j = int(d)
        s = (pow10[i]*j)%13
        for t in range(13):
            r = (s+t)%13
            dp[i+1][r] = (dp[i+1][r] + dp[i][t])%mod
print(dp[n][5])

Buggy submission (verdict: Runtime Error):
S = input()
n = len(S)
mod = 10**9 + 7
pow10 = [0]
for i in range(1,n):
    x = pow10[-1]
    y = 10*x%13
    pow10.append(y)
dp = [[0 for i in range(13)]for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    d = S[-i-1]
    if d = '?':
        for j in range(10):
            s = pow10[i]*j%13
            for t in range(13):
                r = (s+t)%13
                dp[i][r] = (dp[i][r] + dp[i-1][t])%mod
    else:
        j = str(d)
        s = pow10[i]*j%13
        for t in range(13):
            r = (s+t)%13
            dp[i][r] = (dp[i][r] + dp[i-1][t])%mod
print(dp[n][5])
Problem p03026 (python)

Fixed submission:
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - max(c)
F = []
for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while i < N:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if len(G[y]) == 1:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS)

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - max(c)
F = []
for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while i != N:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if y not in F:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS)

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - max(c)
F = []
for i in range(1,N+1):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while len(F) != 0:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if y not in F:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS)

Buggy submission (verdict: Runtime Error):
N = int(input())
G = [[] for i in range(N+1)]
for i in range(N-1):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
c = list(map(int,input().split()))
c.sort()
ans = sum(c) - c[N-1]
F = []
for i in range(N):
    n = len(G[i])
    if n == 1:
        F.append(i)
d = {}
i = 0
while len(F) != 0:
    x = F.pop(0)
    d[x] = c[i]
    i += 1
    if len(G[x]) > 0:
        y = G[x][0]
        G[y].remove(x)
        if y not in F:
            F.append(y)
ANS = []
for i in range(1,N+1):
    ANS.append(d[i])
print(ans)
print(*ANS)
Problem p03031 (python)

Fixed submission:
N,M = map(int,input().split())
S = []
K = []
for i in range(M):
    s = list(map(int,input().split()))
    k = s.pop(0)
    S.append(s)
    K.append(k)
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    sw = [0]*N
    for j in range(N):
        if (i>>j)&1:
            sw[j] = 1
    flag = 1
    for m in range(M):
        po = S[m]
        sum = 0
        for k in range(K[m]):
            if sw[po[k]-1] == 1:
                sum = (sum + 1)%2
        if P[m] != sum:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input())
S = []
K = []
for i in range(M):
    s = list(map(int,input().split()))
    k = s.pop(0)
    S.append(s)
    K.append(k)
P = list(map(int,input().split()))
for i in range(2**N):
    sw = [0]*N
    for j in range(N):
        if (i>>j)&1:
            sw[j] = 1
    flag = 1
    for m in range(M):
        po = S[m]
        sum = 0
        for k in range(K[m]):
            if sw[po[k]-1] == 1:
                sum = (sum + 1)%2
        if P[m] != sum:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)
Problem p03043 (python)

Fixed submission:
N,K = map(int,input().split())
import math
s = 0
for i in range(1,N+1):
    if i >= K:
        s += 1
    else:
        n = math.ceil(math.log((K/i),2))
        s += 2**(-n)
ans = s/N
print(ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
import math
s = 0
for i in range(1,N+1):
    if i >= K:
        s += 1
    else:
        n = math.ceil(log((K/i),2))
        s += 2**(-n)
ans = s/N
print(ans)
Problem p03044 (python)

Fixed submission:
N = int(input())
G = [[] for i in range(N)]

for i in range(N-1):
    u,v,w = map(int,input().split())
    w = w%2
    G[u-1].append((v,w))
    G[v-1].append((u,w))
ans = [ -1 for i in range(N)]
ans[0] = 0
stack = [1]

while len(stack) > 0:
    x = stack.pop()
    p = ans[x-1]
    g = len(G[x-1])
    for i in range(g):
        y = G[x-1][i][0]
        z = G[x-1][i][1]
        a = ans[y-1]
        if a == -1:
            stack.append(y)
            if z == 0:
                ans[y-1] = p
            else:
                ans[y-1] = 1-p
for i in range(N):
    print(ans[i])

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

for i in range(N):
    u,v,w = map(int,input().split())
    w = w%2
    G[u].append((v,w))
    G[v].append((u,w))
ans = [ -1 for i in range(N)]
ans[0] = 0
stack = [1]

while len(stack) > 0:
    x = stack.pop()
    p = ans[x-1]
    g = len(G[x])
    for i in range(g):
        y = G[x][i][0]
        z = G[x][i][1]
        a = ans[y-1]
        if a == -1:
            stack.append(y)
            if z == 0:
                ans[y-1] = p
            else:
                ans[y-1] = 1-p
for i in range(N):
    print(ans[i])
Problem p03147 (python)

Fixed submission:
N = int(input())
H = list(map(int,input().split()))
y = 0
z = H[0]
ans = 0
while len(H) != 0:
    z = H[0]
    f = 1
    while z == 0:
        H.pop(0)
        if len(H) != 0:
            z = H[0]
        else:
            break
    for i in range(len(H)):
        x = H[i]
        if x == 0:
            ans += z
            for j in range(i):
                H[j] -= z
            z = H[0]
            f = 0
            break
        z = min(x,z)
    if f == 1:
        ans += z
        for i in range(len(H)):
            H[i] -= z
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input().split())
H = list(map(int,input().split()))
y = 0
z = H[i]
ans = 0
for i in range(N):
    x = H[i]
    if x >= y:
        y = x
    else:
        ans += y
        z = min(z,x)
        for j in range(i,N):
            p = H[j]
            z = min(z,p)
            H[j] -= z
print(ans)
Problem p03161 (python)

Fixed submission:
N,K = map(int,input().split())
H = list(map(int,input().split()))
dp = [10**9 for i in range(N+1)]
dp[1] = 0
for i in range(2,N+1):
    a = 10**9
    for j in range(1,K+1):
        if i - j - 1 < 0:
            continue
        x = H[i-1-j] - H[i-1]
        if x < 0:
            x = -x
        a = min(dp[i-j]+x,a)
    dp[i] = a
print(dp[N])

Buggy submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))
dp = [10**9 for i in range(N+1)]
dp[1] = 0
for i in range(2,N+1):
    a = 10**9
    for j in range(1,K+1):
        if i - 1 - j < 0:
            continue
        x = H[i-1-j] - H[i-1]
        if x < 0:
            x = -x
    a = min(dp[i-j]+x,a)
    dp[i] = a
print(dp[N])
Problem p03163 (python)

Fixed submission:
N,W = map(int,input().split())
dp = [[0 for i in range(W+1)] for j in range(N+1)]
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(W+1):
        if j < w:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
print(dp[N][W])

Buggy submission (verdict: Runtime Error):
dp = [[0 for i in range(W+1)] for j in range(N+1)]
N,W = map(int,input().split())
for i in range(1,N+1):
    w,v = map(int,input().split())
    for j in range(W+1):
        if j < w:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w]+v)
ans = 0
for i in range(W+1):
    x = dp[N][i]
    ans = max(ans,x)
print(ans)