Harryxun/stf_run huggingface dataset:
import math

n = int(input())
fac_n = math.factorial(n)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
print(len(make_divisors(fac_n)) % (10**9+7))

### FIXED CODE ###

def solve():
    n = int(input())
    keta = [0] * (n+1)
    for i in range(2, n+1):
        for j in range(2, int(pow(i, 0.5))+1):
            if i % j: continue
            ex = 0
            while i % j == 0:
                i = i // j
                ex += 1
            keta[j] += ex
        if i != 1:
            keta[i] += 1

    mod = 1000000007
    ans = 1
    for ex in keta:
        ans = ans * (ex + 1)
        ans %= mod
    print(ans)

if __name__ == '__main__':
    solve()
While True:
  a, op, b = map(str, raw_input().split())
  a = int(a)
  b = int(b)
  if op == "+":
    print a+b
  elif op == "-":
    print a-b
  elif op == "*":
    print a*b
  elif op == "/":
    print a/b
  else:
    break

### FIXED CODE ###

while True:
  s = raw_input().split()
  a = int(s[0])
  op = s[1]
  b = int(s[2])
  if op == '?':
    break
  elif op == '+':
    print (a+b)
  elif op == '-':
    print (a-b)
  elif op == '*':
    print (a*b)
  elif op == '/':
    print (a/b)
def resolve():
    n=int(input())
    l=list(map(int, input().split()))
    ans='YES'
    l.sort()
    for i in range(n-1):
        if l[i]==l[i+1]:
            ans='NO'
    print(ans)

resolve()

### FIXED CODE ###

def resolve():
    s=input()
    num=0
    for i in range(len(s)):
        for j in range(len(s)+1):
            s1=s[i:j]
            if 'B' not in s1 and 'D' not in s1 and 'E' not in s1 and 'F' not in s1\
                    and 'H' not in s1 and 'I' not in s1 and 'J' not in s1 and 'K' not in s1 and 'L' not in s1 and\
                    'M' not in s1 and 'N' not in s1 and 'O' not in s1 and 'P' not in s1 and 'Q' not in s1 and\
                    'R' not in s1 and 'S' not in s1 and 'U' not in s1 and 'V' not in s1 and 'W' not in s1 and\
                    'X' not in s1 and 'Y' not in s1 and 'Z' not in s1 and len(s1)>=num:
                num=len(s1)
    print(num)
resolve()
import numpy as np
N = int(input())
A = []
B = []
for _ in range(N):
    A[i], B[i] = map(int, input().split())

A = np.array(A)
B = np.array(B)
am = np.median(A)
bm = np.median(B)

if n % 2 == 0:
    print((bm - am) * 2 + 1)
else:
    print((bm - am) + 1)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    A[i], B[i] = map(int, input().split())

am = np.median(A)
bm = np.median(B)

if N % 2 == 0:
    print(int((bm - am) * 2 + 1))
else:
    print(int((bm - am) + 1))
N = int(input())
AN = list(map(int, input().split()))

AN2 = AN[AN % 2 == 0]
(AN % 2 == 0).size
if AN2[AN2 % 3 == 0].size + AN2[AN2 % 5 ==0].size - AN2[AN2 % 15 ==0].size == AN2.size:
    print('APPROVED')

else:
    print('DENIED')


### FIXED CODE ###

import numpy as np


N = int(input())
AN = list(map(int, input().split()))
AN = np.array(AN)

AN2 = AN[AN % 2 == 0]

if AN2[AN2 % 3 == 0].size + AN2[AN2 % 5 ==0].size - AN2[AN2 % 15 ==0].size == AN2.size :
    print('APPROVED')

else:
    print('DENIED')
from heapq import heappush, heappop, merge
from collections import defaultdict

def solve():
  N, Q = map(int, input().split())
  events = []
  for _ in range(N):
    s, t, x = map(int, input().split())
    events.append((s-x, 1, x))
    events.append((t-x, -1, x))
    events = sorted(events)

    constructions = []
    under_construction = defaultdict(bool)
    i = 0
    for _ in range(Q):
      d = int(input())
      while i < 2*N and events[i][0] <= d:
        if events[i][1] > 0:
          heappush(constructions, events[i][2])
          under_construction[events[i][2]] = True
        else:
          under_construction[events[i][2]] = False
        i += 1
      while constructions:
      	x = heappop(constructions)
        if under_construction[x]: # x is the minimum coordinate under construction
          heappush(constructions, x)
          print(x)
          break
      else: # no constructions
        print(-1)
        
if __name__ == "__main__":
  solve()

