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

Fixed submission:
import sys
N = int(input())
if N == 1:
  print('Hello World')
  sys.exit()
A = int(input())
B = int(input())
print(A+B)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
if N == 1:
  print('Hello World')
else:
  print(A+B)
Problem p03241 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
ls = []
for i in range(2, int(M**(1/2))+1):
    if M%i == 0:
        ls.append(i)
if N == 1:
    print(M)
    sys.exit()
ans = 1
for x in ls:
    if x >= N:
        ans = max(ans, M//x)
        continue
    if M//x >= N:
        ans = max(ans, x)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
import sys
N, M = map(int, input().split())
ls = []
for i in range(1, int(M**(1/2))+1):
    if M%i == 0:
        ls.append(i)
ans = []
for x in ls:
    ans.append(x)
    ans.append(M//x)
print(ans[bisect.bisect_left(ans, N)])
Problem p03261 (python)

Fixed submission:
import sys
n = int(input())
w = []
for i in range(n):
  word = input()
  if word in w:
    print('No')
    sys.exit()
  w.append(word)
cur = w[0][-1]
for x in w[1:]:
  if cur != x[0]:
    print('No')
    sys.exit()
  cur = x[-1]
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
w = []
for i in range(n):
  word = input()
  if word in w:
    print('No')
    sys.exit()
cur = w[0][-1]
for x in w[1:]:
  if cur != x[0]:
    print('No')
    sys.exit()
  cur = x[-1]
print('Yes')
Problem p03273 (python)

Fixed submission:
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(len(a)):
    s = ''
    for j in range(W):
        if j in ls:
            continue
        else:
            s += a[i][j]
    ans.append(s)
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
ｖH, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(W):
    s = ''
    for j in range(len(a)):
        if i in ls:
            continue
        else:
            s += a[j][i]
    ans.append(s)
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(s)
ls = []
for i in range(W):
    b = ''
    for j in range(len(a)):
        b += a[j][i]
    if b == '.'*len(a):
        ls.append(i)
ans = []
for i in range(W):
    s = ''
    for j in range(len(a)):
        if i in ls:
            continu
        else:
            s += a[j][i]
    ans.append(s)
print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
for i in range(H):
    s = input()
    if s != '.'*W:
        a.append(input())
ls = []
for i in range(W):
    cur = 0
    for j in range(len(a)):
        if a[j][i] == '.':
            cur += 1
    if cur == len(a):
        ls.append(i)
ans = []
for i in ls:
    for s in a:
        ans.append(s[:i] + s[i+1:])
print(*ans, sep='\n')
Problem p03281 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1, N+1):
  num = 0
  if i%2 == 1:
    for j in range(1, i+1):
      if i%j == 0:
        num += 1
    if num == 8:
      ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for num in range(1, n):
    if num%2 == 1:
        continue
    ls = []
    for i in range(num+1):
        if num%i == 0:
            ls.append(i)
    if len(ls) == 8:
        ans += 1
print(ans)
Problem p03316 (python)

Fixed submission:
N = input()
ans = 0
for i in N:
  ans += int(i)
print('Yes' if int(N)%ans == 0 else 'No')

Buggy submission (verdict: Runtime Error):
N = input()
for i in N:
  ans += int(i)
print(ans)
Problem p03323 (python)

Fixed submission:
A, B = map(int, input().split())
if max(A, B) > 8:
    print(':(')
else:
    print('Yay!')

Buggy submission (verdict: Runtime Error):
A, B = map(int input().split())
if max(A, B) > 8:
    print(':(')
else:
    print('Yay!')
Problem p03338 (python)

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

ans = 0
for i in range(1, n):
    cur = 0
    a = set(s[:i])
    b = set(s[i:])
    for A in a:
        if A in b:
            cur += 1
    ans = max(ans, cur)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input().strip()
ans= []

for i in range(1, N-1):
    a = S[:i]
    b = S[i+1:]
    for j in a:
        num = 0
        if j in b:
            num += 1
        ans.append(num)
print(max(ans))
Problem p03351 (python)

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

if abs(a-c) <= d:
    print('Yes')
elif abs(a-b) <= d and abs(b-c) <= d:
    print('Yes')
else:
    print('No')

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

if abs(a-c) <= d:
    print('Yes')
elif abs(a-b) <= d and abs()-c) <= d:
    print('Yes')
else:
    print('No')

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

