Problem:
 Score : 300 points    Problem Statement Takahashi has N balls. Initially, an integer A_i is written on the i -th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.      Constraints  1 \leq K \leq N \leq 200000  1 \leq A_i \leq N  All input values are integers.         Input Input is given from Standard Input in the following format:  N  K  A_1  A_2 ... A_N       Output Print the minimum number of balls that Takahashi needs to rewrite the integers on them.        Sample Input 1 5 2
1 1 2 2 5      Sample Output 1 1  For example, if we rewrite the integer on the fifth ball to 2 , there are two different integers written on the balls: 1 and 2 .
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1 .       Sample Input 2 4 4
1 1 2 2      Sample Output 2 0  Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.       Sample Input 3 10 3
5 1 3 2 4 1 1 2 3 4      Sample Output 3 3

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
ans = [0]*(n)
for a in A:
  ans[a-1] += 1
ans.sort(reverse=True)
print(sum(ans[k:]))

Solution (Python):
N,K = map(int, input().split())
a_list = list(map(int, input().split()))
counter_list = [0]*N
for i in a_list:
    counter_list[i-1] += 1

counter_list.sort(reverse=True)

ans = N - sum(counter_list[:K])    

print(ans)

Solution (Python):
import collections as c
n,k = map(int,input().split())
x = list(map(int,input().split()))
y = c.Counter(x)
s = []
for i in y.items():
    s.append([i[1],i[0]])
s.sort()
ans = 0
for i in range(len(s)-k):
    ans += s[i][0]
print(ans)

Solution (Python):
n,k  =map(int, input().split())
A = list(map(int, input().split()))

d = {}
for a in A:
    d[a] = d.get(a, 0) + 1

if len(d) <= k:
    print(0)
else:
    d = sorted(d.values())
    cnt = 0
    for i in range(len(d)-k):
        cnt += d[i]
    print(cnt)

Solution (Python):
N,K=map(int,input().split())
A={}
for i in input().split():
  A[i]=A.get(i,0)+1
A=sorted(A.values())
print(sum(A[0:len(A)-K]))

Solution (Python):
from collections import deque

N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

nums = deque(nums)

while True:
  if nums[0] == 0:
    nums.popleft()
  else:
    break
nums = list(nums)
if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))

dic={}
for i in A:
    if i not in dic.keys():
        dic[i]=1
    else:
        dic[i]+=1
dic=sorted(dic.items(),key=lambda x:x[1],reverse=True)
k=0
ans=0
for key,value in dic:
    if k>=K:
        ans+=value
    k+=1
print(ans)

Solution (Python):

from collections import Counter
import sys
sys.setrecursionlimit(10**6)


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

c = Counter(a)

c = list(c.most_common())

len_c = len(c)


ans = 0
while(len_c-k > 0):
    
    
    
    i, j = c.pop()
    len_c -= 1
    ans += j
print(ans)

Solution (Python):

"""
Created on Wed Sep 23 15:50:08 2020

@author: liang
"""

N, K = map(int,input().split())
d = [0]*N
A = [int(x) for x in input().split()]

for a in A:
    d[a-1] += 1
    
d.sort(reverse=True)

ans = N - sum(d[:K])

print(ans)

Solution (Python):
n,k = map(int,input().split())
A = list(map(int,input().split()))
L = [0] * n
ans = 0

for a in A:
  L[a-1] += 1
L = sorted(L)
for i in range(n-k):
  ans += L[i]

print(ans)

Solution (Python):
n,k = map(int,input().split())
A = list(map(int,input().split()))
D = dict.fromkeys(range(1,n+1),0)
ans = 0
for a in A:
  D[a] += 1
D = sorted(D.items(), key=lambda x:x[1])
for i in range(n-k):
  ans += D[i][1]
print(ans)

Solution (Python):
from collections import Counter as CC

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = CC(A)
C = sorted(B.values())
print(sum(C[:max(0, len(C) - K)]))

