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):
from collections import Counter
N,K=map(int,input().split())
a = list(map(int,input().split()))
d=Counter(a)
ans=sum(sorted(d.values(),reverse=1)[:K])
print(N-ans)

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
a = list(map(int,input().split()))
d=Counter(a)
d=sorted(d.items(),key=lambda x:x[1])
ans=0
for i in range(len(d)-K):
        ans+=d[i][1]
print(ans)

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))
c=Counter(A)
count=0
if len(c)<=K:
    print(0)
else:
    x=c.most_common()[K:]
    for a in x:
        count+=a[1]
    print(count)

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

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

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

LD = list(dic.values())

L = sorted(LD)

if len(L) <= K:
    print(0)
else:
    print(sum(L[:-K]))

Solution (Python):
N, K = map(int, input().split())
args = list(map(int, input().split()))
ballset = set(args)
balls = {}
for ball in ballset:
    balls[ball] = 0
for i in args:
    balls[i] += 1
count = len(ballset)
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))

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

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )


print( sum( numAppeared[K:N] ) )

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

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

print( sum( numAppeared[i] for i in range(K,N) ) )

Solution (Python):
from collections import Counter
N,K=map(int,input().split())
nums=list(input().split())
a=Counter(nums)
print(sum(sorted(a.values(), reverse=True)[K:]))

Solution (Python):
N,K=map(int,input().split())
nums=list(input().split())
used_balls=0
dict={}
for n in nums:
  if n not in dict.keys():
    dict[n]=1
  else:
    dict[n]+=1
tmp=0
for d in sorted(dict.items(),key=lambda x: x[1],reverse=True):
  tmp+=1
  if tmp<=K:
    used_balls+=d[1]
  else:
    break
    
print(N-used_balls)

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

c = Counter(a)
c = sorted(c.items(), key=lambda x:x[1])
res = 0
for _, i in c[:len(c)-k]:
    res += i
print(res)

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

B = [0 for i in range(n+1)]

for i in range(n) :
    B[A[i]] += 1

B.sort(reverse=1)

print(sum(B[k:]))

Solution (Python):

"""
Created on Fri Mar  1 01:07:09 2019

@author: yuta
"""
import collections

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

"""
TLE解法
def main(nk,a):
    k = nk[1]
    a_uni = list(set(a)) 
    a_uni_num = [0]*len(a_uni) 
    for i in range(len(a_uni)):
        for j in range(len(a)):
            if a[j] == a_uni[i]:
                a_uni_num[i] += 1
    a_uni_num_sort = sorted(a_uni_num) 
    red_num = len(a_uni) - k 
    print(sum(a_uni_num_sort[:red_num]))

main(NK,A)
"""
def main(nk,a):
    k = nk[1]
    values,counts = zip(*collections.Counter(a).most_common())
    print(sum(counts)-sum(counts[:k]))
main(NK,A)

Solution (Python):
import collections
n,k = map(int, input().split())
num = list(map(int, input().split()))
cns = collections.Counter(num)
f = [cns[i] for i in cns]
f.sort(reverse=True)
print(sum(f[k::]))

Solution (Python):
import sys
input = sys.stdin.readline
import collections
n,k = map(int, input().split())
num = list(map(int, input().split()))
cns = collections.Counter(num)
f = [cns[i] for i in cns]
f.sort(reverse=True)
print(sum(f[k::]))

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(str,input().split()))
a_c=collections.Counter(a)
l=sorted(a_c.values())
ans=0
for i in range(len(l)-k):
    ans+=l[i]
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter([int(i) for i in input().split()]).most_common()
cnt = 0
for a in A[K:]:
    cnt += a[1]
print(cnt)

Solution (Python):
N, K = map(int, input().split())
l = list(map(int, input().split()))
cnt = [0 for _ in range(N)]
for i in l:
    cnt[i - 1] += 1
cnt.sort(reverse = True)
total = 0
for i in range(K):
    total += cnt[i]
print(N - total)

Solution (Python):