if (a-c) <= d:
    print('Yes')
elif (a-b) <= d and (b-c) <= d:
    print('Yes')
else:
    print('No')
Problem p03416 (python)

Fixed submission:
A, B = map(int, input().split())
ans = 0
for x in range(A, B+1):
    if str(x) == str(x)[::-1]:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
ans = 0
for x in range(A, B+1):
    if str(x) == str(x).reverse():
        ans += 1
print(ans)
Problem p03485 (python)

Fixed submission:
import math
a, b = map(int, input().split())
x = (a+b)/2
print(math.ceil(x))

Buggy submission (verdict: Runtime Error):
import sys
s = input()
t = input()
s.sort()
t.sort()
for x, y in zip(s, t[::-1]):
    if x > y:
        print('No')
        sys.exit()
    elif x == y:
        continue
    else:
        print('Yes')
        sys.exit()
if len(s) <= len(t):
    print('Yes')
else:
    print('No')
Problem p03486 (python)

Fixed submission:
s, t = list(input()), list(input())
s.sort()
t.sort(reverse=True)
S = ''.join(s)
T = ''.join(t)
if S < T:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import sys
s = input()
t = input()
s.sort()
t.sort()
for x, y in zip(s, t[::-1]):
    if x > y:
        print('No')
        sys.exit()
    elif x == y:
        continue
    else:
        print('Yes')
        sys.exit()
if len(s) <= len(t):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s, t = input(), input()
s.sort()
t.sort(reverse=True)
if s < t:
    print('Yes')
else:
    print('No')
Problem p03543 (python)

Fixed submission:
N = input().strip()
if N[0] == N[1] == N[2] or N[1] == N[2] == N[3]:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = input()
cur = 0
for x, y in zip(N, N[1:]):
    if x == y:
        ans += 1
if cur >= 2:
    print('Yes')
else:
    print('No')
Problem p03546 (python)

Fixed submission:
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += c[A[h][w]][1]
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        uf A[h][w] != -1:
        ans += c[A[h][w]][1]
print(ans)
Problem p03583 (python)

Fixed submission:
N = int(input())
ok = False

for i in range(1, 3501):
    for j in range(1, 3501):
        if N*(i+j) < 4*i*j:
            w = 1 / (4/N - 1/i - 1/j)
            if abs(int(w)-w) < 10**-7:
                print(i, j, int(w))
                ok = True
                break
    if ok:
        break

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

for i in range(1, 3501):
    for j in range(1, 3501):
        w = (4/N - 1/i - 1/j)**-1
        if w > 0 and abs(int(w) - w) < 10**-7:
            print(i, j, int(w))
            ok = True
            break
    if ok:
        break
Problem p03623 (python)

Fixed submission:
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print('A')
else:
  print('B')

Buggy submission (verdict: Runtime Error):
x, a, b = map(int, input().split())
if abs(x-a) < abs(x-b):
  print(A)
else:
  print(B)
Problem p03625 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse=True)
d = defaultdict(int)
ls = []
for x in A:
    d[x] += 1
    if d[x] == 2:
        ls.append(x)
        if len(ls) == 2:
            break
    elif d[x] == 4:
        ls.append(x)
        break
if len(ls) == 2:
    print(ls[0]*ls[1])
else:
Problem p03636 (python)

Fixed submission:
s = input()
print(s[0]+str(len(s)-2)+s[-1])

Buggy submission (verdict: Runtime Error):
s = input()
print(s[0]+str(len(s)+s[-1]))
Problem p03720 (python)

Fixed submission:
N, M = [int(i) for i in input().strip().split()]
A=[]
for i in range(M):
    A.append(input().strip().split())
B =[]
for i in range(M):
    B.append(int(A[i][0]))
    B.append(int(A[i][1]))
for i in range(N):
    print(B.count(i+1))

Buggy submission (verdict: Runtime Error):
N, M = [int(i) for i in input().strip().split()]
A = [[int(i) for i in input().strip().split()] for j in range(M)]
B = {}
for i in range(N):
    for j in range(M):
        if A[j][0] == i+1:
            B[i] = A[j][1]
for i in range(N):
    print(len(B[i]))
Problem p03721 (python)

Fixed submission:
N, K = map(int, input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))
a.sort()
sum = 0
for i, x in enumerate(a):
    sum += x[1]
    if sum >= K:
        print(a[i][0])
        break