Solution (Python):
n, k = map(int, input().split())
alst = list(map(int, input().split()))
alst.sort()
bef = -1
cnt_lst = []
cnt = 0
for a in alst:
  if a == bef:
    cnt += 1
  else:
    cnt_lst.append(cnt)
    cnt = 1
    bef = a
cnt_lst.append(cnt)
ans = 0
l = len(cnt_lst)
cnt_lst.sort()
for i in range(l - k):
  ans += cnt_lst[i]
print(ans)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
s = list(map(int, input().split()))

num = Counter(s)


if len(num) <= k:
    print(0)

else:
    cnt = len(num) - k
    ans = 0
    i = 0
    for v in sorted(num.values()):
        if cnt == i:
            break
        ans += v
        i += 1

    print(ans)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,k = i_map()
    a = i_list()
    dic = {}
    for i in a:
        dic[i] = dic.get(i,0) + 1

    l = len(dic.keys())

    if l <= k:
        print(0)
        exit()
    l = l - k
    ans = 0
    cnt = 0

    for i in sorted(dic.values()):
        ans += i
        cnt += 1
        if cnt == l:
            break
    print(ans)







if __name__=="__main__":
    main()

Solution (Python):
n,k= map(int,input().split())
Xl = list(map(int,input().split()))
from collections import Counter
Xdic = Counter(Xl)
valuelist = sorted(list(Xdic.values()), reverse=True)
print(sum(valuelist[k:]))

Solution (Python):
from collections import Counter

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

L = Counter(A)

ans = N
for a, cnt in L.most_common(K):
  ans -= cnt

print(ans)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = [0]
c = n
d = 1
for i in range(n-1):
    if a[i] == a[i + 1]:
        d += 1
        c -= 1
    else:
        b.append(d)
        d = 1
b.append(d)
b.sort()
for i in range(len(b) - 1):
    b[i+1] += b[i]
print(b[max(0, c-k)])

Solution (Python):
N,K=map(int,input().strip().split())
A=list(map(int,input().strip().split()))

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

dn=sorted(d.items(),key=lambda x:x[1])

if K>=len(d):
    print(0)
else:
    cnt=0
    ans=0
    for n in range(len(dn)):
        ans+=dn[n][1]
        cnt+=1
        if cnt==len(d)-K:
            break
    print(ans)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
A = list(map(int, input().split()))
CA = Counter(A)

kouho = CA.most_common()[::-1]
ans = 0
idx = 0
while idx < len(CA) - k:
    key, val = kouho[idx]
    ans += val
    idx += 1
print(ans)

Solution (Python):
from collections import Counter

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

    unchange = sum(tuple[1] for tuple in Counter(A).most_common(K))
    print(N-unchange)

main()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
ans=0
for i in range(n):
  if a[i] in d: d[a[i]]+=1
  else: d[a[i]]=1
dd = sorted(d.values(), reverse = True)
if len(dd)<=k:
  print(0)
else:
  ans=n
  for i in range(k):
    ans -= dd[i]
  print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
import collections

a=collections.Counter(a)
key=list(a.values())
key.sort()
ans=sum(key[:len(key)-k])
print(ans)

Solution (Python):
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
c=[0]*(n+1)
for i in a:
    c[i]+=1
print(sum(sorted(c)[:-k]))

Solution (Python):
from collections import Counter, deque, defaultdict
n, k = map(int, input().split())
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
    t[x]+=1
B = list(t.values())
B.sort()
if(len(B)<=k):
    print(0)
    exit()

ans = sum(B[:len(B)-k])
print(ans)

Solution (Python):
from collections import Counter, deque, defaultdict
n, k = map(int, input().split())
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
    t[x]+=1
B = []
for x in t.values():
    B.append(x)
B.sort()
if(len(B)<=k):
    print(0)
    exit()
    
ans = 0
for i in range(0, len(B)):
    ans+=B[i]
    if len(B)-(i+1) <= k:
        break
