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

Fixed submission:
from collections import deque

h, w = map(int, input().split())
C = list(map(int, input().split()))
C = tuple([C[0]-1, C[1]-1])
D = tuple(map(int, input().split()))
D = tuple([D[0]-1, D[1]-1])
maze = [list(input()) for _ in range(h)]

visit = [[False]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maze[i][j] == "#":
            visit[i][j] = True

DQ = deque([C])
DQ_warp = deque([])

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

ans = 0

while DQ or DQ_warp:
    while DQ:
        now = DQ.popleft()
        if now == D:
            print(ans)
            exit()
        x, y = now[0], now[1]
        if visit[x][y]:
            continue
        visit[x][y] = True
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0<=nx<=h-1 and 0<=ny<=w-1 and visit[nx][ny]==False:
                DQ.append(tuple([nx, ny]))

        for i in range(-2, 3):
            for j in range(-2, 3):
                if i == j == 0: continue
                nx = x + i
                ny = y + j
                if 0<=nx<=h-1 and 0<=ny<=w-1 and visit[nx][ny]==False:
                    DQ_warp.append(tuple([nx, ny]))

    if DQ_warp:
        DQ = DQ_warp.copy()
        DQ_warp = deque([])
        ans += 1

print(-1)

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

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int. input().split())
Ch, Cw, Dh, Dw = Ch-1, Cw-1, Dh-1, Dw-1

maze = [input() for _ in range(H)]
visit = [[-1] * W for _ in range(H)]
visit[Ch][Cw] = 0

DQ = deque([[Ch, Cw]])
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

while DQ:
  px, py = DQ.popleft()
  if px==Dh and py==Dw:
    print(visit[px][py])
    exit()
  
  for i in range(4):
    nx = px + dx[i]
    ny = py + dy[i]
    if 0<=nx<=H-1 and 0<=ny<=C-1 and maze[nx][ny]=="." and  (visit[nx][ny]>visit[px][py] or visit[nx][ny]==-1):
      visit[nx][ny] = visit[px][py]
      DQ.append([nx, ny])
    
  for i in range(-2, 3):
    for j in range(-2, 3):
      if i==j==0:
        continue
      nx = px + i
      ny = py + j
      if 0<=nx<=H-1 and 0<=ny<=C-1 and maze[nx][ny]=="." and visit[nx][ny]==-1:
        visit[nx][ny] = visit[px][py] + 1
        DQ.append([nx, ny])

print(-1)
Problem p02585 (python)

Fixed submission:
from itertools import accumulate

n, k = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [p - 1 for p in P]

check = [False] * n
loops = []

for i in range(n):
    if check[i]:
        continue
    check[i] = True
    next = P[i]
    tmp = [i]
    while next != i:
        check[next] = True
        tmp.append(next)
        next = P[next]
    loops.append(tmp)

ans = int(-1e9)

for loop in loops:

    num = len(loop)
    div = k // num
    r = k % num
    if r == 0:
        r = num
        div -= 1
    L = [C[p] for p in loop]
    ans_tmp = int(-1e9)
    sumL = sum(L)
    by_loop = max(sumL, 0) * div
    if k > num and sumL <= 0:
        r = num
    L += L[:r]
    ACC = [0] + list(accumulate(L))

    for i in range(num):
        for j in range(i + 1, i + r + 1):
            ans_tmp = max(ans_tmp, ACC[j] - ACC[i] + by_loop)

    ans = max(ans, ans_tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
ans = 0

for loop in loops:

    num = len(loop)
    div = k // num
    r = k % num
    if r == 0:
        r = num
        div -= 1
    L = [C[p] for p in loop]
    ans_tmp = -1e9
    sumL = sum(L)
    by_loop = max(sumL, 0) * div
    if k > num and sumL <= 0:
        r = num
    L += L[:r]
    ACC = [0] + list(accumulate(L))

    for i in range(num):
        for j in range(i + 1, i + r + 1):
            ans_tmp = max(ans_tmp, ACC[j] - ACC[i] + by_loop)

    ans = max(ans, ans_tmp)
print(ans)
Problem p02586 (python)

Fixed submission:
import sys

R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            here = dp[k][i][j]
            # 次の行に移動する場合
            if i + 1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                # 移動先のアイテムを取る場合
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
            # 次の列に移動する場合
            if j + 1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from numba import njit

R, C, K = map(int, input().split())
item = [[0]*C for _ in range(R)]
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r-1][c-1] = v

