Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys

def main():
    N,*S = map(int, open(0).read().split())
    S = sorted(S)

    g = [S.pop(-1)]

    for _ in range(N):
        lg = len(g)
        for p in g[:lg]:
            for i in range(len(S)-1,-1,-1):
                s = S[i]
                if s != -1 and p > s:
                    g.append(s)
                    S[i] = -1
                    break
            else:
                print('No')
                sys.exit()
        g.sort(reverse=True)
    print('Yes')

if __name__=='__main__':
    main()

### FIXED CODE ###

## 他の方と処理内容がほぼ同じなのに何でTLEになるか分からないので、他の方のコードでテスト
N = int(input())
a = list(map(int,input().split(' ')))
a.sort()
    

fathers = [a.pop()]
for _ in range(N):
    sons = list()
    b = list()
    
    for father in fathers:
        while a:
            x = a.pop()
            if father > x:
                sons.append(x)
                break
            else:
                b.append(x)
                
    a = a + b[::-1]
    fathers.extend(sons)
    fathers.sort(reverse = True)
    
    
    
if len(fathers) == 2**N:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = [k for k,v in h_count.items() if v == max_h]
max_w_list = [k for k,v in w_count.items() if v == max_w]

for h in max_h_list:
    for w in max_w_list:
        if [h, w] not in hw:
            print(ans)
            sys.exit()
print(ans - 1)

### FIXED CODE ###

H, W, M = map(int, input().split())
hw = [list(map(int, input().split())) for _ in range(M)]

h_count = {}
w_count = {}
for h,w in hw:
    if h in h_count:
        h_count[h] += 1
    else:
        h_count[h] = 1
    if w in w_count:
        w_count[w] += 1
    else:
        w_count[w] = 1

max_h = max(h_count.values())
max_w = max(w_count.values())
ans = max_h + max_w

max_h_list = set([k for k,v in h_count.items() if v == max_h])
max_w_list = set([k for k,v in w_count.items() if v == max_w])

num = 0
for h,w in hw:
    if h in max_h_list and w in max_w_list:
        num += 1

if num < len(max_h_list)*len(max_w_list):
    print(ans)
else:
    print(ans-1)
### BUGGY CODE ###


