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

Fixed submission:
import sys
from copy import copy

sys.setrecursionlimit(10**5)

# 木の根を返す
def find(x, S):
    if S[x] == x:
        return x
    else:
        S[x] = find(S[x], S)
        return S[x]

# xとyが同じ集合に属すかの判定
def same(x, y, S):
    return find(x, S) == find(y, S)

# xとyの属する集合を結合
def unite(x, y, S):
    rx = find(x, S)
    ry = find(y, S)
    if rx == ry:
        return None
    else:
        S[rx] = ry

if __name__ == '__main__':
    [N, M] = [int(i) for i in input().split()]

    S = [int(i) for i in range(N+1)]
    p = [0] + [int(num) for num in input().split()]

    for i in range(M):
        [x, y] = [int(i) for i in input().split()]
        unite(x, y, S)

    score = 0
    for i in range(1, N+1):
        if same(i, p[i], S):
            score += 1
    print(score)

Buggy submission (verdict: Runtime Error):
from typing import Union, List
import sys
from copy import copy

sys.setrecursionlimit(10**5)

# 木の根を返す
def find(x: int, S: List[int]) -> int:
    if S[x] == x:
        return x
    else:
        S[x] = find(S[x], S)
        return S[x]

# xとyが同じ集合に属すかの判定
def same(x: int, y: int, S: List[int]) -> bool:
    return find(x, S) == find(y, S)

# xとyの属する集合を結合
def unite(x: int, y: int, S: List[int]) -> None:
    rx = find(x, S)
    ry = find(y, S)
    if rx == ry:
        return None
    else:
        S[rx] = ry

if __name__ == '__main__':
    [N, M] = [int(i) for i in input().split()]

    S = [int(i) for i in range(N+1)]
    p = [0] + [int(num) for num in input().split()]

    for i in range(M):
        [x, y] = [int(i) for i in input().split()]
        unite(x, y, S)

    score = 0
    for i in range(1, N+1):
        if same(i, p[i], S):
            score += 1
    print(score)
Problem p03557 (python)

Fixed submission:
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    A.sort()
    B.sort()
    C.sort()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        if not A2B[i] == N:
            ans += B2C[A2B[i]]

    print(ans)

Buggy submission (verdict: Runtime Error):
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    A.sort()
    B.sort()
    C.sort()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i-1]]

    print(ans)

Buggy submission (verdict: Runtime Error):
def binary_serch(target, num_list):
    ok = len(num_list)
    ng = -1

    while(abs(ok - ng) > 1):
        mid = int((ok + ng) / 2)
        mid_num = num_list[mid]
        if target < mid_num:
            ok = mid
        else:
            ng = mid

    return ok


if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    A.sort()
    B.sort()
    C.sort()

    # index
    A2B = [binary_serch(a, B) for a in A]

    # 累積和
    B2C = []
    tmp = 0
    for b in B[::-1]:
        tmp = tmp + (N - binary_serch(b, C))
        B2C.append(tmp)

    B2C = B2C[::-1]

    ans = 0

    for i in range(N):
        ans += B2C[A2B[i]]

    print(ans)
Problem p03722 (python)

