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

Fixed submission:
from collections import deque

k = int(input())
q = deque(range(1,10))
for i in range(k):
    x = q.popleft()
    if x % 10 != 0:
        q.append(10 * x + (x % 10 - 1))
    q.append(10 * x + (x % 10))
    if x % 10 != 9:
        q.append(10 * x + (x % 10 + 1))
print(x)

Buggy submission (verdict: Runtime Error):
k=int(input())
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9): #上記の操作を9回繰り返せば10^5個以上のルンルン数を列挙できる
  tmp=[]
  for val in cand[-1]:
    if val%10!=0: #末尾が0のときは(末尾-1)を付け加えた数はルンルン数にならない
      tmp.append(val*10+(val%10-1))
    tmp.append(val*10+(val%10))
    if val%10!=9: #末尾が9のときは(末尾+1)を付け加えた数はルンルン数にならない
      tmp.append(val*10+(val%10+1))
cand.append(tmp)
ans=[]
for i in range(len(cand)):
  for val in cand[i]:
    ans.append(val)

print(ans[k-1])
Problem p02756 (python)

Fixed submission:
S = input()
Q = int(input())
re = False
front = []
back = []

for i in range(Q):
    t = input()
    
    if len(t) == 1:
        re = not re
        
    else:
        q, f, c = t.split()
        if (re == True and int(f) == 2) or (re == False and int(f) == 1):
            front.append(c)
        elif (re == True and int(f) == 1) or (re == False and int(f) == 2):
            back.append(c)

if re == False:
    front.reverse()
    F = "".join(front)
    B = "".join(back)
    print(F + S + B)
else:
    back.reverse()
    S = S[::-1]
    F = "".join(front)
    B = "".join(back)
    print(B + S + F)

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())
re = False
front = []
back = []

for i in range(Q):
    t = input()
    
    if len(t) == 1:
        re = not re
        
    else:
        q, f, c = t.split()
        if (re == True and int(f) == 2) or (re == False and int(f) == 1):
            front.append(c)
        elif (re == True and int(f) == 1) or (re == False and int(f) == 2):
            back.append(c)

if re == False:
    front.reverse()
    F = "".join(front)
    B = "".join(back)
    print(F + S + B)
else:
    back.reverse()
    S.reverse()
    F = "".join(front)
    B = "".join(back)
    print(B + S + F)
Problem p02767 (python)

Fixed submission:
import statistics

N = int(input())
X = [int(i) for i in input().split()]
X.sort()
mid = statistics.mean(X)
ans = 0
ans1 = 0
ans2 = 0

for i in range(N):
    ans1 += (X[i] - int(mid)) ** 2
    ans2 += (X[i] - int(mid) - 1) ** 2
ans = min(ans1, ans2)

print(ans)

Buggy submission (verdict: Runtime Error):
import statistics

N = int(input())
X = [int(i) for i in input().split()]
X.sort()
mid = statistics.mean(X)
ans = 0
ans1 = 0
ans2 = 0
print(mid)
for i in range(N):
    ans1 += (X[i] - int(mid)) ** 2
    ans2 += (X[i] - int(mid) - 1) ** 2
ans = min(ans1, ans2)

print(ans)
Problem p03309 (python)

Fixed submission:
import statistics

N = int(input())
A = [int(i) for i in input().split()]
B = [(A[i] - (i+1)) for i in range(N)]
b = statistics.median(B)
sum = 0
for i in range(N):
    sum += abs(B[i] - b)
print(int(sum))

Buggy submission (verdict: Runtime Error):
import statistics

N = int(input())
A = [int(i) for i in input().split()]
B = [(A[i] - (i+1)) for i in range(N)]
b = statistics.median(B)
sum = 0
for i in range(N):
    sum += abs(B[i] - b)
print(int(sum))

Buggy submission (verdict: Runtime Error):
import statistics

N = int(input())
A = [int(i) for i in input().split()]
B = [A[i] - (i+1) for i in range(N)]
b = statistics.median(B)
sum = 0
for i in range(N):
    sum += abs(B[i] - b)
