Problem: The Kingdom of Takahashi has N towns, numbered 1 through N.  There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.  Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.  Help the king by writing a program that answers this question.

Submission attempts (in order):
n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break

n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n)
res = []
next = 0
 
for i in range(n):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
	amari=k%n
    ans=li[amari-1]
	print(ans)

n,k=map(int,input().split())
pl=list(map(int,input().split()))
cl=[0]*2*n
res=[]
next=0
for x in range 2*n:
  if cl[next]==0:
    cl[next]=1
    next=pl[next]-1
  if cl[next]==1:
    res.append(next+1)
    cl[next]=2
    next=pl[next]-1
  else:
    lroop=len(res)
    k-=count.cl(1)
    num=k%lroop
    print(res[num-1])
    break
else:
  print(next+1)

n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
  amari=k%n
  ans=li[amari-1]
  print(ans)


n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
    print(next+1)
amari=k%n
	ans=li[amari-1]
	print(ans)
n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(n+10):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
	amari=k%n
	ans=li[amari-1]
	print(ans)

n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
	amari=k%n
    ans=li[amari-1]
	print(ans)


n,k=map(int,input().split())
pl=list(map(int,input().split()))
cl=[0]*2*n
order=[]
next=0
for i in range(k):
  if cl[next]==0:
    cl[next]=1
    next=pl[next]-1
  elif cl[next]==1:
    cl[next]=2
    order.append(pl[next])
    next=pl[next]-1
  else:
    kk=len(order)
    hasuu=cl.count(1)
    newk=k-hasuu
    ans=newk%kk
    print(order[ans])
    break
else:
  print(pl[next])


n,k=map(int,input().split())
pl=list(map(int,input().split()))
cl=[0]*2*n
order=[]
next=0
for i in range(k):
  if cl[next]==0:
    cl[next]=1
    next=pl[next]-1
  elif cl[next]==1:
    cl[next]=2
    order.append(next+1)
    next=pl[next]-1
  else:
    kk=len(order)
    hasuu=cl.count(1)
    newk=k-hasuu
    ans=newk%kk
    print(order[ans])
    break
else:
  print(pl[next])


n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
    print(next+1)
amari=k%n
	ans=li[amari-1]
	print(ans)
n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(n+10):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
  amari=k%n
  ans=li[amari-1]
  print(ans)


n,k=map(int,input().split())
pl=list(map(int,input().split()))
cl=[0]*2*n
order=[]
next=0
for i in range(k):
  if cl[next]==0:
    cl[next]=1
    next=pl[next]-1
  elif cl[next]==1:
    cl[next]=2
    order.append(pl[next])
    next=pl[next]-1
  else:
    kk=len(order)
    hasuu=order.count(1)
    newk=k-hasuu
    ans=newk%kk
    print(order[ans])
    break
else:
  print(pl[next])

n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(n+10):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
	amari=k%n
    ans=li[amari-1]
	print(ans)


n,k=map(int,input().split())
pl=list(map(int,input().split()))
cl=[0]*2*n
order=[]
next=0
for i in range(k):
  if cl[next]==0:
    cl[next]=1
    next=pl[next]-1
  elif cl[next]==1:
    cl[next]=2
    order.append(next+1)
    next=pl[next]-1
  else:
    kk=len(order)
    hasuu=cl.count(1)
    newk=k-hasuu
    ans=newk%kk
    print(order[ans])
    break
else:
  print(next+1)


Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Runtime Error

Accepted