Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

m = max(a)
ans = [0 for _ in range(m)]
azk = [0 for _ in range(m)]

for i in range(m):
    ans[i] = a.count(i + 1)
    azk[i] = round(ans[i] * (ans[i] - 1) / 2)
dic = {}

for i in range(n):
    ppt = 0
    if a[i] in dic:
        print(dic[a[i]])
        continue
    for j in range(m):
        if (j + 1) == a[i]:
            ppt += round((ans[j] - 1)*(ans[j] - 2) / 2)
        else:
            ppt += azk[j]
    dic[a[i]] = ppt
    print(ppt)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))

b = [0 for _ in range(max(a))]
for i in a:
    b[i - 1] += 1
ans = 0
for i in b:
    ans += int(i * (i-1) / 2)

for i in a:
    print(ans - (b[i - 1] - 1))
Buggy python submission (verdict: Runtime Error):
n = str(input())
ans = 'Yes'
if len(n)%2 == 1:
    ans = No
else:
    for i in range(0, len(n)-1, 2):
        if n[i] != 'h' or n[i + 1] != 'i':
            ans = 'No'

print(ans)

Fixed submission:
n = str(input())
ans = 'Yes'
if len(n)%2 == 1:
    ans = 'No'
else:
    for i in range(0, len(n)-1, 2):
        if n[i] != 'h' or n[i + 1] != 'i':
            ans = 'No'

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())

x = []
for i in range(q):
    x.append(input().split())
for i in range(q-1, -1, -1):
    if x[i] == '1' and  x[i-1] == '1':
        x[i] = '0'
        x[i - 1] = '0'
    if x[i] == '1':
        for j in range(i-1, -1 , -1):
            if x[j][0] == '2':
                if x[j][1] == '1':
                    x[j][1] == '2'
                else:
                    x[j][2] == '1'
for i in range(q):
    if x[i][0] == '0':
        continue
    elif x[i][0] == '1':
        s = s[::-1]
    elif x[i][1] == '1':
        s = x[i][2] + s
    else:
        s = s + x[i][2]
print(s)

Fixed submission:
s = str(input())
q = int(input())

x = []
pre = ''
post = ''
isone = False
for i in range(q):
    x = input().split()
    if x[0] == '1':
        if isone:
            isone = False
        else:
            isone = True
    elif x[1] == '1':
        if isone:
            post += x[2]
        else:
            pre += x[2]
    else:
        if isone:
            pre +=x [2]
        else:
            post += x[2]
    if i == q - 1:
        if isone:
            s = post[::-1] + s[::-1] + pre
        else:
            s = pre[::-1] + s + post
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
q = int(input())

for i in range(q):
    x = input().split()
    if x[0] == '1':
        s = s[::-1]
    elif x[1] == '1':
        s = x[2] + s
    else:
        s = s + x[2]
print(s)

Fixed submission:
s = str(input())
q = int(input())

x = []
pre = ''
post = ''
isone = False
for i in range(q):
    x = input().split()
    if x[0] == '1':
        if isone:
            isone = False
        else:
            isone = True
    elif x[1] == '1':
        if isone:
            post += x[2]
        else:
            pre += x[2]
    else:
        if isone:
            pre +=x [2]
        else:
            post += x[2]
    if i == q - 1:
        if isone:
            s = post[::-1] + s[::-1] + pre
        else:
            s = pre[::-1] + s + post
print(s)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
ans = []
tmp = True
for i in range(n): ans.append('a')

for i in range(m):
    s, c = map(int, input().split())

    if s == 1 and c == 0:
        tmp = False
        break

    if s > n:
        tmp = False
        break

    if c < 0 or c > 9:
        tmp = False
        break

    if ans[s - 1] == 'a':
        ans[s - 1] = str(c)
    else:
        if ans[s - 1] != str(c):
            tmp = False
            break

if ans[0] == a: ans[0] = '1'
for i in range(n):
    if ans[i] == a: ans[i] = '0'

if tmp:
    for i in range(n):
        print(ans[i], end='')
    print()
else:
    print('-1')



Fixed submission:
n, m = map(int, input().split())
ans = []
tmp = True
for i in range(n): ans.append('a')