print(int(sum))

Buggy submission (verdict: Runtime Error):
import statistics

N = int(input())
A = [int(i) for i in input().split()]
B = [A[i] - (i+1) for i in range(N)]
B.sort()
b = statistics.median(B)
sum = 0
for i in range(N):
    sum += B[i] - b
print(sum)
Problem p03860 (python)

Fixed submission:
s1, s2, s3 = input().split()
print("{0}{1}{2}".format(s1[0], s2[0], s3[0]))

Buggy submission (verdict: Runtime Error):
s1, s2, s3 = input().split()
print(f"A{s2[0]}C")

Buggy submission (verdict: Runtime Error):
s1, s2, s3 = input().split()

print(f"{s1[0]}{s2[0]}{s3[0]}")

Buggy submission (verdict: Runtime Error):
s1, s2, s3 = input().split()

print(f"{s1[0]}{s2[0]}{s3[0]}")
Problem p02748 (python)

Fixed submission:
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]

    x_ret = min(refrigerators)
    y_ret = min(microwaves)
    ret = x_ret + y_ret
    for x, y, c in tickets:
        p = refrigerators[x - 1] + microwaves[y - 1] - c
        ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline


def main():
    a, b, m = map(int, input().split())
    refrigerators = list(map(int, input().split()))
    microwaves = list(map(int, input().split()))
    tickets = [list(map(int, input().split())) for _ in range(m)]
    tickets_map = {}
    for x, y, c in tickets:
        key = f'{x - 1}:{y - 1}'
        tickets_map[key] = c

    ret = 99999999999999
    for x in range(a):
        for y in range(b):
            key = f'{x}:{y}'
            d = tickets_map.get(key, 0)
            p = refrigerators[x] + microwaves[y] - d
            ret = min(ret, p)
    print(ret)


if __name__ == '__main__':
    main()
Problem p02690 (python)

Fixed submission:
hoge = {}
for i in range(1000):
    hoge[i] = i**5
for i in range(1000):
    hoge[-i] = -i**5
x = int(input())
for i in hoge.items():
    for j in hoge.items():
        if i[1] - j[1] == x:
            print(i[0], j[0])
            break
    else:
        continue
    break

Buggy submission (verdict: Runtime Error):
hoge = {}
for i in range(100):
    hoge[i] = i**5
for i in range(100):
    hoge[-i] = -i**5
x = int(input())
for i in hoge.items():
    for j in hoge.items():
        if i[1] - j[1] == x:
            print(i[0], j[0])
            return
Problem p02755 (python)

Fixed submission:
import math
[a, b] = [int(i) for i in input().split()]

for i in range(3000):
    if math.floor(i*0.08)==a and math.floor(i*0.1)==b:
        print(i)
        break
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
[a, b] = [int(i) for i in input().split()]

for i in range(3000):
    if math.floor(i*0.08)==a and math.floor(i*0.1)==b:
        print(i)
        return
print(-1)
Problem p02817 (python)

Fixed submission:
def main():
    [s, t] = input().split()
    print(t + s)

if __name__ == "__main__":
	main()

Buggy submission (verdict: Runtime Error):
def main():
  [n, k] = [int(i) for i in input().split()]
  [r, s, p] = [int(i) for i in input().split()]
  T =  input()
  
  my = T.replace("r", "hoge").replace("s", "r").replace("p", "s").replace("hoge", "p") 
  for i in range(k, n):
    if my[i] == my[i-k]:
      my = my[:i] + "l" + my[i+1:]  
      
  print(my.count("r")* r + my.count("s")*s + my.count("p")* p)
  
if __name__ == "__main__":
  main()
Problem p02818 (python)

Fixed submission:
def main():
  [a, t, k] = [int(i) for i in input().split()]
  if a + t <= k:
    a = 0
    t = 0
  elif a <= k:
    t = t - (k - a)
    a = 0
  else:
    a = a - k
  print(a, t)

if __name__ == "__main__":
  main()