Fixed submission:
def main():
    [N, M] = [int(i) for i in input().split()]
    edge = [[10**100] * N for _ in range(N)]

    E = []

    for i in range(M):
        E.append([int(i) for i in input().split()])

    dist = [-1*10**100 for i in range(N)]
    dist[0] = 0

    flag = False

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist[b-1] = newLen
        if i == N-1 and dist[N-1] > predist:
            flag = True
        predist = dist[N-1]

    if flag:
        print('inf')
    else:
        print(dist[N-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    [N, M] = [int(i) for i in input().split()]

    E = []

    for i in range(M):
        E.append([int(i) for i in input().split()])

    dist = [-1*10**100 for i in range(N)]
    dist[0] = 0

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist[b-1] = newLen

    dist2 = dist.copy()

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist2[a-1] + c
            if newLen > dist2[b-1]:
                dist2[b-1] = newLen

    if dist != dist2:
        print('inf')
    else:
        print(dist[N-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    [N, M] = [int(i) for i in input().split()]

    E = []

    for i in range(M):
        E.append([int(i) for i in input().split()])

    dist = [-1*10**100 for i in range(N)]
    dist[0] = 0

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist[b-1] = newLen

    dist2 = dist.copy()

    for i in range(N):
        for [a, b, c] in E:
            newLen = dist[a-1] + c
            if newLen > dist[b-1]:
                dist2[b-1] = newLen

    if dist != dist2:
        print('inf')
    else:
        print(dist[N-1])


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

Fixed submission:
n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

k = min(n-1, k)

inf = 100000000

dp = [inf for _ in [0]*n]

def cost(i, j):
	return abs(h[i] - h[j])

for i in range(k+1):
	dp[i] = cost(0, i)

for i in range(k+1, n):
	
	dp[i] = min([dp[i-j] + cost(i-j, i) for j in range(1, k+1)])

print(dp[-1])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

n, k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]

k = min(n-1, k)

inf = 100000000

dp = [inf for _ in [0]*n]

@lru_cache
def cost(i, j):
	return abs(h[i] - h[j])

for i in range(k+1):
	dp[i] = cost(0, i)

for i in range(k+1, n):
	
	dp[i] = min([dp[i-j] + cost(i-j, i) for j in range(1, k+1)])

print(dp[-1])
Problem p03160 (python)

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

dp = [100000] * n

dp[0] = 0

for i in range(0, n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[i-1] - h[i])
    else:
        a = dp[i-1] + abs(h[i] - h[i-1])
        b = dp[i-2] + abs(h[i] - h[i-2])
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

inf = 1000000000

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

@lru_cache(maxsize=1000)
def dp(i):

    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1] - h[0])
    elif 2 <= i:
        return min(dp(i-1) + abs(h[i]-h[i-1]), dp(i-2) + abs(h[i] - h[i-2]))
    else:
        return inf

print(dp(n-1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10000)

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

def dp(i):

    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1] - h[0])
    elif 2 <= i:
        return min(dp(i-1) + abs(h[i]-h[i-1]), dp(i-2) + abs(h[i] - h[i-2]))
    else:
        return 100000000

print(dp(n-1))

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

def dp(i):

    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1] - h[0])
    elif 2 <= i:
        return min(dp(i-1) + abs(h[i]-h[i-1]), dp(i-2) + abs(h[i] - h[i-2]))
    else:
        return 100000000

print(dp(n-1))

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

def dp(i):

    if i == 0:
        return 0
    elif i == 1:
        return abs(h[1] - h[0])
    elif 2 <= i:
        return min(dp(i-1) + abs(h[i]-h[i-1]), dp(i-2) + abs(h[i] - h[i-2]))
    else:
        return 100000000

print(dp(n-1))
Problem p03160 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
dp[1] = abs(a[0] - a[1])

for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(a[i-2] - a[i]) , dp[i - 1] + abs(a[i - 1] - a[i]))

print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
 
dp = [0] * n
dp[0] = 0
dp[1] = abs(a[0] - a[1])
#dp[2] = dp[0]
for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(a[i-2] - a[i]) , d[i - 1] + abs(a[i - 1] - a[i]))

