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

Fixed submission:
import math
mod = 10**9 + 7
n, m = map(int, input().split())
ans = math.factorial(n)*math.factorial(m)
if abs(n-m) > 1:
    ans = 0
elif abs(n-m) == 0:
    ans *= 2
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import math
mod = 10e+9 + 7
n, m = map(int, input().split())
ans = math.factorial(n)*math.factorial(m)
if abs(n-m) > 1:
    ans = 0
elif abs(n-m) == 0:
    ans *= 2
print(ans % mod)

Buggy submission (verdict: Runtime Error):
import math
mod = 10e+9 + 7
n, m = map(int, input().split())
if abs(n-m) > 1:
    ans = 0
elif abs(n-m) == 1:
    ans = (math.factorial(n) % mod)*(math.factorial(m) % mod)
else:
    ans = (math.factorial(n) % mod)*(math.factorial(m) % mod)*2
print(int(ans % mod))
Problem p02678 (python)

Fixed submission:
from collections import deque
 
n,m = list(map(int, input().split()))
put = [1]*(n+1)
 
ab = [[] for i in range(n+1)]
for i in range(m):
	a,b = map(int, input().split())
	ab[a].append(b)
	ab[b].append(a)

q = deque([1])
flg = [-1]*n
flg[0] = 0

while q:
	item = q.popleft()
	for i in ab[item]:
		if put[i]:
			flg[i-1]=item
			q.append(i)
			put[i]=0
 
if -1 in flg:
	print("No")
	exit()
 
print("Yes")
for i in range(1,len(flg)):
	print(flg[i])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
tr = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    tr[a-1].append(b)
    tr[b-1].append(a)
if not tr[0]:
    print('No')
else:
    mark = [10**7]*n
    mark[0] = -1
    cnt = 0
    i=0
    from collections import deque
    que = deque()
    def mk(mark,que,cnt):
        i = que.popleft()-1
        for j in range(len(tr[i])):
            if tr[i][j]!=1:
                mark[tr[i][j]-1] = min(i+1,mark[tr[i][j]-1])
                cnt+=1
                que.append(tr[i][j])
                if cnt == n:
                    return mark
            else:
                continue
        else:
            mark = mk(mark,que,cnt)
            return mark
    que.append(1)
    mark=mk(mark,que,cnt)
    if 10**7 in mark:
        print('No')
    else:
        print('Yes')
        for i in range(1,n):
            print(mark[i])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
tr = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    tr[a-1].append(b)
    tr[b-1].append(a)
if not tr[0]:
    print('No')
else:
    mark = [10**7]*n
    mark[0] = -1
    cnt = 0
    i=0
    def mk(mark,i,cnt):
        for j in range(len(tr[i])):
            if tr[i][j]!=1:
                mark[tr[i][j]-1] = min(i+1,mark[tr[i][j]-1])
                cnt+=1
                if cnt == n-1:
                    return mark
            else:
                continue
        else:
            for j in range(len(tr[i])):
                mark = mk(mark,tr[i][j]-1,cnt)
            else:
                return mark
    mark=mk(mark,0,cnt)
    if 10**7 in mark:
        print('No')
    else:
        print('Yes')
        for i in range(1,n):
            print(mark[i])

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
tr = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    tr[a-1].append(b)
    tr[b-1].append(a)
if not tr[0]:
    print('No')
    exit()
else:
    mark = [10**7]*n
    mark[0] = -1
    cnt = 0
    i=0
    def mk(mark,i,cnt):
        for j in range(len(tr[i])):
            if tr[i][j]!=1:
                mark[tr[i][j]-1] = min(i+1,mark[tr[i][j]-1])
                cnt+=1
                if cnt == n-1:
                    return mark
            else:
                continue
        else:
            for j in range(len(tr[i])):
                mark = mk(mark,tr[i][j]-1,cnt)
            else:
                return mark
    mark=mk(mark,0,cnt)
    if 10**7 in mark:
        print('No')
    else:
        print('Yes')
        for i in range(1,n):
            print(mark[i])