Buggy submission (verdict: Runtime Error):
def main():
  [a, t, k] = [int(i) for i in input().split()]
  if a + t >= k:
    a = 0
    t = 0
  elif a >= k:
    a = 0
    t = t - (k -a)
  else:
    a = a - k:

if __name__ == "__main__":
  main()
Problem p03043 (python)

Fixed submission:
[n, k] = [int(i) for i in input().split()]
total = 0
for i in range(1, n+1):
    point = i
    prob = 1/n
    while(point < k):
        point *= 2
        prob /= 2
    total += prob
print(total)

Buggy submission (verdict: Runtime Error):
[n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in range(m):
    idx = a.index(max(a))
    a[idx] = int(a[idx] / 2)
print(sum(a))

Buggy submission (verdict: Runtime Error):
[n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
for i in range(m):
    a[-1] = int(a[-1] / 2)
    a.sort()
print(sum(a))
Problem p03106 (python)

Fixed submission:
[a, b, n] = [int(i) for i in input().split()]
hoge = []
for i in range(1, 101):
    if a%i==0 and b%i==0:
        hoge.append(i)
hoge.sort(reverse=True)
print(hoge[n-1])

Buggy submission (verdict: Runtime Error):
[a, b, n] = [int(i) for i in input().split()]
hoge = []
for i in range(1, 101):
    if i%a==0 and i%b==0:
        hoge.append(i)
print(hoge[n-1])
Problem p03161 (python)

Fixed submission:
[n, k] = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [10 ** 10 for _ in range(n)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    for j in range(1, min(i, k)+1):
        if i - j >= 0:
            dp[i] = min(dp[i] , dp[i-j] + abs(h[i] - h[i-j]))
print(dp[n-1])

Buggy submission (verdict: Runtime Error):
[n, k] = [int(i) for i in input().split()]
h = np.array([int(i) for i in input().split()])
dp = [10 ** 5 for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(k+1):
        if i + j < n:
            dp[i + j] = min(dp[i + j] , dp[i] + abs(h[i] - h[i+j]))
print(dp[n-1])
Problem p03162 (python)

Fixed submission:
n = int(input())
action = []
for i in range(n):
    action.append([int(i) for i in input().split()])
dp = [[0 for _ in range(3)] for _ in range(n+1)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + action[i][k])
print(max(dp[n]))

Buggy submission (verdict: Runtime Error):

def resolve():
    n = int(input())
    action = []
    for i in range(n):
        action.append([int(i) for i in input().split()])
    df = []
    df.append(max(action[0]))
    prev = action[0].index(max(action[0]))
    for i in range(1, n):
        tgt = max([action[i][j] for j in range(len(action[i])) if j != prev])
        prev = action[i].index(tgt)
        df.append(tgt)
    print(sum(df))

if __name__ = "__main__":
    resolve()
Problem p03371 (python)

Fixed submission:
[a, b, ab, x, y] = [int(i) for i in input().split()]
price = []
price.append(a * x + b * y)
if x > y:
    price.append(2 * ab * y + a * (x-y))
else:
    price.append(2 * ab * x + b * (y-x))
price.append(ab * 2 * max(x, y))
print(min(price))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = 1
b = 1
mx = 10 ** 10
while (a <= b and a * a <= n):
    if n % a == 0:
        b = int(n / a)
        mx = min(mx, max(a, b))
    a += 1
print(len(str(mx)))
Problem p02787 (python)

Fixed submission:

def main():

    H, N = map(int, input().split())

    ab = [tuple(map(int, input().split())) for _ in range(N)]

    INF = float("inf")
    dp = [[INF for _ in range(H+1)] for _ in range(N+1)]
    dp[0][0] = 0


    for i in range(1, N+1):
        for h in range(H+1):
            aaa = h-ab[i-1][0] if h-ab[i-1][0] >= 0 else 0
            tmp = dp[i][aaa] if dp[i][aaa] != INF else 0
            dp[i][h] = min(dp[i-1][h], tmp + ab[i-1][1])

    print(dp[-1][H])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):

def main():

    H, N = map(int, input().split())

    ab = [tuple(map(int, input().split())) for _ in range(N)]

    INF = float("inf")
    dp = [[INF for _ in range(H+1)] for _ in range(N+1)]
    dp[0][0] = 0


    for i in range(1, N+1):
        for h in range(H+1):

            tmp = dp[i][h-ab[i-1][0]] if dp[i][h-ab[i-1][0]] != INF else 0
            #if ab[i-1][0] <= h:
            dp[i][h] = min(dp[i-1][h], tmp + ab[i-1][1])

            #else:
            #    dp[i][h] = dp[i-1][h]

            #if i == 3 and h == 9:
            #    print(dp[i][h-ab[i-1][0]], h, ab[i-1][0], tmp, ab[i-1][1] )

    print(dp[-1][H])
    #print(dp)

if __name__ == "__main__":
    main()
Problem p02802 (python)

Fixed submission:
from collections import defaultdict

N, M = map(int, input().split())

submit = defaultdict(list)
for i in range(M):
    p,s = map(str, input().split())
    submit[p].append(s)


wa = 0
ac = 0
for k in submit.keys():
    if "AC" in submit[k]:
        for i in range(len(submit[k])):
            if submit[k][i] == "WA":
                wa += 1
            elif submit[k][i] == "AC":
                ac += 1
                break
        


print(ac, wa)

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

N, M = map(int, input().split())

submit = defaultdict(list)
for i in range(M):
    p,s = map(str, input().split())
    submit[p].append(s)


wa = 0
ac = 0
for k in submit.keys():
    for i in range(N):
        if submit[k][i] == "AC":
            wa += i
            ac += 1
            break

print(ac, wa)
Problem p02936 (python)

Fixed submission:
N,Q = map(int, input().split())
import copy
import sys

sys.setrecursionlimit(10**6)
es = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)


point = [0] * N

for i in range(Q):
    p,x = map(int, input().split())
    point[p-1] += x 

ans = [0] * N
ans[0] = point[0] # 一番上の根なのでこれだけ
visited = [False] * N
visit_cnt = 1
from collections import deque
nexts = deque([0])
while len(nexts) >= 1:
    now = nexts.popleft()
    visited[now] = True

    for next in es[now]:
        if visited[next] == True:
            continue
        nexts.append(next)
        ans[next] = ans[now] + point[next]


print(*ans)

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

sys.setrecursionlimit(10**6)
es = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)


point = [0] * N

for i in range(Q):
    p,x = map(int, input().split())
    point[p-1] += x 

ans = [0] * N
ans[0] = point[0] # 一番上の根なのでこれだけ
visited = [False] * N
visit_cnt = 1
from collections import deque
nexts = deque([0])
while len(nexts) >= 1:
    now = nexts.popleft()
    visited[now] = True

     for next in es[now]:
        if visited[next] == True:
            continue
        nexts.append(next)
        ans[next] = ans[now] + point[next]


print(*ans)

Buggy submission (verdict: Runtime Error):
N,Q = map(int, input().split())
import copy
es = {}
for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    if a in es:
        es[a].append(b)
    else:
        es[a] = [b]


point_root = [0] * N
query = [None]
for i in range(Q):
    p,x = map(int, input().split())
    point_root[p-1] += x 

ans = [0] * N
visited = [False] * N
ans[0] = point_root[0]
visited[0] = True
def solve(node, point):
    ans[node] = point
    visited[node] = True
    if all(visited) == True:
        print(*ans)
        exit()

    if es.get(node, None) != None:
        next_nodes = copy.deepcopy(es[node]) # これからポイントを足し行くやつら

        for i in next_nodes:
            solve(i, point+point_root[i])
solve(0, point_root[0])
Problem p02949 (python)

Fixed submission:
N,M,P = map(int, input().split())

es = []

for i in range(M):
    a,b,c = map(int, input().split())
    es.append((a-1, b-1, c))

INF = float("inf")

d = [INF for _ in range(N)] 
d[0] = 0
"""
頂点Nに向かうまでに関係ない閉路に注意する

無限にコインを拾える場合、
・ある閉路を一周したときの得点と支払いの収支がプラス
・その閉路からゴールまで行ける
である。これがない場合、全てのノードを経由してゴールまで行く（N-1回移動）までにコインの枚数が最大になる
なので、一回ベルマンフォード法をやった後もう一回行って一回目と２回目でゴールまでのコイン枚数に変化があればゴ、
ールに行くまでの道に無限にコインをとれる閉路があるといえる

"""

def solve(start, f):
    for i in range(N):
        for a,b,c, in es:
            if d[a] != INF and d[a] + (-c) + P < d[b]:
                # ２週目と区別する。２週目で更新される部分は-INFとか適当に置いておくと、ゴールまでの影響がわかる
                if f == 0:
                    d[b] = d[a] + (-c) + P
                else:
                    d[b] = -INF


    return d[-1]


first=solve(0,0)
second=solve(0, 1)
if first != second:
    print(-1)
else:
    print(max(-first, 0))

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

es = []

for i in range(M):
    a,b,c = map(int, input().split())
    es.append((a-1, b-1, c))

INF = float("inf")

d = [INF for _ in range(N)] 
d[0] = 0
"""
頂点Nに向かうまでに関係ない閉路に注意する

無限にコインを拾える場合、
・ある閉路を一周したときの得点と支払いの収支がプラス
・その閉路からゴールまで行ける
である。これがない場合、全てのノードを経由してゴールまで行く（N-1回移動）までにコインの枚数が最大になる
なので、一回ベルマンフォード法をやった後もう一回行って一回目と２回目でゴールまでのコイン枚数に変化があればゴ、
ールに行くまでの道に無限にコインをとれる閉路があるといえる

"""

def solve(start):
    for i in range(N):
        for a,b,c, in es:
            if d[a] != INF and d[a] + (-c) + P < d[b]:
                d[b] = d[a] + (-c) + P
                

                if i == N-1 and b == N-1:
                    return -1


    return max(-d[-1][0])


first=solve(0)
if first == -1:
    print(-1)
else:
    second=solve(0)
    if first == second:
        print(max(first, 0))
    else:
        print(-1)
Problem p03001 (python)

Fixed submission:
w,h,x,y = map(int, input().split())


if w == 0 or h == 0:
    print(0,0)

if x == 0 or y == 0:
    print(h*w/2, 0)
else:
    if y/x == h/w:
        if x != w and y != h:
            num = 1
        else:
            num = 0
    else:
        num = 0

    print(h*w/2, num)

Buggy submission (verdict: Runtime Error):


w,h,x,y = map(int, input().split())


if y/x == h/w:
    num = 1
else:
    num = 0

print(h*w/2, num)
Problem p03006 (python)

Fixed submission:


N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]

pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            pq.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))


ans = N
for p,q in pq:
    cost = 0
    for x,y in xy:
        if  (x+p, y+q) not in xy:
            cost += 1

    ans = min(ans, cost)

print(ans)

Buggy submission (verdict: Runtime Error):



"""
・あるボールから（p,q）の移動で別のボールに移れるならコストが０、そうでなければ１
　→あるボールの位置(x,y) + (p,q) の位置にボールがあるかどうか、全てのボールについて確認する。なければコスト＋１
・p,qの選び方は、全ボールの間隔を試すと行けそう(N <= 50 なので間に合いそう)

"""



N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]

pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            pq.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))


ans = N
for p,q in pq:
    cost = 0
    for x,y in xy:
        if  (x+p, y+q) not in xy:
            cost += 1

    ans = min(ans, cost)

print(cost)

Buggy submission (verdict: Runtime Error):



N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]

"""
・あるボールから（p,q）の移動で別のボールに移れるならコストが０、そうでなければ１
　→あるボールの位置(x,y) + (p,q) の位置にボールがあるかどうか、全てのボールについて確認する。なければコスト＋１
・p,qの選び方は、全ボールの間隔を試すと行けそう(N <= 50 なので間に合いそう)

"""


pq = []
for i in range(N):
    for j in range(N):
        if i != j:
            # 同じ間隔（同じp,qのパターン）が起こりうるのでdictで管理するほうがいいかも
            pq.append((xy[i][0] - xy[j][0], xy[i][1] - xy[j][1]))