print(dp[n - 1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
 
dp = [0] * n
dp[0] = 0
dp[1] = abs(a[0] - a[1])
dp[2] = dp[0]
for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(a[i-2] - a[i]) , d[i - 1] + abs(a[i - 1] - a[i]))
 
print dp[n - 1]

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

dp = [0] * n
dp[0] = 0
dp[1] = abs(a[0] - a[1])
dp[2] = dp[0]
for i in range(2, n):
  dp[i] = min(dp[i-2] + abs(a[i-2] - a[i]) , d[i - 1] + abs(a[i - 1] - a[i]))

print(dp[n - 1])
Problem p03162 (python)

Fixed submission:
n = int(input())
a = []
b = []
c = []
for i in range(n):
    m,v,p = map(int,input().split())
    a.append(m)
    b.append(v)
    c.append(p)
d = [[0]*3 for i in range(n)]
d[0][0]=a[0]
d[0][1]=b[0]
d[0][2]=c[0]
for i in range(1,n):
    for j in range(3):
        if j == 0:
            d[i][j] = max(d[i-1][1],d[i-1][2]) + a[i]
        elif j == 1:
            d[i][j] = max(d[i-1][0],d[i-1][2]) + b[i]
        else:
            d[i][j] = max(d[i-1][0],d[i-1][1]) + c[i]
print(max(d[-1][0],d[-1][1],d[-1][2]))

Buggy submission (verdict: Runtime Error):
n = int(input())
dp = [[0]*n for i in range(n)]
for i in range(n):
    l = list(map(int , input().split()))
    if i == 0:
        dp[0][0]=l[0]
        dp[0][0]=l[1]
        dp[0][0]=l[2]
    else:
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+l[0]
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+l[1]
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+l[2]
print(max(dp[-1][0], dp[-1][1], dp[-1][2]))
Problem p03160 (python)

Fixed submission:
import sys

n = int(input())
h_list = [int(x) for x in input().split(" ")]

dp = [sys.maxsize] * len(h_list)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])
for i in range(2, len(dp)):
  dp[i] = min(dp[i - 1] + abs(h_list[i] - h_list[i-1]), dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

print(dp[-1])

Buggy submission (verdict: Runtime Error):
from typing import List
import sys

n = int(input())
h_list: List[int] = [int(x) for x in input().split(" ")]

dp: List[int] = [sys.maxsize] * len(h_list)
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])
for i in range(2, len(dp)):
  dp[i] = min(dp[i - 1] + abs(h_list[i] - h_list[i-1]), dp[i - 2] + abs(h_list[i] - h_list[i - 2]))

print(dp[-1])
Problem p03160 (python)

Fixed submission:
n = int(input())
initial_vals = list(map(int, input().split(" ")))


# print(calc(0, n - 1))


arr = [0 for x in range(n)]

arr[1] = abs(initial_vals[0] - initial_vals[1])

for i in range(2, len(arr)):
    arr[i] = min(
        arr[i - 1] + abs(initial_vals[i - 1] - initial_vals[i]),
        arr[i - 2] + abs(initial_vals[i - 2] - initial_vals[i]),
    )

print(arr[n - 1])

Buggy submission (verdict: Runtime Error):
import pysnooper
import tabulate

n = int(input())
initial_vals = list(map(int, input().split(" ")))


@pysnooper.snoop()
def calculate_paths(vals):

    if len(vals) == 3:
        return min(abs(vals[0] - vals[2]), abs(vals[0] - vals[1]))
    elif len(vals) == 2:
        return abs(vals[0] - vals[1])
    elif len(vals) > 3:
        return min(
            calculate_paths(vals[:-1]) + abs(vals[-2] - vals[-1]),
            calculate_paths(vals[:-2]) + calculate_paths(vals[-3:-1]),
        )
    else:
        print("weird:" + str(vals))


table = [[None for x in range(n)] for x in range(n)]

for i in range(n - 1):
    table[i][i + 1] = abs(initial_vals[i] - initial_vals[i + 1])
    if len(initial_vals) > i + 2:
        table[i][i + 2] = abs(initial_vals[i] - initial_vals[i + 2])


def calc(from_stone, to_stone):
    if (to_stone - from_stone) == 1:
        return table[from_stone][to_stone]
    elif (to_stone - from_stone) == 2:
        return min(
            table[from_stone][to_stone],
            table[from_stone][to_stone - 1] + table[to_stone - 1][to_stone],
        )
    else:
        table[from_stone][to_stone] = min(
            calc(from_stone, to_stone - 1) + table[to_stone - 1][to_stone],
            calc(from_stone, to_stone - 2) + table[to_stone - 2][to_stone],
        )
        return table[from_stone][to_stone]


