Buggy python submission (verdict: Time Limit Exceeded):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
N, K = map(int, sys.stdin.readline().split())
A = inpl()
dic = {}
for i in range(N):
    dic[i+1] = A[i]
i = 1
visit = []
visit_set = set()
while i not in visit:
    visit.append(i)
    i = dic[i]
find = visit.index(i)
if K < find:
    print(visit[K])
else:
    root = visit[find:]
    length = len(root)
    K = (K-find) % length
    print(root[K])


Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

Buggy python submission (verdict: Runtime Error):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
N, K = map(int, sys.stdin.readline().split())
A = inpl()
dic = {}
for i in range(N):
    dic[i+1] = A[i]
i = 1
visit = []
visit_set = set()
while i not in visit:
    visit.append(i)
    i = dic[i]
find = visit.index(i)
if K < find:
    print(visit[K])
else:
    visit = visit[find:]
    length = len(visit) - find
    K = (K-find) % length
    print(visit[K])

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

Buggy python submission (verdict: Runtime Error):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
N, K = map(int, sys.stdin.readline().split())
A = inpl()
dic = {}
for i in range(N):
    dic[i+1] = A[i]
i = 1
visit = [1]
flag = 0
while dic[i] not in visit:
    visit.append(dic[i])
    i = dic[i]
    if len(visit) == K:
        print(visit[-1])
        flag = 1
        break
if not flag:
    find = visit.index(dic[i])
    visit = visit[find:]
    length = len(visit) - find
    K = (K-find) % length
    print(visit[K])

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

Buggy python submission (verdict: Runtime Error):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
N, K = map(int, sys.stdin.readline().split())
A = inpl()
dic = {}
for i in range(N):
    dic[i+1] = A[i]
i = 1
visit = [1]
while dic[i] not in visit:
    visit.append(dic[i])
    i = dic[i]
find = visit.index(dic[i])
visit = visit[find:]
length = len(visit) - find
K = (K-find)%length
print(visit[K])

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

Buggy python submission (verdict: Runtime Error):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
sys.setrecursionlimit(410000)

x = inpl()
n = x[0]
k = x[1]
m = [0 for i in range(0, 300000)]
dic = [0 for i in range(0, 300000)]

A = inpl()

t = 0
i = 0
roop = 0
while True:
    if i == k:
        print(t + 1)
        break
    if m[t] == 0:
        m[t] = 1
        dic[t] = i
        t = A[t] -1
    else:
        roop = i - dic[t]
        break
    i += 1

for i in range(0, (k - i) % roop):
    t = A[t] - 1

print(t + 1)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)

Buggy python submission (verdict: Runtime Error):
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))
sys.setrecursionlimit(410000)

x = inpl()
n = x[0]
k = x[1]
m = [0 for i in range(0, 200001)]
dic = [0 for i in range(0, 200001)]

A = inpl()

t = 0
i = 0
roop = 0
while True:
    if i == k:
        print(t + 1)
        break
    if m[t] == 0:
        m[t] = 1
        dic[t] = i
        t = A[t] -1
    else:
        roop = i - dic[t]
        break
    i += 1

for i in range(0, (k - i) % roop):
    t = A[t] - 1

print(t + 1)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
visit = []
visit_set = set()
while i not in visit_set:
    visit.append(i)
    visit_set.add(i)
    i = A[i] - 1
find = visit.index(i)
if K < find:
    print(visit[K] + 1)
else:
    root = visit[find:]
    K = (K-find) % len(root)
    print(root[K] + 1)