set_xy = set(xy)
ans = N
for p,q in pq:
    cost = 0
    for x,y in xy:
        if  (x+p, y+q) not in set_xy:
            cost += 1

    ans = min(ans, cost)

print(cost)
Problem p03032 (python)

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

ans = 0

for i in range(N+1): # 左端から取り出す回数
    for j in range(N+1-i): # 右端から取り出す回数
        L = V[:i]
        if j == 0:
            R = []
        else:
            R = V[-j:]
        LR = L + R
        if len(LR) > K:
            continue
        num_drop = min(len(LR), K-i-j)
        LR.sort()
        total = sum(LR)
        idx = 0
        while idx < num_drop:
            if LR[idx] < 0:
                total -= LR[idx]
                idx += 1
            else:
                break
        ans = max(ans, total)


print(ans)

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

ans = 0
nums = min(N, K)
for i in range(nums+1): # 左端から取り出す回数
    for j in range(nums+1-i): # 右端から取り出す回数
        for k in range(nums+1-i-j): # Dに戻す個数
            L = V[:i]
            R = V[N-j:]
            #print(L, R, i, j, k)
            if L == []: L = [0]
            if R == []: R = [0]
            LR = L + R
            LR.sort()
            cnt = 0
            while cnt < k:
                if LR[cnt] < 0:
                    cnt += 1
                else:
                    break
            ans = max(ans, sum(LR[cnt:]))