print(calc(0, n - 1))
Problem p03173 (python)

Fixed submission:
import fileinput


def solve_slimes(slimes):
    slime_union_table = [0] * len(slimes) * len(slimes)
    slime_cost_table = [0] * len(slimes) * len(slimes)

    for i in range(len(slimes)):
        slime_union_table[i] = slimes[i]

    for gap in range(1, len(slimes)):
        for li in range(len(slimes) - gap):
            split_size = slime_union_table[li] + slime_union_table[li + 1 + (gap - 1) * len(slimes)]
            slime_union_table[li + gap * len(slimes)] = split_size

            for split in range(0, gap):
                split_cost = slime_cost_table[li + split * len(slimes)] + slime_cost_table[li + split + 1 + (gap - split - 1) * len(slimes)] + split_size

                if slime_cost_table[li + gap * len(slimes)] == 0:
                    slime_cost_table[li + gap * len(slimes)] = split_cost

                else:
                    slime_cost_table[li + gap * len(slimes)] = min(
                        split_cost,
                        slime_cost_table[li + gap * len(slimes)]
                    )
    return slime_cost_table[len(slimes) * (len(slimes) - 1)]


inp = fileinput.FileInput()

inp.readline()
slimes = [int(v) for v in inp.readline().split()]

print(solve_slimes(slimes))

Buggy submission (verdict: Runtime Error):
import fileinput


def solve_slimes(slimes):
    slime_union_table = [0] * len(slimes) * len(slimes)
    slime_cost_table = [0] * len(slimes) * len(slimes)

    for i in range(len(slimes)):
        slime_union_table[i] = slimes[i]

    for gap in range(1, len(slimes)):
        for li in range(len(slimes) - gap):
            split_size = slime_union_table[li] + slime_union_table[li + 1 + (gap - 1) * len(slimes)]
            slime_union_table[li + gap * len(slimes)] = split_size

            for split in range(0, gap):
                split_cost = slime_cost_table[li + split * len(slimes)] + slime_cost_table[li + split + 1 + (gap - split - 1) * len(slimes)] + split_size

                if slime_cost_table[li + gap * len(slimes)] == 0:
                    slime_cost_table[li + gap * len(slimes)] = split_cost

                else:
                    slime_cost_table[li + gap * len(slimes)] = min(
                        split_cost,
                        slime_cost_table[li + gap * len(slimes)]
                    )
    return slime_cost_table[len(slimes) * (len(slimes) - 1)]


inp = fileinput.FileInput()

inp.readline()
slimes = [int(v) for v in inp.readline().split()]

print(solve_slimes(slimes)
Problem p03160 (python)

Fixed submission:
N=int(input())
h=list(map(int,input().split()))
a=[]
for i in range(N):
  a.append(0)
a[0]=0
a[1]=abs(h[1]-h[0])
for i in range(2,N):
  a[i]=min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]))
print(a[N-1])

Buggy submission (verdict: Runtime Error):
hhhh

Buggy submission (verdict: Runtime Error):

N=int(input())
h=list(map(int,input().split()))
a=[]
a[0]=0
a[1]=abs(h[1]-h[0])
for i in range(2,N):
  a[i]=min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]))
print(a[N-1])
Problem p03160 (python)

Fixed submission:
n = int(input()) # n >= 2
h = list(map(int, input().split())) # h_i >= 1

cost2 = 0;
cost1 = abs(h[1] - h[0]);

for i in range(2, n):
    cost = min(cost1 + abs(h[i] - h[i - 1]), cost2 + abs(h[i] - h[i - 2]))
    cost2, cost1 = cost1, cost

print(cost1)

Buggy submission (verdict: Runtime Error):
n = int(input()) # n >= 2
h = list(map(int, input().split())) # h_i >= 1

