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

ans = 0
b = [1]
for i in range(k):
  if a[b[-1] - 1] in b:
    c = a[b[-1] - 1]
    break
  b.append(a[b[-1] - 1])

d = b[:b.index(c)]
b = b[b.index(c):]

k = k - len(d)
k = k % len(b)
#print(d,b,k)
ans = b[k]
print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
n,k = map(int,input().split())

a = list(map(int,input().split()))

b = [1 for i in range(n)]


now = 0
next = a[now] - 1
c = []
for i in range(n):
    if b[next] == 0:
        d = c[:c.index(next)]
        e = c[c.index(next):]
        #print(d,e)
        break
    #print(now)
    b[now] = 0
    c.append(now)
    next = a[now] - 1
    #print(" ",next)
    now = next

if k >= len(d):
    k = k - len(d)
    k = k % len(e)
    print(e[k]+1)

else:
    print(d[k]+1)

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

ans = 0
b = [1]
for i in range(k):
  if a[b[-1] - 1] in b:
    c = a[b[-1] - 1]
    break
  b.append(a[b[-1] - 1])

d = b[:b.index(c)]
b = b[b.index(c):]

k = k - len(d) - k // len(b) * len(b)
#print(d,b,k)
ans = b[k]
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
n,k = map(int,input().split())

a = list(map(int,input().split()))

b = [1 for i in range(n)]


now = 0
next = a[now] - 1
c = []
for i in range(n):
    if b[next] == 0:
        d = c[:c.index(next)]
        e = c[c.index(next):]
        #print(d,e)
        break
    #print(now)
    b[now] = 0
    c.append(now)
    next = a[now] - 1
    #print(" ",next)
    now = next

if k >= len(d):
    k = k - len(d)
    k = k % len(e)
    print(e[k]+1)

else:
    print(d[k]+1)

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

ans = 0
b = [1]
for i in range(k):
  if a[b[-1] - 1] in b:
    c = a[b[-1] - 1]
    break
  b.append(a[b[-1] - 1])

d = b[:b.index(c)]
b = b[b.index(c):]

k = k - len(d) - k // len(b) * len(b)
#print(d,b,k)
ans =a[k]
#print(ans)
print(ans)

Fixed submission:
# coding: utf-8
# Your code here!
n,k = map(int,input().split())

a = list(map(int,input().split()))

b = [1 for i in range(n)]


now = 0
next = a[now] - 1
c = []
for i in range(n):
    if b[next] == 0:
        d = c[:c.index(next)]
        e = c[c.index(next):]
        #print(d,e)
        break
    #print(now)
    b[now] = 0
    c.append(now)
    next = a[now] - 1
    #print(" ",next)
    now = next

if k >= len(d):
    k = k - len(d)
    k = k % len(e)
    print(e[k]+1)

else:
    print(d[k]+1)

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

ans = 0
b = [1]
for i in range(k):
  if a[b[-1] - 1] in b:
    c = a[b[-1] - 1]
    break
  b.append(a[b[-1] - 1])

d = b[:b.index(c)]
b = b[b.index(c):]

k = k - k // len(b) * len(b) + 1
#print(d,b,k)

for i in d:
    ans = a[i - 1]
    #print(ans)
for i in range(k):
  ans = a[ans - 1]
  #print(ans)
print(ans)



Fixed submission:
# coding: utf-8
# Your code here!
n,k = map(int,input().split())

a = list(map(int,input().split()))

b = [1 for i in range(n)]


now = 0
next = a[now] - 1
c = []
for i in range(n):
    if b[next] == 0:
        d = c[:c.index(next)]
        e = c[c.index(next):]
        #print(d,e)
        break
    #print(now)
    b[now] = 0
    c.append(now)
    next = a[now] - 1
    #print(" ",next)
    now = next

if k >= len(d):
    k = k - len(d)
    k = k % len(e)
    print(e[k]+1)

else:
    print(d[k]+1)