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):
import collections 
n,k=map(int,input().split())
c=list(map(int,input().split()))
l=collections.Counter(c)
s=l.most_common()
p=[]
if len(s)<=k:
    print(0)
else:
    d=0
    for a,b in s[:k]:
        d+=b
    print(n-d)

Solution (Python):
from collections import Counter

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

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

C = Counter(A)
v = list(C.values())
v = sorted(v)

div = len(v)
ans = 0
if div <= K:
    ans = 0
else:
    ans += sum(v[0:div-K])
print(ans)

Solution (Python):


from collections import Counter, defaultdict

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N, K = MI()
    C = Counter(MI())
    return N - sum((c for _, c in C.most_common(K)))


if __name__ == "__main__":
    print(main())

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

ans = 0
for i,(k,v) in enumerate(ctr.most_common()):
    if i < K: continue
    ans += v
print(ans)

Solution (Python):



def main():
    from collections import Counter

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

    for index, (key, ai) in enumerate(sorted(Counter(a).items(), key=lambda x: x[1], reverse=True), 1):
        if index > k:
            ans += ai

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    from collections import Counter

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

    for index, (key, value) in enumerate(sorted(Counter(a).items(), key=lambda x: x[1], reverse=True), 1):
        if index > k:
            ans += value

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import collections

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())

num_A = collections.Counter(A)
res = 0
for i, (k, v) in enumerate(sorted(num_A.items(), key=lambda x: x[1])):
  if len(num_A) - K < i + 1:
    break
  res += v
print res

Solution (Python):
import collections


N, K = map(int, input().split(' '))
A = input().split(' ')
counter_A = collections.Counter(A)
diversity = len(counter_A) - K
ans = 0
if diversity <= 0:
    print(ans)
    exit()
for item in counter_A.most_common()[-1*diversity:]:
    ans += item[1]
print(ans)

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

count = {}

for a in A:
    if a in count.keys():
        count[a] += 1
    else:
        count[a] = 1

v = list(sorted(count.values(), key=lambda x: -x))

ret = 0
for i in range(K, len(v)):
    ret += v[i]
print(ret)

Solution (Python):
import collections 
def inpl(): return [int(i) for i in input().split()]

N, K = inpl()
A = list(sorted(collections.Counter(inpl()).values()))
if len(A) <= K:
    print(0)
else:
    print(sum(A[:len(A)-K]))

Solution (Python):
n,m = map(int,input().split())
lis = list(map(int,input().split()))
li = [0 for i in range(n)]
for i in range(n):li[lis[i]-1] += 1
li.sort(reverse = True)
ans = 0
for k in range(m):
    ans += li[k]
print(n-ans)

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = Counter(A)
values_list = list(c.values())
values_list.sort()
ans = 0
for i in range(len(values_list)-K):
    ans += values_list[i]
print(ans)

Solution (Python):
import bisect
N, K = map(int, input().split())
a=list(map(int, input().split()))
nlis=[0]*200001
s=0
for i in range(N):
    if nlis[a[i]]==0:
        s+=1
    nlis[a[i]]+=1
nlis.sort(reverse=True)

print(sum(nlis[K:]))

Solution (Python):
import bisect
N, K = map(int, input().split())
a=list(map(int, input().split()))
nlis=[0]*200001
s=0
for i in range(N):
    if nlis[a[i]]==0:
        s+=1
    nlis[a[i]]+=1
nlis.sort()
l=bisect.bisect_left(nlis, 1)

print(sum(nlis[l:l+s-K]))

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

D = {}

for a in A:
    if not a in D:
        D[a] = 1
    else:
        D[a] += 1

list = list(D.items())

list = sorted(list, key=lambda x: x[1])

count = 0

l = len(list) - K
i = 0
while (l >= 1):
    count += list[i][1]
    i += 1
    l -= 1

print(count)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
xs = map(int, input().split())

ctr = Counter(xs)

cnts = sorted(ctr.values())

ans = n - sum(cnts[-k:])

print(ans)