cost2 = 0;
cost1 = abs(h[1] - h[0]);

for i in range(2, n):
    cost = min(cost1 + abs(h[i] - h[i - 1]), cost2 + abs(h[i] - h[i - 2]))
    cost2, cost1 = cost1, cost

print(cost)

Buggy submission (verdict: Runtime Error):
n = int(input()) # n >= 2
h = list(map(int, input().split())) # h_i >= 1

cost2 = 0;
cost1 = abs(h[1] - h[0]);

for i in range(2, n):
    cost = min(cost1 + abs(h[i] - h[i - 1]), cost2 + abs(h[i] - h[i - 2]))
    cost2, cost1 = cost1, cost
    

print(cost)

Buggy submission (verdict: Runtime Error):
def cost(h, length):
    if length == 1:
        return 0
    elif length == 2:
        return abs(h[1] - h[0])
    else:
        variants = [cost(h, length - 1) + abs(h[length - 1] - h[length - 2]), cost(h, length - 2) + abs(h[length - 1] - h[length - 3])]
        return min(variants)

n = int(input()) # n >= 2
h = list(map(int, input().split())) # h_i >= 1
print(cost(h, n))
Problem p03160 (python)

Fixed submission:
N  = input()
line = raw_input()
cost = line.split(' ')

for i in range(0,N):
	cost[i] = int(cost[i])

dp = [0]*(N)

dp[0] = 0
dp[1] = abs(cost[1] - cost[0])

for n in range(2,N):
	dp[n] = min(abs(cost[n] - cost[n-1]) + dp[n-1], abs(cost[n] - cost[n-2]) + dp[n-2])

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N  = input()
line = raw_input()
cost = line.split(' ')

for i in range(0,N):
	cost[i] = int(cost[i])

dp = [0]*(N)

dp[0] = 0
dp[1] = abs(cost[1] - cost[0])

for n in range(2,N):
	dp[n] = min(abs(cost[n] - cost[n-1]) + dp[n-1], abs(cost[n] - cost[n-1]) + dp[n-2])

print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N  = input()
cost = []
dp = [0]*(N)

for i in range(0,N):
	cost.append(input())

dp[0] = 0
dp[1] = abs(cost[1] - cost[0])

for n in range(2,N):
	dp[n] = min(abs(cost[n] - cost[n-1]) + dp[n-1], abs(cost[n] - cost[n-1]) + dp[n-2])

return dp[N-1]
Problem p03160 (python)

Fixed submission:
N = int(input())
h = list(map(int,input().split()))
dp = [999999] * N

dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(N-2):
    dp[i + 2] = min((dp[i] + abs(h[i] - h[i+2])), (dp[i+1] + abs(h[i+1] - h[i+2])))
   