@njit
def solve(R, C, K, item):
    DP = [[[0, 0, 0, 0] for _ in range(C)] for _ in range(R)]

    DP[0][0][1] = item[0][0]

    for i in range(R):
        for j in range(C):
            for k in range(4):
                if i > 0:  # 前の行から
                    DP[i][j][0] = max(DP[i][j][0], max(DP[i-1][j]))  # 取らない
                    DP[i][j][1] = max(DP[i][j][1], max(DP[i-1][j])+item[i][j])  # 取る

                if j > 0:  # 前の列から
                    DP[i][j][k] = max(DP[i][j][k], DP[i][j-1][k])  # 取らない
                    if k >= 1:
                        DP[i][j][k] = max(DP[i][j][k], DP[i][j-1][k-1]+item[i][j])  # 取る

    print(max(DP[R-1][C-1]))

solve(R, C, K, item)

Buggy submission (verdict: Runtime Error):
import sys

R, C, K = map(int, input().split())
item = [[0]*C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, sys.stdin.readlines().split())
    item[r-1][c-1] = v

DP = [[[0, 0, 0, 0] for _ in range(C)] for _ in range(R)]

DP[0][0][1] = item[0][0]

for i in range(R):
    for j in range(C):
        for k in range(4):
            if i > 0:  # 前の行から
                DP[i][j][0] = max(DP[i][j][0], max(DP[i-1][j]))  # 取らない
                DP[i][j][1] = max(DP[i][j][1], max(DP[i-1][j])+item[i][j])  # 取る

            if j > 0:  # 前の列から
                DP[i][j][k] = max(DP[i][j][k], DP[i][j-1][k])  # 取らない
                if k >= 1:
                    DP[i][j][k] = max(DP[i][j][k], DP[i][j-1][k-1]+item[i][j])  # 取る

print(max(DP[R-1][C-1]))
Problem p02612 (python)

Fixed submission:
n = int(input())

i = 0
while i*1000<n:
    i += 1

print((i)*1000-n)

Buggy submission (verdict: Runtime Error):
v
Problem p02647 (python)

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

for i in range(min(50, k)):
    DP = [0] * (n+1)
    for j in range(n):
        light = A[j]
        DP[max(0, j-light)] += 1
        DP[min(n, j+light+1)] -= 1

    for j in range(1, n):
        DP[j] += DP[j-1]

    A = DP[:-1]

print(*A)

Buggy submission (verdict: Runtime Error):
for i in range(min(k, 50)):
    l = [0] * n
    for j in range(n):
        for k in range(max(0, j-a[j]), min(n, j+a[j]+1)):
            l[k] += 1

    a = l[:]

    if min(a) == n:
        break

a = list(map(str, a))
print(" ".join(a))
Problem p02684 (python)

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

town = 0
cnt = 0

# memo = []
# visited = [False] * n
# visited[0] = -1

# start = 0
# loop = 10**8
# start_cnt = 0
# for i in range(n*2):
#     town = A[town]
#     memo.append(town)
#     if visited[town] != False:
#         start_cnt = i + 1
#         loop = i - visited[town]
#         break
#     else:
#         visited[town] = i
#
# for i in range((k-start_cnt)%loop):
#     town = A[town]
#
# print(town+1)

visited = [False] * n
visited[0] = 0

for i in range(n):
    town = A[town]
    if visited[town]:
        good_town = town
        break
    visited[town] = i+1

town = good_town

for i in range(n):
    town = A[town]
    if town == good_town:
        loop = i + 1

if k >= visited[good_town]:
    k = ((k-visited[good_town])%loop)+visited[good_town]


town = 0
for i in range(k):
    town = A[town]
print(town+1)

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

town = 0
cnt = 0

memo = []
visited = [False] * n
visited[0] = -1

start = 0
for i in range(min(n, k)):
    town = A[town]
    memo.append(town)
    if visited[town] != False:
        start_cnt = i + 1
        loop = i - visited[town]
        break
    else:
        visited[town] = i

for i in range((k-start_cnt)%loop):
    town = A[town]

print(town+1)
Problem p02848 (python)

Fixed submission:
n=int(input())
s=input()

l=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

ans=""

for a in s:
  index = l.index(a)
  index=(index+n)%26
  ans += l[index]

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()

