Harryxun/stf_run huggingface dataset:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = np.array(lr())
A.sort()
square = A[:, None] + A[None, :]
B = square.flatten()
B.sort()
answer = B[-M:].sum()
print(answer)
# 32

### FIXED CODE ###

import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split())) # applies to numbers only
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
A = np.array(rl())
A.sort()

def shake_cnt(x):
    Y = np.searchsorted(A,x-A)
    return N*N - Y.sum()

right = 10 ** 6
left = 0 #握手するのがM人以上
while right > left + 1:
    mid = (left+right) // 2
    if shake_cnt(mid) >= M:
        left = mid
    else:
        right = mid

X = np.searchsorted(A, right-A) #握手しない人数
Acum = np.zeros(N+1, np.int64)
Acum[1:] = A.cumsum()

shake = N*N - X.sum()
happy = (Acum[-1] - Acum[X]).sum() + (A * (N-X)).sum()
happy += (M-shake) * left
print(happy)
A, B = map(int, input().split())

for i in range(1,1010):
  if (i*0.08//A==1)&(i*0.1//B==1):
    ans = i
    break
    
print(ans)

### FIXED CODE ###

A, B = map(int, input().split())

for i in range(1,1010):
  if (int(i*0.08)==A)&(int(i*0.1)==B):
    print(i)
    break
else:
    print(-1)
s = input()

L = []
cnt = 0

for x in s:
    if x == "A" or x == "C" or x == "G" or x == "T":
        cnt += 1
    else:
        L.append(cnt)
        
max(L)

### FIXED CODE ###

s = list(input())

L = []
cnt = 0

for x in s:
    if x == "A" or x == "C" or x == "G" or x == "T":
        cnt += 1
    else:
        L.append(cnt)
        cnt = 0
L.append(cnt)

print(max(L))
N, M = map(int, input().split())
if N%2:
    for i in range(1, M+1):
        print(1/0)
        print(i, N-i)
else:
    for i in range(1, M+1):
        if i <= -(-(N//2)//2):
            print(i, N-i+1)
        else:
            print(i+1, N-i+1)


### FIXED CODE ###

N, M = map(int, input().split())
if N%2:
    for i in range(1, M+1):
        print(i, N-i)
else:
    if M%2:
        for i in range(1, M+1):
            if i <= -(-(N//2)//2):
                print(i, N-i+1)
            else:
                print(i+1, N-i+1)
    else:
        for i in range(1, M+1):
            if i < -(-(N//2)//2):
                print(i, N-i+1)
            else:
                print(i+1, N-i+1)
x = input()
happy500 = (x % 500) * 1000
happy5(500 - (x % 500) * x) % 5 * 5
print(happy500 + happy5)

### FIXED CODE ###

x = int(input())
happy500 = (x // 500) * 1000
happy5 = ((x % 500) // 5) * 5
print(happy500 + happy5)
a,b=map(int,imput().split())
print("Even" if a*b==0 else "Odd")

### FIXED CODE ###

a, b = map(int, input().split())
print("Even" if a*b % 2 == 0 else "Odd")
def calc_range_num(h,height,max_height,ans):#各階層にいくつ区間があるか
    for i in range(len(h)):
        if h[i]>=height and height != 0:
            if i+1<len(h) and h[i]>h[i+1] and h[i+1] <=height:
            #基本的には、高さが下がったところでインクリメント
                ans+=1
            elif i==len(h)-1 and h[i]>height:
                ans+=1
    height+=1
    if height>max_height:
        return ans
    else:
        ans = calc_range_num(h,height,max_height,ans)
    return ans
            
N = int(input())
h = list(map(int, input().split()))
max_height=max(h)
ans=0
print(calc_range_num(h,1,max_height,ans))

### FIXED CODE ###

AB,BC,CA = map(int, input().split())
print(int(AB*BC/2))
# -*- coding: utf-8 -*-
import sys


def main():
    N,M = list(map(int, sys.stdin.readline().split()))
    AB_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(M) ]


    edge = {}
    # { int : set }
    # { the number of human : {friends} }

    for a,b in AB_list:
        edge.setdefault(a, set())
        edge[a].add(b)

        edge.setdefault(b, set())
        edge[b].add(a)
    

    visited = [None] + [0]*N
    #  0: not visited,  1:visited

    max_relation = 0

    for i in range(1, N+1):
        if visited[i] == 0:
            visited[i] = 1
            ret = dfs(edge, visited, i)
            max_relation = max(max_relation, ret)
    
    
    print( max_relation )


def dfs(edge, visited, num):
    res =[]

    if num in edge:
        for next_node in edge[num]:
            if visited[next_node] == 0:
                visited[next_node] = 1
                
                d = dfs(edge, visited, next_node)
                res.append(d)


    if res:
        return 1 + sum(res)
    else:
        return 1


if __name__ == "__main__":
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from collections import Counter


def main():
    N,M = list(map(int, sys.stdin.readline().split()))
    AB_list = [ list(map(int, sys.stdin.readline().split())) for _ in range(M) ]


    ##############################
    # Union Find
    parents = [-1] * (N + 1)

    def find(x :int) -> int:
        if parents[x] < 0:
            return x
        
        parents[x] = find( parents[x] )
        return parents[x]

    def union(x,y):
        root_x = find(x)
        root_y = find(y)

        if root_x == root_y:
            return
        
        depth_x = parents[root_x]
        depth_y = parents[root_y]

        if depth_x <= depth_y:
            parents[root_y] = root_x

            if depth_x == depth_y:
                parents[root_x] -= 1

        else:
            parents[root_x] = root_y
    ##############################


    for a,b in AB_list:
        union(a,b)
    
    group = [ find(num) for num in range(1,N+1) ]
    cnt = Counter(group)
    
    print(cnt.most_common(1)[0][1])


if __name__ == "__main__":
    main()
N, K = int(input()), int(input())
P = [int(v) for v in input().split()]

print(sum(sorted(P)[:K]))

### FIXED CODE ###

N, K = [int(v) for v in input().split()]
P = [int(v) for v in input().split()]

print(sum(sorted(P)[:K]))
n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(0,n.2):
  if a[i] % 2 == 1:
    count += 1
print(count)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
count = 0
for i in range(0,n,2):
  if a[i] % 2 == 1:
    count += 1
print(count)
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)

r1,c1,r2,c2=map(int,input().split())
n1=r2+c2+2
n2=r2+c1+1
n3=r1+c2+1
n4=r1+c1
l=[r2+1,r2+1,r1,r1]
p=10**9+7
buf=1
cnt=0
l=[0]*(10**6+10)
l2=[0]*20
inv=[0]*(10**6+10)
l[1]=1
for i in range(2,n1+3,1):#n1+1
    l[i]=(l[i-1]*i)%p
l2[1]=1
for i in range(2,10,1):
    l2[i]=(l2[i-1]*i)%p
#print(l2)
print((((l[n1]*modinv(l[r2+1],p)*modinv(l[n1-r2-1],p))%p)-(l[n2]*modinv(l[r2+1],p)*modinv(l[n2-r2-1],p))-(l[n3]*modinv(l[r1],p)*modinv(l[n3-r1],p))+(l[n4]*modinv(l[r1],p)*modinv(l[n4-r1],p)))%p)

### FIXED CODE ###

import sys
sys.setrecursionlimit(500*500)
def modpow(a,n,p):
    if n==0:
        return 1
    x=modpow(a,n//2,p)
    x=(x*x)%p
    if (n%2)==1:
        x=(x*a)%p
    return x%p
def modinv(a,p):
    return modpow(a,p-2,p)

r1,c1,r2,c2=map(int,input().split())
n1=r2+c2+2
n2=r2+c1+1
n3=r1+c2+1
n4=r1+c1
l=[r2+1,r2+1,r1,r1]
p=10**9+7
buf=1
cnt=0
l=[0]*(10**7+10)
inv=[0]*(10**7+10)
l[1]=1
for i in range(2,n1+3,1):#n1+1
    l[i]=(l[i-1]*i)%p
print((((l[n1]*modinv(l[r2+1],p)*modinv(l[n1-r2-1],p))%p)-(l[n2]*modinv(l[r2+1],p)*modinv(l[n2-r2-1],p))-(l[n3]*modinv(l[r1],p)*modinv(l[n3-r1],p))+(l[n4]*modinv(l[r1],p)*modinv(l[n4-r1],p)))%p)
while True:
  data = input().split()
  a = int(data[0])
  op = data[1]
  b=int(data[2])
  
  if op=='0':
    break
  
  if  op=='+':
    print("{:d}".format(a+b))
  elif op=='-':
    print("{:d}".format(a-b))
  elif op=='/':
    print("{:d}".format(a/b))
  elif op=="*":
    print("{:d}".format(a*b))


### FIXED CODE ###

while True:
  a,op,b = input().split()
  a=int(a)
  op=str(op)
  b=int(b)
  
  if op=='?':
    break
  elif  op=='+':
    print("{:d}".format(a+b))
  elif op=='-':
    print("{:d}".format(a-b))
  elif op=='/':
    print("{:d}".format(a//b))
  elif op=="*":
    print("{:d}".format(a*b))
a,b,c=int(input().split)
if a+b+c>21:
    print("bust")
else print("win")


### FIXED CODE ###

print('bust'if sum(map(int,input().split()))>=22else 'win')
import math

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

n = int(input())
print(make_divisors(math.factorial(n)) % (pow(10,9) + 7))

### FIXED CODE ###

import math
import collections

def trial_division(n):
    #素因数を格納するリスト
    factor = []
    #2から√n以下の数字で割っていく
    tmp = int(math.sqrt(n)) + 1
    for num in range(2,tmp):
        while n % num == 0:
            n //= num
            factor.append(num)
    #リストが空ならそれは素数
    factor.append(n)
    return factor

n = int(input())
c = collections.Counter([])
for num in range(2, n+1):
  prime_list = trial_division(num)
  c.update(prime_list)
res = 1
for prime, count in c.most_common():
  if(prime > 1):
    res = res * (count + 1)
print(res % (pow(10,9) + 7))
import sys
import functools
sys.setrecursionlimit(100000000)
n = input()


@functools.lru_cache(None)
def doit(index: int, carry: int) -> int:
    if index >= len(n):
        return 0 if carry == 0 else 2
    d = int(n[index])
    if carry > 0:
        return min(10 - d + doit(index + 1, 0), 9 - d + doit(index + 1, 1))
    else:
        return min(d + doit(index + 1, 0), d + 1 + doit(index + 1, 1))


print(min(doit(0, 0), 1 + doit(0, 1)))


### FIXED CODE ###

import sys
import functools
# sys.setrecursionlimit(100000000)
n = input()
# import random
# n = ''.join(str(random.randint(1,9)) for _ in range(10**6))

#
# @functools.lru_cache(None)
# def doit(index: int, carry: int) -> int:
#     if index >= len(n):
#         return 0 if carry == 0 else 2
#     d = int(n[index])
#     if carry > 0:
#         return min(10 - d + doit(index + 1, 0), 9 - d + doit(index + 1, 1))
#     else:
#         return min(d + doit(index + 1, 0), d + 1 + doit(index + 1, 1))
#
#
# print(min(doit(0, 0), 1 + doit(0, 1)))


dp = [0, 2]
for d in reversed(n):
    d = int(d)
    dp = [min(d + dp[0], d + 1 + dp[1]), min(10 - d + dp[0], 9 - d + dp[1])]

print(min(dp[0], 1 + dp[1]))
A,B=map(int,input().split())
res=-(-B//A)
print(res)

### FIXED CODE ###

import sys
read=sys.stdin.buffer.read
S,T=map(iter,read().split())
cnt=0
for s,t in zip(S,T):
  if s==t:
    cnt+=1
print(cnt)
r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
d_a=[1]*A
d_b=[0]*B
d_c=[-1]*C
d=d_a+d_b+d_c
if K>A+B+C:
    print(A-B)
else:
    ans=0
    for i in range(K):
        ans+=d[i]
    print(ans)

### FIXED CODE ###

r=input().split()
A=int(r[0])
B=int(r[1])
C=int(r[2])
K=int(r[3])
if K<=A:
    print(K)
elif K<=A+B:
    print(A)
else:
    print(2*A-K+B)
n, d = map(int, input().split())
lst = []
for _ in range(n):
  x = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist += (lst[i][k] - lst[j][k])**2
    j = 1
    while j**2 <= dist:
      if j**2 == dist:
        ans += 1
        break
      j += 1
print(ans)

### FIXED CODE ###

n, d = map(int, input().split())
lst = []
for _ in range(n):
  x = list(map(int, input().split()))
  lst.append(x)
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = 0
    for k in range(d):
      dist += (lst[i][k] - lst[j][k])**2
    j = 1
    while j**2 <= dist:
      if j**2 == dist:
        ans += 1
        break
      j += 1
print(ans)
import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
    A = list(set(A))
    N2 = len(A) + 1
  else:
    # N = 3
    # A = [7,6,8]
    # N = 3
    # A = [12,15,18]
    N = 3
    N2 = 2
    A = [1,1000000000,1000000000]

  x = 0
  for i in range(N2):
    if N == 1:
      tmp  = 1000000000
    elif N2 == 2 :
      tmp = A[i]
      # tmp = functools.reduce(fractions.gcd, A[i])
    else:
      tmp = functools.reduce(fractions.gcd, A[0:i]+A[i+1:])
    if tmp > x:
      x = tmp
  
  print(x)
  
main()

### FIXED CODE ###

import functools
import fractions

def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # N = 3
    # A = [7,6,8]
    N = 3
    A = [12,15,18]
    # N = 3
    # A = [1,1000000000,1000000000]

  AL = [0] * N    
  AR = [0] * N
  for i in range(N):
    if i != 0:
      AL[i] = fractions.gcd(AL[i-1],A[i])
    else:
      AL[i] = A[i]
    j = N - i - 1
    if j!= N - 1:
      AR[j] = fractions.gcd(AR[j+1],A[j])
    else:
      AR[j] = A[j]
      
  if 'get_ipython' in globals():   
    print(AL)
    print(AR)
  
  x = 0
  for i in range(N):
    if i == 0:
      tmp = AR[i+1]
    elif i == N - 1:
      tmp = AL[i-1]
    else:
      tmp = fractions.gcd(AL[i-1],AR[i+1])
    if tmp > x: x = tmp
  
  print(x)
    
main()
s = input()
s2 = ''
for c in s:
    if c in ('A','T','C','G'):
        s2 += '1'
    else:
        s2 += '0'

print(s,s2)

tmp = 0
ret = 0
    if c == '1':
        tmp += 1
    else:
        ret = max(ret, tmp)
        tmp = 0
ret = max(ret, tmp)
print(ret)


### FIXED CODE ###

s = input()
s2 = ''
for c in s:
    if c in ('A','T','C','G'):
        s2 += '1'
    else:
        s2 += '0'


tmp = 0
ret = 0
for c in s2:
    if c == '1':
        tmp += 1
    else:
        ret = max(ret, tmp)
        tmp = 0
ret = max(ret, tmp)
print(ret)
import sympy
n = int(input())
a = 0
for j in range(1,n+1):
    a += j * len(sympy.divisors(j))
print(a)

### FIXED CODE ###

n=int(input())
ans=0
for i in range(1,n+1):
  ans+=(i+i*(n//i))*(n//i)//2
print(ans)
a,b,c = map(int, input().split())
  
a=int(a)
b=int(b)
c=int(c)
x=int(x)

x=b//a
  
if x>=c:
  print(c)
else :
  print(x)


### FIXED CODE ###

a,b,c = map(int, input().split())
  
a=int(a)
b=int(b)
c=int(c)

x=b//a
x=int(x)

if x>=c:
  print(c)
else :
  print(x)
s = input()
s.sort()
if s[0]==s[1] and s[2]==s[3]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = [i for i in input()]
s.sort()
if s[0]==s[1] and s[2]==s[3] and len(set(s)) != 1:
  print("Yes")
else:
  print("No")
n = int(input())
s = input()
Alphabet = [q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m]
for j in range(1,n):
  r = 0
  StringL = s[0:j]
  StringR = s[j:n]
  for i in Alphabet:
    if StringL.count(i) == 0:
      pass
    else:
      if StringR.count(i) == 0:
        pass
      else: r = r + 1
print(r)

### FIXED CODE ###

n = int(input())
s = input()
Alphabet = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
h = 0
for j in range(1,n):
    StringL = s[0:j]
    StringR = s[j:n]
    r = 0
    for i in Alphabet:
        if StringL.count(i) == 0:
            pass
        else:
            if StringR.count(i) == 0:
                pass
            else: r = r + 1
        if r > h:
            h = r
print(h)
a, b, c = map(int, input().spulit())
if (a / c) <= b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

d,t,s=map(int,input().split())
if d<=t*s:
    print("Yes")
else:
    print("No")
import math
A,B = map(int,input().split(" "))
print((A * B) // math.gcd(A, B))

### FIXED CODE ###

import fractions
A,B = map(int,input().split(" "))
print(int((A * B) / fractions.gcd(A, B)))
nums = input()
numlist = list(nums.split(' '))

if numlist[0] = "0"
print(1)

elif numlist[1] = "0"
print(2)

elif numlist[2] = "0"
print(3)

elif numlist[3] = "0"
print(4)

elif numlist[4] = "0"
print(5)


### FIXED CODE ###

# coding: utf-8
# Your code here!
x=input().split()



if(x[0]=="0"):
    print(1)
elif(x[1]=="0"):
    print(2)
elif(x[2]=="0"):
    print(3)
elif(x[3]=="0"):
    print(4)
elif(x[4]=="0"):
    print(5)
from collections import Counter
n= int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
pq = []
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0:
      p = -p
      q = -q
    pq.append((p,q))
c = Counter(pq)
print(n-c.most_common()[0][1])

### FIXED CODE ###

n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))
#15rectangle
H,W=(int(i) for i in input().split())
while H!=0 or W!=0:
    for i in range(H-1):
        S=""
        for j in range(W):
            S+="#"
        print(S)
    for j in range(W):
        S+="#"
    print(S, end="")
    H,W=(int(i) for i in input().split())
    if H!=0 or W!=0:
        print("\n")

### FIXED CODE ###

#15rectangle
H,W=(int(i) for i in input().split())
while H!=0 or W!=0:
    for i in range(H-1):
        S=""
        for j in range(W):
            S+="#"
        print(S)
    S=""
    for j in range(W):
        S+="#"
    print(S, end="")
    H,W=(int(i) for i in input().split())
  #  if H!=0 or W!=0:
    print("\n")
n=int(input())
d=li(map(int,input().split())
 
sum=0
for i in range(n-1):
    for l in range(i+1,n):
        sum+=d[i]*d[l]
print(sum)

### FIXED CODE ###

n=int(input())
d=list(map(int,input().split()))
 
sum=0
for i in range(n-1):
    for l in range(i+1,n):
        sum+=d[i]*d[l]
print(sum)
*a=map(int,open(0))
m=max(a)
t=m*3-sum(a)
if t%2==1:t+=3
print(t//2)

### FIXED CODE ###

a,b,c=map(int,input().split())
a,b,c=sorted([a,b,c])

#parity=set(list(map(lambda x: x % 2,[a,b,c])))
parity=list(map(lambda x: x % 2,[a,b,c]))

if len(set(parity))==1:
    print(int((3*max(a,b,c)-a-b-c)/2))
else:
    if (b-a)%2==0:
        ex=1
    else:
        ex=2
    print(int((max(a,b,c)-a)/2)+int((max(a,b,c)-b)/2)+int((max(a,b,c)-c)/2) + ex)
#借り物 テスト
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): 
    for j in range(i+1,n+1):
        dist1=j-i
        dist2=abs(x-i)+abs(y-j)+1
        #dist3=abs(y-i)+abs(x-j)+1
        d=min(dist1,dist2) 
        ans[d]+=1 
for i in range(1,n):
    print(ans[i])

### FIXED CODE ###

n,x,y=map(int,input().split())
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
    for j in range(i+1,n+1):
        dist1=j-i
        dist2=abs(x-i)+abs(y-j)+1
        dist3=abs(y-i)+abs(x-j)+1
        d=min(dist1,dist2,dist3) #最短距離は上式により求められる
        ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
    print(ans[i])
import sys
import collections

n, m = map(int, sys.stdin.readline().split())
p = list(range(n))
r = [set([i]) for i in range(n)]


def li_(): return [int(x)-1 for x in sys.stdin.readline().split()]


def find(x):
    if p[x] != x:
        p[i] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    tmp = r[y]
    for i in tmp:
        p[i] = x
    r[x] = r[x] | r[y]
    r[y] = r[x]


flist = [0] * m
elist = [0] * m
for i in range(m):
    flist[i], elist[i] = li_()

flist.reverse()
elist.reverse()

ans = [0] * m
ans[0] = int(n*(n-1)/2)

for i in range(m-1):
    a, b = flist[i], elist[i]
    if find(a) != find(b):
        union(a, b)
    tmp = ans[0]
    c = sorted(collections.Counter(p).values(), reverse=True)
    for j in c:
        if j == 1:
            break
        tmp -= int(j * (j - 1) / 2)
    ans[i + 1] = tmp
    if tmp == 0:
        break

for i in range(m):
    print(ans[m-i-1])


### FIXED CODE ###


import sys
import collections

n, m = map(int, sys.stdin.readline().split())
p = list(range(n))
r = [1] * n


def li_(): return [int(x)-1 for x in sys.stdin.readline().split()]


def find(x):
    global p
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    if y > x:
        x, y = y, x
    p[y] = x
    r[x] += r[y]
    r[y] = r[x]


flist = [0] * m
elist = [0] * m
for i in range(m):
    flist[i], elist[i] = li_()

flist.reverse()
elist.reverse()

ans = [0] * m
ans[0] = int(n*(n-1)/2)

for i in range(m-1):
    a, b = flist[i], elist[i]
    if find(a) != find(b):
        ans[i + 1] = ans[i] - r[find(a)]*r[find(b)]
        union(a, b)
    else:
        ans[i+1] = ans[i]
    if ans[i+1] == 0:
        break

for i in range(m):
    print(ans[m-i-1])
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D))]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    res *= new_l[n]**new_l[n+1]
    res %= 998244353
print(res%998244353)


### FIXED CODE ###

N = int(input())
D = [int(x) for x in input().split()]
new_l = [0 for n in range(max(D)+1)]
for n in range(N):
    new_l[D[n]] += 1
if new_l[0] == 1 and D[0] == 0:
    res = 1
    for n in range(max(D)):
        res *= pow(new_l[n],new_l[n+1],998244353)
    print(res%998244353)
else:
    print(0)
a=int(input())
print(sum(list(map(int,input())))-a)

### FIXED CODE ###

a=int(input())
print(sum(list(map(int,input().split())))-a)
s = input()
if "".join(s.sort()) == "abc":
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s = input()
 
if not s.count("a") == 1:
  print("No")
elif not s.count("b") == 1:
  print("No")
elif not s.count("c") == 1:
  print("No")
else:
  print("Yes")
n = int(input())
a = lsit(map(int,input().split()))

stack = [a[0]]
s = 0
for i in range(1,n):
    if a[i]<stack[-1]:
        s = s + abs(a[i] - stack[-1])
    else:
        stack.append(a[i])
print(s)

### FIXED CODE ###

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

stack = [a[0]]
s = 0
for i in range(1,n):
    if a[i]<stack[-1]:
        s = s + abs(a[i] - stack[-1])
    else:
        stack.append(a[i])
print(s)
n = sorted(list(map(int,input().split())),revese=True)
print(10*n[0]+n[1]+n[2])



### FIXED CODE ###

n = sorted([int(num) for num in input().split()])
print(n[2]*10+n[1]+n[0])
L = [int(x) for x in input().split]
L.sort()
print(L[1] * L[1] / 2)

### FIXED CODE ###

L = [int(x) for x in input().split()]
L.sort()
print(L[1] * L[0] // 2)
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()
tugi = [0]+a
cyclestart = []
town  =1
temp = [town, ]

while True:
    town = tugi[town]
    if town in temp:
        i = temp.index(town)
        notcycle = temp[:i]
        cycle = temp[i:]
        cyclestart.append(town)
        break
    temp.append(town)
k -= len(notcycle)
print(cycle[k%len(cycle)])

### FIXED CODE ###

import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()
tugi = [0]+a
town  =1
route = [0]*n
route[0] = town
used = [False]*n
used[0] = True
for i in range(n):
    town = tugi[town]
    if used[town-1]:
        i = route.index(town)
        notcycle = route[:i]
        cycle = route[i:]
        break
    used[town-1] = True
    route[i+1] = town

for i in range(n):
    if cycle[i] == 0:
        cycle = cycle[:i]
        break

if len(notcycle) >k:
    print(notcycle[k])
else:
    k -= len(notcycle)
    print(cycle[k%len(cycle)])