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

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

sam = sum(A)
baketu = [0]*(100001)
for a in A:
    baketu[a] += 1

for q in range(Q):
    sam = sam + baketu[B[q]] * (C[q] - B[q])
    baketu[C[q]] += baketu[B[q]]
    baketu[B[q]] = 0
    #print(baketu)
    print(sam)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

sam = float(sum(A))
baketu = [0]*(10**5)
for a in A:
    baketu[a] += 1

for q in range(Q):
    sam = sam + baketu[B[q]] * (C[q] - B[q])
    baketu[C[q]] += baketu[B[q]]
    baketu[B[q]] = 0
    print(sam)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
for q in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

sam = sum(A)
baketu = [0]*(10**5)
for a in A:
    baketu[a] += 1

for q in range(Q):
    sam = sam + baketu[B[q]] * (C[q] - B[q])
    baketu[C[q]] += baketu[B[q]]
    baketu[B[q]] = 0
    print(sam)
Problem p02534 (python)

Fixed submission:
K = int(input())
if K == 1:
    print("ACL")
elif K == 2:
    print("ACLACL")
elif K == 3:
    print("ACLACLACL")
elif K == 4:
    print("ACLACLACLACL")
elif K == 5:
    print("ACLACLACLACLACL")

Buggy submission (verdict: Runtime Error):
K = int(input())
print([ACL]*K)
Problem p02553 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
print(max(a*c,a*d,b*c,b*d))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
print(max[a*c,a*d,b*c,b*d])
Problem p02811 (python)

Fixed submission:
K,X= map(int,input().split())

if 500*K >= X:
  print("Yes")
else:
  print("No")

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

if 500*K >= X:
  print("Yes")
 else:
  print("No")

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

if 500*X >= X:
  print("Yes")
 else:
  print("No")
Problem p02983 (python)

Fixed submission:
#ABC133 C

L,R = map(int,input().split())
A = []
if R - L > 2019:
    print(0)
elif 2 <= R - L and R - L <= 2019:
    for i in range(L,R):
        for j in range(i+1,R+1):
            A.append((i*j)%2019)
    print(min(A))
elif R - L == 1:
    print((R*L)%2019)

Buggy submission (verdict: Runtime Error):
#ABC133 C

L,R = map(int,input().split())
A = []
if R - L > 2019:
    print(0)
elif 2 <= R - L and R - L <= 2019:
    for i in range(L,R):
        for j in range(i+1,R+1):
            A.append((i*j)%2019)
    print(min(A))
elif R - L = 1:
    print((R*L)%2019)

Buggy submission (verdict: Runtime Error):
#ABC133 C

L,R = map(int,input().split())
A = []
if R - L > 2019:
    print(0)
elif 2 <= R - L and R - L <= 2019:
    for i in range(L,R):
        for j in range(i+1,R+1):
            A.append((i*j)%2019)
            print(min(A))
elif R - L = 1:
    print((R*L)%2019)

Buggy submission (verdict: Runtime Error):
#ABC133 C

L,R = map(int,input().split())
A = []
if R - L > 2019:
    print(0)
else:
    for i in range(L,R):
        for j in range(i+1,R+1):
            A.append((i*j)%2019)

print(min(A))
Problem p02988 (python)

Fixed submission:
#ABC132 B

n = int(input())
P = list(map(int,input().split()))
K = 0
for i in range(n-2):
    if (P[i] < P[i+1] and P[i+1] < P[i+2]) or (P[i+2] < P[i+1] and P[i+1] < P[i]):
        K += 1
        
print(K)

Buggy submission (verdict: Runtime Error):
#ABC132 B

n = int(input())
K = 0
for i in range(n-2):
    if (P[i]<P[i+1] and P[i+1] < P[i+2]) or (P[i+2]<P[i+1] and P[i+1]<P[i]):
        K += 1
        
print(K)

Buggy submission (verdict: Runtime Error):
n = int(input())
K = 0
for i in range(n-2):
    if P[i]<P[i+1]<P[i+2] or P[i+2]<P[i+1]<P[i]:
        K += 1
        