### FIXED CODE ###

from heapq import heappush, heappop, merge
from collections import defaultdict
import sys
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()

def solve():
    N, Q = map(int, line_input())
    events = []
    for _ in range(N):
        s, t, x = map(int, line_input())
        events.append((s-x, 1, x))
        events.append((t-x, -1, x))
    for _ in range(Q):
        d = int(single_input())
        events.append((d, 2, d))
    events = sorted(events)

    constructions = []
    under_construction = defaultdict(bool)
    ans = ''
    for _, flag, coord in events:
        if flag == 1:
            heappush(constructions, coord)
            under_construction[coord] = True
        elif flag == -1:
            under_construction[coord] = False
        else:
            while constructions:
                x = heappop(constructions)
                if under_construction[x]: # x is the minimum coordinate under construction
                    heappush(constructions, x)
                    ans += str(x) + '\n'
                    break
            else: # no constructions
                ans += '-1\n'
    print(ans)
    
if __name__ == "__main__":
    solve()
N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A = A[::-1]
# print("#", A)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if memo[X] != None: return memo[X]
    if X < 0: return -(1000000007)
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))

tab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
A_cmp = {}
for Ai in sorted(A):
    A_cmp[tab[Ai]] = Ai
A = list(A_cmp.values())
A.sort(key=lambda x: -x)

memo = [None] * (N + 1)
memo[0] = 0

import sys
sys.setrecursionlimit(100000)

def dp(X):
    if X < 0: return -(1000000007)
    if memo[X] != None: return memo[X]
    #
    rets = []
    for i, Ai in enumerate(A):
        rets.append(dp(X - tab[Ai]) + 1)
    #
    ret = max(rets)
    memo[X] = ret
    return ret

ans_len = dp(N)

N_tmp = N
ans = ''
for i in range(ans_len):
    for j, Aj in enumerate(A):
        if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):
            ans += str(Aj)
            N_tmp -= tab[Aj]
            break

print(ans)
# C - Sqrt Inequality
a,b,c = map(int,input().split())
rta,rtb,rtc = map(math.sqrt,[a,b,c])

if rta + rtb < rtc:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

# C - Sqrt Inequality
import decimal
a,b,c = input().split()
a,b,c = map(decimal.Decimal,[a,b,c])
sqrt = decimal.Decimal(0.5)
if a**sqrt + b**sqrt < c**sqrt:
    print('Yes')
else:
    print('No')
s = input()
for i in range(len()s):
  if i % 2 == 0 && s[i] == "R":
    print("No")
    exit()
  elif i % 2 == 1 %% s[i] == "L":
    print("No")
    exit()
print("Yes")

### FIXED CODE ###

s = input()
for i in range(len(s)):
  if i % 2 == 0 and s[i] == "L":
    print("No")
    exit()
  elif i % 2 == 1 and s[i] == "R":
    print("No")
    exit()
print("Yes")
n=int(input())
d=[]
for i in range(n):
    d.append(int(input()))
ans=0
for l in range(n):
    for i in range(l+1,n):
        ans+=d[l]*d[i]
print(ans)


### FIXED CODE ###

n=int(input())
d=[]
"""for i in range(n):
    d.append(int(input()))
"""
d=list(map(int,input().split()))

ans=0
for l in range(n):
    for i in range(l+1,n):
        ans+=d[l]*d[i]
print(ans)
H, W, A, B = map(int, input().split())
if H==1:
    print("".join(map(str,[1]*A+[0]*(W-A))))
elif W==1:
    for i in [1]*B+[0]*(H-B):
        print(i)
elif W%A==0 and H%B==0:
    a, b = 0, 0
    l = [[0]*W for _ in range(H)]
    while B*b<H and A*a<W:
        for i in range(A):
            for j in range(B):
                l[A*a+i][B*b+j] = 1
        a += 1
        b += 1
    for i in l:
        print("".join(map(str,i)))
else:
    print("No")

### FIXED CODE ###

H, W, A, B = map(int, input().split())
l = [[0]*W for _ in range(H)]

for i in range(B):
    for j in range(A):
        l[i][j] = 1

for i in range(B, H):
    for j in range(A, W):
        l[i][j] = 1

for i in l:
    print("".join(map(str, i)))
a=int(input())
b=list(input())
c=0
for i in range(a):
  if b[i]=='A' and b[i+1]=='B' and b[i+2]=='c':
    c+=1
  
print(c)    


### FIXED CODE ###