for i in range(m):
    s, c = map(int, input().split())

    if s < 1 or s > n:
        tmp = False
        break
    if c < 0 or c > 9:
        tmp = False
        break

    if n != 1 and s == 1 and c == 0:
        tmp = False
        break

    if ans[s - 1] == 'a':
        ans[s - 1] = str(c)
    else:
        if ans[s - 1] != str(c):
            tmp = False
            break

if n != 1 and ans[0] == 'a': ans[0] = '1'
for i in range(n):
    if ans[i] == 'a': ans[i] = '0'

if tmp:
    for i in range(n):
        print(ans[i], end='')
    print()
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
s = []
for _ in range(n):
    s.append(input())

t = list(set(s))
dd = len(t)
cnt = [0 for _ in range(dd)]
for i in range(dd):
    for y in s:
        if t[i] == y: cnt[i]+=1
ans = []
for i in range(dd):
    if cnt[i] == max(cnt):
        ans.append(t[i])
ans.sort()
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
cnt = {}
for _ in range(n):
    s = input()
    if not s in cnt:
        cnt[s] = 1
    else:
        cnt[s] = cnt[s] + 1

maxv = max(cnt.values())
ans = []
for x, c in cnt.items():
    if c == maxv: ans.append(x)
ans.sort()
for x in ans:
    print(x)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    t = input()
    s.append(t)

t = list(set(s))
cnt = [0 for _ in range(len(t))]
for i in range(len(t)):
    for y in s:
        if t[i] == y: cnt[i]+=1
ans = []
for i in range(len(t)):
    if cnt[i] == max(cnt):
        ans.append(t[i])
ans.sort()
for i in range(len(ans)):
    print(ans[i])


Fixed submission:
n = int(input())
cnt = {}
for _ in range(n):
    s = input()
    if not s in cnt:
        cnt[s] = 1
    else:
        cnt[s] = cnt[s] + 1

maxv = max(cnt.values())
ans = []
for x, c in cnt.items():
    if c == maxv: ans.append(x)
ans.sort()
for x in ans:
    print(x)
Buggy python submission (verdict: Runtime Error):
import sys
import math
import itertools

a, b = map(int, input().split())
print(int(a * b / math.gcd(a, b)))

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)

a, b = map(int, input().split())
print(int(a * b / gcd(a, b)))
Buggy python submission (verdict: Runtime Error):
day = ['SUN', 'MON','TUE','WED','THU','FRI','SAT']
s = input()
for x in range(len(day)):
    if day[x] == s:
        print(7 - x)
        sys.exit()

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

day = ['SUN', 'MON','TUE','WED','THU','FRI','SAT']
s = input()
for x in range(len(day)):
    if day[x] == s:
        print(7 - x)
        sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n = int(input())
i = floor(sqrt(n))
dis = 0
while True:
    f = i / n
    j = floor(f)
    if f - j > 0:
        dis += 1
        continue
    print(i + j)
    sys.exit()

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

n = int(input())
for i in range(ceil(sqrt(n)), 0, -1):
    f = n / i
    j = floor(f)
    if f - j > 0: continue
    print(i + j - 2)
    sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
#print(a)
for i in range(n-2):
    for j in range(i+1, n-1):
        l = bisect_right(a, max(abs(a[i] - a[j]), a[j]))
        r = bisect_left(a, abs(a[i] + a[j]))
        #print(a[i], a[j], l, r)
        ans = ans - l + r
print(ans)

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans = ans - j - 1 + bisect_left(a, abs(a[i] + a[j]))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
#print(a)
for i in range(n-1):
    for j in range(i+1, n):
        l = bisect_right(a, max(abs(a[i] - a[j]), a[j]))
        r = bisect_left(a, abs(a[i] + a[j]))
        #print(a[i], a[j], l, r)
        ans = ans - l + r
print(ans)

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        ans = ans - j - 1 + bisect_left(a, abs(a[i] + a[j]))
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input().split()
N = int(a)
ans = 0.5
if N%2 == 0:
    pass
else:
    ans = (N+1)/(2*N)

print(ans)

Fixed submission:
a = input().split()
N = int(a[0])
ans = 0.5
if N%2 == 0:
    pass
else:
    ans = (N+1)/(2*N)

print(ans)