import math
H, W, A, B = map(int,input().split())
e = 10**9 + 7
def power(a,b):
    if b == 0:
        return 1
    elif b == 1:
        return a % e
    elif b%2 == 0:
        return power(a,b//2)**2 % e
    else:
        return power(a,b//2)**2*a % e
    
M = [1]

for i in range(1,H+W):
    a = M[i-1]*i%e
    M.append(a)
def c(a,b):
    return M[a+b-2]*power(M[a-1],e-2)*power(M[b-1],e-2)%e

T = 0
for i in range(B+1,W+1):
    P = c(H-A,i)
    Q = c(A,W-i+1)
    T = (T + P*Q)
print(T%e)

### FIXED CODE ###

import math
H, W, A, B = map(int,input().split())
e = 10**9 + 7
def power(a,b):
    if b == 0:
        return 1
    elif b == 1:
        return a % e
    elif b%2 == 0:
        return power(a,b//2)**2 % e
    else:
        return power(a,b//2)**2*a % e
    
M = [1]
for i in range(1,H+W):
    a = M[i-1]*i%e
    M.append(a)
N= [0]*(H+W)
N[H+W-1] = power(M[H+W-1], e-2)
for i in range(H+W-2, -1, -1):
    N[i] = N[i+1] * (i+1) % e

def c(a,b):
    return M[a]*N[b]*N[a-b]%e

T = 0
for i in range(W-B):
    P = c(H+W-A-i-2,H-A-1)
    Q = c(A+i-1,i)
    T = (T + P*Q)
print(T%e)
### BUGGY CODE ###

from math import factorial

def modpow(a, n, p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

def cmb(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
ans = modpow(2, n, mod) - 1
ans -= (cmb(n, a) + cmb(n, b))

print(ans % mod)


### FIXED CODE ###

def cmb(n, r, mod):
    numerator = 1
    # n * (n-1) * ... * (n-r+1)
    for i in range(n-r+1, n+1):
        numerator = (i * numerator) % mod
    denominator = 1
    # r * (r-1) * ... * 1
    for i in range(1, r+1):
        denominator = (i * denominator) % mod
    # y^(mod-2) % mod
    fermat = pow(denominator, mod-2, mod)
    return (numerator * fermat) % mod


n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = pow(2, n, mod) - 1
ans -= (cmb(n, a, mod) + cmb(n, b, mod))

print(ans % mod)
### BUGGY CODE ###

K = int(input())
import math
i = 0
l = list(range(K+1))[1:]

for a in l:
    for b in l:
        for c in l:
            i += math.gcd(math.gcd(a,b), c)
print(i)


### FIXED CODE ###

K = int(input())
import math
i = 0
l = list(range(K+1))[1:]

for a in l:
    for b in l:
        for c in l:
            i += math.gcd(math.gcd(a,b), c)
print(i)
### BUGGY CODE ###

N = int(input())
A_lis = [int(input()) for i in range(N)]
a_max = max(A_lis)
for a in A_lis:
  if a == a_max:
    print(sorted(A_lis)[N-2])
  else:
    print(a_max)
  

### FIXED CODE ###

N = int(input())
A_lis = [int(input()) for i in range(N)]
A_lis_sort = sorted(enumerate(A_lis),key = lambda x:x[1])
max_index = A_lis_sort[-1][0] 
for i in range(N):
  if i == max_index:
    print(A_lis_sort[-2][1])
  else:
    print(A_lis_sort[-1][1])
### BUGGY CODE ###

# N分木におけるxの親は、0-indexedのときに、(x - 1) // N
# 一度0-indexedに戻すため、最初に-1したうえで、(x - 1) // Nを繰り返す
# 初めて一致した点が(0-indexedにおける)答えなので、+1して答え

import sys
readline = sys.stdin.readline

N,Q = map(int,readline().split())

def solve():
  for i in range(Q):
    v,w = map(int,readline().split())
    v -= 1
    w -= 1
    while v != w:
      if v > w:
        v = (v - 1) // N
      else:
        w = (w - 1) // N
    print(v + 1)

solve()

### FIXED CODE ###

# N分木におけるxの親は、0-indexedのときに、(x - 1) // N
# 一度0-indexedに戻すため、最初に-1したうえで、(x - 1) // Nを繰り返す
# 初めて一致した点が(0-indexedにおける)答えなので、+1して答え

import sys
readline = sys.stdin.readline

N,Q = map(int,readline().split())

for i in range(Q):
  v,w = map(int,readline().split())
  if N == 1:
    print(min(v,w))
    continue
  v -= 1
  w -= 1
  while v != w:
    if v > w:
      v = (v - 1) // N
    else:
      w = (w - 1) // N
  print(v + 1)
### BUGGY CODE ###

def sf(s,queries):

    is_reversed = 0

    for query in queries:
        addl = []
        addr = []
        if query[0] == '1':
            is_reversed ^= 1
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if is_reversed == 0 and f == '1' or is_reversed == 1 and f == '2':
                addl = [c]
            elif is_reversed == 0 and f == '2' or is_reversed == 1 and f == '1':
                addr = [c]

            s = addl + s + addr

    return ''.join(s) if not is_reversed else ''.join(reversed(s))


if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(sf(s,ql))


### FIXED CODE ###

from collections import deque

def msf(s,queries):
    queue = deque(s)
    addl = queue.appendleft
    addr = queue.append
    is_reversed = 0

    for query in queries:
        if query[0] == '1':
            is_reversed ^= 1
            addl,addr = addr,addl
        elif query[0] == '2':
            f = query[1]
            c = query[2]
            if f == '1':
                addl(c)
            elif f == '2':
                addr(c)
    return ''.join(queue) if not is_reversed else ''.join(reversed(queue))

if __name__ == '__main__':
    s = list(input())
    q = int(input())
    ql = [input().split() for i in range(q)]
    print(msf(s,ql))
### BUGGY CODE ###

def f(n):
  cnt = 0
  for i in range(int(n**1/2 // 1)):
    for j in range(int(((2*n)**1/2-i)//1)):
      for k in range(int(((2*n)**1/2-i)//1)):
        if (i+1)**2 + (j+1)**2 + (k+1)**2 + (i+1)*(j+1) + (j+1)*(k+1) + (k+1)*(i+1) == n:
          cnt += 1
  return cnt
    
N = int(input())
for i in range(N):
  print(f(i+1))

### FIXED CODE ###

n = int(input())
a = [0]*n
cnt = 0
for i in range(1,100):
  for j in range(1,100):
    for k in range(1,100):
      b = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if b <= n:
        a[b-1] += 1

for i in a:
  print(i)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
result=A[0]
x=1
while x<N:
    result=result*A[x]
    x+=1
if result>10**18:
    print(-1)
else:
    print(result)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
sorted(A)
result=1
if 0 in A:
    result=0
for i in A:
    if result==0:
        break
    result*=i
    if result>1000000000000000000:
        result=-1
        break

print(result)
### BUGGY CODE ###

from collections import deque

def bfs(count,adj):
    st = deque([(0,-1)])
    while st:
        n,par = st.popleft()
        val = count[n]   
        for node in adj[n]:
            if node == par:
                continue
            else:
                count[node] += val
                st.append([node,n])
    return count

        
N,Q = map(int, input().split())
A = [[] for i in range(N)]

for _ in range(N-1):
    a,b = map(int, input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

cnt = [0]*N   
for q in range(Q):
   p,x = map(int, input().split())
   cnt[p-1] += x

cnt = bfs(cnt,A)

print(*cnt)

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline
        
N,Q = (int(i) for i in input().split())
A = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = (int(i) for i in input().split())
    A[a-1].append(b-1)
    A[b-1].append(a-1)

cnt = [0]*N   
for q in range(Q):
   p,x = (int(i) for i in input().split())
   cnt[p-1] += x

st = deque([(0,-1)])
while st:
    n,par = st.popleft()
    val = cnt[n]   
    for node in A[n]:
        if node == par:
            continue
        else:
            cnt[node] += val
            st.append([node,n])

print(*cnt)
### BUGGY CODE ###

n,q = map(int, input().split())
s = input()

for i in range(q):
    l,r = map(int, input().split())
    sr = s[l-1:r]
    print(sr.count('AC'))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t=[0]*(N+1)

for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])
### BUGGY CODE ###

def resolve():
    n = int(input())
    am = []

    from collections import deque

    for i in range(n):
        am.append(deque(list(map(lambda x: int(x) - 1, input().split()))))

    cnt = n * (n - 1) // 2

    day = 0
    while cnt > 0:
        day += 1
        match = 0
        blocked = {}
        done = {}
        for i in range(n):
            if i in done:
                continue
            if len(am[i]) == 0:
                continue
            j = am[i][0]
            if j in blocked:
                continue
            if j not in done and am[j][0] == i:
                am[i].popleft()
                am[j].popleft()
                done[i] = 1
                done[j] = 1
                match += 1
            else:
                blocked[i] = 1

            if match == cnt:
                break

        if match == 0:
            print(-1)
            return
        else:
            cnt -= match

    print(day)
    
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    a = []

    for i in range(n):
        row = list(map(lambda x: int(x) - 1, input().split()))
        row.reverse()
        a.append(row)

    q = set()

    def check(i):
        if len(a[i]) == 0:
            return
        j = a[i][-1]
        if i == a[j][-1]:
            p = (i, j) if i < j else (j, i)
            q.add(p)

    for i in range(n):
        check(i)

    day = 0
    while len(q) > 0:
        day += 1
        prev_q, q = q, set()

        for p in prev_q:
            (i, j) = p
            a[i].pop()
            a[j].pop()

        for p in prev_q:
            (i, j) = p
            check(i)
            check(j)

    for i in range(n):
        if len(a[i]) != 0:
            print(-1)
            return
    print(day)
    
resolve()
### BUGGY CODE ###

n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = []
for i in range(n):
    j = i-1
    while (j >= 0):
        m = rlist[i] - rlist[j]
        mlist.append(m)
        j -= 1
mlist.sort()
print(mlist[-1])
        
        



### FIXED CODE ###

n = int(input())
rlist = []
for i in range(n):
    r = int(input())
    rlist.append(r)
mlist = [rlist[1] - rlist[0]]
mini = rlist[0]
for i in range(1,n):
    if(rlist[i-1] < mini):
        mini = rlist[i-1]
    m = rlist[i] - mini
    if(m>mlist[-1]):
        mlist.append(m)
print(mlist[-1])
### BUGGY CODE ###

#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    for i in range(n):
        new_dict = ball_dict.copy()
        new_dict[a[i]] -= 1
        ans = 0
        for v in new_dict.values():
            ans += v * (v - 1) // 2
        print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a_sort = sorted(a)

    ball_dict = {}
    count = 1
    for i in range(1, n):
        if a_sort[i] == a_sort[i - 1]:
            count += 1
        else:
            ball_dict.setdefault(a_sort[i - 1], count)
            count = 1
    ball_dict.setdefault(a_sort[n - 1], count)

    ans = 0
    for v in ball_dict.values():
        ans += v * (v - 1) // 2

    ans_dict = {}
    for v in ball_dict.values():
        if v not in ans_dict:
            ans_dict.setdefault(v, ans - (v - 1))

    for i in range(n):
        print(ans_dict[ball_dict[a[i]]])

if __name__ == '__main__':
    main()
### BUGGY CODE ###

# E - Colorful Blocks
import sys
readline = sys.stdin.readline

MOD = 998244353
N, M, K = map(int, readline().split())

# 予め階乗を計算しておく
f = [1]
for i in range(N):
    f.append(f[i] * (i+1) % MOD)

f_inv = [1] * N
f_inv[N-1] = pow(f[N-1], MOD-2, MOD)
for i in range(N-1)[::-1]:
    f_inv[i] = f_inv[i+1] * (i+1) % MOD

# 組み合わせ関数
def comb_mod(n, r, p):
    return (f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p))%p

ans = 0
for i in range(K+1):
    ans = (ans + (M*pow(M-1, N-1-i, MOD)) * comb_mod(N-1, i, MOD))%MOD

print(ans)


### FIXED CODE ###

# E - Colorful Blocks

MOD = 998244353
N, M, K = map(int, input().split())

# 予め階乗を計算しておく
f = [1]
for i in range(N):
    f.append(f[i]*(i+1)%MOD)

# 組み合わせ関数
def comb_mod(n, r, p):
    return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p)

ans = 0
for i in range(K+1):
    ans = (ans + (M*pow(M-1, N-1-i,MOD)) * comb_mod(N-1, i, MOD))%MOD

print(ans)
### BUGGY CODE ###

# -coding: utf-8 -

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

s = [i for i in range(a,b+1)]
add = "\n"
#print(s)

if len(s) < k*2:
    strs = [str(num) for num in s]
    k = add.join(strs)
else:
    s_left = s[:k]
    s_right = s[-k:]
    s2 = s_left+s_right
    strs = [str(num) for num in s2]
    k = add.join(strs)
print(k)



### FIXED CODE ###

# -coding: utf-8 -

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

s = range(a,b+1)
s_small = s[:k]
s_large = s[-k:]
ans = list(set(s_small)|set(s_large))
ans = sorted(ans)
for i in ans:
    print(i)
### BUGGY CODE ###

# C
n, q = map(int, input().split())
s = input()
ans = []
for i in range(q):
    l, r = map(int, input().split())
    ans.append(s[l-1:r].count('AC'))
    
for v in ans:
    print(v)

### FIXED CODE ###

n, q = map(int, input().split())
s = input()

a = [0]*(n)
for j in range(1, n):
    if s[j-1] == 'A' and s[j] == 'C':
        a[j] += 1
        
csum = [0]*(n+1)
for i in range(n):
    csum[i+1] = csum[i] + a[i]

for i in range(q):
    l, r = map(int, input().split())
    print(csum[r]-csum[l])
### BUGGY CODE ###

from collections import defaultdict
n, m = map(int, input().split())
l = []
dic = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    dic[p].append(y)
    l.append([p, y])
for key, value in dic.items():
    dic[key] = sorted(value)
for p, y in l:
    print(str(p).zfill(6)+str(dic[p].index(y)+1).zfill(6))


### FIXED CODE ###

from collections import defaultdict
n, m = map(int, input().split())
l = []
dic = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    dic[p].append(y)
    l.append([p, y])
for key, value in dic.items():
    dic[key] = {num: index+1 for index,num in enumerate(sorted(value))}
for p, y in l:
    print(str(p).zfill(6)+str(dic[p][y]).zfill(6))
### BUGGY CODE ###

import numpy as np
h,w=map(int,input().split())
INF=10**10
a=[[INF for i in range(w)] for j in range(h)]
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=0
for i in range(h):
    for j in range(w):
        k=a[i][j]+1

        if i!=h-1:
            if k<a[i+1][j]:
                a[i+1][j]=k

        if j!=w-1:
            if k<a[i][j+1]:
                a[i][j+1]=k

for i_ in range(h):
    for j_ in range(w):
        i=h-1-i_
        j=w-1-j_
        k=a[i][j]+1
        if i!=0:
            if k<a[i-1][j]:
                a[i-1][j]=k

        if j!=0:        
            if k<a[i][j-1]:
                a[i][j-1]=k


arr=np.array(a)
ans=arr.max()
print(ans)

### FIXED CODE ###

h,w=map(int,input().split())
INF=10**10
a=[[INF for i in range(w)] for j in range(h)]
ans=0
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            a[i][j]=0
            
for i in range(h):
    for j in range(w):
        k=a[i][j]+1

        if i!=h-1:
            if k<a[i+1][j]:
                a[i+1][j]=k
        if j!=w-1:
            if k<a[i][j+1]:
                a[i][j+1]=k

for i in range(h):
    for j in range(w):
        k=a[-1-i][-1-j]+1
        if i!=h-1:
            if k<a[-i-2][-j-1]:
                a[-i-2][-j-1]=k

        if j!=w-1:        
            if k<a[-i-1][-j-2]:
                a[-i-1][-j-2]=k

for i in range(h):
    ans=max(ans,max(a[i]))
print(ans)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

def main():
    n = int(input())

    def calc_idx(x, y):
        if x > y:
            x, y = y, x
        return x + y*(y-1)//2

    # create graphs & calc indegree
    n_game = n * (n-1) // 2
    edge = [[] for i in range(n_game)]
    indegree = [0] * n_game
    for i in range(n):
        ai = list(map(lambda x: int(x)-1, input().split()))

        for j in range(1, n-1):
            g1 = calc_idx(i, ai[j-1])
            g2 = calc_idx(i, ai[j])
            edge[g1].append(g2)
            indegree[g2] += 1


    ans = 0
    cand = deque([(i, 1) for i in range(n_game) if indegree[i] == 0])
    n_ts = 0
    while len(cand) > 0:
        u, day = cand.popleft()
        ans = max(ans, day)
        n_ts += 1
        for v in edge[u]:
            indegree[v] -= 1
            if indegree[v] == 0:
                cand.append((v, day+1))

    if n_ts != n_game:
        ans = -1

    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline

n = int(input())
a = [list(map(lambda x: int(x)-1, input().split())) for _ in range(n)]

def calc_idx(x, y):
    if x > y:
        x, y = y, x
    return x + y*(y-1)//2

n_game = n * (n-1) // 2
edge = [[] for i in range(n_game)]
for i in range(n):
    for j in range(1, n-1):
        g1 = calc_idx(i, a[i][j-1])
        g2 = calc_idx(i, a[i][j])
        edge[g1].append(g2)

indegree = [0] * n_game
for i in range(n_game):
    for v in edge[i]:
        indegree[v] += 1

ans = 0
cand = [i for i in range(n_game) if indegree[i] == 0]
ts = []
while cand:
    ts.extend(cand)
    cand2 = []
    for ci in cand:
        for v in edge[ci]:
            indegree[v] -= 1
            if indegree[v] == 0:
                cand2.append(v)
    cand = cand2
    ans += 1

if len(ts) != n_game:
    ans = -1

print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
flag = True
while(flag):
    count = 0
    A_2 = list(itertools.combinations(A,2))
    for comb in A_2:
        diff = abs(comb[0] - comb[1])
        if diff not in A:
            A.append(diff)
        else:
            count += 1
    else:
        if (count == len(A_2)):
            flag = False
if K in A:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')



### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
import fractions
import functools
gcd = functools.reduce(fractions.gcd, A)
A_max = max(A)
if (A_max >= K and K % gcd == 0):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n = ii()
a = li()
aco = a
aco = list(set(aco))
lis = [0]*(10**3)
rootn = 10**3
for i in range(len(aco)):
    for nm in range(2,rootn):
        if aco[i] % nm != 0:
            continue
        ima = 0
        while(aco[i]%nm == 0):
            ima += 1
            aco[i] = aco[i] //nm
        lis[nm] = max(lis[nm],ima)
aco = list(set(aco))
mod = 10**9 + 7
gcd = 1
for i in range(2,rootn):
    gcd *= (i ** lis[i]) % mod
for i in range(len(aco)):
    gcd *= aco[i] % mod

ans = 0
for i in range(n):
    ans += pow(a[i],mod-2,mod) * gcd % mod
print(ans% mod)
    




### FIXED CODE ###

P = 10**9 + 7
N = 1000001
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n = int(input())
lili = list(map(int,input().split()))
import copy
lili2 = copy.copy(lili)
#a>b
inin = 1
lili = list(set(lili))
for i in range(2,10 ** 3+2):
    count = 0
    for j in range(len(lili)):
        if lili[j] % i != 0: continue
        now = 0
        while (lili[j] % i == 0):
            now += 1
            lili[j] = lili[j] // i
        count = max(count,now)
    inin = inin * (i ** count) % P
lili = list(set(lili))
for i in range(len(lili)):

    inin = inin * lili[i] %P

ans = 0
for i in range(n):
    ans += inin * (pow(lili2[i],P-2,P)) %P
    ans % P
print(ans %P)
### BUGGY CODE ###

import numpy as np


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


    if len(A) > K:
        set_A = set(A)
        
        count = np.empty(len(set_A), dtype=int)
        i = 0
        for s_a in set_A:
            count[i] = A.count(s_a)
            i += 1

        sorted_count = np.sort(count)
        reduce_num = len(set_A) - K
        
        sum_count = 0
        counter = 0
        for c in sorted_count:
            if counter == reduce_num :
                break
            sum_count += c
            counter += 1

        print(sum_count)
    else:
        print(0)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from collections import Counter


def main()->None:
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(Counter(a).values(), reverse=True)
    print(sum(a[k:]))

if __name__ == "__main__":
    main()