Problem p02684 (python)

Fixed submission:
n,k=map(int,input().split())
a = list(map(int,input().split()))
visit = []
visit = [0]*n
pos=0
move=[]
roop=[]
while visit[pos]!=2:
    if visit[pos]==0:
        move.append(pos)
    else:
        roop.append(pos)
    visit[pos]+=1
    pos = a[pos]-1
if len(move)>k:
    print(move[k]+1)
else:
    mod = (k-(len(move)-len(roop)))%len(roop)
    print(roop[mod]+1)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a = list(map(int,input().split()))
rep = []
rep.append(1)
onf = 0
def repeat(i,rep):
    if a[i] not in rep:
        rep.append(a[i])
        repeat(a[i]-1,rep)
    else:
        rep.append(a[i])
        return 1
onf=repeat(0,rep)
if onf==0:
    print(rep)
else:
    lr = len(rep)
    for i in range(lr):
        if rep[i]==rep[lr-1]:
            start=i
            rep2 = rep[i:lr-1]
            break
    mod = len(rep2)
    modL = [i%mod for i in range(start,start+mod)]
    resM = k%mod
    for i in range(mod):
        if resM == modL[i]:
            print(rep2[i])
Problem p02812 (python)

Fixed submission:
N = int(input())
S = list(input())
cnt =0
for i in range(N-2):
  if S[i] =="A":
    if S[i+1] =="B":
      if S[i+2] == "C":
        cnt +=1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(input())
cnt =0
for i in range(n-2):
  if S[i] =="A":
    if S[i+1] =="B":
      if S[i+2] == "C":
        cnt +=1
print(cnt)
Problem p02818 (python)

Fixed submission:
A,B,K = input().split(" ")
A = int(A)
B = int(B)
K = int(K)

if K>=A:
  K -=A
  A = 0
  if K>=B:
    B = 0
  else:
    B -=K
else:
  A -=K
print(A,B)

Buggy submission (verdict: Runtime Error):
A,B,K=input().split(" ")
if K<=A:
  A -= K
  print(str(A)+" "+str(B))
else:
  A = 0
  B -= K - A
  print(str(A)+" "+str(B))

Buggy submission (verdict: Runtime Error):
A,B,K=input().split(" ")
if K<=A:
  A -= K
  print(str(A),str(B))
else:
  A = 0
  B -= K - A
  print(str(A),str(B))
Problem p02823 (python)

Fixed submission:
n,a,b = map(int,input().split())
diff = abs(a-b)
 
