Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1

saisyo = count.index(count[-1]) + 1

if(K > saisyo):
    loop_kazu = len(count) - saisyo
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)

else:
    print(count[K-1]+1)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]])
    print(count)
    if(Check[count[-1]] == 1):
        break
 
    Check[count[-1]] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1

if(K > saisyo):
    loop_kazu = len(count) - saisyo
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)

else:
    print(count[K] + 1)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
    if(Check[count[-1] - 1] == 1):
        break
 
    Check[count[-1] -1] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1
 
loop_kazu = len(count) - saisyo
K_loop = K - saisyo
 
ans_index = K_loop % loop_kazu
ans = count[saisyo + ans_index] + 1
 
print(ans)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
    if(Check[count[-1] - 1] == 1):
        break
 
    Check[count[-1]] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1
 
loop_kazu = len(count) - saisyo
K_loop = K - saisyo
 
ans_index = K_loop % loop_kazu
ans = count[saisyo + ans_index] + 1
 
print(ans)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
    if(Check[count[-1]] == 1):
        break
 
    Check[count[-1]] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1
 
loop_kazu = len(count) - saisyo
K_loop = K - saisyo
 
ans_index = K_loop % loop_kazu
ans = count[saisyo + ans_index] + 1
 
print(ans)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
    if(Check[count[-1] == 1]):
        break
 
    Check[count[-1]] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1
 
loop_kazu = len(count) - saisyo
K_loop = K - saisyo
 
ans_index = K_loop % loop_kazu
ans = count[saisyo + ans_index] + 1
 
print(ans)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Runtime Error):
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    countCheck = copy.copy(count)
    count.append(A[count[-1]]-1)
    if(Check[count[-1] == 1]):
        break
 
    Check[count[-1]] = 1
    i += 1
 
 
saisyo = count.index(count[-1]) + 1
 
loop_kazu = len(count) - saisyo
K_loop = K - saisyo
 
ans_index = K_loop % loop_kazu
ans = count[saisyo + ans_index] + 1
 
print(ans)
 

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
N,K = list(map(int, input().split()))

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

count = [0]
Check = [0] * N
while True:
    countCheck = copy.copy(count)
    count.append(A[count[-1]]-1)
    if(Check[count[-1] == 1]):
        break

    Check[count[-1]] += 1
#    print(countCheck, count)

#print(count)


saisyo = count.index(count[-1]) + 1

loop_kazu = len(count) - saisyo

#print(loop_kazu)
K_loop = K - saisyo

ans_index = K_loop % loop_kazu
#print(ans_index)

ans = count[saisyo + ans_index] + 1

print(ans)

#hoge = count[loop:loop_kaisuu]
#ans = hoge[(K - loop) % loop_kaisuu]

#ans = count[K % loop] + 1

#print(ans)

Fixed submission:
import copy
N,K = list(map(int, input().split()))
 
A = list(map(int, input().split()))
 
count = [0]
Check = [0] * N
for i in range(K):
    count.append(A[count[-1]]-1)
#    print(count)
    if(Check[count[-1]-1] == 1):
        break
 
    Check[count[-1]-1] = 1
    i += 1
 
saisyo = count.index(count[-1]) + 1
#print(count,saisyo)
 
if(saisyo == len(count)):
    saisyo = 0
 
loop_kazu = len(count) - saisyo
 
if(K > loop_kazu):
    K_loop = K - saisyo
 
    ans_index = K_loop % loop_kazu
    ans = count[saisyo + ans_index] + 1
 
    print(ans)
 
else:
    print(count[K]+1)