n=int(input())
s=list(input())
d=0
for i in range(n):
  if n-(i+1)>=2:
    if s[i]=='A' and s[i+1]=='B' and s[i+2]=='C':
      d+=1
  else:
    pass
print(d)
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import collections
N = int(input())
A = list(map(int, input().split()))
cA = collections.Counter(A)

LIM = 10 ** 6 + 1
# LIM = 25

A.sort()
dp = [1] * LIM

for i in set(A):
    s = i * 2
    while s <= LIM:
        dp[s] = 0
        s += i

ans = 0
# print(dp)
for a in A:
    # print("{} {}".format(dp[a], cA[a]))
    if dp[a] and cA[a] == 1:
        print(a)
        ans += 1
print(ans)

### FIXED CODE ###

import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import collections
N = int(input())
A = list(map(int, input().split()))
cA = collections.Counter(A)

LIM = 10 ** 6 + 1
# LIM = 25

A.sort()
dp = [1] * LIM

for i in set(A):
    s = i * 2
    while s < LIM:
        dp[s] = 0
        s += i

ans = 0
# print(dp)
for a in A:
    # print("{} {}".format(dp[a], cA[a]))
    if dp[a] and cA[a] == 1:
        # print(a)
        ans += 1
print(ans)
print(int(input)* 22/7)

### FIXED CODE ###

r = int(input())
print( 2* 22/7 * r)
import math
r = input().split()
t = int(r[0])
a = math.pi * t**2
b = 2 * t * math.pi
print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b))

### FIXED CODE ###

Input = float(input())
Area = Input**2*3.141592653589
Circumference = Input*2*3.141592653589
print('{0:.6f} {1:.6f}'.format(Area,Circumference))
import math

def a(xs, m):
    k = xs.index(m) + 1
    ops = []
    a = xs[0];
    for i in range(1, len(xs)):
        b = xs[i]
        if a > b:
            d = a - b
            n = int(math.ceil(d / float(m)))
            d2 = m - b
            n2 = int(math.ceil(d2 / float(m)))
            if n2 > 0 and n2 < n:
                b += n2 * m
                ops.append((k, i + 1, n2))
                k = i + 2
                m = b
                d = b - a
                n = int(math.ceil(d / float(m)))
            b += n * m
            ops.append((k, i + 1, n))
        a = b
    return ops

def b(xs, m):
    k = xs.index(m) + 1
    ops = []
    a = xs[-1]
    for i in range(len(xs) - 2, -1, -1):
        b = xs[i]
        if a < b:
            d = a - b
            n = int(math.ceil(d / float(m)))
            d2 = m - b
            n2 = int(math.ceil(d2 / float(m)))
            if n2 > 0 and n2 < n:
                b += n2 * m
                ops.append(k, i, n2)
                k = i + 1
                m = b
                d = a - b
                n = int(math.ceil(d / float(m)))
            b += n * m
            ops.append((k, i, n))
        a = b
    return ops

n = input()
xs = map(int, raw_input().split())
M = max(xs)
m = min(xs)
if M > 0 and m >= 0:
    ops = a(xs, M)
elif M <= 0 and m < 0:
    ops = b(xs, m)
else:
    ops1 = a(xs, M)
    ops2 = b(xs, m)
    if len(ops1) <= len(ops2):
        ops = ops1
    else:
        ops = ops2
c = 0
for _, _, n in ops: c += n
print c
for a, b, n in ops:
    for _ in range(n):
        print a, b


### FIXED CODE ###

def a(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x > m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] < 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 1):
        if xs[i] > xs[i + 1]:
            xs[i + 1] += xs[i]
            ops.append((i, i + 1))
    return ops

def b(xs):
    k = 0
    m = 0
    ops = []
    for i, x in enumerate(xs):
        if x < m:
            k = i
            m = x
    for i, x in enumerate(xs):
        if xs[i] > 0:
            xs[i] += m
            ops.append((k, i))
    for i in range(len(xs) - 2, -1, -1):
        if xs[i] > xs[i + 1]:
            xs[i] += xs[i + 1]
            ops.append((i + 1, i))
    return ops
            
n = input()
xs = map(int, raw_input().split())
m = min(xs)
M = max(xs)
if abs(M) >= abs(m):
    ops = a(xs)
else:
    ops = b(xs)
print len(ops)
for a, b in ops:
    print a + 1, b + 1
a,b,x=map(int,input().split())
B=b//x
A=a//x

print(B-A+not(a%x))

### FIXED CODE ###

a,b,x=map(int,input().split())
B=b//x
A=a//x

print(B-A+ (a%x == 0))
n=int(input())
x=int(input())
print(1000*x-n)