Buggy submission (verdict: Runtime Error):
N, K = [int(i) for i in input().split()]
a = [0]*N
b = [0]*N
for i in range(N):
    a[i], b[i] = [int(i) for i in input().split()]

c = 0
d = 0
for i in b:
    c += i
    if c >= K:
        break
    d += 1
    
A = []
for i in range(d):
    A += [a[i]]*b[i]
A.sort()
print(A[K])
Problem p03730 (python)

Fixed submission:
A, B, C = [int(i) for i in input().split()]

for i in range(B):
    if (A*i)%B == C:
        print('YES')
        break
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]

for i in range(B):
    if (A*i)%B == C:
      	print('YES')
        break
else:
  	print('NO')

Buggy submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split()]
a = 0

for i in range(1,B):
    if A*i%B == C:
      	a += 1
        print('YES')
if a != 0:
    print('NO')
Problem p03760 (python)

Fixed submission:
o = input().strip()
e = input().strip()

a = ''

if len(o)-len(e) == 0:
    for i in range(len(o)):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(len(e)):
        a += o[i]
        a += e[i]
    a += o[len(o)-1]
    print(a)

Buggy submission (verdict: Runtime Error):
o = input().strip()
e = input().strip()

a = ''

if len(o)-len(e) == 0:
    for i in range(len(o)):
        a += o[i]
        a += e[i]
    print(a)
else:
    for i in range(len(e)):
        a += o[i]
        a += e[i]
    a += o[len(o)]
    print(a)
Problem p03814 (python)

Fixed submission:
s = input().strip()

a = []
b = []

for i in range(len(s)):
    if s[i] == 'A':
        a.append(i)
    elif s[i] == 'Z':
        b.append(i)
print(max(b)-min(a)+1)

Buggy submission (verdict: Runtime Error):
s = input().strip()

a = []
b = []

for i in range(len(s)):
    if s[i] == 'A':
        a.append(i)
    elif s[i] == 'Z':
        b.append(i)
print(b.max()-a.min()+1)

Buggy submission (verdict: Runtime Error):
s = input().strip()

a = 0
b = 0

for i in s:
    if s[i] == 'A':
        a = i
    elif s[i] == 'Z':
        b = i
print(b-a+1)
Problem p03836 (python)

Fixed submission:
sx, sy, tx, ty = map(int, input().split())

ans = ''
if sx <= tx and sy <= ty:
    ans += 'R'*abs(sx-tx) + 'U'*abs(sy-ty) + 'L'*abs(sx-tx) + 'D'*abs(sy-ty)
    ans += 'L' + 'U'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'D'
    ans += 'R' + 'D'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'U'
    print(ans)
elif sx > tx and sy <= ty:
    ans += 'L'*abs(sx-tx) + 'U'*abs(sy-ty) + 'R'*abs(sx-tx) + 'D'*abs(sy-ty)
    ans += 'R' + 'U'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'D'
    ans += 'L' + 'D'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'U'
    print(ans)
elif sx > tx and sy > ty:
    ans += 'L'*abs(sx-tx) + 'D'*abs(sy-ty) + 'R'*abs(sx-tx) + 'U'*abs(sy-ty)
    ans += 'R' + 'D'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'U'
    ans += 'L' + 'U'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'D'
    print(ans)
elif sx <= tx and sy > ty:
    ans += 'R'*abs(sx-tx) + 'D'*abs(sy-ty) + 'L'*abs(sx-tx) + 'U'*abs(sy-ty)
    ans += 'L' + 'D'*(abs(ty-sy)+1) + 'R'*(abs(tx-sx)+1) + 'U'
    ans += 'R' + 'U'*(abs(ty-sy)+1) + 'L'*(abs(tx-sx)+1) + 'D'
    print(ans)

Buggy submission (verdict: Runtime Error):
0 0 1 2
Problem p03958 (python)

Fixed submission:
import sys
import heapq
K, T = map(int, input().split())
m = [-int(i) for i in input().split()]
heapq.heapify(m)

if T == 1:
    print(K-1)
    sys.exit()

while len(m) > 1:
    l = heapq.heappop(m)
    r = heapq.heappop(m)
    if r+1 != 0:
        heapq.heappush(m, l+1)
        heapq.heappush(m, r+1)
    else:
        if l+1 != 0:
            heapq.heappush(m, l+1)