print(ans)

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

ans = 0
nums = min(N, K)
for i in range(nums): # 左端から取り出す回数
    for j in range(nums-i): # 右端から取り出す回数
        for k in range(nums-i-j): # Dに戻す個数
            L = V[:i]
            R = V[N-j:]
            if L == []: L = [0]
            if R == []: R = [0]
            LR = L + R
            LR.sort()
            cnt = 0
            while cnt <= k:
                if LR[cnt] < 0:
                    cnt += 1
                else:
                    break
            ans = max(ans, sum(LR[cnt:]))

print(ans)
Problem p03044 (python)

Fixed submission:
N = int(input())

es = [[] for _ in range(N)]

for i in range(N-1):
    u,v,w = map(int, input().split())

    es[u-1].append((v-1,w))
    es[v-1].append((u-1,w))

ans = [-1] * N

ans[0] = 0

queue = [0]

while len(queue) > 0:
    next_queue = []
    for curr in queue:
        for next,w in es[curr]:
            if ans[next] == -1:
                    next_queue.append(next)
                    if w % 2 == 0:
                        ans[next] = ans[curr]
                    else:
                        ans[next] = 1 if ans[curr] == 0 else 0

    if len(next_queue) > 0:
        queue = next_queue
    else:
        queue = []

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):



N = int(input())
es = [[] for _ in range(N)]

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


ans = [-1] * N

def dfs(node, c):

    ans[node] = c
    for next,w in es[node]:
        # 未着色であれば
        if ans[next] == -1:
            if w % 2 == 0:
                # 距離が偶数なら同じ色
                dfs(next, c)
            else:
                # 距離が異なるなら違う色
                if c == 0:
                    dfs(next, 1)
                else:
                    dfs(next, 0)

dfs(0,0)

print(*ans, sep="\n")

Buggy submission (verdict: Runtime Error):



N = int(input())
es = [[] for _ in range(N)]

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


ans = [-1] * N

def dfs(node, c):

    ans[node] = c
    for next,w in es[node]:
        # 未着色であれば
        if ans[next] == -1:
            if w % 2 == 0:
                # 距離が偶数なら同じ色
                dfs(next, c)
            else:
                # 距離が異なるなら違う色
                if c == 0:
                    dfs(next, 1)
                else:
                    dfs(next, 0)

dfs(0,0)

print(ans, sep="\n")
Problem p03047 (python)

Fixed submission:

n,k = map(int, input().split())

print(n-k+1)

Buggy submission (verdict: Runtime Error):

n,k = map(int, input().split())

print(n-l+1)