print(ans)

Solution (Python):
n, k= map(int, input().split())
a = list(map(int, input().split()))
import collections

a = collections.Counter(a)
key = list(a.values())

key.sort()

ans = sum(key[:len(key)-k])
print(ans)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
X=[0 for _ in range(N+1)]
for a in A:
    X[a]+=1
X.sort(reverse=True)
print(N-sum(X[0:K]))

Solution (Python):
N, K = map(int, input().split())
a = list(map(int,input().split()))

a_dict = {}

for i in range(N):
    if a[i] not in a_dict.keys():
        a_dict[a[i]] = 1
    else:
        a_dict[a[i]] += 1

ans = 0
if len(a_dict) <= K:
    print(ans)
else:
    sort_a_dict_list = sorted(a_dict.items(), key=lambda x:x[1])

    for j in range(len(a_dict) - K):
        ans += sort_a_dict_list[j][1]
    print(ans)

Solution (Python):
n, k = map(int, input().split())
an = [int(num) for num in input().split()]

kind = {}
for a in an:
  if not a in kind:
    kind[a] = 1
  else :
    kind[a] += 1

sortedKind = sorted(kind.items(), key=lambda x:x[1])    

if len(sortedKind) > k:
  count = 0
  for check in sortedKind[:len(sortedKind)-k]:
    count += check[1]
  print(count)
else :
  print(0)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for a in A:
  d[a] = d.get(a, 0) + 1
X = sorted(d.values(), reverse = True)
if len(X) <= K:
  print(0)
else:
  ans = N
  for i in range(K):
    ans -= X[i]
  print(ans)

Solution (Python):
import collections

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

values,counts = zip(*collections.Counter(A).most_common())
ans = 0

B = counts[K:]

for i in B:
    ans += i
print(ans)

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
import collections
c = collections.Counter(a)
li = []
ans = 0
for v,num in  c.items():
    li.append((v,num))
ll = sorted(li,key=lambda x: x[1],reverse=True)

for i in range(k,len(ll)):
    
    ans += ll[i][1]

print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
dic = {}

for a in A:
  if a in dic.keys():
    dic[a] += 1
  else:
    dic[a] = 1
    
dic = sorted(dic.items(), key = lambda x:x[1], reverse=True)

ans = 0
for (i,j) in dic[K:]:
  ans += j
  
print(ans)

Solution (Python):
N, K = map(int, input().split())
*A, = map(int, input().split())
d = [0]*(N+1)
for a in A:
    d[a] += 1
d.sort()
d.reverse()
print(sum(d[K:]))

Solution (Python):


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

count = {}
for val in A:
    if val in count:
        count[val] += 1
    else:
        count[val] = 1

ans = 0
diff = len(set(A)) - K
if diff > 0:
    count_sorted = sorted(count.items(), key=lambda x:x[1])
    for k,v in count_sorted:
        ans += v
        diff -= 1
        if diff == 0:
            break

print(ans)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))

dic={}
for i in range(N+1):
    dic[i]=0
for i in A:
    dic[i]+=1

dic_sort=sorted(dic.values(),reverse=True)

print(sum(dic_sort[K:]))

Solution (Python):
n,k = map(int,input().split())
from collections import Counter
s = list(map(int,input().split()))
num = Counter(s)
if len(num) <= k:
    print(0)
else:
    n = len(num) - k
    a = 0
    ans = 0
    for i in sorted(num.values()):
        if a == n:
            break
        
        ans += i
        a += 1
        
    print(ans)

Solution (Python):
from collections import Counter
 
N, K = map(int, input().split())
A = list(map(int, input().split()))
 



 


A = Counter(A).most_common()
 


s = 0
for i in range(min(K, len(A))):
  s += A[i][1]
  
print(N-s)

Solution (Python):
from collections import Counter

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







A = Counter(A).most_common()



s = 0
for i in range(min(K, len(A))):
  s += A[i][1]
  
print(N-s)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))