N,K=map(int,input().split())
A=list(map(int,input().split()))
sA=set(A)
ans=0
d={}
for s in sA:
	d[s]=0
for a in A:
	d[a]+=1
d=sorted(d.items(),key=lambda x:x[1])
for i in range(len(sA)-K):
	ans+=d[i][1]
print(ans)

Solution (Python):
import collections

n,k = (int(i) for i in input().split())
c = collections.Counter([int(i) for i in input().split()])
l = sorted(c.values())
if len(l) > k:
  print(sum(l[:len(l)-k]))
else:
  print(0)

Solution (Python):
from collections import Counter

n,k=map(int,input().split())
l=list(map(int,input().split()))
a=Counter(l)
c=a.most_common()
m=len(c)
sum=0
if k>m:
  print(0)
else:
  for i in range(k):
    sum+=c[i][1]
  print(n-sum)

Solution (Python):
N, K = map(int, input().split())
l = list(map(int, input().split()))
c = [0 for i in range(N)]
for i in l:
    c[i - 1] += 1
c.sort(reverse = True)
total = 0
for i in range(K):
    total += c[i]
print(N - total)

Solution (Python):
N, K = map(int, input().split())
l = list(map(int, input().split()))
cnt = [0 for i in range(N)]
for i in l:
    cnt[i - 1] += 1
cnt.sort(reverse = True)
total = 0
for i in range(K):
    total += cnt[i]
print(N - total)

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

from collections import Counter

most2 = Counter(A).most_common(K)

count = 0
for m in most2:
    count = count + m[1]

print(N-count)

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

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
set_a = set(a)
ans = 0
i = -1
c = Counter(a).most_common() 
while len(set_a) > k:
    set_a.remove(c[i][0])
    ans += c[i][1]
    i-=1
print(ans)

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

Solution (Python):

import copy
import numpy as np
import random


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

count_dic = {}

for i in range(len(a)):
    if a[i] in count_dic.keys():
        count_dic[a[i]] += 1
    else:
        count_dic[a[i]] = 1



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

ans = 0

while len(count_list)>k:
    
    delte_tuple = count_list[-1]
    add_tuple = count_list[0]
    count_list[0] = tuple([add_tuple[0],add_tuple[1]+delte_tuple[1]])
    ans += delte_tuple[1]
    del count_list[-1]

print(ans)

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

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










num = [0]*max(A)
cnt = [0]*max(A)


for a in A:
    if num[a-1] == 0:
        num[a-1] = 1

    cnt[a-1] += 1

kind = sum(num)

if kind > K:
    new_cnt = sorted([e for e in cnt if e != 0])
    res = sum(new_cnt[:(kind-K)])
else:
    res = 0

print(res)

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

print(sum(sorted(d.values())[:-K]))

Solution (Python):
import collections
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
l = IL()
setl = set(l)

if len(setl) <= K:
	print(0)
else:
	cl = collections.Counter(l)
	ans = 0
	for i in cl.most_common()[K:]:
		ans += i[1]
	print(ans)

Solution (Python):
import collections
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]

kind = dict(collections.Counter(ball))

if len(kind) <= K:
    print(0)
else:
    skind = sorted(kind.items(),key=lambda x: x[1])
    sumNum = 0
    for i in range(len(skind)-K):
        sumNum += skind[i][1]
    print(sumNum)

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

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

Solution (Python):
import collections
from operator import itemgetter
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]

kind = dict(collections.Counter(ball))

if len(kind) <= K:
    print(0)
else:
    skind = sorted(kind.items(),key=itemgetter(1))
    sumNum = 0
    for i in range(len(skind)-K):
        sumNum += skind[i][1]
    print(sumNum)

Solution (Python):


















import collections
import math


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

c = collections.Counter(A)

now = len(c)
ans = 0
for _, i in c.most_common()[::-1]:
  if now <= K:
    break
  ans += i
  now -= 1

print(ans)

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

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().split()))
from collections import Counter
C=Counter(A)
ans=0
l=len(C)
ans=0
if l<=k:
    print(ans)