l=["A","B","C","D","E","F","G","H","I","J","K","L","M","","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

ans=""

for a in s:
  index = l.index(a)
  index=(index+n)%26
  ans += l[index]

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()

l=["A","B","C","D","E","F","G","H","I","J","K","L","M","L","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

ans=""

for a in s:
  index = l.index(a)
  index=(index+n)%26
  ans += l[index]

print(ans)
Problem p02900 (python)

Fixed submission:
import fractions

a, b = map(int, input().split())

ans = 0
g = fractions.gcd(a, b)

i = 2
table = []

while i * i <= g:
    while g % i == 0:
        g //= i
        table.append(i)
    i += 1
if g > 1:
    table.append(g)

print(len(set(table)) + 1)

Buggy submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())

ans = 0
g = math.gcd(a, b)

i = 2
table = []

while i * i <= g:
    while g % i == 0:
        g //= i
        table.append(i)
    i += 1
if g > 1:
    table.append(g)

print(len(set(table)) + 1)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
tree = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    tree[a].append(b)
    tree[b].append(a)

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
tree = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    tree[a].append(b)
    tree[b].append(a)

ans = [0 for _ in range(n)]

for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

checked = [False] * n
checked[0] = True


def function(now, count):
    ans[now] += count
    for i in tree[now]:
        if checked[i] == False:
            checked[i] = True
            function(i, ans[now])

function(0, 0)

for a in ans:
    print(a)

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

root = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    root[a-1].append(b-1)
# print(root)

ans = [0 for _ in range(n)]
def f(r, y):
    for j in root[r]:
        ans[j] += y
        # print(ans)
        s = j
        f(s, y)

for i in range(q):
    p, x = map(int, input().split())
    ans[p-1] += x
    # print(ans)
    f(p-1, x)

ans = map(str, ans)
print(" ".join(ans))
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())

if r-l>2019:
    print(0)
    exit()

numbers = list(range(l, r+1))


amari = list(set([x%2019 for x in numbers]))
#print(amari)


cnt = 2019
for i in range(len(amari)):
    for j in range(len(amari)):
        if i == j:
            continue
        if amari[i]*amari[j]%2019 < cnt:
            cnt = amari[i]*amari[j]%2019


print(cnt)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())

numbers = list(range(l, r+1))

if r-l>2019:
    print(0)
    exit()


amari = list(set([x%2019 for x in numbers]))


cnt = 2019
for i in range(len(amari)):
    for j in range(len(amari)):
        if i == j:
            continue
        if amari[i]*amari[j]%2019 < cnt:
            cnt = amari[i]*amari[j]%2019


print(cnt)

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split())

numbers = list(range(l, r+1))

amari = list(set([x%2019 for x in numbers]))

mods = []
for i in range(len(amari)):
    for j in range(len(amari)):
        if i == j:
            continue
        mods.append((amari[i]*amari[j]%2019))

print(min(mods))
Problem p02995 (python)

Fixed submission:
import fractions

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

