Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])
~                                   

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])

Buggy python submission (verdict: Runtime Error):
import numpy as np
N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))
new_l= np.array([A[0]])
for i in range(K):
    r = i%N
    if A[new_l[r]-1] in new_l:
        target = A[new_l[r]-1]
        break
    new_l=np.append(new_l,A[new_l[r]-1])
    i+=1

index = np.where(new_l == target)
index=list(index)[0][0]
right = new_l[:index]
left  = new_l[index:]
pattern = K-len(right)
n = pattern % len(left)
print(left[n-1])

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
new_l=[A[0]]
for i in range(K):
    r = i%N
    if A[new_l[r]-1] in new_l:
        target = A[new_l[r]-1]
        break
    new_l.append(A[new_l[r]-1])
    i+=1

index = new_l.index(target)
right = new_l[:index]
left  = new_l[index:]
pattern = K-len(right)
n = pattern % len(left)
print(left[n-1])

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
new_l=[A[0]]
for i in range(K):
    r = i%N
    if A[new_l[r]-1] in new_l:
        target = A[new_l[r]-1]
        break
    new_l.append(A[new_l[r]-1])
    i+=1

index = new_l.index(target)
right = new_l[:index]
left  = new_l[index:]
pattern = K-len(right)
n = pattern % len(left)
print(left[n-1])

Fixed submission:
n,k = map(int,input().split())
A = [0]+list(map(int,input().split()))
visited = [False for _ in range(n+1)]
pos = 1
x = []
flg = False
for i in range(k):
    if visited[pos] == False:
        x.append(pos)
        visited[pos] = True
        pos = A[pos]
    else:
        flg = True
        pre = x.index(pos)
        loop = x[pre:]
        break
if not flg:
    print(pos)
else:
    print(loop[(k-pre)%len(loop)])