else:
    B=[]
    for i in C.keys():
        B.append([i,C[i]])
    B=sorted(B,key=lambda x:x[1])
    for i in range(l-k):
        ans+=B[i][1]
    print(ans)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
lst=list(map(int,input().split()))
new_lst=[]
result=0
if len(list(set(lst)))<=k:
    print(result)
    exit()
else:
    c=Counter(lst).most_common()
    for u in range(k,len(c)):
        new_lst.append(c[u][1])
    print(sum(new_lst))

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

count = Counter(A)
res = 0
i = 0
for k,v in count.most_common():
    if K>i:
        i+=1
        continue
    res += v
print(res)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
A=Counter(list(map(int,input().split()))).most_common()
diff=len(A)-k
A=A[::-1]
if diff==0:
  print(0)
else:
  print(sum(list(map(lambda x:x[1],A[:diff]))))

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

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

print(sum(sorted(count.values())[:-k]))

Solution (Python):
N,K = map(int,input().split())
d = {}
for i in list(map(int,input().split())):
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1
l = []
for k,v in sorted(d.items(), key=lambda x: x[1]):
    l.append(v)

ans = 0
for i in range(len(l)-K):
    ans += l[i]

print(ans)

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

d = {}
for a in A:
  if(a not in d):
    d[a] = 1
  else:
    d[a] += 1

print(sum(sorted(d.values())[:-K]))

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

d = {}
for a in A:
  if(a not in d):
    d[a] = 1
  else:
    d[a] += 1
if(len(d) <= K):
  print(0)
else:
  tmp = sorted(d.items(), key = lambda x: -x[1])[K:]
  print(sum(t[1] for t in tmp))

Solution (Python):

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

from collections import Counter
from functools import reduce
d = Counter(a)



s =  reduce( lambda x,y:x+y, map(lambda x:x[1], d.most_common()[::-1][:len(d.most_common())-K]))\
  if len(d.most_common())-K >0 else 0
print(s)

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

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

A.sort()

i = 0
counter = -1
pnum = -1
data = []

while i < N:
    if pnum != A[i]:
        data.append(1)
        pnum = A[i]
        counter += 1
    else:
        data[counter] += 1
    i += 1

data.sort()

print sum(data[:counter-K+1])

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
c = sorted(Counter(input().split()).values())
print(sum(c[:max(0, len(c)-k)]))

Solution (Python):
nk = list(map(int, input().split()))
lis = list(map(int, input().split()))

lis.sort()
lis.append(241543903)
num = []
score = 1
kind = 1
ans = 0

for j in range(nk[0]):
    if lis[j] == lis[j+1]:
        score += 1
    else:
        num.append(score)
        score = 1
        kind += 1

kind -= 1
num.sort()

if nk[1] >= kind:
    print(0)
else:
    for k in range(kind - nk[1]):
        ans += num[k]
    print(ans)

Solution (Python):
import collections

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

def solve():
  c = list(collections.Counter(a).values())
  c.sort()
  if(len(c)<=k):
    print(0)
  else:
    print(sum(c[:len(c)-k]))

solve()

Solution (Python):
from collections import Counter


def solve(N, K, As):
    c = Counter(As)
    if len(c) <= K:
        return 0
    m = sorted([(v, k) for (k, v) in c.items()], reverse=True)
    return sum([n[0] for n in m[K:]])


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, K, As))

Solution (Python):
import collections
n,k = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
c = collections.Counter(a)
values,counts = zip(*c.most_common())
if len(counts) >= k:
 ans = sum(counts[k:])
else:
 ans = 0

print(ans)

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

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

c = Counter(a)
values, counts = zip(*c.most_common())

print(np.sum(np.sort(counts)[::-1][k:]))

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

ans = 0
for i in range(variety - K):
    ans += series[i]
print(str(ans))

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

a = sorted(a)
b =[]
tmp = 1
for i in range(0,n-1):
  if a[i]==a[i+1]:
    tmp +=1
  else:
    b.append(tmp)
    tmp = 1