print(K)
Problem p02999 (python)

Fixed submission:
#ABC130 A

X,A = map(int,input().split())
if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
#ABC130 B

N,X = map(int,input().split())
L = list(map(int,input().split()))
D = [0,L[0]]
count = 0
for i in range(2,N+2):
    D.append(D[i-1]+L[i-2])
for i in range(0,N+2):
    if D[i]<= X:
        count += 1

print(count)
Problem p03001 (python)

Fixed submission:
W,H,x,y = map(int,input().split())
if x == W/2 and y == H/2:
    a = 1
else:
    a = 0
print(W*H/2,a)

Buggy submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())
if y == H*x/W or y == H - H*x/W:
    print(W*H,1.split())
else:
    print(W*H,0.split())

Buggy submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())
if y == H*x/W or y == H - H*x/W:
    print(W*H 1)
else:
    print(W*H 0)
Problem p03035 (python)

Fixed submission:
A, B = map(int,input().split())
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B//2)
elif A <= 5:
    print(0)

Buggy submission (verdict: Runtime Error):
#ABC127 A

A, B = map(int,input(),split())
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B/2)
elif A <= 5:
    print(0)
Problem p03434 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)

print(sum(A[0::2])-sum(A[1::2]))

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

print(sum(l[0::2])-sum(l[1::2]))
Problem p03455 (python)

Fixed submission:
a,b = map(int,input().split())
if a*b%2==0:
  print("Even")
else:
  print("Odd")

Buggy submission (verdict: Runtime Error):
a,b = map(int,input().split())
if a*b%2 = 0:
  print("Even")
else:
  print("Odd")
Problem p03470 (python)

Fixed submission:
N = int(input())
A = sorted([input() for _ in range(N)])
print(len(set(A)))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = sorted[input() for _ in range(N)]
print(len(set(A)))
Problem p03471 (python)

Fixed submission:
N,Y = map(int,input().split())
res = (-1,-1,-1)
for x in range(N+1):
  for y in range(N+1-x):
    if N-x-y >=0 and 10000*x + 5000*y + 1000*(N-x-y) == Y:
      res = (x,y,N-x-y)
print(res[0],res[1],res[2])

Buggy submission (verdict: Runtime Error):
N,Y = map(int,input().split())
res = (-1,-1,-1)
for x in range(N+1):
  for y in range(N+1-x):
    if N-x-y >=0 and 10000*x + 5000*y + 1000*z == Y:
      res = (x,y,N-x-y)
print(res[0],res[1],res[2])

Buggy submission (verdict: Runtime Error):
N,Y = map(int,input().split())
res = (-1,-1,-1)
for x in range(N+1):
  for y in range(N+1-x):
    if N-x-y >=0 and 10000*x + 5000*y + 1000*z = Y:
      res = (x,y,N-x-y)
print(res[0],res[1],res[2])
Problem p03478 (python)

Fixed submission:
N,A,B = map(int,input().split())
K = 0
for i in range(1,N+1):
  if A <= sum(map(int,str(i))) <= B:
    K += i
print(K)

