Problem p02684 (python)

Fixed submission:
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0

t=0
rep = False

for i in range(k):
    if i == k:
        print(next+1)
        exit()

    if li2[next] == 1:
        t = li.index(next+1)
        rep = True
        li.pop()
        break

    li.append(A[next])
    li2[next] = 1
    next = A[next]-1


tmp = (k-t)%len(li[t:])
print(li[tmp+t])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
li2[next] = 1
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        li.pop()
        t = li.index(next+1)
        rep = True
        break

if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
elif len(li) > k:
    print(li[k-1])
else:
    tmp = k%len(li[t:])
    print(li[tmp])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n+1000):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break

if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
elif len(li) > k:
    print(li[k-1])
else:
    tmp = k%len(li[t:])
    print(li[tmp])

Buggy submission (verdict: Runtime Error):
6 727202214173249351
6 5 2 5 3 2

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break

if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
elif len(li) > k:
    print(li[k-1])
else:
    tmp = k%len(li[t:])
    print(li[tmp])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break

if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break

if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    if t==0:
        print(g[0])
    else:
        print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True and t != 0:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
elif rep == True:
    tmp = k%len(li)
    print(li[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True and t != 0:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = (k%len(li[t:])) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0
t=0
rep = False

for i in range(n):
    li.append(A[next])
    li2[next] = 1
    next = A[next]-1

    if li2[next] == 1:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = k%len(li[t:]) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li.append(1)

next = 0
t=0
rep = False
for i in range(n):
    li.append(A[next])
    next = A[next]-1

    if A[next] in li:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = k%len(li[t:]) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li.append(1)

next = 0
t=0
rep = False
for i in range(n):
    li.append(A[next])
    next = A[next]-1

    if A[next] in li:
        t = li.index(A[next])
        rep = True
        break


if rep == True:
    tmp = k%len(li[t:]) - len(li[0:t])
    g=li[t:]
    print(g[tmp])
else:
    print(li[k])

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li.append(1)

next = 0
t=0
for i in range(n):
    li.append(A[next])
    next = A[next]-1

    if A[next] in li:
        t = li.index(A[next])
        break


tmp = k%len(li[t:]) - len(li[0:t])

g=li[t:]
print(g[tmp])