print(dp[N-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
h = list(map(int,input().split()))
dp = [999999] * N

dp[0] = 0
dp[1] = abs(h[0]-h[1])
for i in range(N-2):
    dp[i + 2] = min((dp[i] + abs(h[i] - h[i+2])), (dp[i+1] + abs(h[i+1] - h[i+2])))
    print(dp)
print(dp[N-1])
Problem p03353 (python)

Fixed submission:
s = input()
k = int(input())
arr = set()
arr.add(s)
for i in range(len(s)-1):
    if i > 5:
        break
    for j in range(0, len(s)):
        arr.add(s[j:j+i+1])

arr = list(arr)
arr.sort()
print(arr[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
arr = set()
arr.add(s)
for i in range(len(s)-1):
    for j in range(1, len(s)):
        arr.add(s[j:j+i+1])
arr = list(arr)
arr.sort()
print(arr[k-1])
Problem p03361 (python)

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = "Yes"
for i in range(1, h-1):
    for j in range(1, w-1):
        if s[i][j] == "#" and s[i - 1][j] == "." and s[i + 1][j] == "." and s[i][j - 1] == "." and s[i][j + 1] == ".":
          r = "No"
print(r)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
r = "Yes"
for i in range(1, h-1):
    for j in range(1, w-1):
        if a[i][j] == "#" and a[i - 1][j] == "." and a[i + 1][j] == "." and a[i][j - 1] == "." and a[i][j + 1] == ".":
          r = "No"
print(r)
Problem p03998 (python)

Fixed submission:
d = dict(a=list(input()), b=list(input()), c=list(input()))
op = 'a'
while True:
    if not d[op]:
        print(op.upper())
        break
    op = d[op].pop(0)

Buggy submission (verdict: Runtime Error):
d = dict(a=input(), b=input(), c=input())
op = 'a'
while True:
    if not d[op]:
        print(op.upper())
        break
    op = d[op].pop(0)
Problem p03447 (python)

Fixed submission:
argent = int(input())
gateau = int(input())
donut = int(input())

argent -= gateau
argent %= donut
print(argent)

Buggy submission (verdict: Runtime Error):
n = int(input())
def c(x,y):
    if 0 <= x < n and 0 <= y < 2:
        if cache[y][x] != " ":
            return cache[y][x]

        if x == 0 and y == 0:
            total = matrice[0][0]
        else:
            if x > 0:
                tt1 = c(x-1,y)
            else:
                tt1 = 0
            if y > 0:
                tt2 = c(x,y-1)
            else:
                tt2 = 0
            total = max(tt1,tt2) + matrice[y][x]
        cache[y][x] = total
        return total

    
matrice = []
cache = [ [" " for i in range(n)] for a in range(2) ] 
for i in range(2):
    matrice.append( [ int(i) for i in input().split() ] )

print( c(n-1,1) )
Problem p03448 (python)

Fixed submission:
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    tt = int(input())
    total = 0

    for yen500 in range(a+1):
        for yen100 in range(b+1):
            for yen50 in range(c+1):
                if yen500 * 500 + yen100 * 100 + yen50 * 50 == tt:
                    total += 1

    print(total)

main()

Buggy submission (verdict: Runtime Error):
def main()
    a = int(input())
    b = int(input())
    c = int(input())
    tt = int(input())
    total = 0

    for yen500 in range(a+1):
        for yen100 in range(b+1):
            for yen50 in range(c+1):
                if yen500 * 500 + yen100 * 100 + yen50 * 50 == tt:
                    total += 1

    print(total)

main()
Problem p03449 (python)

Fixed submission:
n = int(input())
def c(x,y):
    if 0 <= x < n and 0 <= y < 2:
        if cache[y][x] != " ":
            return cache[y][x]

        if x == 0 and y == 0:
            total = matrice[0][0]
        else:
            if x > 0:
                tt1 = c(x-1,y)
            else:
                tt1 = 0
            if y > 0:
                tt2 = c(x,y-1)
            else:
                tt2 = 0
            total = max(tt1,tt2) + matrice[y][x]
        cache[y][x] = total
        return total

    
matrice = []
cache = [ [" " for i in range(n)] for a in range(2) ] 
for i in range(2):
    matrice.append( [ int(i) for i in input().split() ] )

print( c(n-1,1) )

Buggy submission (verdict: Runtime Error):
    n = int(input())
    def c(x,y):
        if 0 <= x < n and 0 <= y < 2:
            if cache[y][x] != " ":
                return cache[y][x]
     
            if x == 0 and y == 0:
                total = matrice[0][0]
            else:
                if x > 0:
                    tt1 = c(x-1,y)
                else:
                    tt1 = 0
                if y > 0:
                    tt2 = c(x,y-1)
                else:
                    tt2 = 0
                total = max(tt1,tt2) + matrice[y][x]
            cache[y][x] = total
            return total
     
        
    matrice = []
    cache = [ [" " for i in range(n)] for a in range(2) ] 
    for i in range(2):
        matrice.append( [ int(i) for i in input().split() ] )
     
    print( c(n-1,1) )