dic = {}
for i in range(N):
  a = A[i]
  if a not in dic: dic[a] = 1
  else: dic[a] += 1


dic = sorted(dic.items(), key=lambda x:x[1])



ans = 0
for i in range(max(len(dic)-K, 0)):
  ans += dic[i][1]
  
print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N + 1)]

for a in A:
    B[a] += 1
nums = [b for b in B if b > 0]
nums.sort()
n = len(nums)
print(0 if n<=K else sum(nums[:n - K]))

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N + 1)]

for a in A:
    B[a] += 1
nums = [b for b in B if b > 0]
nums.sort()
n = len(nums)
print(0 if n<=K else sum(nums[:n - K]))

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))

cnt=Counter(A)
cnt_sorted=sorted(cnt.items(), reverse=True,key=lambda x:x[1])

sum=0
for i in range(min(K,len(cnt))):
    sum+=cnt_sorted[i][1]

print(N-sum)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

rest_key_num = max(0, len(num_map) - k)
values = sorted(list(num_map.values()))
res = 0
for j in range(rest_key_num):
    res += values[j]
print(res)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*(2*10**5+1)
ans=0
for i in range(n):
    x[a[i]]+=1
z=[x[i] for i in range(2*10**5+1) if x[i]!=0]
z=sorted(z)
for i in range(max(len(z)-k,0)):
    ans+=z[i]
print(ans)

Solution (Python):
def count_list(lst):
    count_lst = [0] * (max(lst) + 2) 

    for i in lst:
        count_lst[i] += 1

    return count_lst


def main():
    n, k = map(int, input().split())
    a_lst = list(map(int, input().split()))
    new_lst = list(set(a_lst))
    types = len(new_lst)

    if types <= k:
        print(0)
    else:
        erase = types - k
        count_lst = count_list(a_lst)
        count_lst.sort()
        count = 0

        tmp = 0
        for i in count_lst:
            if i != 0:
                count += i
                tmp += 1

            if tmp == erase:
                break

        print(count)


if __name__ == '__main__':
    main()

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
import collections
a = collections.Counter(A)
b = a.most_common()
ans = 0
if len(b) > K:
    for i in range(K,len(b)):
        ans += b[i][1]
print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N+1)]
 
for a in A:
  B[a] += 1
nums = [b for b in B if b > 0]
nums.sort()
n = len(nums)
if n <= K:
  print(0)
else:
  print(sum(nums[:n-K]))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
ac=sorted(list(Counter(a).values()))
le=len(ac)
if le<=k:
  print(0)
else:
  count=0
  for i in range(le-k):
    count+=ac[i]
  print(count)

Solution (Python):



def main():
    n, k = map(int, input().split())
    li = [0] * n
    a = list(map(int, input().split()))
    for i in a:
        li[i - 1] += 1

    li.sort(reverse=True)
    print(sum(li[k:]))


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
a = list(map(int, input().split()))

sum = 0
c = Counter(a).most_common()
if K > len(c):
    print(0)
    exit()
for i in range(K):
    sum += c[i][1]
print(len(a) - sum)

Solution (Python):
import collections
N ,K = map(int,input().split())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
valu = list(counterA.values())
valu.sort()
kind = len(set(lsA))
if kind <= K:
    ans = 0
else:
    ans = sum(valu[:kind - K])
print(ans)

Solution (Python):
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]

a.sort()

times=[0]*(n+1)
for i in a:
    times[i]+=1
times.sort()


for i in range(n+1):
    if times[i]!=0:
        j=i
        break

ans=0
if len(times)>k-j:
    for i in range(j,len(times)-k):
        ans+=times[i]
print(ans)

Solution (Python):
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

num_dic = {}
for a in a_list:
  count = num_dic.get(a, 0)
  num_dic[a] = count + 1

replace_num = len(num_dic.keys()) - K
replace_num = 0 if replace_num < 0 else replace_num
ans = 0
for i, taple in enumerate(sorted(num_dic.items(), key = lambda x:x[1])):
  if i == replace_num:
    break
  ans += taple[1]