Solution (Python):
import collections
n,k = map(int,input().split())
a = list(map(int,input().split()))
d = collections.Counter(a)
v = list(d.values())
v.sort()
v.reverse()
if len(v) <= k:
  print(0)
else:
  print(n-sum(v[:k]))

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

x = A[0]
L = []
c = 1
for i in range(len(A) - 1):
	if x == A[i + 1]:
		c += 1
	else:
		L.append(c)
		c = 1
	x = A[i + 1]

L.append(c)

L = sorted(L)

n = len(L)

ans = 0

if n <= K:
	print(0)
else:
	for i in range(n - K):
		ans += L[i]
	print(ans)

Solution (Python):
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
ac = collections.Counter(a).most_common()
ans = 0
for i in range(len(ac)):
    if i + 1 > k:
        ans += ac[i][1]
print(ans)

Solution (Python):
n,k = map(int, input().split())
list_a = list(map(int, input().split()))
dict_a = {}
for i in range(n):
    try:
        dict_a[list_a[i]] += 1
    except KeyError:
        dict_a[list_a[i]] = 1
list_val = []
for value in dict_a.values():
    list_val.append(value)
list_val.sort()
list_val.reverse()
ans = 0
for i in range(k,len(list_val)):
    ans += list_val[i]
print(ans)

Solution (Python):

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

ans = []
k = a[0]
c = 0
for i in range(n):
    if k == a[i]:
        c += 1
    else:
        ans.append(c)
        c = 1
        k = a[i]
    if i == n-1:
        ans.append(c)

ans.sort()
ans = ans[::-1]

if len(ans)<=kk:

    print(0)
else:
    ass = 0
    for i in range(kk,len(ans)):
        ass += ans[i]
    print(ass)

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

count_dict = {}
for i in range(len(A)):
	if A[i] in count_dict.keys():
		count_dict[A[i]] += 1
	else:
		count_dict[A[i]] = 1

if len(count_dict.keys()) <= K:
	print(0)
else:
	need = len(count_dict.keys()) - K
	temp = sorted(count_dict.values())
	res = 0
	for i in range(need):
		res += temp[i]
	print(res)

Solution (Python):
'''input
5 2
1 1 2 2 5
'''
n,k = map(int,raw_input().split())
arr = map(int,raw_input().split())
ind = [0]*(n+1)
for i in range(n):
	ind[arr[i]] += 1
ind.sort()
aa = 0
for i in range(n+1):
	if ind[i] > 0:
		aa += 1
if aa <= k:
	print "0"
else:
	ans = 0
	for i in range(n):
		if aa == k:
			break
		if ind[i] > 0:
			ans += ind[i]
			aa -= 1
	print ans

Solution (Python):

n,k = [int(x) for x in input().split()]

d = {}
for x in input().split():
    x = int(x)
    if x not in d:
        d[x] = 0
    d[x] += 1

cnt = 0
ret = 0
for kk,v in sorted(d.items(), key=lambda x:-x[1]):
    cnt += 1
    if cnt>k:
        ret += v
print(ret)

Solution (Python):
from collections import Counter
import sys

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

if k>=len(c):
    print(0)
    sys.exit()
d = c.values()
print(sum(sorted(d)[:len(c)-k]))

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

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

b = {}

for i in a:
    if i in b:
        b[i] += 1
    else:
        b[i] = 1

c = []
for i in b:
    c.append(b[i])
c.sort()
c.reverse()

if len(c) <= k:
    print(0)
else:
    print(sum(c[k:]))

Solution (Python):
from collections import Counter

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

ACounter=Counter(A)
Acommon=ACounter.most_common()

count=len(Acommon)
answer=0
index=-1

while(count>K):
  answer+=Acommon[index][1]
  count-=1
  index-=1
print(answer)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, K = reads()
A = reads()

freq = defaultdict(lambda: 0)
for a in A:
  freq[a] += 1
ans = N - sum(sorted(freq.values())[-K:])
print(ans)

Solution (Python):
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
from collections import defaultdict
d = defaultdict(int)
for ele in a:
  d[ele] += 1
print(sum(sorted(d.values(), reverse=True)[k:]))