if a[n-2]==a[n-1]:
  b.append(tmp)
elif a[n-2]!=a[n-1]:
  b.append(tmp)
  
b = sorted(b)
if len(b)<=k:
  print(0)
else:
  print(sum(b[:len(b)-k]))

Solution (Python):
from collections import Counter

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))

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

Solution (Python):
from collections import Counter

n,k = map(int,input().split())
n_lst = list(map(int,input().split()))
cnt_lst = Counter(n_lst).most_common()
ans = 0

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

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

from collections import defaultdict
d = defaultdict(int)

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

l = sorted(d.values())
M = len(d.keys())
if M<=K:
    print(0)
else:
    print(sum(l[:M-K]))

Solution (Python):
N, K = map(int, input().split())
L = list(map(int,input().split()))
l = []
import collections as coll
c = coll.Counter(L)
for x in c.items():
    tmp = (x[1],x[0])
    l.append(tmp)
l=sorted(l)
ans = 0
for i in range(len(l)-K):
    ans += l[i][0]
print(ans)

Solution (Python):
(n, k) = map(int, input().split())
count_dict = {}
for i in input().split():
    a = int(i)
    if not a in count_dict:
        count_dict[a] = 1
    else:
        count_dict[a] += 1
count = sorted(count_dict.items(), key=lambda x: x[1])
sum = 0
for i in range(len(count) - k):
    sum += count[i][1]
print(sum)

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

    import collections
    count = collections.Counter(A)
    pq = sorted([(v, k) for k, v in count.items()], key=lambda x: x[0])
    ans = 0

    if len(count) <= K:
        return 0

    for v, k in pq:
        ans += v
        del count[k]
        if len(count) <= K:
            return ans
    return -1


print(solve())

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

ar = []
tmp = -1
for a in li:
    if a != tmp:
        tmp = a
        ar.append(1)
    else:
        ar[-1] += 1
ar.sort()

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

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1
count = 0
for i, v in enumerate(sorted(B.values())):
    if len(B) - i <= K:
        break
    count += v
print(count)

Solution (Python):
import collections

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

cnt = 0
for i in range(len(d)):
    if i >= k:
        cnt += d[i][1]
print(cnt)

Solution (Python):
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
a = collections.Counter(A)
b = a.most_common()
L = len(b)
i = K
count = 0
while i < L:
    count+=b[i][1]
    i+=1
print(count)

Solution (Python):
from collections import Counter

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

count = 0
if len(A) > k:
    for i in range(len(A) - k):
        count += A[k + i][1]
        
print(count)

Solution (Python):
import collections
def ma():return map(int, input().split())
def lma():return list(map(int, input().split()))
a,b=ma()
x = lma()
c = collections.Counter(x)
k = c.most_common()
if b >= len(c):
    print(0)
else:
    s=0
    for i in range(b,len(c)):
        s+=k[i][1]
    print(s)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = input().split()
A_dict = sorted(Counter(A).items(), key=lambda x: x[1])
must_dec = len(A_dict) - K
ans = 0
for i in range(must_dec):
    ans += A_dict[i][1]
print(ans)

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

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

Solution (Python):
from collections import Counter


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

N, K = inpl()
A = inpl()
C = Counter(A)
C = list(sorted(C.items(), key=lambda x: x[1]))

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

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

from collections import Counter
C = list(Counter(A).most_common())

Ans = 0
for i in range(len(C)-K):
    Ans += C[-1-i][1]

print(Ans)

Solution (Python):



import collections as col

def solveProblem(neededBallKind,BallsList):
	AsListCounter = col.Counter(BallsList)
	allBallKind = len(AsListCounter)
	sortCounter = sorted(AsListCounter.items(),reverse=False,key=lambda x:x[1])
	replaceBallCount = 0
	replaceBallKind = allBallKind-neededBallKind
	if replaceBallKind <= 0:
		answer = 0
	else:
		for k,v in sortCounter:
			replaceBallCount = replaceBallCount + v
			replaceBallKind = replaceBallKind - 1
			if replaceBallKind <= 0:
				break
		answer = replaceBallCount
	return answer

