Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    n, k, *a = map(int, sys.stdin.read().split())
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print(path[d])
            break
        path = path + [nx]
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    nx = 1
    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if nx in root:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        root.append(nx)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    now = 1
    count = 0
    roop_start = 0
    while count <= k:
        count += 1
        next = a[now]
        if next in root:
            roop_start = next
            break
        else:
            root.append(next)
            now = next
    else:
        print(now)

    root_end = now
    roop_end_index = count - 1
    roop_start_index = root.index(roop_start)

    left_count = k - count
    items = roop_end_index - roop_start_index + 1

    p, q = divmod(left_count, items)
    index = roop_start_index + q


    print(root[index])



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    now = 1
    count = 0
    roop_start = 0
    while count <= k:
        count += 1
        next = a[now]
        if next in root:
            roop_start = next
            break
        else:
            root.append(next)
            now = next
    else:
        print(now)

    root_end = now
    roop_end_index = count - 1
    roop_start_index = root.index(roop_start)

    left_count = k - count
    items = roop_end_index - roop_start_index + 1

    p, q = divmod(left_count, items)
    index = roop_start_index + q


    print(root[index])



if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    start = a[1]
    root.append(start)
    now = start
    roop = 0
    while True:
        next = a[now]
        if next in root:
            roop = next
            break
        else:
            root.append(next)
            now = next

    if roop == 0:
        ans = root[k]
    else:
        roop_start = root.index(roop)
        step = roop_start + 1
        if k <= step:
            ans = ans[k]
        else:
            m = len(root) - roop_start
            p, q = divmod(k - step + 1, m)
            index = roop_start + q
            ans = root[index]
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()