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

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

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
    for j in range(i+1,i+2+1):
        if j<n :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
n,k = map(int,input().split())
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
N = input()
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize]*N
dp[0]=0

for i in range(int(N)):
    for j in range(i+1,i+2+1):
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
import sys
N = input()
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in range(i+1,i+2+1):
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
N = input()
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in range(i+1,i+2+1):
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
N = input()
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in range(i+1,i+2)+1:
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
N = input()
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in range(i+1,i+2):
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
N = input().split(" ")
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N[0])):
    for j in [i+1,i+N[1]]:
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])

Buggy submission (verdict: Runtime Error):
N = input()
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N)):
    for j in [i+1,i+2]:
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])
Problem p03161 (python)

Fixed submission:
import sys
n,k = map(int,input().split())
h = map(int,input().split())
h = list(h)

dp = [sys.maxsize]*n
dp[0]=0

for i in range(n):
    for j in range(i+1,i+k+1):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
N = input().split(" ")
h = map(int,input().split())
h = list(h)

dp = [99999999 for i in range(100)]
dp[0]=0

for i in range(int(N[0])):
    for j in [i+1,i+N[1]]:
        if j<int(N) :
            dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]))

print(dp[int(N)-1])
Problem p03759 (python)

Fixed submission:
#
from collections import Counter

a,b,c = map(int,input().split())
if(b-a ==  c-b):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
from collections import Counter

a,b,c = map(int,input())
if(abs(b-a)==abs(c-b)):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):

from collections import Counter
import sys
a,b,c = map(int,input())
if(abs(b-a)==abs(c-b)):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
# Hello World program in Python
from collections import Counter as cn

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(cn(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))
Problem p03760 (python)

Fixed submission:
#
from collections import Counter

k = input()
p = input()
d = len(k)
f = len(p)
g=""
diff = abs(d-f)

if d>f :
     d = d-diff
     g = k[d:len(k)]
   
else:
    f = f-diff
    g=p[f:len(p)]


r=""
i = 0
for i in range(d):
    r += "".join(k[i]+p[i])
    #print(r)
    
print(r+g)

Buggy submission (verdict: Runtime Error):

from collections import Counter

k = input()
p = input()
d = len(k)
f = len(p)
g=""
diff = abs(d-f)

if d>f :
     d = d-diff
     g = k[d:len(k)]
   
else:
    f = f-diff
    g=p[f:len(p)]


r=""a
i = 0
for i in range(d):
    r += "".join(k[i]+p[i])
    #print(r)
    
print(r+g)
Problem p03761 (python)

Fixed submission:
from collections import Counter
 
n = int(input())
l = []
 
for i in range(n):
    s = input()
    l.append(Counter(s))
    
cnt = l[0]
for i in range(1,n):
        cnt = cnt & l[i]
        
print("".join(sorted(cnt.elements())))

Buggy submission (verdict: Runtime Error):
#
from collections import Counter as cn

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(Counter(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))

Buggy submission (verdict: Runtime Error):
# Hello World program in Python
from collections import Counter as cn

d = int (input())
l = []
for k in range(d):
  r = input()
  p = cn(r)
  l.append(p)

oi = l[0]

for g in range(1,n):
    oi = oi & l[g]
    print(oi)
    
print("".join(sorted(oi.elements())))

Buggy submission (verdict: Runtime Error):
# Hello World program in Python
from collections import Counter as cn

d = int (input())
l = []
for k in range(d):
  r = input()
  p = cn(r)
  l.append(p)

oi = l[0]

for g in range(n):
    oi = oi & l[g]
    print(oi)
    
print("".join(sorted(oi.elements())))
Problem p03589 (python)

Fixed submission:
N = int(input())