if __name__ == '__main__':
	_,K = map(int,input().strip().split(' '))
	AsList = list(map(int,input().strip().split(' ')))
	solution = solveProblem(K,AsList)
	print("{}".format(solution))

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = dict()
for x in a:
    try: d[x] += 1
    except: d[x] = 1
l = sorted(list(d.values()))
if len(l) <= k: print(0)
else: print(sum([l[i] for i in range(len(l) - k)]))

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

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *


d = defaultdict(int)
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
for i in range(n):
    d[a[i]] += 1
count = 0
size = len(d)
for i, v in sorted(d.items(),key=lambda x:x[1]):
    if size <= k:
        break
    count += v
    size -= 1
print(count)

Solution (Python):
N,K = list(map(int,input().split()))
data = list(map(int,input().split()))
s = {}
ans = 0
for i in data:
    if i not in s:
        s[i] = 1
    else:
        s[i] += 1

if len(s) <= K:
    print('0')
    
else:
    fl = 0
    for k,v in sorted(s.items(),key = lambda x:x[1]):
        ans += v
        fl += 1
        if len(s)-K == fl:
            print(ans)
            break

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):
from collections import Counter
n,k=map(int,input().split())
a=Counter(input().split())
ans=0
keys,counts=zip(*a.most_common())
for num,(key,count) in enumerate(zip(keys,counts)):
    if int(num)>k-1:ans+=count
print(ans)

Solution (Python):
import sys

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


bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
dic = {}
for a in A:
    if not(a in dic):
        dic[a]=1
    else:
        dic[a]+=1
val = sorted(dic.values())

rc = len(val) - K
ans = 0
for r in range(rc):
    ans += val[r]
print(ans if ans >=0 else 0)

Solution (Python):
from collections import Counter

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

x = Counter(A).most_common()[::-1]
count = [x[i][1] for i in range(len(x)-K)]
print(int(sum(count)))

Solution (Python):
N,K=map(int,input().split())
D=dict()
for i in input().split():
    if i in D:
        D[i]+=1
    else:
        D[i]=1
L=[]
for i in D:
    L.append(D[i])
L.sort()
print(sum(L[:-K]))

Solution (Python):
N,K=map(int,input().split())
D=dict()
for i in input().split():
    if i in D:
        D[i]+=1
    else:
        D[i]=1
L=[]
for i in D:
    L.append(D[i])
L.sort()
print(sum(L[:-K]))

Solution (Python):
import collections

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

num = collections.Counter(A).most_common()[::-1]
ans = 0

if len(num) > K:
    for i in range(len(num) - K):
        ans += num[i][1]
print(ans)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


N, K = il()
A = il()
d = {}
c = 0
for a in A:
    try:
        d[a] += 1
    except KeyError:
        d[a] = 1
k = K - len(d)
if k >= 0:
    print(0)
    exit()
sd = sorted(d.items(), reverse=True, key=lambda x: x[1])
s = 0
for _, v in sd[k:]:
    s += v
print(s)

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

total = 0
for i, (k, v) in enumerate(sorted(mdict.items(), key=lambda x: -x[1])):
  if i >= K:
    total += v

print(total)

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

import collections

arr2 = collections.Counter(arr)

sm = list(arr2.items())

sm.sort(key=lambda x : x[1],reverse=True)

ans = 0

if len(sm) > k:
    for j in sm[k:]:
        ans += j[1]

print(ans)

Solution (Python):
N,K = map(int,input().split(" "))
A = input().split(" ")
A = [int(i) for i in A]
A = sorted(A)
D = [0] * (N+1)
for i in range(len(A)):
    D[A[i]] += 1

flag = 0
for i in range(len(D)):
    if D[i] > 0:
        flag += 1
if flag <= K:
    print(0)