Buggy submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
S = sum(i for i in range(1,N+1) if A <= sum(list(map(int,str(i))) <= B)
print(S)
Problem p03493 (python)

Fixed submission:
n = input()
result = sum(list(map(int,str(n))))
print(result)

Buggy submission (verdict: Runtime Error):
def d(n):
  while n%2 == 0:
    n /= 2
    ans += 1
  return ans

n = int(input())
a = map(int,input().split())
t = min(list(map(d,a)))

print(t)

Buggy submission (verdict: Runtime Error):
def d(n):
  while n%2 == 0:
    n /= 2
    ans += 1
  return ans

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

print(ans)

Buggy submission (verdict: Runtime Error):
n = input()
def sum(n):
  s = str(n)
  a = list(map(int, s))
  return sum(a)

print(sum(n))

Buggy submission (verdict: Runtime Error):
a,b,c = map(int.input())
print(a+b+c)
Problem p03494 (python)

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

K = 0
while all(a%2 == 0 for a in A):
  A = [a/2 for a in A]
  K += 1
  
print(K)

Buggy submission (verdict: Runtime Error):
def d(n):
  while n%2 == 0:
    n /= 2
    ans += 1
  return ans

n = int(input())
a = map(int,input().split())
t = min(list(map(d,a)))

print(t)

Buggy submission (verdict: Runtime Error):
def d(n):
  while n%2 == 0:
    n/= 2
    ans+= 1
  return ans

n = int(input())
a = map(int,input().split())
ans = min(map(d,a))

print(ans)

Buggy submission (verdict: Runtime Error):
def d(n):
  while n%2 == 0:
    n /= 2
    ans += 1
  return ans

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

print(ans)
Problem p02705 (python)

Fixed submission:
import math

r = int(input())

ans = 2 * math.pi * r
print(ans)

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

ans = 2 * math.pi * r
print(ans)
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = [int(s) for s in input().split()]

pos = 0
count = 1
for i in range(n):
    pos += l[i]
    if pos > x:
        break
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(s) for s in input().split()]

pos = 0
index = 0
while pos < x:
    pos += l[index]
    index += 1
print(index)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(s) for s in input().split()]

pos = 0
index = 0
while pos <= x:
    pos += l[index]
    index += 1
print(index)
Problem p03544 (python)

Fixed submission:
n = int(input())
l = [2, 1]

for i in range(2, n + 1):
        li = l[i - 1] + l[i - 2]
        l.append(li)
print(l[len(l) - 1])

Buggy submission (verdict: Runtime Error):
n = int(input())
l = [2, 1]

for i in range(2, n + 1):
        li = l[i - 1] + l[i - 2]
        l.append(li)
print(li)
Problem p03635 (python)

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

print((n - 1) * (m - 1))

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

print((n - 1) * (m - 1))
Problem p02830 (python)

Fixed submission:
n=int(input())

a,b=input().split()
a=a[:n]
b=b[:n]
n=0
for i in a:
	print(a[n],end='')
	print(b[n],end='')
	n+=1
print()

Buggy submission (verdict: Runtime Error):
n=int(input())
a=str(input())
b=str(input())

a=a[:n]
b=b[:n]
x=0
for i in a:
	print(a[x],b[x],end='')
	x+=1
print()
Problem p02534 (python)

Fixed submission:
a = int(input())
print('ACL'*a)

Buggy submission (verdict: Runtime Error):
a = input()
print('ACL'*a)
Problem p02621 (python)

Fixed submission:
a = input()
b = int(a)
print(b+b**2+b**3)

Buggy submission (verdict: Runtime Error):
a = int,input()
b = a+(a**2)+a**3
print('b=',b)

Buggy submission (verdict: Runtime Error):
a = (int,input())
b = (int,sum(a+a**2+a**3))
print(b)

Buggy submission (verdict: Runtime Error):
a = int,input()
print(a+(a**2)+(a**3))

Buggy submission (verdict: Runtime Error):
a = int,input()
print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
a = int,input()
print(a+(a*a)+(a*a*a))

Buggy submission (verdict: Runtime Error):
a = int,input()
b = int,sum(a + a^2 + a^3)
print(b)

Buggy submission (verdict: Runtime Error):
a = (int,input())
print(a + a^2 + a^3)

Buggy submission (verdict: Runtime Error):
a = int,input()
print(a+a^2+a^3)
Problem p02981 (python)

Fixed submission:
N, A, B = map(int,input().split())
t = N*A
if t > B:
  print(B)
else:
  print(t)

Buggy submission (verdict: Runtime Error):
N, A, B = map(int,input().split())
t = N*A
if t > B:
  print(B)
elif t < B:
  print(t)
elif t = B:
  print(B)
Problem p02993 (python)

Fixed submission:
S = list(input())
for i in range(3):
    if(S[i]==S[i+1]):
        print('Bad')
        exit()
