Buggy python submission (verdict: Runtime Error):
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [0 for _ in range(n)]
hash_a[0] = 1
cnt = 0
two = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Buggy python submission (verdict: Runtime Error):
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [0 for _ in range(n)]
hash_a[0] = 1
cnt = 0
two = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [False for _ in range(n)]
hash_a[0] = True
cnt = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if not hash_a[dir - 1]:
        hash_a[dir - 1] = True
    else:
        k %= cnt - 1
print(dir)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [0 for _ in range(n)]
hash_a[0] = 1
cnt = 0
two = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [False for _ in range(n)]
hash_a[0] = True
cnt = 0
while True:
    k -= 1
    if k == 0:
        break
    dir = a[dir - 1]
    if not hash_a[dir - 1]:
        hash_a[dir - 1] = True
    else:
        k %= cnt
    cnt += 1
print(dir)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
dir = a[0]
hash_a = [0 for _ in range(n)]
hash_a[0] = 1
cnt = 0
two = 0
while True:
    k -= 1
    cnt += 1
    if k == 0:
        break
    dir = a[dir - 1]
    if hash_a[dir - 1] == 0 or hash_a[dir - 1] == 1 or hash_a[dir - 1] == 2:
        hash_a[dir - 1] += 1
        if hash_a[dir - 1] == 2:
            two += 1
    elif hash_a[dir - 1] == 3:
        k = (k + cnt) - (cnt - (two * 2))
        k %= two
        hash_a = [-k for _ in range(n)]
print(dir)