if diff%2==0:
  print(diff//2)
else :
  print(min(a - 1, n - b) + 1 + diff // 2)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
diff = abs(a-b)

if diff%2==0:
  print(diff//2)
else :
  print(min(A - 1, N - B) + 1 + diff // 2)
Problem p02882 (python)

Fixed submission:
import math
import sys
a,b,x = map(int,input().split())
if a*a*b == x:
    print(0)
    sys.exit()
tan = a**3/(2*(a**2*b-x))
if tan<=(a/b):
    tan = 2*x/(b**2*a)
rad = math.atan(tan)
deg= 90- (rad * 180/math.pi)
print(deg)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
tan = a**3/(2*(a**2*b-x))
if tan<=(a/b):
    tan = 2*x/(b**2*a)
rad = math.atan(tan)
deg= 90- (rad * 180/math.pi)
print(deg)

Buggy submission (verdict: Runtime Error):
import math
a,b,x = map(int,input().split())
tan = a**3/(2*(a**2*b-x))
if tan<=(a/b):
    tan = 2*x/(b**2*a)
rad = math.atan(tan)
deg= 90-math.degrees(rad)
print(deg)
Problem p02928 (python)

Fixed submission:
n,k=map(int,input().split())
A = list(map(int,input().split()))
lA = len(A)
mod=10**9+7
cnt1=0
for i in range(lA):
    for j in range(i+1,lA):
        if A[i] > A[j]:
            cnt1+=1
cnt2=0
for i in range(lA):
    for j in range(lA):
        if A[i] > A[j]:
            cnt2+=1
print((cnt1*k+cnt2*(k*(k-1)//2))%mod)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A = list(map(int,input().split()))
B = A*k
lA = len(A)
lB = len(B)
mod=10**9+7
cnt1=0
for i in range(lA):
    for j in range(i+1,lA):
        if A[i] > A[j]:
            cnt1+=1
cnt2=0
for i in range(lA):
    for j in range(lA):
        if A[i] > A[j]:
            cnt2+=1
print((cnt1*k+cnt2*(k*(k-1)//2))%mod)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
a = list(map(int,input().split()))
B = a*k
lB = len(B)
mod=10**9+7
cnt=0
for i in range(lB):
    for j in range(i+1,lB):
        if B[i] > B[j]:
            cnt+=1
print(cnt%mod)
Problem p02936 (python)

Fixed submission:
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
point = [0]*n
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for _ in range(q):
    a,b = map(int,input().split())
    a = a -1
    point[a]+=b
stack = [];
stack.append(0)
visited = [False]*n
while stack:
    x = stack.pop()
    visited[x] = True
    for y in graph[x]:
        if visited[y] == False:
            point[y] += point[x]
            stack.append(y)
print(*point)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,input().split())
graph = [[] for _ in range(n)]
point = [0]*n
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for _ in range(q):
    a,b = map(int,input().split())
    a = a -1
    point[a]+=b
def dfs(now, prev = -1):
    for next in graph[now]:
        if next == prev:
            continue
        point[next] += point[now]
        dfs(next, now)
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
n,q = map(int,input().split())
graph = [[] for _ in range(n)]
point = [0]*n
for i in range(n-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
for _ in range(q):
    a,b = map(int,input().split())
    a = a -1
    point[a]+=b
def dfs(now, prev = -1):
    for next in graph[now]:
        if next == prev:
            continue
        point[next] += point[now]
        dfs(next, now)
dfs(0)
print(*point)
Problem p02995 (python)

Fixed submission:
import fractions
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//fractions.gcd(x,y)
    cnt -= n//lcm
    return n - cnt

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

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//math.gcd(x,y)
    cnt -= int(n//lcm)
    return n - cnt

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

Buggy submission (verdict: Runtime Error):
import math
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//math.gcd(x,y)
    cnt -= n//lcm
    return n - cnt

print(calc(b,c,d)-calc(a-1,c,d))
Problem p03262 (python)

Fixed submission:
import numpy as np
import fractions
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = np.diff(a)
if n>1:
    gcd = fractions.gcd(d[0],d[1])
    if n>3:
        for i in range(2,n-1):
            gcd = fractions.gcd(gcd,d[i])
    print(gcd)
else:
    print(d[0])

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
d = np.diff(a)
if n>1:
    gcd = math.gcd(d[0],d[1])
    if n>3:
        for i in range(2,n-1):
            gcd = math.gcd(gcd,d[i])
    print(gcd)
else:
    print(d[0])
Problem p03419 (python)

Fixed submission:
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(n*m-2)
else:
    print((m-2)*(n-2))

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or M==1:
    print(n*m-2)
else:
    print((m-2)*(n-2))
Problem p03830 (python)

Fixed submission:
import math
mod = 10**9+7
n = int(input())
n = math.factorial(n)
ans = 1
i = 2
while i*i<=n:
    cnt = 1
    while n % i == 0:
        cnt += 1
        n //= i
    i = i + 1
    ans = ans*cnt

if n != 1:
    ans = ans*2
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import sympy
import math
mod = 10**9+7
n = int(read())
cnt = sympy.divisor_count(math.factorial(n))
print(cnt%mod)
Problem p02918 (python)

Fixed submission:
# -*- coding: utf-8 -*-
from collections import deque
n, k = map(int, input().split())
s = input()

unhapiness = 0
div = deque([])
left = "R"
right = "L"
cntr = 0
s = s + "L"
for si in s:
    right = si
    if (left == "R") & (right == "L"):
        if 0 < cntr < n:
            unhapiness += 2
            div.append(cntr)
        else:
            unhapiness += 1
            div.appendleft(cntr)

    left = si
    cntr +=1

for i in range(k):
    p = div.pop()
    if 0 < p < n:
        unhapiness -= 2
    else:
        unhapiness -= 1
    if len(div) < 1:
        unhapiness += 1
        break
print(n-unhapiness)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
from collections import deque
n, k = map(int, input().split())
s = input()

unhapiness = 0
div = deque([])
conv = deque([])
left = "R"
right = "L"
cntr = 0
s = s + "L"
for si in s:
    right = si
    if (left == "R") & (right == "L"):
        if 0 < cntr < n:
            unhapiness += 2
            div.append(cntr)
        else:
            unhapiness += 1
            div.appendleft(cntr)
    if (left == "L") & (right == "R"):
        conv.appendleft(cntr)

    left = si
    cntr +=1

for i in range(k):
    p = div.pop()
    conv.pop()
    if 0 < p < n:
        unhapiness -= 2
    else:
        unhapiness -= 1

print(n-unhapiness)
Problem p03160 (python)

Fixed submission:
# -*- coding: utf-8 -*-
INF = 1000000000
n = int(input())
h = list(map(int, input().split()))
dp = [INF]*n
dp[0] = 0

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

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
INF = 1000000
n = int(input())
h = list(map(int, input().split()))
dp = [INF]*n


def rec(i):
    # print("i = " + str(i))
    if dp[i] < INF:
        return dp[i]
    if i == 0:
        return 0
    res = INF
    # print("before: " + str(res))
    res = min(res, rec(i-1) + abs(h[i] - h[i-1]))
    # print("after: " + str(res))
    if i > 1:
        res = min(res, rec(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return dp[i]


print(rec(n-1))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
INF = 1000000
n = int(input())
h = list(map(int, input().split()))
dp = [INF]*n

def chmin(a, b):
    if a > b:
        return b
    else:
        return a


def chmax(a, b):
    if a < b:
        return b
    else:
        return a


def rec(i):
    if dp[i] < INF:
        return dp[i]
    if i == 0:
        return 0
    res = INF
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    if i > 1:
        res = chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return dp[i]

print(rec(n-1))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
INF = 10000
n = int(input())
h = list(map(int, input().split()))
dp = [INF]*n

def chmin(a, b):
    if a > b:
        return b
    else:
        return a


def chmax(a, b):
    if a < b:
        return b
    else:
        return a


def rec(i):
    if dp[i] < INF:
        return dp[i]
    if i == 0:
        return 0
    res = INF
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    if i > 1:
        res = chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]))
    dp[i] = res
    return dp[i]

print(rec(n-1))
Problem p02684 (python)

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

history = {}
cycle = []
pos = 1
isEnd = False
for i in range(2*N):
    if pos in history:
        for j in range(len(cycle)):
            if cycle[j] == pos:
                head = cycle[:j]
                cycle = cycle[j:]
                isEnd = True
                break

    if isEnd:
        break

    history[pos] = 1
    cycle.append(pos)
    pos = As[pos-1]


#print(cycle)

if K < len(head):
    print(head[K])
else:
    mod = (K-len(head)) % len(cycle)
    print(cycle[mod])

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

history = {}
cycle = []
pos = 1
isEnd = False
for i in range(2*N):
    if pos in history:
        for j in range(len(cycle)):
            if cycle[j] == pos:
                head = cycle[:j]
                cycle = cycle[j:]
                isEnd = True
                break

    if isEnd:
        break

    history[pos] = 1
    cycle.append(pos)
    pos = As[pos-1]


#print(cycle)

if K <= len(head):
    print(head[K])
else:
    mod = (K-len(head)) % len(cycle)
    print(cycle[mod])
Problem p03436 (python)

Fixed submission:
H, W = map(int, input().split())

Ss = []
white_count = 0
for i in range(H):
    s = list(input())
    for masu in s:
        if masu == '.':
            white_count += 1
    Ss.append(s)

# print('white_count', white_count)


def search():
    global Ss_hosu
    #global min_hosu
    Ss_hosu[0][0] = 1
    que = [[0, 0]]
    while len(que) > 0:
        x, y = que.pop(0)
        my_value = Ss_hosu[y][x]
        for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            if 0 <= x + dx <= W - 1 and 0 <= y + dy <= H - 1:
                if Ss[y + dy][x + dx] == '.' and Ss_hosu[y + dy][x + dx] is None:
                    Ss_hosu[y+dy][x+dx] = my_value + 1
                    que.append([x + dx, y + dy])

  
Ss_hosu = [[None for _ in range(W)] for _ in range(H)]
search()
min_hosu = Ss_hosu[H-1][W-1]

# for s in Ss_hosu:
#     print(s)

# print('min_hosu', min_hosu)

if min_hosu is None:
    print(-1)
else:
    print(white_count - min_hosu)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())

Ss = []
white_count = 0
for i in range(H):
    s = list(input())
    for masu in s:
        if masu == '.':
            white_count += 1
    Ss.append(s)

# print('white_count', white_count)


def search():
    global Ss_hosu
    #global min_hosu
    Ss_hosu[0][0] = 1
    que = [[0, 0]]
    while len(que) > 0:
        x, y = que.pop(0)
        my_value = Ss_hosu[y][x]
        for dx, dy in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
            if 0 <= x + dx <= W - 1 and 0 <= y + dy <= H - 1:
                if Ss[y + dy][x + dx] == '.' and Ss_hosu[y + dy][x + dx] is None:
                    Ss_hosu[y+dy][x+dx] = my_value + 1
                    que.append([x + dx, y + dy])

    # Ss_hosu[y][x] = value
    # if x == W-1 and y == H-1:
    #     min_hosu = value
    # for dx, dy in [[1,0], [-1,0], [0,1], [0,-1]]:
    #     if 0 <= x+dx <= W-1 and 0 <= y+dy <= H-1:
    #         if Ss[y+dy][x+dx] == '.' and Ss_hosu[y+dy][x+dx] is None:
    #             search(x+dx, y+dy, value=value+1)


Ss_hosu = [[None for _ in range(W)] for _ in range(H)]
search()
min_hosu = Ss_hosu[H-1][W-1]

# for s in Ss_hosu:
#     print(s)

# print('min_hosu', min_hosu)

print(white_count - min_hosu)
Problem p03854 (python)

Fixed submission:
import sys

sys.setrecursionlimit(1000000)
S = input()


def start_with(i):
    if i == len(S):
        print('YES')
        sys.exit(0)

    try:
        if S[i:i+5] == 'dream':
            start_with(i+5)
        if S[i:i+7] == 'dreamer':
            start_with(i+7)
        if S[i:i+5] == 'erase':
            start_with(i+5)
        if S[i:i+6] == 'eraser':
            start_with(i+6)
        return
    except IndexError:
        return


start_with(0)
print('NO')

Buggy submission (verdict: Runtime Error):
import sys


def start_with(s):
    if s == '':
        print('YES')
        sys.exit(0)

    try:
        if s[0:5] == 'dream':
            start_with(s[5:])
        if s[0:7] == 'dreamer':
            start_with(s[7:])
        if s[0:5] == 'erase':
            start_with(s[5:])
        if s[0:6] == 'eraser':
            start_with(s[6:])
    except IndexError:
        return


S = input()
start_with(S)
print('NO')
Problem p03035 (python)

Fixed submission:
a,b=map(int,input().split())
if a>=13:
  b=b
elif a>=6:
  b=b//2
else:
  b=0
print(b)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a>=13:
elif a>=6:
  b=b//2
else:
  b=0
print(b)
Problem p03071 (python)

Fixed submission:
a,b=map(int,input().split())
if a == b:
  print(a*2)
else :
  print(2*max(a,b)-1)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(max(a,b)+max(max(a,b)-1,min(a,b))
Problem p03206 (python)

Fixed submission:
s="Christmas"
for i in range(25-int(input())):
  s += " Eve"
print(s)

Buggy submission (verdict: Runtime Error):
s="Christmas"
for i in range(25-int(input()):
  s += " Eve"
print(s)
Problem p03284 (python)

Fixed submission:
a,b=map(int,input().split())
print(int(a%b!=0))

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
print((int)a%b==0)
Problem p02684 (python)

Fixed submission:
def main():
    nums = list(map(int, input().split()))
    n, k = nums[0], nums[1]
    graph = {}
    out = list(map(int, input().split()))
    for i in range(n):
        graph[i + 1] = out[i]
    
    cycle_length = None
    visited = {}
    ans = None

    def go(x, rem):
        while rem:
            x = graph[x]
            rem -= 1
        
        nonlocal ans
        ans = x
        return x

    def dfs(i, rem):
        j = i
        while rem:
            if j in visited:
                nonlocal cycle_length
                cycle_length = visited[j] - rem
                steps = rem % cycle_length
                go(j, steps)
                return
            visited[j] = rem
            rem -= 1
            j = graph[j]

        nonlocal ans
        if not ans:
            ans = j
        return j

    dfs(1, k)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    nums = list(map(int, input().split()))
    n, k = nums[0], nums[1]
    graph = {}
    out = list(map(int, input().split()))
    for i in range(n):
        graph[i + 1] = out[i]
    
    cycle_length = None
    visited = {}
    ans = None

    def go(x, rem):
        while rem:
            x = graph[x]
            rem -= 1
        
        nonlocal ans
        ans = x
        return x

    def dfs(i, rem):
        #print("visit", i)
        nonlocal ans
        if rem == 0:
            ans = i
            return
        if i in visited:
            nonlocal cycle_length
            cycle_length = visited[i] - rem
            steps = rem % cycle_length
            ans = go(i, steps)
            return 
        visited[i] = rem
        dfs(graph[i], rem - 1)
        return

    dfs(1, k)
    print(ans)

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

Fixed submission:
import math 
h = int(input())
ans = 0
t = int(math.log2(h)+1)

for i in range(t):
  ans += 2**i
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a = []
b = []
toki = []
h, n = map(int, input().split())
for i in range(n):
  ai, bi =  map(float, input().split())
  toki.append((ai, bi))

def yeah(hp, toki):
  mp = 0
  dps = 0
  kou = 0
  for ai, bi in toki:
    t = ai
    if (hp - ai) <= 0:
      t = hp
    dps2 = float(t/bi)
    if dps <= dps2:
      dps = dps2
      mp = bi
      kou = t
  return (hp-kou, mp)
mp = 0
zan = h
while True:
  zan, mp2 = yeah(zan, toki)
  mp += mp2
  if zan <=0:
    break
print(int(mp))
Problem p02843 (python)

Fixed submission:
import math
N = input()
A = [100, 101, 102, 103, 104, 105]
if len(str(N))  <= 2:
  print(0)
  quit()
last = int(N[-2] + N[-1])
head = int(N[0:-2])
if 105 * head >= int(N):
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import math
N = input()
A = [100, 101, 102, 103, 104, 105]
if len(str(N))  < 2:
  print(0)
  quit()
last = int(N[-2] + N[-1])
head = int(N[0:-2])
if 105 * head >= int(N):
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
import math
N = input()
A = [100, 101, 102, 103, 104, 105]
if len(str(N))  < 2:
  print(0)
  quit()
last = int(N[-2] + N[-1])
head = int(N[0:-2])
if last / head <= 5:
  print(1)
else:
  print(0)
Problem p03023 (python)

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

Buggy submission (verdict: Runtime Error):
N = map(int, input())
print((N -2) * 180)
Problem p03029 (python)

Fixed submission:
A, P = map(int, input().split())
print((A * 3 + P)//2)

Buggy submission (verdict: Runtime Error):
import sys
_args = sys.argv
_A = _args[1]
_P = _args[2]

if _A > 0 :
    _P=_P+_A*3

_ANS =math.floor(_P/2)

print(_ANS)