else:
    print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(3):
  	if(s[i]==s[i+1]):
  		print('Bad')
 		exit()
else:
  	print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(3):
  	if(s[i] == s[i+1]):
  		print('Bad')
 		exit()
else:
  	print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(3):
  	if(s[i] == s[i+1]):
  		print('Bad')
 		exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(3):
  	if(s[i] == s[i+1]):
  		print('Bad')
 		exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range(3):
  if(s[i] == s[i+1]):
  	print('Bad')
 	exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range[3]:
  if(s[i] == s[i+1]):
  	print('Bad')
 	exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range[3]:
  if (s[i] == s[i+1]):
  	print('Bad')
  	exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range[3]:
  if (s[i] == s[i] + 1):
  print('Bad')
  exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range[3]:
  if (s[i] == s[i+1] ):
  print('Bad')
  exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = list(input())
for i in range[9]:
  if (s[i] == s[i] + 1):
  print('Bad')
  exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = input()
for i in range[9]
if (s[i] == s[i] + 1):
  print('Bad')
  exit()
else:
  print('Good')

Buggy submission (verdict: Runtime Error):
s = input()
for i in range[1111-9999]
if (s[i] = s[i] + 1):
  print('Bad')
  exit()
else:
  print('Good')
Problem p03029 (python)

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

Buggy submission (verdict: Runtime Error):
a,p = map(int,input().split())
a == a*3*p
a + p == int,ap
print(ap)

Buggy submission (verdict: Runtime Error):
a,p = map(int,input().split())
ap = (int,input())
a == 3*p
a + p == ap
print(ap)
Problem p03035 (python)

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

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

Fixed submission:
import sys
N = int(input())
An = list(map(int,input().split()))
a = 1
if 0 in An:
    print("0")
    sys.exit()
else:
    for i in range(N):
        a *= An[i]
        if a > 10**18:
            print("-1")
            sys.exit()
    if a <= 10**18:
        print(a)
        sys.exit()

Buggy submission (verdict: Runtime Error):
import numpy
N = input()
An = input().split()
AnS = numpy.prod(An)
print(AnS)
Problem p02784 (python)

Fixed submission:
enemy, num = map(int,input().split())
skills = list(map(int,input().split()))
print("Yes") if sum(skills) >= enemy else print("No")

Buggy submission (verdict: Runtime Error):
enemy, num = input().split()
skills = list(map(input().split()))
print("Yes") if max(skills) >= enemy else print("No")
Problem p03493 (python)

Fixed submission:
num_list = list(input())
count = 0
if num_list[0] == "1": count +=1 
if num_list[1] == "1": count +=1 
if num_list[2] == "1": count +=1 
print(str(count))

Buggy submission (verdict: Runtime Error):
num_list = list(input())
count = 0
if num[0] == "1": count +=1 
if num[1] == "1": count +=1 
if num[2] == "1": count +=1 
print(str(count))
Problem p03324 (python)

Fixed submission:
D,N=map(int,input().split())
if N<100:
  print(100**D*N)
  exit()
print(100**D*101)

Buggy submission (verdict: Runtime Error):
D,N=input().split()
print(100**D*5)
Problem p02642 (python)

Fixed submission:
import sys
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    _ = input()
    a_list = list(map(int, input().split()))
    res_set = set(a_list)
    # キーに要素、値に出現回数を持つカウンタ
    a_counter = Counter(a_list)
    for e in a_counter.items():  # e:(整数，出現回数)
        if e[1] == 1:
            for i in range(e[0] * 2, 10**6 + 1, e[0]):  # その整数を含まない倍数
                res_set.discard(i)
        else:
            for i in range(e[0], 2 * 10**6 + 1, e[0]):  # その整数を含む倍数
                res_set.discard(i)
    print(len(res_set))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from sympy import divisors
