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):
nk = list(map(int,input().split()))
a = list(map(int,input().split()))

cli = []
for i in range(nk[0]+1):
	cli.append(0)

for i in range(nk[0]):
	cli[a[i]] += 1

c = sorted(cli, reverse = True)

m = 0
for i in range(nk[1]):
	m += c[i]

ans = nk[0] - m
if ans < 0:
	ans = 0
	
print(ans)

Solution (Python):
import collections

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
a = collections.Counter(A)
asort = sorted(a.items(), key = lambda x:x[1])

ans = 0
l = len(asort)
for j in range(len(asort)):
    if l <= K:
        break
    else:
        l -= 1
        ans += asort[j][1]
print(ans)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a = [i for i in input().split()]
cnt = Counter(a)
li = list(cnt.values())
li.sort()
ll = len(li)
if ll > k:
    print(sum(li[:ll-k]))
else:
    print(0)

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

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

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

for i in range(len(d)):
    if diverse > k:
        ans += d[i][1]
        diverse -= 1
    else:
        break
print(ans)

Solution (Python):
"""
【ABC081】
C - Not so Diverse



import sys
from collections import Counter


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  
def MI(): return map(int, sys.stdin.readline().rstrip().split())        
def II(): return int(sys.stdin.readline().rstrip())                     
def S(): return sys.stdin.readline().rstrip()                           

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

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

Solution (Python):

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

reduce_type = len(set(A)) - K

A_dict = {str(i):0 for i in set(A)}
for a in A:
  A_dict[str(a)] += 1
del A
list_del_num = sorted(list(A_dict.values()))[:reduce_type]

ans = sum(list_del_num)
print(ans)

Solution (Python):
N, K = map(int, input().split())
As = list(map(int, input().split()))
Ns = {}
for A in As:
  if not(A in Ns):
    Ns[A] = 0
  Ns[A] += 1
Ns2 = sorted(Ns.values())

if len(Ns2) <= K:
  print(0)
  exit()
r = sum(Ns2[:-K])
print(r)

Solution (Python):
import collections

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

counter = collections.Counter()
for num in nums:
    counter[num] += 1
counts = sorted(counter.values())

res = 0
for i in range(0, max(0, len(counts) - k)):
    res += counts[i]
print(res)

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

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

    B = [[a, d[a]] for a in d]
    count = 0
    if len(B) > K:
        B = sorted(B, key = lambda x: x[1])
        for i in range(len(B)-K):
            count += B[i][1]
    return count

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

Solution (Python):
from sys import stdin
N,K = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
data = sorted(data) + [-1]
equ_count = []
cnt = 1
for i in range(0,N):
    if data[i] == data[i+1]:
        cnt += 1
    else:
        equ_count.append(cnt)
        cnt = 1
L = len(set(data))
if L <= K:
    ans = 0
else:
  ite = L - K - 1
  ans = 0
  for j in sorted(equ_count)[0:ite]:
    ans += j
print(ans)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
d={}
for i in range(N):
    if A[i] in d:
        d[A[i]]+=1
    else:
        d[A[i]]=1
l=list(d.values())
l.sort()
n=len(l)
print(sum(l[0:-K]))

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

count = {}

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

tmp = []
for k, v in count.items():
    tmp.append(v)

tmp = sorted(tmp)

total = 0
for i in range(len(tmp) - K):
    total += tmp[i]

print(total)

Solution (Python):
from collections import Counter

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

tmp=[]
for key,v in c.items():
    tmp.append(v)
tmp.sort()

ans=0
for i in range(len(tmp)-k):
    ans+=tmp[i]
print(ans)

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

kouho = [0] * (2 * 10 ** 5 + 1)
ans = 0

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

num = 0
kouho.sort()

for i in range(len(kouho)):
    if kouho[i] != 0:
        
        num += 1

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

cnt = 0

for i in range(len(kouho)):
    if cnt >= num-k:
        break
    if kouho[i] != 0:
        
        ans += kouho[i]
        cnt += 1

print(ans)

Solution (Python):


from collections import Counter

n, k = map(int, input().split())
a = list(sorted(map(int, input().split())))
c = Counter(a)
current_k = len(c)
xlst = c.most_common(current_k)[k:]

answer = 0
for x in xlst:
    answer += x[1]

print(answer)

Solution (Python):
import collections

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

c = collections.Counter(a)
cval = sorted([i for i in c.values()])

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

Solution (Python):
from collections import*
n,k,*a=map(int,open(0).read().split())
c=Counter(a).most_common()
print(n-sum(c[i][1] for i in range(min(len(set(a)),k))))

Solution (Python):
from collections import Counter
n,k,*a=map(int,open(0).read().split())
if len(set(a))<=k:
	print(0)
	exit()
else:
	c=Counter(a).most_common(k)
	n-=sum(c[i][1] for i in range(k))
	print(n)

Solution (Python):
nums , types = map(int, input().split())
array = list(map(int,input().split()))
array.sort()
type_count = 0
count = 0
result = 0
ary_count = []
array.append(1000000000)

for i in range (nums):
    if array[i] == array[i +1]:
        count += 1
    elif array[i] < array[i +1]:
        ary_count.append(count)
        type_count += 1
        count = 0

ary_count.sort()

if type_count > types:
    for i in range(type_count - types):
        result += ary_count[i]+1
print(result)

Solution (Python):
N,K = map(int,input().split())
li = list(map(int,input().split()))
d = {}
total = []
for i in li:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1

sorted_d = sorted(d.values())

s = len(d) - K
for i in sorted_d[:s]:
  total.append(i)
print(sum(total))

Solution (Python):
N, K = map(int, input().split())
A = map(int, input().split())
dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

dic_sort = sorted(dic.values(), reverse=True)
cnt = 0
result = 0
for v in dic_sort:
    cnt += 1
    if cnt <= K:
        continue
    result += v

print(result)

Solution (Python):
import collections
n, k = map(int, input().split())
a = collections.Counter(list(map(int, input().split()))).most_common()
total = 0
for i, t in enumerate(a):
    if i >= k:
        total += t[1]
print(total)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = [int(s) for s in input().split()]
c = Counter(A)
ans = N - sum([v for _, v in c.most_common(K)])
print(ans)

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



move=0

dic={}
for num in li :
  if num in dic.keys() :
    dic[num]=dic[num]+1
  else :
    dic[num]=1

now=len(dic)


for key, v in sorted(dic.items(), key=lambda x: x[1]):
  
  if k>=now :
    break
  
  
  move+=v
  now=now-1
  
print(move)

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

B.sort()

for i in range(len(B)):
    if B[i]!=0:
        type+=1
K=type-K
for i in range(len(B)):
    if K<=0:
        break
    if B[i]!=0:
        count+=B[i]
        K-=1

print(count)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) <= k:
    print(0)
else:
    b = Counter(a)
    t = len(set(a)) - k
    c = b.most_common()[:-t-1:-1]
    d = 0
    for e in c:
        d = d + e[1]
    print(d)

Solution (Python):
import collections

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

c = collections.Counter(A)
n = len(c)
c_sorted = sorted(c.values())
cnt = 0
for i in range(max(0, n - K)):
    cnt += c_sorted[i]
print(cnt)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = Counter(a)
mo = sorted(cnt.values())

ans = 0
for i in range(max(0,len(mo)-k)):
    ans += mo[i]
print(ans)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = Counter(a)
mo = cnt.most_common()[::-1]

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

Solution (Python):
import collections

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

c = collections.Counter(a).most_common()

cnt = 0
cntdiff = 0
for i, j in c:
    cntdiff += 1
    if cntdiff > k:
        cnt += j
print(cnt)

Solution (Python):
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
tmp = len(list(set(A)))
li = collections.Counter(A)
value,counts = zip(*li.most_common())
for i in range(K,tmp,1):
    ans += counts[i]
print(ans)

Solution (Python):
from collections import Counter


n, k = map(int, input().split())
num_list = list(map(int, input().split()))
cnt = Counter(num_list)
print(sum(sorted(cnt.values())[:-k]))

Solution (Python):
from collections import Counter
import heapq
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = list(Counter(A).values())
heapq.heapify(c)
kind = len(c)

cnt = 0
while K < kind:
    kind -= 1
    cnt += heapq.heappop(c)

print(cnt)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=a[0]
cnt=1
x=[]
for i in range(1,n):
	if b==a[i]:
		cnt+=1
	else:
		x.append([a[i-1],cnt])
		cnt=1
		b=a[i]
x.append([a[-1],cnt])
x.sort(key=lambda x:-x[1])
y=0
for i in range(min(k,len(x))):
	y+=x[i][1]
print(n-y)

Solution (Python):

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = set(A)
    L = [0 for i in range(N+1)]
    for i in A:
        L[i] += 1
    L.sort()
    if len(B) <= K:
        print('0')
    else:
        print(str(sum(L[0:N+1-K])))


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter

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

count = list(Counter(A).items())
count.sort(key=lambda A : A[1])

rNum = len(count) - K
ans = sum([a[1] for a in count[:rNum]])

print(ans)

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

if len(set(as_)) <= k:
  print(0)
  exit()

d = {}

for a in as_:
  if a in d:
    d[a] += 1
  else:
    d[a] = 1

ans = 0
d = sorted(d.items(), key=lambda x: x[1])
for k, v in d[:-k]:
  ans += v
print(ans)

Solution (Python):
n, k = map(int,input().split())
a = list(map(int,input().split()))
d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
c = sorted(d.items(),key = lambda x:x[1], reverse=True)
ans = 0
for i in range(min(k,len(c))):
    ans += c[i][1]

print(n-ans)

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

A_dict = {}
for a in A:
    if a in A_dict:
        A_dict[a] += 1
    else:
        A_dict[a] = 1

A_sorted = sorted(A_dict.items(), key=lambda x:x[1], reverse=True)
rewrite = 0
while len(A_sorted) > K:
    tmp = A_sorted.pop()
    rewrite += tmp[1]

print(rewrite)

Solution (Python):

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

from collections import defaultdict
d = defaultdict(int)
for i in a:
    d[i]+=1
not_change_cnt = 0
for i,v in enumerate(sorted(d.values(),reverse=True)):
    if i+1 > k:
        break
    else:
        not_change_cnt+=v
print(n-not_change_cnt)

Solution (Python):
from collections import defaultdict
N,K,*A=map(int,open(0).read().split())

dic = defaultdict(int)
for a in A:
  dic[a] += 1

dic_values = sorted(list(dic.values()))
ans = 0
for i in range(max(len(dic_values)-K,0)):
  ans += dic_values[i]
print(ans)

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

c = collections.Counter(X)
c = c.most_common()[::-1]

count = 0
if (len(c) > M):
	for i in range(len(c)-M):
		count += c[i][1]

print(count)

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

Solution (Python):
import sys
from collections import defaultdict
input = sys.stdin.readline

n, k = map(int, input().split())
a_tuple = tuple(map(int, input().split()))
count_dict = defaultdict(int)

for i in a_tuple:
    count_dict[i] += 1

n = len(count_dict.keys())

if n <= k:
    print(0)
else:
    ans = sum(tuple(sorted(count_dict.values()))[:n-k])
    print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set(a)
l=[0]*(n+1)
for i in range(n):
    l[a[i]]+=1
l=[i for i in l if i>0]
l.sort()
le=len(s)
c=0
for i in range(len(l)):
    if le<=k:
        break
    else:
        c+=l[i]
        le-=1
print(c)

Solution (Python):
n, k = map(int, input().rstrip("\n").split())
numbers_dict = dict()
for number in map(int, input().rstrip("\n").split()):
    numbers_dict[number] = numbers_dict.get(number, 0) + 1

print(sum(sorted(numbers_dict.values(), reverse=True)[k:]))

Solution (Python):
n,k = map(int,input().split())
arr = list(map(int,input().split()))
d = {}
for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a]+=1

if len(d) < k+1:
    print(0)
else:
    sup = len(d)-k
    a = []
    for k in d.keys():
        a.append(d[k])
    a.sort()
    
    ans = sum(a[:sup])
    print(ans)

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
can = []
for i in range(n):
  now = a[i]
  try:
    if now == can[-1][0]:
      can[-1][1] += 1
    else:
      can.append([now,1])
  except:
    
    can.append([now,1])
    
can.sort(key= lambda x:x[1])
l = len(can)
ans = 0
if l-k > 0:
  for j in range(l-k):
    ans += can[j][1]
  print(ans)
else:
  print(0)

Solution (Python):
from collections import defaultdict
if __name__ == '__main__':
    N, K = map(int, input().split())
    A = [None]*N
    A = list(map(int, input().split()))

    Adict = [0]*N
    for a in A:
        Adict[a-1] += 1
    num = len(set(A))

    
    Adict = sorted(Adict,reverse=True)
    count=0
    for _ in range(num - K):
        while True:
            min_num = Adict.pop()
            count += min_num
            if min_num != 0:
                break
    
    print(count)

Solution (Python):
from collections import Counter

n,k = map(int,input().split())
lst = list(map(int,input().split()))
typ = list(set(lst))

ans = 0
NumList = Counter(lst)
num = sorted(NumList.items(),key=lambda x:x[1])
for l in range(len(typ)-k):
    ans += num[l][1]
print(ans)

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

    TMP = [0] * N

    for i in A:
        TMP[i-1] += 1
    
    sort_TMP = sorted(TMP, reverse=True)
    max_ball = 0
    cnt = 1

    for a in sort_TMP:
        if cnt <= K:
            cnt += 1
            max_ball += a
        else:
            break
    
    print(N-max_ball)


main()

Solution (Python):
n, k = map(int,input().split())
a = list(map(int,input().split()))
d = {}
for i in a:
  if i not in d.keys():
    d[i] = 1
  else:
    d[i] += 1
d = sorted(d.values())
print(sum(d[:len(d)-k]) if len(d) > k else 0)

Solution (Python):

import sys, math, fractions, collections


def solve(N: int, K: int, A: "List[int]"):
    c = collections.Counter(A)
    c = [cc[1] for cc in c.most_common()]
    print(int(sum(c[K:])))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    K = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, K, A)

if __name__ == '__main__':
    main()

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

c= collections.Counter(a)
b=c.most_common()[::-1]
d=len(set(a))
ans=0
if d-k<=0:
    print(ans)
    exit()
    
for i in range(d-k):
    ans+=b[i][1]
print(ans)

Solution (Python):
n, k = list(map(int, input().split()))
a = list(input().split())
a_unique = list(set(a))
d = {}
for i in range(len(a_unique)):
	d.setdefault(a_unique[i],0)
for i in range(n):
	d[a[i]] += 1
if len(d) <= k:
	print(0)
else:
	diff = len(d) - k
	d_value = list(d.values())
	d_value.sort()
	print(sum(d_value[:len(d)-k]))

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

num = [0]*(N+1)

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

V = N+1 - num.count(0)

if V <=K:
    print(0)
else:
    num.sort()
    num.reverse()
    print(sum(num[K:]))

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

num = [0]*2000001

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

V = 2000001 - num.count(0)

if V <=K:
    print(0)
else:
    num.sort()
    num.reverse()
    print(sum(num[K:]))

Solution (Python):
import bisect

N,K = [int(zz) for zz in input().split()]
A = [int(zz) for zz in input().split()]
B = set(A)

A.sort()
ans = []
for i in B:
    p = bisect.bisect_right(A, i) - bisect.bisect_left(A, i)
    ans.append(p)

ans.sort()
j = 0
for i in range(len(B)-K):
    j += ans[i]
print(j)

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

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a2 = {}
for i in a:
    a2.setdefault(i, 0)
    a2[i] += 1
a3 = list(a2.values())
a3.sort()
if len(a3) <= k:
    print(0)
else:
    num = 0
    for i in range(len(a3) - k):
        num += a3[i]
    print(num)

Solution (Python):
N, K = map(int, input().split())
nums = list(map(int, input().split()))
dict = {}
for num in nums:
  if num in dict.keys():
    dict[num] += 1
  else:
    dict[num] = 1
if len(dict.keys()) <= K:
  print(0)
else:
  sorted_list = sorted(dict.items(), key=lambda x: x[1])
  change = len(dict.keys()) - K
  ans = 0
  for i in range(change):
    ans += sorted_list[i][1]
  print(ans)

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
A=Counter(list(map(int,input().split())))
l=len(A.keys())
if l<=K:print(0)
else:
    v,c=zip(*A.most_common(K))
    print(N-sum(c))

Solution (Python):
from collections import Counter

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

    c = Counter(A)
    sorted_c = sorted(c.values())

    answer = 0
    for i in range(len(c.keys())-K):
        answer += sorted_c[i]
    print(answer)

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

d = {}

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

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

dif = len(set(a)) - k

if dif <= 0:
    print(0)
    exit()


c = 0

for i in range(dif):
    c += d[i][1]

print(c)

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

ldic = co.Counter(A)        
l = list(ldic.values())
ls = sorted(l,reverse=True)

print(sum(ls[K:]))

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math






def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,K = inputMap()
    A = inputList()
    
    Adict = {}
    for i in A:
        if i in Adict:
            Adict[i] += 1
        else:
            Adict[i] = 1
            
    if len(Adict) <= K:
        print(0)
        sys.exit()
        
    
    i = 0
    ans = 0
    for k, v in sorted(Adict.items(), key=lambda x: -x[1]):
        
        if i < K:
            i += 1
            continue
        
        ans += v
        
    print(ans)
            	
if __name__ == "__main__":
	main()

Solution (Python):
import collections
N,K = map(int,input().split(' '))
A = list(map(int,input().split(' ')))
B = collections.Counter(A)
ball_count = B.most_common()
ball_count.sort(key=lambda x:x[1])
M = len(ball_count)
num = 0
for i in range(0,M-K):
  x,y = ball_count[i]
  num += y
print(num)

Solution (Python):
import collections

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

B = collections.Counter(A)
C = list(B.values())

C.sort(reverse=True)
print(sum(C[K:]))

Solution (Python):
import sys

def main():
	n,k = map(int,input().split())
	a = list(map(int,input().split()))
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	b = sorted(b.items(), key=lambda x: x[1])
	nagasa = len(b)
	cost = 0
	for i in range(nagasa-k):
		cost += b[i][1]
	print(cost)

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

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

A.sort()
countlist=[]
num=0
for i in range(N):
    if A[i]!=num:
        countlist.append(1)
        num=A[i]
    else:
        countlist[-1]+=1
countlist.sort()

cnt=0
shu=len(set(A))
if shu>K:
    ans=sum(countlist[:shu-K])
else:
    ans=0
print(ans)

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

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()


res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

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

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()


res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
c = sum(map(lambda x: x[1], Counter(input().split()).most_common(k)))
print(n - c)

Solution (Python):

from collections import Counter


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


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


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


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
a = input().split()
cnt = Counter(a)
del_num = len(cnt) - k

print(sum(sorted(cnt.values())[:del_num]))

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
print(sum(sorted(Counter(map(int,input().split())).values())[:-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

L.sort(reverse=True)
print(sum(L[K:]))

Solution (Python):
from collections import Counter

n,k = map(int, input().split())
a = input().split()
cnt = Counter(a)
del_num = len(cnt) - k

print(sum(sorted(cnt.values())[:del_num]))

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = input().split()
cnt = Counter(A)
del_num = len(cnt) - K

print(sum(sorted(cnt.values())[:del_num]))

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

types = {}
balls = map(int, input().split())

for ball in balls:
    if ball in types:
        types[ball] += 1
    else:
        types[ball] = 1

ball_nums_sorted = sorted(types.values(), reverse=True)

types_count = len(types.keys())
rewrite_count = 0
while (K < types_count):
    rewrite_count += ball_nums_sorted.pop()
    types_count -= 1

print(rewrite_count)

Solution (Python):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ball = [0]*N
C = 0
for i in range(N):
  if ball[A[i]-1] == 0:
    C += 1
  ball[A[i]-1] += 1
if C <= K:
  ans = 0
else:
  ans = 0
  ball = [i for i in ball if i > 0]
  ball.sort()
  for i in range(C-K):
    ans += ball[i]
print(ans)

Solution (Python):
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1
V = list(D.values())
V.sort(reverse=True)
print(sum(V[K:]))

Solution (Python):
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
D = defaultdict(lambda: 0)
for a in A:
    D[a] += 1
V = list(D.values())
V.sort(reverse=True)
print(sum(V[K:]))

Solution (Python):
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


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

skip = K
ans = 0
for a, cnt in Counter(A).most_common():
    skip -= 1
    if skip < 0:
        ans += cnt
print(ans)

Solution (Python):
N,K = map(int,input().split())
a = list(map(int,input().split()))
adic = {}
for c in a:adic[c] = adic.get(c,0) + 1
alist = sorted([adic[c] for c in adic.keys()])
print(sum(alist[:len(alist)-K]))

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

counter = Counter(a_list).most_common()[::-1]

count = 0
for i in range(max((len(counter) - k), 0)):
    count += counter[i][1]

print(count)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
numberlist = []
now = [A[0], 1]
for i in range(1, N):
	if now[0] == A[i]:
		now[1] += 1
	else:
		numberlist.append(now)
		now = [A[i], 1]
numberlist.append(now)
ans = 0
if K < len(numberlist):
	M = len(numberlist) - K
	numberlist.sort(key = lambda v: v[1])
	for i in range(0, M):
		ans += numberlist[i][1]
print(ans)

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

b = defaultdict(int)
for i in range(n):
    b[a[i]] += 1

c = list(b.values())
c.sort()

ans = 0
for i in range(len(c) - k):
    ans += c[i]

print(ans)

Solution (Python):



def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h() if m > 1 else typ(input()) for _ in range(n)]


def main():
    N, K = read_h()
    A = read_h()

    cnt = [0] * (N + 1)
    for a in A:
        cnt[a] += 1

    ans = sum(sorted(cnt, reverse=True)[K:])
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
import sys
N, K = map(int, input().split())
a_lis = [int(_) for _ in input().split()]

counter = sorted(Counter(a_lis).items(), key=lambda x: x[1])

if len(counter) > K:
    ans_list = counter[:len(counter) - K]
    count = sum([item[1] for item in ans_list])
    print(count)
    sys.exit()

print(0)

Solution (Python):
from collections import Counter

n,k=map(int, input().split())
A=Counter(list(map(int, input().split())))
List=sorted(A.values())
ans=0
for i in range(len(A)-k):
    ans+=List[i]
print(ans)

Solution (Python):
row = input().split()
N = int(row[0])
K = int(row[1])
a = list(map(int, input().split()))
a.sort()
num = []
i = 0
count = 0
while i < N:
    j = 0
    while True:
        if a[i] == a[i+j]:
            count += 1
            j += 1
        else:
            num.append(count)
            i = i+j
            count = 0
            break
        if i+j >= N:
            num.append(count)
            i = i+j
            break
num.sort()
ans = 0
for i in range(len(num) - K):
    ans += num[i]
print(ans)

Solution (Python):
import collections

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


a = collections.Counter(a)


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


out = 0
if len(a_sort) <= k:
    print(0)
else:
    for i in range(len(a_sort)-k):
        out += a_sort[i][1]
    print(out)

Solution (Python):
N,K=map(int, input().split())
A=list(map(int, input().split()))
ball={}
result=0
for i in range(N):
  if A[i] in ball.keys():
    ball[A[i]]+=1
  else:
    ball[A[i]]=1
sorted_ball = sorted(list(ball.values()))
if len(sorted_ball) > K:
  for i in range(len(sorted_ball)-K):
    result+=sorted_ball[i]
print(result)

Solution (Python):
from collections import Counter

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(Counter(a).values())

print(sum(b[:(len(b)-k)]))

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

dic={}

for i in range(n):
    if not a[i] in dic:
        dic[a[i]]=0
    dic[a[i]]+=1

keys=list(dic.keys())
list=[]

for i in range(len(keys)):
    list.append(dic[keys[i]])

list.sort(reverse=True)
count=0
for i in range(k,len(list)):
    count+=list[i]
print(count)