for h in range((N + 3) // 4, 3501):
    for n in range((N + 3) // 4, 3501):
        a = N * h * n
        b = 4 * h * n - N * (h + n)
        if a > 0 and b > 0 and a % b == 0:
            print("{0} {1} {2}".format(h, n, a//b))
            exit()

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

A.sort()
left = A[0]
right = A[N - 1]
ans = right - left
for i in range((N - 2) // 2):
    if i % 2 == 0:
        ans += right - A[1 + i]
        ans += A[N - 2 - i] - left
        right = A[1 + i]
        left = A[N - 2 - i]
    else:
        ans += left - A[1 + i]
        ans += A[N - 2 - i] - right
        left = A[1 + i]
        right = A[N - 2 - i]

if N % 2 == 1:
    ans += max(abs(right - A[N // 2]), abs(left - A[N // 2]))

print(ans)
Problem p02646 (python)

Fixed submission:
p1 , s1=map(int , input().split()) 
p2 , s2=map(int , input().split())
t=int(input()) 
if abs(p1-p2) > t*(s1-s2):
  print("NO")
else:
  print("YES")

Buggy submission (verdict: Runtime Error):
def sackRace(p1, s1, p2, s2): 
      
    # Since starting points are always 
    # different, they will meet if following  
    # conditions are met. 
    # (1) Speeds are not same 
    # (2) Difference between speeds divide the 
    #     total distance between initial points.  
    return ( (s1 > s2 and (p2 - p1) % (s1 - s2) == 0)  
         or (s2 > s1 and (p1 - p2) % (s2 - s1) == 0)) 
p1 , s1=map(int , input().split()) 
p2 , s2=map(int , input().split())
t=int(input()) 
if sackRace(p1 , s1 , p2 , s2):
  print("NO")
else:
  print("YES)
Problem p03543 (python)

Fixed submission:
n = int(input())
print("No" if ((n//10) % 111 and (n%1000) % 111) else "Yes")

Buggy submission (verdict: Runtime Error):
n = input()
print("No" if ((n//10) % 111 and (n%1000) % 111) else "Yes")

Buggy submission (verdict: Runtime Error):
n = input()
print("No" if ((n//10) % 111 and (n%1000) % 111) else "Yes")
Problem p02780 (python)

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

N, K = map(int, readline().split())
p = list(map(int, readline().split()))

t = sum(p[:K])
m = (t + K) / 2
for i in range(1, N - K + 1):
    t = t - p[i - 1] + p[i + K - 1]
    m = max(m, (t + K)/2)

print(m)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
readline = sys.stdin.readline

N, K = map(int, readline().split())
p = list(map(int, readline().split()))

p = np.array(p)
a = [sum(p[i:i+K] + 1) / 2 for i in range(N - K)]
print(max(a))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
readline = sys.stdin.readline

N, K = map(int, readline().split())
p = list(map(int, readline().split()))

p = np.array(p)
a = [sum(p[i:i+K] + 1) / 2 for i in range(N - K)]
print(max(a))
Problem p02837 (python)

Fixed submission:
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = [], []
    for j in range(a):
        _x, _y = map(int, readline().split())
        x.append(_x - 1), y.append(_y)
    X.append(x)
    Y.append(y)

M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = zip(*[list(map(int, readline().split())) for j in range(a)])
    x = [_x - 1 for _x in x]
    X.append(x)
    Y.append(y)

while True:
    pass
M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
readline = sys.stdin.readline


N = int(readline())
A = []
X, Y = [], []
for i in range(N):
    a = int(readline())
    A.append(a)
    x, y = zip(*[list(map(int, readline().split())) for j in range(a)])
    x = [_x - 1 for _x in x]
    X.append(x)
    Y.append(y)


M = 2 ** N
count = 0
for code in range(M - 1, -1, -1):
    contra = False
    for i in range(N):
        if ((code >> i) & 1) == 1:
            x, y = X[i], Y[i]
            for j in range(len(x)):
                if y[j] != ((code >> x[j]) & 1):
                    contra = True
                    break
            if contra:
                break
    if not contra:
        _count = 0
        for i in range(N):
            _count += ((code >> i) & 1)
        count = max(count, _count)

print(count)
Problem p02845 (python)

Fixed submission:
import sys; readline = sys.stdin.readline
from collections import deque


N = int(readline())
A = list(map(int, readline().split()))
P = 10**9 + 7


a = 1
state = [0, 0, 0]

for i in range(N):
    c = state.count(A[i]) 
    a *= c
    a %= P
    if c == 0:
        print(0)
        exit(0)
    state[state.index(A[i])] = A[i] + 1

print(a)

Buggy submission (verdict: Runtime Error):
import sys; readline = sys.stdin.readline
from collections import deque


N = int(readline())
A = list(map(int, readline().split()))
P = 10**9 + 7


a = 1
state = [0, 0, 0]

for i in range(N):
    c = state.count(A[i]) 
    a *= c
    a %= P
    state[state.index(A[i])] = A[i] + 1

print(a)
Problem p02846 (python)

Fixed submission:
import sys; readline = sys.stdin.readline
from collections import deque

t1, t2 = map(int, readline().split())
a1, a2 = map(int, readline().split())
b1, b2 = map(int, readline().split())

T = t1 + t2

avgA = t1 * a1 + t2 * a2
avgB = t1 * b1 + t2 * b2
if avgA == avgB:
    print('infinity')
    exit(0)

if avgA < avgB:
    a1, a2, b1, b2 = b1, b2, a1, a2
    avgA, avgB = avgB, avgA

d1 = a1 - b1
d2 = a2 - b2

if d1 > 0:
    print(0)
    exit(0)

y0 =  -d1 * t1
dy = (avgA - avgB)

n = y0 // dy

if y0 % dy == 0:
    print((n + 1) * 2 - 2)
else:
    print((n + 1) * 2 - 1)

Buggy submission (verdict: Runtime Error):
import sys; readline = sys.stdin.readline
from collections import deque

t1, t2 = map(int, readline().split())
a1, a2 = map(int, readline().split())
b1, b2 = map(int, readline().split())

T = t1 + t2

avgA = t1 * a1 + t2 * a2
avgB = t1 * b1 + t2 * b2
if avgA == avgB :
    print('infinity')
    exit(0)

if avgA < avgB:
    a1, a2, b1, b2 = b1, b2, a1, a2
    avgA, avgB = avgB, avgA

d1 = a1 - b1
d2 = a2 - b2

if d1 > 0:
    print(0)
    exit(1)

y0 =  -d1 * t1
dy = (avgA - avgB)

n = y0 // dy

if y0 % dy == 0:
    print((n + 1) * 2 - 2)
else:
    print((n + 1) * 2 - 1)
Problem p02867 (python)

Fixed submission:
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

si2i = sorted(range(len(A)), key=lambda x:A[x])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= N - 2:
    print(yes)
else:
    print(no)

Buggy submission (verdict: Runtime Error):
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

si2i = sorted(range(len(A)), key=lambda x:A[i])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= N - 2:
    print(yes)
    assert False
else:
    print(no)

Buggy submission (verdict: Runtime Error):
import sys; readline = sys.stdin.readline
from collections import deque
from collections import Counter

N = int(readline())
A = list(map(int, readline().split()))
B = list(map(int, readline().split()))

A, B = zip(*sorted(zip(A, B), key=lambda x:x[1]))

A_s = sorted(A)
B_s = sorted(B)

no = "No"
yes = "Yes"

for i in range(len(A_s)):
    if A_s[i] > B_s[i]:
        print(no)
        exit(0)

for i in range(1, len(A_s)):
    if A_s[i] < B_s[i - 1]:
        print(yes)
        exit(0)

assert False

si2i = sorted(range(len(A)), key=lambda x:A[i])

a = 0
count = 0
while True:
    a = si2i[a]
    if a == 0:
        break
    count += 1

if count <= N - 2:
    print(yes)
else:
    print(no)
Problem p02885 (python)

Fixed submission:
import sys; readline = sys.stdin.readline
from collections import deque


A, B = map(int, readline().split())
print(max(0, A - 2 * B))

Buggy submission (verdict: Runtime Error):
import sys; readline = sys.stdin.readline
from collections import deque


A, B = map(int, readline().split())
print(max(A - 2 * B))
Problem p02903 (python)

Fixed submission:
import sys; from collections import deque; readline = sys.stdin.readline

H, W, A, B = map(int, readline().split())

#for s in range(W):
#    a = (H - 2*B) * s + W*B - H*A
#    b = W - 2*A
#    if a % b == 0 and a // b >= 0:
#        t = a // b
#        break
#
#if s == W:
#    print('No')
#else:
#    count = []

for y in range(B):
    print(''.join(map(str, [1]*A + [0]*(W-A))))

for y in range(B, H):
    print(''.join(map(str, [0]*A + [1]*(W-A))))

Buggy submission (verdict: Runtime Error):
import sys; from collections import deque; readline = sys.stdin.readline

H, W, A, B = map(int, readline().split())

#for s in range(W):
#    a = (H - 2*B) * s + W*B - H*A
#    b = W - 2*A
#    if a % b == 0 and a // b >= 0:
#        t = a // b
#        break
#
#if s == W:
#    print('No')
#else:
#    count = []

for y in range(B):
    print(''.join([1]*A + [0]*(W-A)))

for y in range(B, H):
    print(''.join([0]*A + [1]*(W-A))
Problem p02952 (python)

Fixed submission:
import sys, math
from collections import deque

readline = sys.stdin.readline

A = int(readline())

n = math.floor(math.log10(A)) + 1

count = 0
for i in range(1, n, 2):
    count += 9 * 10 ** (i - 1)

if n % 2 == 1:
    count += A - 10 ** (n - 1) + 1

print(count)

Buggy submission (verdict: Runtime Error):
import sys, math
from collections import deque

readline = sys.stdin.readline

A = int(readline())

n = math.floor(math.log10(A)) + 1

count = 0
for i in range(1, n, 2):
    count += 9 * 10 ** (i - 1)

if n % 2 == 1:
    count += A - 10 ** (i - 1) + 1

print(count)
Problem p02981 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

N, A, B = map(int, readline().split())

print(min(N * A, B))

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline

N, A, B = map(int, readline().split())

print(min(N * A), B)
Problem p02995 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

A, B, C, D = map(int, readline().split())

def get_gcd(x, y):
    while True:
        if x > y:
            t = x % y
            a = y
            x = t
        else:
            t = y % x
            a = x
            y = t
        if t == 0:
            return a

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
lcm = C * D // get_gcd(C, D)
cd = B // lcm - (A - 1) // lcm


ans = B - (A - 1) - (c + d - cd)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, fractions

readline = sys.stdin.readline

A, B, C, D = map(int, readline().split())

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
lcm = C * D // fractions.gcd(c, d)
cd = B // lcm - (A - 1) // lcm

ans = B - (A - 1) - (c + d - cd)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys, fractions

readline = sys.stdin.readline

A, B, C, D = map(int, readline().split())

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
lcm = C * D // fractions.gcd(c, d)
cd = B // lcm - (A - 1) // lcm

ans = B - (A - 1) - (c + d - cd)

print(ans)
Problem p03006 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

N = int(readline())

XY = [list(map(int, readline().split())) for i in range(N)]

diff_list = {}

for x1, y1 in XY:
    for x2, y2 in XY:
        if x1 == x2 and y1 == y2:
            continue
        diffx = x2 - x1
        diffy = y2 - y1
        diff = (diffx, diffy)
        if not (diff in diff_list): diff_list[diff] = 0
        diff_list[diff] += 1

values = diff_list.values()
if len(values) > 0:
    m = max(values)
    ans = N - m
else:
    ans = 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.readline

N = int(readline())

XY = [list(map(int, readline().split())) for i in range(N)]

diff_list = {}

for x1, y1 in XY:
    for x2, y2 in XY:
        if x1 == x2 and y1 == y2:
            continue
        diffx = x2 - x1
        diffy = y2 - y1
        diff = (diffx, diffy)
        if not (diff in diff_list): diff_list[diff] = 0
        diff_list[diff] += 1

m = max(diff_list.values())

ans = N - m

print(ans)
Problem p03043 (python)

Fixed submission:
import sys, math

N, K = map(int, sys.stdin.readline().split())

immediate_win = (N - (K - 1)) / N if K <= N else 0

s = 0
for k in range(1, min(K - 1, N) + 1):
    r = K / k
    c = math.ceil(math.log2(r))
    p = 0.5 ** c
    s += p / N
print(s + immediate_win)

Buggy submission (verdict: Runtime Error):
import sys, math

N, K = map(int, sys.stdin.readline().split())

immediate_win = (N - (K - 1)) / N if K <= N else 0

s = 0
for k in range(1, min(K - 1, N) + 1):
    r = K / k
    c = math.ceil(math.log2(r))
    p = 0.5 ** c
    s += p / N
print(s + immediate_win)
Problem p03044 (python)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(200000)
 
readline = sys.stdin.readline
 
N = int(readline())
 
nodes = [deque() for i in range(N)]
node_colors = [-1 for i in range(N)]
 
for i in range(N - 1):
    u,v,w = map(int, readline().split())
    u, v = u - 1, v - 1
    nodes[u].append([v, w])
    nodes[v].append([u, w])
 
 
node_colors[0] = 0
 
def process(u, parent, w): 
    p_color = node_colors[parent]
    node_colors[u] = p_color if w % 2 == 0 else 1 - p_color
    
    for v, w in nodes[u]:
        if v == parent:
            continue
        process(v, u, w)
 
for v, w in nodes[0]:
    process(v, 0, w)
 
for c in node_colors:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline

N = int(readline())

nodes = [deque() for i in range(N)]
node_colors = [-1 for i in range(N)]

for i in range(N - 1):
    u,v,w = map(int, readline().split())
    u, v = u - 1, v - 1
    nodes[u].append([v, w])
    nodes[v].append([u, w])


node_colors[0] = 0

def process(u, parent, w): 
    p_color = node_colors[parent]
    node_colors[u] = p_color if w % 2 == 0 else 1 - p_color
    
    for v, w in nodes[u]:
        if v == parent:
            continue
        process(v, u, w)

for v, w in nodes[0]:
    process(v, 0, w)

for c in node_colors:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline

N = int(readline())

nodes = [deque() for i in range(N)]
node_colors = [-1 for i in range(N)]

for i in range(N - 1):
    u,v,w = map(int, readline().split())
    u, v = u - 1, v - 1
    nodes[u].append([v, w])
    nodes[v].append([u, w])


node_colors[0] = 0

def process(u, parent, w): 
    p_color = node_colors[parent]
    node_colors[u] = p_color if w % 2 == 0 else 1 - p_color
    
    for v, w in nodes[u]:
        if v == parent:
            continue
        process(v, u, w)

for v, w in nodes[0]:
    process(v, 0, w)

for c in node_colors:
    print(c)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque

readline = sys.stdin.readline

N = int(readline())

nodes = [deque() for i in range(N)]
node_colors = [-1 for i in range(N)]

for i in range(N - 1):
    u,v,w = map(int, readline().split())
    u, v = u - 1, v - 1
    nodes[u].append([v, w])
    nodes[v].append([u, w])


node_colors[0] = 0

def process(u, parent, w): 
    p_color = node_colors[parent]
    node_colors[u] = p_color if w % 2 == 0 else 1 - p_color
    
    for v, w in nodes[u]:
        if v == parent:
            continue
        process(v, u, w)

for v, w in nodes[0]:
    process(v, 0, w)

for c in node_colors:
    print(c)
Problem p03047 (python)

Fixed submission:
import sys

readline = sys.stdin.readline

N, K = map(int, readline().split())

ret = N - K + 1

print(ret)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())
print(N)

i = 1
s = 0

while i ** 2 <= N:
    if N % i == 0:
        k = N // i - 1
        if k > i:
            s += k
    i += 1
print(s)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())

i = 1
s = 0

while i ** 2 <= N:
  if N // i == N % i:
    s += i
  i += 1
print(s)
Problem p03050 (python)

Fixed submission:
import sys

N = int(sys.stdin.readline())
i = 1
s = 0

while i ** 2 <= N:
    if N % i == 0:
        k = N // i - 1
        if k > i:
            s += k
    i += 1
print(s)

Buggy submission (verdict: Runtime Error):
import sys

N = int(sys.stdin.readline())

i = 0
count = 0

while i ** 2 <= N:
  if N // i == N % i:
    count += 1

print(count)