from collections import Counter


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    # キーに要素、値に出現回数を持つカウンタ
    a_counter = Counter(a_list)
    ans = 0
    for a in a_list:
        # aの約数の集合
        divs = divisors(a)
        for divisor in divs:
            if a_counter[divisor] > 0:
                if divisor == a and a_counter[divisor] == 1:
                    continue
                break
        else:
            ans += 1
    print(ans)


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

Fixed submission:
import sys
MOD = 998244353


def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow(2, i - 1, MOD)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys
MOD = 998244353


@lru_cache(maxsize=3100)
def pow_mod(i):
    # pow(2, i - 1, MOD)
    if i == 1:
        return 1
    else:
        return pow_mod(i - 1) * 2 % MOD


def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow_mod(i)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import sys
MOD = 998244353


@lru_cache(maxsize=None)
def pow_mod(i):
    # pow(2, i - 1, MOD)
    if i == 1:
        return 1
    else:
        return pow_mod(i - 1) * 2 % MOD


def main():
    input = sys.stdin.buffer.readline
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    dp = [[None] * (s + 1) for _ in range(n + 1)]
#     dp[i][j]:=集合{1..i}の空でない部分集合T全てについて,和がjとなる部分集合の個数の和
    for i in range(n + 1):
        for j in range(s + 1):
            if i == 0 or j == 0:
                dp[i][j] = 0
                continue
            if j > a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + dp[i - 1][j - a[i - 1]]
            elif j == a[i - 1]:
                dp[i][j] = dp[i - 1][j] * 2 + pow_mod(i)
            else:
                dp[i][j] = dp[i - 1][j] * 2
            dp[i][j] %= MOD
    print(dp[n][s])


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

Fixed submission:
S = input()
T = input()
print('Yes' if T[:len(T) - 1] == S else 'No')

Buggy submission (verdict: Runtime Error):
import sys
from itertools import permutations
input = sys.stdin.readline
N = int(input())
S = [input().rstrip('\n') for _ in range(N)]
sum_list = [0] * N
min_list = [0] * N
all_sum = 0
for i in range(N):
    sum = 0
    min = 10**7
    for c in S[i]:
        sum += 1 if c == '(' else -1
        if c == ')' and sum < min:
            min = sum
    sum_list[i], min_list[i] = (sum, min)
    all_sum += sum
if all_sum != 0:
    print('No')
else:
    fin = False
    for p in permutations(range(N), N):
        sum = 0
        for i in p:
            if sum + min_list[i] < 0:
                break
            sum += sum_list[i]
        else:
            print('Yes')
            fin = True
            break
    if not fin:
        print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            fin = True
            break
        check[index] = count
        count += 1
        index = a[index]

if not fin: 
    if (K + 1 - start) % len(loop[start:]) == 0:
        print(loop[-1] + 1)
    else:
        print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
			exit()
        check[index] = count
        count += 1
        index = a[index]


if (K + 1 - start) % len(loop[start:]) == 0:
    print(loop[-1] + 1)
else:
    print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)
Problem p02684 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            fin = True
            break
        check[index] = count
        count += 1
        index = a[index]

if not fin:  # len(loop)<=K
    if (K + 1 - start) % len(loop[start:]) == 0:
        print(loop[-1] + 1)
    else:
        print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)

Buggy submission (verdict: Runtime Error):

N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
            sys.exit()
        check[index] = count
        count += 1
        index = a[index]


if (K + 1 - start) % len(loop[start:]) == 0:
    print(loop[-1] + 1)
else:
    print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(lambda x: int(x) - 1, input().split()))
loop = []
start = 0
index = 0
check = [-1] * N
fin = False
count = 0
while True:
    if check[index] != -1:
        start = check[index]
        break
    else:
        loop.append(index)
        if len(loop) == K + 1:
            print(index + 1)
			exit()
        check[index] = count
        count += 1
        index = a[index]


if (K + 1 - start) % len(loop[start:]) == 0:
    print(loop[-1] + 1)
else:
    print(loop[start + (K + 1 - start) % len(loop[start:]) - 1] + 1)