else:
    DIF = flag - K
    D = sorted(D)
    E = []
    for i in range(len(D)):
        if D[i] > 0:
            E.append(D[i])
    ans = 0
    for i in range(DIF):
        ans += E[i]
    print(ans)

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

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

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
arr = [0 for _ in range(n+1)]

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

tmp = sorted(arr)[n-k+1:n+1]
print(n-sum(tmp))

Solution (Python):


def main():
    sa = input().split(' ')
    N = int(sa[0])
    K = int(sa[1])
    sa = input().split(' ')
    A = [int(s) for s in sa]

    d = dict()
    for a in A:
        if a in d:
            d[a] = d[a] + 1
        else:
            d[a] = 1

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

    r = 0
    if K < len(items):
        n = 0
        for k in range(K):
            n += items[k][1]
        r = N - n

    print(r)


if __name__ == '__main__':
    main()

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

    a_count = Counter(a)
    if len(a_count) <= k:
        print(0)
    else:
        val = list(a_count.values())
        val.sort()
        print(sum(val[:-k]))


abc081_c()

Solution (Python):
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
d = {}
for n in A:
    if n in d.keys():
        d[n] += 1
    else:
        d[n] = 1
if len(d.keys()) <= K:
    print(0)
else:
    val = []
    for k, v in sorted(d.items(), key=lambda x: -x[1]):
        val.append(v)
    ans = 0
    for i in val[K:]:
        ans += i
    print(ans)

Solution (Python):
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from collections import Counter
setrecursionlimit(2147483647)
def f(n=1):
    if n == 1:
        return [int(j) for j in input().split()]
    res = []
    for i in range(n):
        res.append([int(j) for j in input().split()])
    return res
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, k = f()
a = Counter(f())

print(n - sum(map(lambda x:x[1], a.most_common(k))))

Solution (Python):
from collections import Counter


def main():
    n, k = map(int, input().split())
    aa = list(map(int, input().split()))
    counts = Counter(aa)
    if len(counts) <= k:
        print(0)
        return
    res = sum(sorted(counts.values())[:len(counts) - k])
    print(res)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a=list(map(int,input().split()))
q = Counter(a).most_common()
count = 0
i = 0
if len(q) < k:
    print(0)
    exit()
while i < k:
    count += q[i][1]
    i += 1
print(n-count)

Solution (Python):
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
num_file = {}
for i in a_list:
    num_file[i] = 0
for i in a_list:
    num_file[i] += 1
if len(num_file) <= k:
    print(0)
else:
    new_list = sorted(num_file.items(), key = lambda x: x[1])
    ans = 0
    count = 0
    for key, value in new_list:
        ans += value
        count += 1
        if len(new_list)- count == k:
            print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
dict = {}
for Ai in A:
    if Ai in dict:
        dict[Ai] += 1
    else:
        dict[Ai] = 1
count = 0
if len(dict) > K:
    count = sum(sorted(dict.values())[:len(dict) - K])
print(count)

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

summary = {}
for a in A:
    if a not in summary.keys():
        summary[a] = 1
    else:
        summary[a] += 1
s_list = list(summary.values())
s_list.sort()
res = 0
i = 0
while len(s_list)-i > K:
    res += s_list[i]
    i += 1
print(res)

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

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = {}
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
b = []
for i, j in sorted(count.items(), key=lambda x: x[1]):
    b.append(j)
print(sum(b[0:len(b)-k]))

Solution (Python):

from collections import Counter
n, k = map(int, input().split())
a = map(int, input().split())
count = Counter(a)
c = sorted(count, key=lambda x: count[x], reverse=True)
ans = 0
while len(c) - k > 0:
    ans += count[c.pop()]
print(ans)

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

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

def cnt_uniq(li):
    return Counter(li).values()

uniq = sorted(cnt_uniq(a), reverse = True)[k:]
print(sum(uniq))

Solution (Python):
N, K = map(int, input().split())
cnt = [0 for _ in range(N)]

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

ans = 0
for i in sorted(cnt)[:N - K]:
    ans += i

print(ans)