def func(n, p, q):
    return n - (n//p + n//q - n//lcm(p, q))

a, b, c, d = map(int,input().split())

print(func(b, c, d) - func(a-1, c, d))

Buggy submission (verdict: Runtime Error):
import math

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

def func(n, p, q):
    return n - (n//p + n//q - n//lcm(p, q))

a, b, c, d = map(int,input().split())

print(func(b, c, d) - func(a-1, c, d))

Buggy submission (verdict: Runtime Error):
import math

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

def func(n, p, q):
    return n - (n//p + n//q - n//lcm(p, q))

a, b, c, d = map(int,input().split())

print(func(b, c, d) - func(a-1, c, d))
Problem p03044 (python)

Fixed submission:
from collections import deque

n = int(input())

distance = [-1] * n

edge = [dict() for _ in range(n)]

for _ in range(n-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    edge[u][v] = w
    edge[v][u] = w

D = deque([0])
distance[0] = 0

while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + edge[now][i]) % 2
            D.append(i)

for i in distance:
    print(i)

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

n = int(input())

distance = [-1] * n

length = [[0] * n for _ in range(n)]
edge = [[] for _ in range(n)]


for _ in range(n-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    edge[u].append(v)
    edge[v].append(u)
    length[u][v] = w
    length[v][u] = w

D = deque([0])
distance[0] = 0

while D:
    now = D.popleft()
    for i in edge[now]:
        if distance[i] == -1:
            distance[i] = (distance[now] + length[now][i]) % 2
            D.append(i)

for i in distance:
    print(i)
Problem p03061 (python)

Fixed submission:
import fractions

n = int(input())
a = list(map(int, input().split()))
ans = 0

l_gcd = [0]
for i in range(n):
    l_gcd.append(fractions.gcd(l_gcd[-1], a[i]))
# print(l_gcd)

r_gcd = [0]
for i in range(n):
    r_gcd.append(fractions.gcd(r_gcd[-1], a[-(i+1)]))
r_gcd.reverse()
# print(r_gcd)

for i in range(n):
    ans = max(ans, fractions.gcd(l_gcd[i], r_gcd[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math  # fractions

n = int(input())
a = list(map(int, input().split()))
ans = 0

l_gcd = [0]
for i in range(n):
    l_gcd.append(math.gcd(l_gcd[-1], a[i]))
# print(l_gcd)

r_gcd = [0]
for i in range(n):
    r_gcd.append(math.gcd(r_gcd[-1], a[-(i+1)]))
r_gcd.reverse()
# print(r_gcd)

for i in range(n):
    ans = max(ans, math.gcd(l_gcd[i], r_gcd[i+1]))
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = 0

for i in range(n):
    b = a[:i]+a[i+1:]
    ans = max(reduce(math.gcd, b), ans)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
ans = reduce(math.gcd, a)

for i in range(n):
    b = a[:i]+a[i+1:]
    ans = max(reduce(math.gcd, b), ans)

print(ans)
Problem p03160 (python)

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

cost0 = 0
cost1 = abs(h[1]-h[0])
if n ==1:
    print(cost0)
else:
    for i in range(n-2):
        cost0, cost1 = cost1, min(cost0+abs(h[i+2]-h[i]), cost1+abs(h[i+2]-h[i+1]))
    print(cost1)

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

def jump(x):
    if x == 1:
        return 0
    elif x == 2:
        return abs(h[1]-h[0])
    return min(jump(x-2)+abs(h[x-1]-h[x-3]), jump(x-1)+abs(h[x-1]-h[x-2]))

print(jump(n))
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10000)

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

root = [[] for _ in range(n)]

for i in range(m):
    x, y = map(int, input().split())
    root[x-1].append(y-1)

memo = ["empty" for _ in range(n)]

def dp(x):
    if memo[x] == "empty":
        res = 0
        for i in root[x]:
            res = max(res, dp(i)+1)
        memo[x] = res

    return memo[x]

for j in range(n):
    dp(j)

print(max(memo))

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

root = [[] for _ in range(n)]

for i in range(m):
    x, y = map(int, input().split())
    root[x-1].append(y-1)

memo = ["empty" for _ in range(n)]

def dp(x):
    if memo[x] == "empty":
        res = 0
        for i in root[x]:
            res = max(res, dp(i)+1)
        memo[x] = res

    return memo[x]

for j in range(n):
    dp(j)

print(max(memo))
Problem p03244 (python)

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

l0 = l[::2]
l1 = l[1::2]

l0.sort()
l1.sort()

# print(l0)
# print(l1)

memo0 = [[1, l0[0]]]
memo1 = [[1, l1[0]]]
for i in range(1, n//2):
    if memo0[-1][1] == l0[i]:
        memo0[-1][0] += 1
    else:
        memo0.append([1, l0[i]])

    if memo1[-1][1] == l1[i]:
        memo1[-1][0] += 1
    else:
        memo1.append([1, l1[i]])

memo0.sort(reverse=True)
memo1.sort(reverse=True)

memo0.append([0, -1])
memo1.append([0, -1])

# print(memo0)
# print(memo1)

if memo0[0][1]!=memo1[0][1]:
    print(n-memo0[0][0]-memo1[0][0])
else:
    ans1 = n- memo0[0][0]-memo1[1][0]
    ans2 = n- memo0[1][0]-memo1[0][0]
    print(min(ans1, ans2))

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

l0 = []
l1 = []
for i in range(n):
    if i%2==0:
        l0.append(l[i])
    else:
        l1.append((l[i]))

l0.sort()
l1.sort()

# print(l0)
# print(l1)

memo0 = [[1, l0[0]]]
memo1 = [[1, l1[0]]]
for i in range(1, n//2):
    if memo0[-1][1] == l0[i]:
        memo0[-1][0] += 1
    else:
        memo0.append([1, l0[i]])

    if memo1[-1][1] == l1[i]:
        memo1[-1][0] += 1
    else:
        memo1.append([1, l1[i]])

memo0.sort(reverse=True)
memo1.sort(reverse=True)

# print(memo0)
# print(memo1)

if memo0[0][1]!=memo1[0][1]:
    print(n-memo0[0][0]-memo1[0][0])
elif len(memo0)==1 and len(memo1)==1:
    print(n//2)
elif len(memo0)==1:
    print(n-memo0[0][0]-memo1[1][0])
elif len(memo1)==1:
    print(n-memo1[1][0]-memo1[0][0])
else:
    print(n-max(memo0[0][0]+memo1[1][0], memo1[1][0]+memo1[0][0])/0)
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

cnt = 0
while cnt<len(s) and s[cnt]=="1":
    cnt += 1

if cnt == 0:
    print(s[0])
elif cnt >= k:
    print(1)
else:
    print(s[cnt])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

cnt = 0
while s[cnt]=="1":
    cnt += 1
    
if cnt == 0:
    print(s[0])
elif cnt >= k:
    print(1)
else:
    print(s[cnt])
Problem p03434 (python)

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

L.sort(reverse=True)
print(sum(L[0::2]) - sum(L[1::2]))

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

L.sort(reverse=Ture)
print(sum(L[0::2]) - sum(L[1::2]))
Problem p02548 (python)

Fixed submission:

n=int(input())
#d = [list(map(int,input().split())) for _ in range(s)]

def p(val):
    print(val)

count = 0

#cは1以上で、問題文からN-1 a*b <=N-1のものをもとめる
#aを1からふやしてく、cはaとbが決まれば自動歴に決まるので、
for i in range(1,n):
    count +=(n-1)//i

    

        
p(count)

Buggy submission (verdict: Runtime Error):

n=int(input())
#d = [list(map(int,input().split())) for _ in range(s)]

def p(val):
    print(val)

count = 0

#cは1以上で、問題文からN-1 a*b <=N-1のものをもとめる
#aを1からふやしてく、cはaとbが決まれば自動歴に決まるので、
for i in range(1,n):
    

    

        
p(count)
Problem p02658 (python)

Fixed submission:
n=int(input())
mul=1
limit=1000000000000000000
x=input().split()
for i in range (n):
    p=int(x[i])
    if(p==0):
        mul=0
        break
if(mul==0):
    print(mul)
else:
    for i in range (n):
        p=int(x[i])
        mul*=p
        if(mul>limit):
            break
    if(mul>limit):
      print(-1)
    else:
      print(mul)

Buggy submission (verdict: Runtime Error):
n=int(input())
mul=1
limit=1000000000000000000
for i in range (n):
  x=int(input())
  mul*=x
if(mul>limit):
  print(-1)
else:
  print(mul)
Problem p02684 (python)

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

count = 0
i = 1
position = 1
position_list = [1]
position_history = [0] * N
start_loop = 0
def last():
  k = (K - start_loop) % (count - start_loop)
  print(position_list[start_loop+k])

while i > 0:
  position = A[position-1]
  position_history[position-1] += 1
  count += 1
  if count == K:
    print(position)
    break
  elif position_history[position-1] > 1:
    start_loop = position_list.index(position)
    position_list.append(position)
    last()
    break
  else:
    position_list.append(position)

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

count = 0
i = 1
position = 1
position_list = [1]
position_history = [0] * N
start_loop = 0
def last():
  k = (K - start_loop) % (count - start_loop)
  print(position_list[start_loop+k])

while i > 0:
  position = A[position-1]
  position_history[position-1] += 1
  count += 1
  if count == K:
    print(position)
  elif position_history[position-1] > 1:
    start_loop = position_list.index(position)
    position_list.append(position)
    last()
    break
  else:
    position_list.append(position)
Problem p02924 (python)

Fixed submission:
N = int(input())
    
print((N - 1) * N // 2)

Buggy submission (verdict: Runtime Error):
N = int(input())

N_list = list(range(1, N+1, 1))
N_lista = []
for i in range(N):
  if i != (N - 1):
    N_lista.append(N_list[i+1])
  else:
    N_lista.append(N_list[0])

mod_sum = 0

for i in range(N):
  mod_sum += (i + 1) % N_lista[i]
  
print(mod_sum)
Problem p02945 (python)

Fixed submission:
A, B = map(int,input().split())
print(max([A+B,A-B,A*B]))

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split())
print(max[A + B, A - B, A * B])
Problem p02983 (python)

Fixed submission:
import math

L,R = list(map(int,input().split()))

if (R-L) >= 2019:
  print(0)
else:
  l = L % 2019
  r = l + (R - L)
  if r >= 2019:
    print(0)
  else:
    all_e = []
    for i in range(r-l+1):
      for j in range(r-l-i):
        all_e.append((l+i)*(l+i+j+1))
    for i in range(len(all_e)):
      all_e[i] = all_e[i] % 2019
    print(min(all_e))

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

#define ll long long
            
int main() {
    int L, R;
    cin >> L >> R;
  
    int range = R - L;
    vector<int> mod;
  
    if (range >= 2019) {
        cout << 0 << endl;
    } else {
        for (int i = 0; i < (range + 1); i++) {
            for (int j = 1; j <= (range - i); j++) {
                int ij = (L + i) * (L + i + j);
                mod.push_back(ij % 2019);
            }
        }
        vector<int>::iterator iter = min_element(mod.begin(), mod.end());
        cout << *iter << endl;
    }
  
    return 0;
}