Buggy python submission (verdict: Runtime Error):
N = input().split()

ans = 0.5
if N%2 == 0:
    pass
else:
    ans = (N+1)/(2*N)

print(ans)

Fixed submission:
a = input().split()
N = int(a[0])
ans = 0.5
if N%2 == 0:
    pass
else:
    ans = (N+1)/(2*N)

print(ans)

Buggy python submission (verdict: Runtime Error):
N = input().split()

if N%2 == 0:
    ans = 0.5
else:
    ans = (N+1)/(2*N)

print(ans)

Fixed submission:
a = input().split()
N = int(a[0])
ans = 0.5
if N%2 == 0:
    pass
else:
    ans = (N+1)/(2*N)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().split()[0])
aa = input().split()
bb = []

for i in range(1, N+1):
    num = aa.index(str(i))
    bb.append(num + 1)

print(*bb)


Fixed submission:
N = int(input().split()[0])
aa = input().split()
bb = [0]*N

for i in range(0, N):
    bb[int(aa[i]) - 1] = i + 1

print(*bb)

Buggy python submission (verdict: Runtime Error):
N = int(input().split()[0])
aa = input().split()
bb = []

for i in range(1, N+1):
    bb.append(aa.index(str(i+1)))

print(*bb)


Fixed submission:
N = int(input().split()[0])
aa = input().split()
bb = [0]*N

for i in range(0, N):
    bb[int(aa[i]) - 1] = i + 1

print(*bb)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().split()[0])
aa = input().split()
bb = []

for i in range(1, N+1):
    for j in range(0, N):
        if int(aa[j]) == i:
            bb.append(j+1)
            break

print(*bb)

Fixed submission:
N = int(input().split()[0])
aa = input().split()
bb = [0]*N

for i in range(0, N):
    bb[int(aa[i]) - 1] = i + 1

print(*bb)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().split()[0])
aa = input().split()
bb = []

for i in range(1, N+1):
    for j in range(0, N):
        if int(aa[j]) == i:
            bb.append(j+1)

print(*bb)

Fixed submission:
N = int(input().split()[0])
aa = input().split()
bb = [0]*N

for i in range(0, N):
    bb[int(aa[i]) - 1] = i + 1

print(*bb)
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(floor(n*(n-1)*0.5))

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
v = list(map(float, input().split()))

ans = []
for x in permutations(v):
    p = x[0]
    for i in range(1, n):
        p = (p + x[i])/2.0
    ans.append(p)
print(max(ans))

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n = int(input())
v = list(map(float, input().split()))

v.sort()
ans = v[0]
for i in range(1, n):
    ans = (ans + v[i])/2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
now = 0
while True:
    if now > x:
        print(ans)
        sys.exit()
    now += a[ans]
    ans += 1

Fixed submission:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())

n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
now = 0
d = []
d.append(0)
for i in range(len(a)):
    d.append(d[i] + a[i])
for k in d:
    if k <= x:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
k,x=map(int,input(),split())
print("Yes" if 500*k>=x else "No")

Fixed submission:
k,x=map(int,input().split())
print("Yes" if 500*k>=x else "No")
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
h,w=map(int,input(),split())
print((H-h)*(W-w))

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))

Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
h,w=map(int,input(),split())
print((H-h)*(W-w))

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))
Buggy python submission (verdict: Runtime Error):
n,a=map(int,input().split())
print(n*n-a)

Fixed submission:
n=int(input())
a=int(input())
print(n*n-a)

Buggy python submission (verdict: Runtime Error):
n,a=int(input())
print(n*n-a)

Fixed submission:
n=int(input())
a=int(input())
print(n*n-a)
Buggy python submission (verdict: Runtime Error):
n,m=map(intput().split())
print((n-1)*(m-1))

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))

Buggy python submission (verdict: Runtime Error):
n,m=int(intput().split())
print((n-1)*(m-1))

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8


def main():
    N, K = map(int, input().split())
    A = list((map(int, input().split())))

    score = 1
    for i in range(K):
        score *= A[i]

    for i in range(N-K):
        pre = score
        score = score // A[i] * A[K+i]
        if score > pre:
            print("Yes")
        else:
            print("No")


main()


Fixed submission:
# coding: utf-8