print(ans)

Solution (Python):
import sys
from collections import Counter
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a_cnt = sorted(list(Counter(a).values()))
    s = set(a)
    t = max(0, len(s) - k)
    print(sum(a_cnt[0:t]))

if __name__ == '__main__':
    main()

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

ddict = defaultdict(lambda: 0)





n,k = MI()
a = RI()

for i in range(n):
    ddict[a[i]] += 1

d = sorted(ddict.items(),key=lambda x:x[1],reverse=True)


e = d[k:]
ans = 0
for i in range(len(e)):
    ans += e[i][1]
print(ans)

Solution (Python):
import bisect as bs
N, K = (int(x) for x in input().split())
A = sorted([int(x) for x in input().split()])
f = lambda X, x: bs.bisect_right(X,x)-bs.bisect_left(X,x)
cnt = sorted([f(A,a) for a in set(A)],reverse=True)
vrt = len(cnt)
print(sum(cnt[K:]) if vrt > K else 0)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A_dict = dict()
for i in range(N):
    if A_dict.get(A[i]) is None:
        A_dict[A[i]] = 1
    else:
        A_dict[A[i]] += 1
A_dict_len = len(A_dict.keys())
ans = 0
A_dict_sorted = sorted(A_dict.items(), key=lambda a: a[1])

for i in range(max(0, A_dict_len - K)):
    ans += A_dict_sorted[i][1]
print(ans)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
c=collections.Counter(a)
if len(c)<k:
    print(ans)
    exit()
l=c.most_common()
for i in range(1,-k+len(c)+1):
    ans+=l[-i][1]
print(ans)

Solution (Python):
from collections import *
n,m=map(int,input().split())
l=list(map(int,input().split()))
k=len(set(l))
if(k<=m):
    print(0)
else:
    d=defaultdict(int)
    for i in l:
        d[i]+=1
    f=list(d.values())
    f.sort()
    g=k-m
    c=0
    for i in range(g):
        c+=f[i]
    print(c)

Solution (Python):
n,k=map(int, input().split())
a_list=[int(i) for i in input().split()]

dic={}

for i in a_list:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

dic2=sorted(dic.items(), key=lambda x:x[1])

ans=0

if len(dic)>k:
    num=len(dic)-k
    for i in range(num):
        ans+=dic2[i][1]

    
print(ans)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0]*n
for i in range(n):
    b[a[i]-1] += 1
c = [i for i in b if i != 0]
c.sort()
if len(c) - k > 0:
    print(sum((c[0:len(c)-k])))
else:
    print(0)

Solution (Python):
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))

a_cnt = collections.Counter(a)

a_sort = sorted(a_cnt.values(),reverse=True)


print(sum(a_sort[k:]))

Solution (Python):
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

X = [0] * N

for i in range(N):
    X[A[i] - 1] += 1

X = sorted(X, reverse=True)

S = sum(X[:K])

ans = N - S

print(ans)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
count=0
b=len(collections.Counter(a))
c=collections.Counter(a).most_common()

for i in range(min(k,b)):
    count+=c[i][1]

ans=len(a)-count
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter(input().split())

print(sum(sorted(A.values(), reverse=True)[K:]))

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))

B = [0] * (N + 1)
for i in range(N):
    B[A[i]] += 1
B.sort(reverse=True)
cnt = 0

for i in range(K):
    cnt += B[i]
print(N - cnt)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))

B = [0]*(N+1)
for i in range(N):
    B[A[i]] += 1
B.sort(reverse = True)
cnt = 0
for i in range(K):
     cnt += B[i]
print(N - cnt)

Solution (Python):

import collections
N, K=map(int,input().split())
A=list(map(int,input().split()))
C=collections.Counter(A)
KEY=list(C.keys())
count=0
if len(KEY)>K:
    D=len(KEY)-K
    L=C.most_common()[::-1]
    for ii in range(D):
        count+=L[ii][1]