Solution (Python):
from collections import Counter

N,K = list(map(int,input().split(" ")))
A = list(map(int,input().split(" ")))
A2 = dict(Counter(A))
i=0
r = [v for k,v in sorted(A2.items(),key=lambda x:-x[1])]
print(N- sum(r[0:K]))

Solution (Python):
from collections import defaultdict
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
dd = defaultdict(int)
for s in A:
    dd[s]+=1
i=0
ans = 0
for k,v in sorted(dd.items(), key=lambda x: -x[1]):
    i+=1
    ans +=v
    if i==K:
        break
print(N-ans)

Solution (Python):
from collections import Counter
from operator import itemgetter

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

c = dict(Counter(a))
if len(c) <= k:
	print(0)
else:
	hindo = sorted(c.items(), key=itemgetter(1))
	ans = 0
	for i in range(len(hindo) - k):
		ans += hindo[i][1]
	print(ans)

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
s = len(set(a))
ans = 0
dic = {}
for i in range(n):
    dic[a[i]] = 0
for i in range(n):
    dic[a[i]] += 1
ans = 0
for i in sorted(dic.items(), key = lambda x:x[1]):
    if s <= k:
        break
    ans += i[1]
    s -= 1
print(ans)

Solution (Python):
n,k = map(int, input().split())
a = list(map(int, input().split()))
dic = {}
count = 0
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
v = len(dic.items())
for i in sorted(dic.values()):
    if v <= k:
        break
    v -= 1
    count += i
print(count)

Solution (Python):
from collections import defaultdict

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

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

C = defaultdict(int)

for a in A: C[a] += 1

for k,v in sorted(C.items(),key=lambda x:x[1],reverse=True)[:K]:
    N -= v
        
print(N)

Solution (Python):
import math
import sys
from collections import Counter
def getinputdata():

    
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

n = int(arr_data[0][0])
k = int(arr_data[0][1])

arr=arr_data[1]


list01=Counter(arr)





cnt=0
if len(list01) > k:
    
    for key,val in sorted(list01.items(),key=lambda x: x[1]):



        cnt+=list01.pop(key)
        
        
        if len(list01)==k:
            
            break
        

print(cnt)

Solution (Python):
from collections import Counter
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
C = Counter(A)


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

Solution (Python):


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

num = {}
for x in a:
    if x in num:
        num[x] += 1
    else:
        num[x] = 1

nums = []
for x in num:
    nums.append(num[x])
nums = sorted(nums)

res = sum(nums[:len(nums) - k])

print(res)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
cnt = [0] * (N+1)  

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

shurui = 0
for n in range(1, N+1):
    if cnt[n] > 0:
        shurui += 1

if shurui <= K:
    print(0)
else:
    cnt.sort(reverse=True)
    print(sum(cnt[K:shurui]))

Solution (Python):
n, k = map(int, input().split())
d = [0 for _ in range(200001)]

for i in map(int, input().split()):
    d[i] += 1

s = sorted(d)

ans = 0
for i in range(200001-k):
    ans += s[i]

print(ans)

Solution (Python):
lis = list(map(int, input().split()))
lis2 = input().split()
n = lis[0]
k = lis[1]
d = {}

for i in range(n):
    if lis2[i] not in d.keys():
       d[lis2[i]] = 1
    else:
        d[lis2[i]] += 1 
        
if len(list(d.values())) <= k:
    print(0)
else:
    a = list(d.values())
    a.sort()
    a.reverse()
    swap = 0
    for i in range(k,len(a)):
        swap += a[i]
    print(swap)

Solution (Python):
n,k=map(int,input().split())
d=[0 for i in range(200001)]
for i in map(int,input().split()):
    d[i]+=1
d=sorted(d)
ans=0
for i in range(200001-k):
    ans+=d[i]
print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
import collections
count=0
data=collections.Counter(a)
data=sorted(data.items(),key=lambda x:x[1])
if k<len(data):
    for i in range(len(data)-k):
        count+=data[i][1]
else:
    print(0)
    exit()
print(count)