if len(m) == 0:
    print(0)
else:
    print(-m[0]-1)

Buggy submission (verdict: Runtime Error):
import sys
import heapq
K, T = map(int, input().split())
m = [-int(i) for i in input().split()]
heapq.heapify(m)

if T == 1:
    print(K-1)
    sys.exit()

while len(m) > 0:
    l = heapq.heappop(m)
    if len(m) == 0:
        heapq.heappush(m, l)
        break
    r = heapq.heappop(m)
    if r+1 == 0:
        continue
    else:
        heapq.heappush(m, l+1)
        heapq.heappush(m, r+1)
print(-m[0])
Problem p03964 (python)

Fixed submission:
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a-1)//x+1, (b-1)//y+1)
        a, b = x*c, y*c
    print(a+b)

Buggy submission (verdict: Runtime Error):
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = T[0], A[0]
if N == 1:
    print(a+b)
else:
    for x, y in zip(T[1:], A[1:]):
        c = max((a11)//(x+1), (b-1)/(y+1))
        a, b = x*c, y*c
    print(a+b)

Buggy submission (verdict: Runtime Error):
import sys
import math
import bisect
import heapq
import copy
from fractions import gcd
from itertools import permutations, combinations,combinations_with_replacement,product
from collections import defaultdict, Counter, deque

N = int(input())
T, A = [0]*N, [0]*N
for i in range(N):
    T[i], A[i] = map(int, input().split())
a, b = 1, 1
else:
    for x, y in zip(T, A):
        if a>x or b>y:
            c = max(math.ceil(a/x), math.ceil(b/y))
            a, b = x*c, y*c
        else:
            a, b = x, y
    print(a+b)
Problem p03999 (python)

Fixed submission:
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
for i in range(1<<(len(S)-1)):
    ans = 0
    num = format(i, 'b').zfill(len(S)-1)
    start = 0
    for (j, x) in enumerate(num):
        if x == '1':
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))

Buggy submission (verdict: Runtime Error):
import sys

S = input()
if len(S) == 1:
    print(int(S))
    sys.exit()

ls = []
a = [0, 1]
for i in itertools.product(a, repeat=len(S)-1):
    ans = 0
    start = 0
    for j, x in enumerate(i):
        if x == 1:
            ans += int(S[start:j+1])
            start = j + 1
    ans += int(S[start:len(S)])
    ls.append(ans)
print(sum(ls))
Problem p04032 (python)

Fixed submission:
import sys
s = input()
for i, (x, y) in enumerate(zip(s, s[1:])):
    if x == y:
        print(i+1, i+2)
        sys.exit()
if len(s) <= 2:
    print(-1, -1)
    sys.exit()
for i, (x, y, z) in enumerate(zip(s, s[1:], s[2:])):
    if x == z:
        print(i+1, i+3)
        sys.exit()
print(-1, -1)

Buggy submission (verdict: Runtime Error):
import sys
s = input()
for i, (x, y) in enumerate(zip(s, s[1:])):
    if x == y:
        print(i+1, i+2)
        sys.exit()
if len(s) == 2:
    print(-1, -1)
for i, (x, y, z) in enumerate(zip(s, s[1:], s[2])):
    if x == z:
        print(i+1, i+3)
        sys.exit()
print(-1, -1)
Problem p02586 (python)

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

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
            dp[0][r+1][c] = max(dp[i][r][c], dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])

print(max(dp[0][-2][-2], dp[1][-2][-2], dp[2][-2][-2], dp[3][-2][-2]))

Buggy submission (verdict: Runtime Error):

import sys
input = sys.stdin.buffer.readline

R, C, K = map(int,input().split())
RC = [[0] * (C+1) for _ in range(R+1)]

for _ in range(K):
    r, c, v = map(int,input().split())
    RC[r-1][c-1] = v


dp = [[[0] * (C+1) for i in range(R+1)] for j in range(4)]

dp[1][0][0] = RC[0][0]
for r in range(R):
    for c in range(C):
        for i in range(4):
            dp[i][r][c+1] = max(dp[i][r][c], dp[i][r][c+1])
            if i <= 2:
                dp[i+1][r][c+1] = max(dp[i][r][c] + RC[r][c+1], dp[i+1][r][c+1])
        dp[0][r+1][c] = max(max(dp[:][r][c]), dp[0][r+1][c])
        dp[1][r+1][c] = max(dp[1][r+1][c], dp[0][r+1][c] + RC[r+1][c])
        