print(count)

Solution (Python):
from collections import Counter

n, k = list(map(int, input().split()))
a = Counter(map(int, input().split()))
a = list(a.items())
a.sort(key=lambda x: x[1])
opt = len(a) - k
ans = 0
if opt > 0:
    for i in range(opt):
        ans += a[i][1]
print(ans)

Solution (Python):
from collections import Counter
_, K = map(int, input().split())
A = sorted(list(Counter(input().split()).values()))
print(sum(A[:len(A)-K]))

Solution (Python):
from collections import Counter
_, K = map(int, input().split())
A = list(map(int, input().split()))
_, cnt = zip(*Counter(A).most_common()[::-1])
print(sum(cnt[:len(cnt) - K]))

Solution (Python):
import collections
N,K=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
l=len(c)
c=list(c.items())
c.sort(key=lambda x: x[1])
ans=0
for i in c:
  if l<=K:
    break
  ans+=i[1]
  l-=1
print(ans)

Solution (Python):
n, k = map(int, input().split())

from collections import Counter
c = Counter(list(map(int, input().split())))


l = []
m = []
for x, y in c.items():
    l += [y]
    m += [x]

L = sorted(l)
M = len(m)

cnt = 0 
if M <= k:
    print(0)
else:
    for i in range(M-k):
        cnt += L[i]
    print(cnt)

Solution (Python):
from collections import Counter
a,b=map(int, input().split())
c = Counter(list(map(int, input().split())))
cnt = 0
l = []
m = []

for x,y in c.items():
    l += [y]
    m += [x]

M = len(m)
L = sorted(l)
if M <= b:
    print(0)
if M > b:
    for i in range(M-b):
        cnt += L[i]
    print(cnt)

Solution (Python):

import operator
N,K=map(int,input().split())
lst=list(map(int,input().split()))
x=[]
x=set(lst)
if len(x)<=K:
    print(0)
else:
    freq={}
    for i in lst:
        if i in freq:
            freq[i]+=1
        else:
            freq[i]=1
    
    
    s={}
    s = dict(sorted(freq.items(), key=operator.itemgetter(1)))
    
    
    cc=abs(len(x)-K)
    
    v=0
    for key,value in s.items():
        
        v+=s[key]
        
        cc-=1
        if cc==0:
            print(v)
            break

Solution (Python):
from collections import Counter as C

_, k = map(int, input().split())
a = [int(i) for i in input().split()]

c = C(a).values()
d = len(c) - k
if 0 < d:
    print(sum(sorted(c)[:d]))
else:
    print(0)

Solution (Python):
from collections import Counter, deque

_, k = map(int, input().split())
a = [int(i) for i in input().split()]

ans = 0
d = deque(sorted(Counter(a).values()))
while k < len(d):
    ans += d.popleft()
else:
    print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))

d={}

for x in range(n):
  if a[x] not in d:
    d[a[x]]=0
  d[a[x]]+=1
  
ans=0
ans1=[]
for g in d:
  ans1.append(d[g])
  
if len(ans1)<=k:
  print(0)
  
else:
  ans1.sort()
  r=len(ans1)-k
  for t in range(r):
    ans+=ans1[t]
    
  print(ans)

Solution (Python):
N,K = map(int,input().split()) 
A = list(map(int,input().split()))
A.sort()
temp = 1
V = [] 
for i in range(N-1):
    if A[i] == A[i+1]:
        temp+=1 
    else:
        V.append(temp)
        temp = 1

V.append(temp)
V.sort() 
ans = N- sum(V[-K:])
print(ans)

Solution (Python):
import collections
N,K=map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
c = collections.Counter(L)
c=c.most_common()
ans=0
if len(c)>K:
  for i in range(len(c)-K):
    ans+=c[len(c)-i-1][1]
  print(ans)
else:
  print(0)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
A = list(map(int, input().split()))