Solution (Python):
def i2():
 return [int(i) for i in input().split()]
[n,k]=i2()
a=i2()
from collections import Counter
c = Counter(a)
cv=c.values()
print(sum(sorted(list(cv))[:len(cv)-k]))

Solution (Python):
from collections import OrderedDict

temp=input()
n,k=list(map(int,temp.split(" ")))
co=OrderedDict()
ans=[]
temp=input()
nums=list(map(int,temp.split(" ")))
for i in nums:
  if i in co:
	  co[i]+=1
  else:
	  co[i]=1
for i in co:
  ans.append(co[i])
kinds=len(ans)
dif=kinds-k
if dif<=0:
    print(0)
else:
    ans.sort()
    print(sum(ans[:dif]))

Solution (Python):
import heapq

n,k=map(int,raw_input().split())
a=map(int,raw_input().split())



d={}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
l=d.values()
div=max(0,len(l)-k)
if div==0:
    print 0
    exit()


heapq.heapify(l)

ans=0
while div>0:
    ans+=heapq.heappop(l)
    div-=1
print ans

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

def uniq(a):
    d = {}
    for a_ in a:
        if a_ not in d:
            d[a_] = 1
        else:
            d[a_] += 1
    return d.keys(), d.values()

def solve():
    u, c = uniq(a)
    k = len(u) - K
    if len(u) > K:
        print(sum(sorted(c)[:k]))
    else:
        print(0)

solve()

Solution (Python):
from collections import Counter
import numpy as np

N,K=[int(_) for _ in input().split()]
a_lst=[int(_) for _ in input().split()]

counter=Counter(a_lst)
v_arr=np.zeros(len(counter)).astype(int)
for i, (k, v) in enumerate(counter.items()):
    v_arr[i]=v
v_arr=np.sort(v_arr)
total=v_arr.sum()
top=v_arr[-K:].sum()
print(total-top)

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

from collections import Counter
from operator import itemgetter


A_cnt = Counter(A)


print(N - sum([v for k, v in sorted(A_cnt.items(), key = itemgetter(1), reverse = True)[:K]])\
)

Solution (Python):



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

As = list(map(int, input().split()))

cnt = {}

for a in As:
    cnt.setdefault(a, 0)
    cnt[a] += 1

c = len(cnt)
ans = 0

for k, v in sorted(cnt.items(), key=lambda x:x[1]):
    if c <= K:
        break
    c -= 1
    ans += v

print(ans)

Solution (Python):
import collections

if __name__ == '__main__':
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ele_count = len(set(A))
    

    counter = collections.Counter(A)
    ans = 0
    for ele in counter.most_common()[:-(ele_count - K + 1):-1]:
        ans += ele[1]

    print(ans)

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

from collections import defaultdict

d = defaultdict(lambda: 0)

for elem in a:
    d[elem] += 1
    
lst = list(d.items())
lst.sort(key=lambda x: -x[1])

i = k
res = 0

while True:
    try:
        now = lst[i]
    except IndexError:
        break
    res += now[1]
    i += 1

print(res)

Solution (Python):
N,K=map(int,input().split())
a=[0]*N
A=list(map(int,input().split()))
s=set(A)
if len(s)<=K: print(0)
else:
  for i in range(N):
    a[A[i]-1]+=1
  a.sort()
  ans=0
  for i in range(N):
    if N-i<=K:
      print(ans)
      break
    ans+=a[i]

Solution (Python):
from collections import defaultdict

n, k = [int(x) for x in input().split()]

a = [int(x) for x in input().split()]

d = defaultdict(int)

for x in a:
    d[x] += 1

e = sorted(d.items(), key=lambda v:v[1])

m = len(e)

ans = 0

if m-k >= 0:
    for i in range(m-k):
        ans += e[i][1]

print(ans)

Solution (Python):
from collections import defaultdict

n, k = map(int, input().split())
al = [int(i) for i in input().split()]


d = defaultdict(int)
for a in al:
  d[a] += 1


ans = 0
if len(d.keys()) > k:
  
  v = list(d.values())
  v.sort()
  ans = sum(v[:len(d.keys()) - k])
