Problem p02684 (python)

Fixed submission:
n,k = map(int,input().split())
ls = list(map(int,input().split()))
fi = [-1]*(n+1)
fi[1] = 0
a = 0
aa = 0
for i in range(k):
    if fi[ls[a]] == -1:
        fi[ls[a]] = i + 1
        aa = a
        a = ls[a] - 1
    else:
        ind = fi[ls[a]]
        t = (k - ind) % (max(fi) + 1 - ind)
        t += ind
        print(fi.index(t))
        break
else:
    print(ls[aa])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
di = [1]
fi = [-1]*(n+1)
a = 0
for i in range(k):
    if fi[ls[a]] == -1:
        fi[ls[a]] = i
        a = ls[a] - 1
    else:
        ind = fi[ls[a]]
        t = (k - ind) % (max(fi) - ind)
        t += ind
        print(fi.index(t))
        break
else:
    print(a)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
di = [1]
fi = [0]*(n+1)
a = 0
for i in range(k):
    if fi[ls[a]] == 0:
        fi[ls[a]] = i
        a = ls[a] - 1
    else:
        ind = fi[ls[a]]
        t = (k - ind) % (max(fi) - ind)
        t += ind
        print(fi.index(t))
        break
else:
    print(a)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
di = [1]
fi = [0]*(n+1)
a = 0
for i in range(k+1):
    if fi[ls[a]] == 0:
        fi[ls[a]] = i
        a = ls[a] - 1
    else:
        ind = fi[ls[a]]
        t = (k - ind) % (max(fi) - ind)
        t += ind
        print(fi.index(t))
        break
else:
    print(a)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
i = 1
di = [-1]*10
di[0] = 0
if k >= 10**9+7:
  k%= 10**9+7
while True:
    if i == 1:
        a = ls[0]
        di[a-1] = i
        i += 1
        continue
    if i == k+1:
        print(a)
        break
    a = ls[a-1]
    if di[a-1] != -1:
        p = (k+1-di[a-1])%(i-di[a-1])
        s = i-di[a-1]
        if p ==0:
            q = di.index(i-1)+1
            print(q)
        else:
            q = di.index(i-s-1+p)+1
            print(q)
        break
    di[a-1] = i
    i += 1

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
i = 1
di = [-1]*10
di[0] = 0
while True:
    if i == 1:
        a = ls[0]
        di[a-1] = i
        i += 1
        continue
    if i == k+1:
        print(a)
        break
    a = ls[a-1]
    if di[a-1] != -1:
        p = (k+1-di[a-1])%(i-di[a-1])
        s = i-di[a-1]
        if p ==0:
            q = di.index(i-1)+1
            print(q)
        else:
            q = di.index(i-s-1+p)+1
            print(q)
        break
    di[a-1] = i
    i += 1
print(di)

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
ls = list(map(int,input().split()))
i = 1
di = [-1]*10
di[0] = 0
while True:
    if i == 1:
        a = ls[0]
        di[a-1] = i
        i += 1
        continue
    if i == k+1:
        print(a)
        break
    a = ls[a-1]
    if di[a-1] != -1:
        p = (k+1-di[a-1])%(i-di[a-1])
        s = i-di[a-1]
        if p ==0:
            q = di.index(i-1)+1
            print(q)
        else:
            q = di.index(i-s-1+p)+1
            print(q)
        break
    di[a-1] = i
    i += 1