### FIXED CODE ###

n=int(input())
a=n%1000
if a==0:
    print(0)
else:
    print(1000-a)
a, b = map(int, input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
n = gcd(a, b)

def cd(num):
    k = []
    if num%2 == 0:
        if is_prime(2):
    for i in range(1,num+1,2):
        if num%i == 0:
            if is_prime(i):
                k.append(i) 
    return k

def is_prime(num):
    for i in range(2, num):
        if num % i == 0:
            return False
    return True


gc = gcd(a,b)
c = cd(gc)

print(len(c))

### FIXED CODE ###

def f(n):
    res = set()
    for i in range(2, int(n ** 0.5)):
        if n % i: continue
        while not n % i: n //= i
        res.add(i)
    return res | {n}
 
a, b = map(int,input().split())
print(len(f(a) & f(b) | {1}))
n,*a = map(int,open(0).read().split())
a = [a[i] -i -1 for i in range(n)]
a.sort()
if n % 2 == 0:
  b = a[n//2]
  c = b + 1
else:
  b = (a[n//2]+a[n//2+1])//2
  c = b + 2
ans = min([sum([abs(i - j) for i in a]) for j in range(b,c)])
print(ans)

### FIXED CODE ###

n,*a = map(int,open(0).read().split())
a = sorted([a[i] -i for i in range(n)])
print(sum([abs(i - a[n//2]) for i in a]))
A,B= [int(x) for x in input()]

if A <= 5:
    print(0)
elif 6<= a <= 12:
    print(int(B/2))
else:
    print(B)




### FIXED CODE ###

A,B= [int(x) for x in input().split()]

if A <= 5:
    print(0)
elif 6<= A <= 12:
    print(int(B/2))
else:
    print(B)
n = int(input())
s = input()
count = 0
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "B" and s[i+2] =="C":
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
s = input()
count = 0
for i in range(len(list(s))-2):
  if s[i] == "A" and s[i+1] == "B" and s[i+2] =="C":
    count += 1
print(count)
import sys

s = list(input())
t = list(input())

for i in range(len(t)):
    if t[i] not in s:
        print(-1)
        sys.exit()

i = 0
n = 0
for i in range(len(s)):
    if len(s) == i + n + 1:
        break
    
    if s[i] not in t:
        s.pop(i)
        n += 1

count = 0
for j in range(10000000000):
    for k in range(len(s)):
        if count == len(t):
            print(k +  (j * len(s)) + n * (j + 1))
            sys.exit()
            
        #print(a[k +  (j * len(s))], t[count],a, count)
        if s[k] == t[count]:
            count += 1

### FIXED CODE ###

s = input()
t = input()
t_length = len(t)

temp = s[:]
count = 0
ans = 0

for i in range(len(t)):
    a = s.find(t[i])
    if a == -1:
        print(-1)
        exit()

while count < t_length:
    value = temp.find(t[count])
    if value == -1:
        ans += len(temp)
        temp = s[:]
    
    else:
        ans += value + 1
        count += 1
        temp = temp[value + 1:]

print(ans)
N = int(input())

ans = 0
for i in range(2, int(N**0.5)+1):
    cnt = 0
    while N%i == 0:
        N /= i
        cnt += 1
 
    a = 0
    b = 0
    for j in range(1, cnt+1):
        a += j
        if a > cnt:
            break
        b += 1
        
    ans += b

print(0  N == 1 else 1 if ans==0 else ans)

### FIXED CODE ###

from collections import Counter

N = int(input())

def prime(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

c = Counter(prime(N))

ans = 0
for i in c.values():
    if i > 0:
        a = 0
        b = 0
        for j in range(1, i+1):
            a += j
            if a > i:
                break
            b += 1    
        ans += b

print(ans)
N = int(input())
ans = [int(a) for i, a in enumerate(input().split()) if i%2 == 0 and if a%2==1]

print(len(ans))

### FIXED CODE ###

N = int(input())
a = [int(a) for i, a in enumerate(input().split()) if i%2 == 0]
ans = [i for i in a if i%2==1]
print(len(ans))
s = input()
t = input()

if len(s) + 1 == len(t) and s in t:
    print("YES")
    else:
    print("NO")

### FIXED CODE ###

s = input()
t = input()
 
if t[:len(t)-1] == s:
    print("Yes")
else:
    print("No")
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
from functools import lru_cache
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]


N = I()
A = LI()
t = [0, 0, 0]
for a in A:
    t[a-1] += 1
A, B, C = t

dp = [[[0]*(N+1) for i in range(N+1)] for j in range(N+1)]

for k in range(N+1):
    for j in range(N+1):
        for i in range(N+1):
            if (i==0) and (j==0) and (k==0):
                continue
            dp[i][j][k] += N/(i+j+k)
            d = dp[i][j][k]
            if (i<N):
                dp[i+1][j][k] += (i+1)*d/(i+1+j+k)
            if (i>0) and (j<N):
                dp[i-1][j+1][k] += (j+1)*d/(i+j+k)
            if (j>0) and (k<N):
                dp[i][j-1][k+1] += (k+1)*d/(i+j+k)

print(dp[A][B][C])



"""

### FIXED CODE ###

import sys

def I(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (i+j==0) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (i+E+k==0) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0) and (j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0) and (k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

if __name__ == "__main__":
    main()
word = input()
text = []
c = 0
while True:
    read = input().lower().split()
    if read[0] == 'end_of_text':
        break
    else:
        text.append(read)
for i in text:
    for n in i:
        if word in ne:
            c += 1
print(c)

### FIXED CODE ###

word = input().lower()
text = []
c = 0
while True:
    read = input().split()
    if read[0] == 'END_OF_TEXT':
        break
    else:
        text.append(read)
for i in text:
    for n in i:
        if word == n.lower():
            c += 1
print(c)
a,b,c=map(int,input().rstrip().split(' '))
if(a==b and b==c):
	if(a%2==0):
    	print(-1)
	else:
		print(0)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
		tmp_a=(b+c)/2
		tmp_b=(a+c)/2
		tmp_c=(b+a)/2
		a=tmp_a
		b=tmp_b
		c=tmp_c
	print(n)


### FIXED CODE ###

a,b,c=map(int,input().rstrip().split(' '))
if(a==b and b==c):
	if(a%2==0):
		print(-1)
	else:
		print(0)
else:
	n=0
	while(a%2==0 and b%2==0 and c%2==0):
		n+=1
		tmp_a=(b+c)/2
		tmp_b=(a+c)/2
		tmp_c=(b+a)/2
		a=tmp_a
		b=tmp_b
		c=tmp_c
	print(n)
N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>=K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>=K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[num])

### FIXED CODE ###

N,K = map(int, input().split())
A =[0]
B=list(map(int, input().split()))
for m in range(N):
    A.append(B[m])
place=set([])
p=[]
i=1
count=0
while i not in place:
    place.add(i)
    p.append(i)
    i=A[i]
    count+=1
if count>K:
    print(p[K])
else:
    loop=[i]
    start=i
    j=A[i]
    count+=1
    while j!=start:
        loop.append(j)
        j=A[j]
        count+=1
    if count>K:
        print(loop[K-len(p)])
    else:
        num=(K-count)%len(loop)
        print(loop[num])
#-*- coding: utf-8 -*-
print(['No', 'Yes'][input().count('9')])


### FIXED CODE ###

#-*- coding: utf-8 -*-
print(['No', 'Yes']['9' in input()])
import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=np.int64)

#
ans =0
if 0 in A:
    ans =0:
else:
    ans =np.prod(A)
    if ans >10**18:
        ans =-1
print(ans)

### FIXED CODE ###

# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans =1
if 0 in A:
    ans =0
else:
    for i in A:
        ans *=i
        if 10**18 < ans :
            ans = -1
            break
print(ans)
N, M = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)

B = []
for i in range(M):
    b, c = map(int, input().split())
    B.append([b, c])

B.sort(key=lambda x:(-x[1]))
cnt = 0
ans = []
a = 0
b = 0
while cnt <=  N:
    if A[a] <= B[b][1]:
        for k in range(B[b][0]):
            ans.append(B[b][1])
            cnt += 1
        b += 1
    else:
        ans.append(A[a])
        cnt += 1
        a += 1
print(sum(ans[:N])) 

### FIXED CODE ###

N, M = map(int, input().split())

A = sorted(list(map(int, input().split())), reverse=True)

B = []
for i in range(M):
    b, c = map(int, input().split())
    B.append([b, c])

B.sort(key=lambda x:(-x[1]))

cnt = 0
ans = 0
a = 0
b = 0
while True:
    if b <= M-1 and A[a] <= B[b][1]:
        n = min(B[b][0], N-cnt)
        ans += B[b][1]*n
        cnt += n
        if cnt == N:
            print(ans)
            break
        b += 1
    elif a <= N-1:
        cnt += 1
        ans += A[a]
        if cnt == N:
            print(ans)
            break
        a += 1