print(ans)

Solution (Python):



if __name__ == '__main__':
  n,k = map(int,input().split())
  a = list(map(int,input().split()))
  s = sorted(a)
  tmp = s[0]
  count = 0 
  dif_a = [1]
  for i in range(1,n):
    if s[i] == tmp:
      dif_a[count] += 1
    else:
      tmp = s[i] 
      count += 1
      dif_a.append(1)

  ds = sorted(dif_a)
  kind = count + 1
  remove = 0
  for i in range(len(ds)-k):
    remove += ds[i]
  print(remove)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    c = Counter(A)
    v = list(sorted(c.values()))
    print(sum(v[:-K]))


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ks=[]
ele=0
for i in range(max(a)+1): ks.append(0)
for m in a:
  if ks[m]==0: ele+=1
  ks[m]+=1
if ele>k:
  ks.sort()
  p=sum(ks)
  for i in range(len(ks)-k,len(ks)):
      p-=ks[i]
  print(p)
else:
  print(0)

Solution (Python):
N, K = map(int, input().split())
v = [0] * (N + 1)

for a in list(map(int, input().split())):
    v[int(a)] += 1

v = sorted(v, reverse=True)
if 0 in v:
    v = v[:v.index(0)]
v = list(reversed(v))

ans = 0
for i in range(len(v)):
    if len(v) - i <= K:
        break
    ans += v[i]

print(ans)

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

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
num = [0]*(n+1)
for c in a :
    num[c] += 1

num.sort(reverse=True)
ans = 0

for c in num[k:] :
    if c == 0 :
        break
    ans += c

print(ans)

Solution (Python):
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
s = set(a)
if len(s) < k:
    print 0
    exit()
d = dict()
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in sorted(d.values())[:len(s) - k]:
    cnt += i
print cnt

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

ans = 0
unique = count_dict.most_common()
for i in range(len(count_dict) - k):
    ans += unique[len(count_dict)-i-1][1]
print(ans)

Solution (Python):
import sys,collections
from collections import deque
from operator import itemgetter
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,k = Is()
a = Is()
d = collections.defaultdict(int)
for i in range(len(a)):
    d[a[i]] += 1 
dl = sorted(list(d.items()),key=itemgetter(1))
ans = 0
for i in range(len(dl)):
    if len(d) <= k:
        break
    ans += dl[i][1]
    del d[dl[i][0]]
print(ans)

Solution (Python):
N, K= map(int, input().split())
A = map(int, input().split())
d = {}
for a in A:
    if a in d:
        d[a] = d[a] + 1
    else:
        d[a] = 1
o = []
for k, v in d.items():
    o.append(v)
o = sorted(o, reverse=True)

if K >= len(o):
    print(0)
else:
    print(sum(o[K:]))

Solution (Python):
from collections import Counter

n,k = map(int, input().split())
a = input().split()
c = Counter(a)
t = len(c) - k
r = 0

if t > 0:
    serial = c.most_common()[-t:]
    for s in serial:
        r += s[1]

print(r)

Solution (Python):
def solve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    num_dict = {}
    for i, num in enumerate(A):
        if not num in num_dict:
            num_dict[num] = 1
        else:
            num_dict[num] = num_dict[num] + 1
    cnt, ans = 0, 0
    num_dict_size = len(num_dict)
    for k, v in sorted(num_dict.items(), key =lambda x: x[1]):
        if cnt >= num_dict_size - K:
            print(ans)
            return
        else:
            ans += v
            cnt += 1
        
solve()

Solution (Python):



nk = raw_input()
nk = nk.split()
n,k = map(int,nk)

a = raw_input()
a = a.split()
a = map(int,a)

d = {}

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

l = d.values()

ans = 0

if len(l) <= k:
    pass
else:
    l.sort()
    for i in range(len(l)-k):
        ans += l[i]

print ans

Solution (Python):
n, k = map(int, input().split())
dic = {}
a = map(int, input().split())
for i in a:
    if int(i) in dic:
        dic[int(i)] += 1
    else:
        dic[int(i)] = 1