cnt_A = sorted(Counter(A).values())

ans = 0
if len(cnt_A) <= k:
    print(ans)
else:
    for i in range(len(cnt_A) - k):
        ans += cnt_A[i]
    print(ans)

Solution (Python):
import collections as c
n,k=map(int,input().split());a=c.Counter(map(int,input().split()))
print([0,sum(sorted([*a.values()])[:len(a)-k])][len(a)>k])

Solution (Python):
import collections as c
n,k=map(int,input().split());a=c.Counter(map(int,input().split()))
print([0,sum(sorted([i for i in a.values()])[:len(a)-k])][len(a)>k])

Solution (Python):
import collections

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

c = collections.Counter(a)
i = 0
cnt = 0
for key, val in sorted(c.items(), key=lambda x: -x[1]):
    
    cnt += val
    i += 1
    if i >= k:
        break
        
print(n - cnt)

Solution (Python):
import collections
N,K = map(int,input().split())
N_List = list(map(int,input().split()))

Chou_List = collections.Counter(N_List)
if len(Chou_List) <= K:
    print(0)
else:
    Chou_List = sorted(list(Chou_List.values()),reverse=True)
    print(sum(Chou_List[K:]))

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
  cnt = Counter(a)
  ans = sum(sorted(cnt.values())[: num_of_types - k])

print(ans)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
  cnt = Counter(a)
  ans = sum(sorted(cnt.values())[: num_of_types - k])

print(ans)

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
from collections import Counter
a1 = Counter(a).most_common()
num = 0
if k < len(a1):
    for i in range(1,len(a1)-k+1):
        num += a1[-i][1]
    print(num)
else:
    print(0)

Solution (Python):




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """5 2
1 1 2 2 5"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 4
1 1 2 2"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 3
5 1 3 2 4 1 1 2 3 4"""
        output = """3"""
        self.assertIO(input, output)


def resolve():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))
    an = [0] * N
    for i in a:
        an[i-1] += 1
    an.sort(reverse=True)
    ans = 0
    for i in an:
        if K == 0:
            ans += i
        else:
            K -= 1
    print(ans)


if __name__ == "__main__":
    
    resolve()

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

	lst = {}

	for num in A:
		if num in lst:
			lst[num] += 1
		else:
			lst[num] = 1

	lst_sorted = sorted(lst.items(), key = lambda x: x[1])

	len_lst_sorted = len(lst_sorted)

	if len_lst_sorted <= K:
		print(0)
		return
	else:
		ans = 0
		for i in range(len_lst_sorted - K):
			ans += lst_sorted[i][1]
		print(ans)
		return

  
if __name__ == "__main__":
  	main()

Solution (Python):
N, K = map(int, input().split())
A = list(map(int,input().split()))

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

B.sort()

print(sum(B[0:N-K]))

Solution (Python):








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

d = [0]*(n+1)

for i in range(n):
    d[a[i]] += 1

d.sort()

print(sum(d[:n-k+1]))

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
t=list(set(a))
c=sorted(Counter(a).most_common(),key=lambda x:x[1])
num=len(t)-k
if num<0:
    print(0)
    exit()
else:
    ans=0
    for i in range(num):
        ans+=c[i][1]
    print(ans)

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
from collections import Counter
a1 = Counter(a).most_common()
num = 0
if k < len(a1):
    for i in range(1,len(a1)-k+1):
        num += a1[-i][1]
    print(num)
else:
    print(0)

Solution (Python):
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
from collections import Counter
dic=Counter(a)
dic=sorted(dic.items(),key=lambda x:x[1])

ans=0
cnt=0
l=max(len(dic)-k,0)
for i in dic:
  if cnt==l:
    break
  ans=ans+i[1]
  cnt=cnt+1
print(ans)

Solution (Python):
_, k = map(int, input().split())
d = {}
for i in map(int, input().split()):
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.values(), reverse=True)
print(sum(v for v in d[k:]))