def main():
    N, K = map(int, input().split())
    A = list((map(int, input().split())))

    for i in range(N-K):
        if A[i] < A[K+i]:
            print("Yes")
        else:
            print("No")


main()
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    return max(leq_search(xs, x, s, (s+t)//2), leq_search(xs, x, (s+t)//2, t))



def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    S = [None] * (N+1)
    S[0] = 0
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    T = [None] * (M+1)
    T[0] = 0
    for i in range(1, M+1):
        T[i] = T[i-1] + B[i-1]

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print(main())


Fixed submission:
# coding: utf-8

from bisect import bisect_left


def leq_search(xs, x, s, t):
    # x以下で最大のindex
    if t-s <= 5:
        res = 0
        for i in range(s, t):
            if xs[i] <= x:
                res = i
        return res

    i = (s+t)//2
    if xs[i] <= x:
        return leq_search(xs, x, i, t)
    else:
        return leq_search(xs, x, s, i)


def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    S = [None] * (N+1)
    S[0] = 0
    for i in range(1, N+1):
        S[i] = S[i-1] + A[i-1]

    T = [None] * (M+1)
    T[0] = 0
    for i in range(1, M+1):
        T[i] = T[i-1] + B[i-1]

    n_read = 0
    for i in range(N+1):
        # print(i)
        if S[i] > K:
            break
        n = leq_search(T, K-S[i], 0, M+1)
        # print(n, T, K-S[i])
        if n_read < n + i:
            n_read = n + i
    
    return n_read


print(main())
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 1
    for a in A:
        ans *= a
    
    return ans if ans <= 10**18 else -1


print(main())


Fixed submission:
# coding: utf-8


def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        return 0

    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            return -1
    
    return ans


print(main())
Buggy python submission (verdict: Runtime Error):
# coding: utf-8


def main():
    a, b = map(float, input().split())

    a = int(a)
    b = str(b)
    # print(b)
    b = b[0] + b[2] + b[3]
    b = int(b)
    # print(b)
    # exit()
    
    return a*b // 100


print(main())


Fixed submission:
# coding: utf-8


def main():
    a, b = map(str, input().split())
    # print(b)

    a = int(a)
    b = str(b)
    # print(b)
    if len(b) == 1:
        b = b[0] + "00"
    elif len(b) == 3:
        b = b[0] + b[2] + "0"
    else:
        b = b[0] + b[2] + b[3]
    # b = b[0] + b[2] + b[3]
    b = int(b)
    # print(b)
    # exit()
    
    return a*b // 100


print(main())
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = [a-1 for a in A]  # 0-index

    cnt = 0
    i = 0
    appeared = [0]
    roop_s = None
    n_roop = None
    for _ in range(N):
        i = A[i]
        cnt += 1

        if cnt == K:
            return i+1

        # if i == 0:
        if i in appeared:
            for j in range(len(appeared)):
                if appeared[j] == i:
                    roop_s = j
                    n_roop = len(appeared) - roop_s
                    break

            break
        
        appeared.append(i)

    # K > cnt
    rest = (K-roop_s) % n_roop
    i = appeared[roop_s]
    for _ in range(rest):
        i = A[i]

    return i+1


print(main())


Fixed submission:
# coding: utf-8


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A = [a-1 for a in A]  # 0-index

    cnt = 0
    i = 0
    # appeared = [0]
    appeared = [False] * N
    appeared[0] = True
    arrive = [None] * (N+1)
    arrive[0] = 0
    roop_s = None
    n_roop = None
    for k in range(N):
        i = A[i]
        cnt += 1

        if cnt == K:
            return i+1

        if appeared[i]:
            for j in range(N+1):
                if arrive[j] == i:
                    roop_s = j
                    n_roop = (k+1) - roop_s
                    break
        # if i in appeared:
            # for j in range(len(appeared)):
            #     if appeared[j] == i:
            #         roop_s = j
            #         n_roop = len(appeared) - roop_s
            #         break

            break

        # appeared.append(i)
        appeared[i] = True
        arrive[k+1] = i

    # K > cnt
    rest = (K-roop_s) % n_roop
    # i = appeared[roop_s]
    i = arrive[roop_s]
    for _ in range(rest):
        i = A[i]

    return i+1


print(main())