len_all = len(dic.keys())
a = [[i, dic[i]] for i in dic.keys()]
a = sorted(a, key=lambda x: x[1])

ans = 0
if k == len_all:
    print(0)
else:
    for i in range(len_all - k):
        ans += a[i][1]
    print(ans)

Solution (Python):
from collections import Counter

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

cnt = list(Counter(As).values())
cnt.sort(reverse=True)

print(sum(cnt[K:]))

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

data={}

for num in A:
        if num in data:
                data[num]+=1
        else:
                data[num]=1
num=[int(i) for i in data.values()]

num.sort()

num.reverse()

ans=sum(num)

if len(num)<=K:
        print(0)
else:
        for i in range(K):
                ans-=num[i]
        print(ans)

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

cnt = {}

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

cnt = sorted(cnt.items(), key=lambda x: x[1])
ans = 0

for i in range(len(cnt)):
    if len(cnt) - i <= K:
        break
    ans += cnt[i][1]

print(ans)

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
ls = []
for ai, c in cnt.items():
    ls.append((c, ai))
ls.sort()
ans = 0
for i in range(len(ls) - k):
    ans += ls[i][0]
print(ans)

Solution (Python):
eN, K = map(int, input().split())
d = {}
for a in input().split():
    a = int(a)
    d[a] = d.get(a, 0) + 1
if len(d) <= K:
    print(0)
else:
    aa = list(sorted(d, key=lambda a: d[a]))
    print(sum(d[a] for a in aa[:len(aa)-K]))

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

if len(ctr) <= K:
    print(0)
else:
    print(sum(sorted(ctr.values())[:len(ctr) - K]))

Solution (Python):
from collections import Counter
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
C = Counter(A)
V = [C[k] for k in C]
V.sort()
if(len(V) <= K):
    print(0)
else:
    print(sum(V[:len(V)-K]))

Solution (Python):
from collections import Counter

def solve():
  N,K = map(int,input().split())

  counter = Counter(map(int,input().split()))

  k = len(counter)

  if k <= K:
    return 0

  n = k-K
  return sum(sorted(counter.values())[:n])

print(solve())

Solution (Python):


import sys
import math
import collections

N, K = list(map(int, sys.stdin.readline().rstrip().split()))
As = list(map(int, sys.stdin.readline().rstrip().split()))

count = collections.defaultdict(int)

for A in As:
    count[A] += 1

values = list(sorted(count.values()))

print(sum(values[:len(values)-K]))
exit(0)

Solution (Python):
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    c = Counter(A)
    v = list(sorted(c.values()))
    if len(v) <= K:
        print(0)
        return
    print(sum(v[:-K]))






if __name__ == '__main__':
    main()

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

B.sort()
B.reverse()

ans = 0
for i in range(K, N):
    ans += B[i]
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
counter = Counter(input().split())
arr = counter.most_common()
print(sum(map(lambda x:x[1], arr[K:])))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*200000
for i in a:
    l[i-1] += 1
l = sorted(l)
s = len(list(set(a)))
ret = 0
for i in range(s-k):
    ret += l[-s+i]
print(ret)

Solution (Python):
from collections import Counter

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
C = Counter(A)
D = C.items()[:]
D.sort(key=lambda x: x[1])

ans = 0
X = len(D)
for e, v in D:
    if X > K:
        ans += v
    X -= 1
print ans

Solution (Python):

from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N, K = inpl()
A = inpl()
C = Counter(A)

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

Solution (Python):
from collections import Counter
from operator import itemgetter

n, k = map(int, input().split())
a = Counter(map(int, input().split()))
sa = sorted(a.items(), key=itemgetter(1), reverse=True)

if len(sa) <= k:
    print(0)
else:
    print(sum(c for m, c in sa[k:]))

Solution (Python):
from collections import defaultdict

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())


d = defaultdict(int)

for i in a:
	d[i] += 1


s = d.values()

s = sorted(s)[::-1]
print sum(s[k:])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    s = sum(sorted(d.values(), reverse=True)[:k])

    return n - s



print(main())