print(max(dp[:][R-1][C-1]))
Problem p02642 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
for k, v in Counter(A).items():
    if v != 1:
        ans.discard(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
watched = set()
for k, v in Counter(A).items():
    if v != 1:
        ans.remove(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = list(map(int, input().split())) 
ans = set(A)
watched = set()
for k, v in Counter(A).items():
    if v != 1:
        ans.remove(k)
    temp = {k*i for i in range(2,10**6//k + 1)}
    ans -= ans&temp
print(len(ans))
Problem p02684 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N, K = map(int,input().split())
A = list(map(int, input().split())) 
check = [0]*N
tele_lis = []
start = []
def tele(x):
    check[x-1] = 1
    tele_lis.append(x)
    if check[A[x-1]-1] == 0:
        tele(A[x-1])
    else:
        start.append(A[x-1])
        return
tele(1)
for i in range(N):
    if start[0] == tele_lis[i]:
        break
if i >= K:
    print(tele_lis[K])
else:
    print(tele_lis[i::][(K-i) % (sum(check)-i)])

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int, input().split())) 
check = [0]*N
tele_lis = []
global start
start = []
def tele(x):
    check[x-1] = 1
    tele_lis.append(x)
    if check[A[x-1]-1] == 0:
        tele(A[x-1])
    else:
        start.append(A[x-1])
        return
tele(1)
for i in range(N):
    if start[0] == tele_lis[i]:
        break
    
print(tele_lis[i::][(K-i) % (sum(check)-i)])
Problem p02733 (python)

Fixed submission:
import itertools
H, W, K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
def check(k):
    if k <= K:
        return(True)
    else:
        return(False)
        
noans = 0
def make_lst(i):
    global noans, lst, havelst
    temp = S[0][i]
    for h in range(H-1):
        if y[h]:
            lst.append(temp)
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    lst.append(temp)
    if check(max(lst)):
        havelst = 1
    else:
        noans = 1
#    print(y,i,lst, "makelst")
               
def nocut(i):
    global cutnum, lst, havelst, noans
    prelst = []
    temp = S[0][i]
    if i == W-1:
        if not check(temp):
            noans = 1
    j = 0
    for h in range(H-1):            
        if y[h]:
            lst[j] += temp
            prelst.append(temp)
            j += 1
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
        if i == W-1:
            if not check(temp):
                noans = 1
    prelst.append(temp)
    lst[-1] += temp
    if check(max(lst)):
#        print(y,i,lst,"nocut", "cutnum = ",cutnum)
        return(True)
    else:
        cutnum += 1
        lst = prelst        
#        print(y,i,lst,"cut","cutnum =",cutnum)
        
                 
ans = float("inf")    
for y in itertools.product((0, 1), repeat=H-1):
    havelst = 0
    lst = []
    cutnum = sum(y)
    for x in range(W):
        if noans:
            break
        if havelst:
            nocut(x)
        else:
            make_lst(x)
#    print(y,cutnum)
    if noans:
        noans = 0
        continue
    else:
        ans = min(cutnum, ans)
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
H, W, K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
def check(k):
    if k <= K:
        return(True)
    else:
        return(False)
        
noans = 0
def make_lst(i):
    global noans, lst, havelst
    temp = S[0][i]
    for h in range(H-1):
        if y[h]:
            lst.append(temp)
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    lst.append(temp)
    if check(max(lst)):
        havelst = 1
    else:
        noans = 1
               
def nocut(i):
    global cutnum, lst, havelst
    prelst = []
    temp = S[0][i]
    j = 0
    for h in range(H-1):
        if y[h]:
            lst[j] += temp
            prelst.append(temp)
            j += 1
            temp = S[h+1][i]
        else:
            temp += S[h+1][i]
    prelst.append(temp)
    lst[-1] += temp
    if check(max(lst)):
        return(True)
    else:
        cutnum += 1
        lst = prelst        
                 
ans = float("inf")
cutlst = []    
for y in itertools.product((0, 1), repeat=H-1):
    havelst = 0
    lst = []
    cutnum = sum(y)
    for x in range(W):
        if noans:
          	noans = 0
            break
        if havelst:
            nocut(x)
        else:
            make_lst(x)
    ans = min(cutnum, ans)
print(ans)