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

ca = collections.Counter(a)
lk = ca.most_common(k)
sk = sum([lk[i][1] for i in range(len(lk))])
print(n-sk)

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

from collections import defaultdict
dic = defaultdict(int)
for a in al:
    dic[a] += 1

l = [i for i in dic.values()]
l = sorted(l)

a = len(l) - k

ans = 0
for i in range(max(a,0)):
    ans += l[i]

print(ans)

Solution (Python):
dbflag=0
def debug(*args):
  if dbflag: print(*args)

result = 0


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


A = [int(i) for i in input().split(' ')]

bag = {}

for x in A:
	if 'x'+str(x) in bag:
		bag['x'+str(x)]+=1
	else:
		bag['x'+str(x)] = 1

debug(bag)
L = sorted(bag.items(),key= lambda x:x[1])
debug(L,len(L),K)
cnt = len(L) - K

if cnt > 0:
	result = sum(y[1] for y in L[0:cnt])
	debug([y[1] for y in L[0:cnt]])
else:
	result = 0


print(result)

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

values = Counter(A).values()
length = len(values)
values = sorted(values)
ANS = 0

for i in range(length - K):
  ANS += values[i]
print(ANS)

Solution (Python):
import collections

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

c = collections.Counter(A) 

List=sorted(c.values())[::-1]


print(sum(List[K:]))

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

values = Counter(A).values()
length = len(values)
values = sorted(values)
ANS = 0

for i in range(length - K):
  ANS += values[i]
print(ANS)

Solution (Python):
from collections import Counter 

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

now_k=len(set(a))
d=now_k-k
arr=Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print(sum(b[:d]))

Solution (Python):
import collections

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

now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print(sum(b[:d]))

Solution (Python):
import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))
now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()

b=sorted([arr[i][1] for i in range(now_k)])

cnt=now_k
cnt2=0
flg=0
for i in b:
  cnt-=1
  cnt2+=i
  if cnt==k:
    print(cnt2)
    flg=1
    break
if flg==0:
  print(0)

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

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

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

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

b = [0]*n

if len(list(set(a))) <=k:
    print(0)
else:
    for i in a:
        b[i-1]+=1
    b.sort(reverse=True)
    del b[0:k]
    print(sum(b))

Solution (Python):
from collections import Counter
n,k = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]

c = Counter(l)

ans = 0
for k,v in c.most_common()[k:]:
    ans += v
    
print(ans)

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

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
values = list(D.values())
values.sort()
print(sum(values[:len(values)-K]))

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

l = list(balls.values())
l.sort()

answer = 0
if K < len(l):
  for i in range(0, len(l) - K):
    answer += l[i]
print(answer)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
size=len(Counter(A).most_common())
if K >= size:
    print(0)
else:
    values, counts = zip(*Counter(A).most_common()[::-1])
    ans=0
    for i in range(size-K):
        ans += counts[i]
    print(ans)

Solution (Python):
import collections
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = collections.Counter(a_list)
d = b.most_common()[k:]
sum = 0
for i in d:
    sum += i[1]
print(sum)

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

a_values = collections.Counter(a)

o = len(a_values) - k
values, counts = zip(*a_values.most_common()[::-1])

if o <= 0:
    print(0)
else:
    print(sum(counts[:o]))

Solution (Python):
N,K = [int(i) for i in input().split()]
AAA = [int(i) for i in input().split()]
 
count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
count=sorted([i for i in count if i!=0])
 
if len(count)<=K:
    print("0")
    exit()
else:
    print(sum(count[:-K]))

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

count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
count=sorted([i for i in count if i!=0])

if len(count)<=K:
    print("0")
    exit()
else:
    print(sum(count[:-K]))

Solution (Python):
from sys import stdin
from itertools import groupby

n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()

lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

lin.sort()

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

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

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

Solution (Python):
import collections

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

set_A = set(A)
c = collections.Counter(A)
cnts = []
for a, t in c.items():
    cnts.append([t, a])
cnts.sort()
ans = 0
for cnt in cnts:
    if len(set_A) <= k:
        print(ans)
        break
    else:
        ans += cnt[0]
        set_A.remove(cnt[1])

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import defaultdict as ddict
A_dict = ddict(int)
for a in A:
    A_dict[a] += 1
A_tupple = sorted(A_dict.items(), key=lambda x:x[1],reverse=True)
ans = 0
for a in A_tupple[K:]:
    ans += a[1]
print(ans)

Solution (Python):
N,K = map(int, input().split())
A = list(map(int, input().split()))
B ={}
for i in A:
    if i not in B.keys():
        B[i] = 1
    else:
        B[i] += 1
C = sorted(B.items(), key=lambda x: -x[1])
count = 0
while len(C) > K:
    a,b = C.pop()
    count += b
print(count)

Solution (Python):

import collections

N,K = map(int, input().split())
A_list = [int(e) for e in input().split()]

counted = collections.Counter(A_list)
count_listed = list(counted.values())
count_listed.sort(reverse=True)

ans = 0

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

Solution (Python):
from collections import Counter

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

lenght = len(set(A))-K
ans = 0
if lenght<=0:print(ans), exit()
else:
    for k, v in Counter(A).most_common()[::-1][:lenght]:
        ans += v
print(ans)

Solution (Python):
def examC():
    N, K = LI()
    A = LI()
    d = defaultdict(int)
    for i in A:
        d[i] +=1
    cur = 0
    que = []
    heapq.heapify(que)
    for i in d.values():
        heappush(que,i)
    for i in range(len(d)-K):
        cur += heappop(que)
    print(cur)

import sys,copy,bisect,itertools,heapq
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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

count = collections.Counter(list_a)
sort_c = sorted(count.items(), key=lambda x:x[1])
num_kind = len(sort_c)

result = 0
for i in range(num_kind - k):
  result += sort_c[i][1]
print(result)

Solution (Python):
from collections import Counter as C
N, K = map(int, input().split())
A = sorted(C([int(a) for a in input().split()]).values())[::-1]
print(sum(A) - sum(A[:K]))

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
species = list(set(A))
dic = {}
for i in species:
    dic[i] = 0
for i in A:
    dic[i] += 1
if K >= len(species):
    print(0)
else:
    tmp = sorted(dic.values(),reverse=1)
    print(sum(tmp[K:]))

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
species = list(set(A))
dic = {}
for i in species:
    dic[i] = 0
for i in A:
    dic[i] += 1
if K >= len(species):
    print(0)
else:
    tmp = sorted(dic.values(),reverse=1)
    print(sum(tmp[K:]))

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

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
Alist = Counter(list(map(int, input().split()))).most_common(K)
for key, value in Alist:
    N -= value
print(N)

Solution (Python):
n,k = map(int, input().split())
a = [int(i) for i in input().split()]
adict = {}
for ai in a:
    adict[str(ai)] = adict.get(str(ai), 0)+1
a = sorted(adict.values())
print(sum(a[:len(a)-k]))

Solution (Python):
import sys
import collections

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')

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

c = collections.Counter(nums)
d = c.most_common()[::-1]
print(sum([d[i][1] for i in range(len(d) - K)]))

Solution (Python):
import heapq
import collections as c
N, K = map(int, input().split())
A = c.Counter(list(map(int, input().split())))
S = len(list(A.keys()))

V = list(A.values())
heapq.heapify(V)

ans = 0
for _ in range(max(0,S-K)):
	ans += heapq.heappop(V)

print(ans)

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

N,K = map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
d = len(c)
ans = 0
c_sorted = sorted(c.items(),key = lambda x:x[1])
for i in c_sorted:
    if K >= d:
        break
    ans += i[1]
    d -= 1
print(ans)

Solution (Python):
import collections

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

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
for i in li:
    ans+=i[1]
print(ans)

Solution (Python):
from collections import Counter

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

c = Counter(aa)
ans = 0
if len(c) > k:  
  cc = c.most_common()[::-1]
  for i in range(len(cc)-k):
    ans += cc[i][1]

print(ans)

Solution (Python):
N, K = [int(i) for i in input().split()]
B = sorted([int(i) for i in input().split()])
D ={}
bag = 0

for i in B:
    if i in D:
        D[i] += 1
    else:
        D[i] = 1

LLL = sorted(list(D.values()))
AA = len(D) - K
if len(D) <= K:
    print(0)
else:
    for i in range(AA):
        bag += LLL[i]
    print(bag)

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

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

k = len(list(set(A)))
d = defaultdict(int)

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

print(sum(sorted(d.values())[:max(0, k - K)]))

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

for i in input().split():
  B[int(i)] += 1

print(sum(sorted(B)[:-K]))

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

def one_int():
    return int(input())

def one_str():
    return input()

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

N, K = two_int()
A = many_int()

dicts={}
for i in A:
    if i in dicts:
        dicts[i]+=1
    else:
        dicts[i]=1

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

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

sums = 0
for i in items[:len(items) - K]:
    sums += i[1]

print(sums)

Solution (Python):
N, K = map(int, input().split())
a = list(map(int, input().split()))
d = {}
cnt = 0
for v in a:
  if not v in d:
    d[v] = 1
    cnt += 1
  else:
    d[v] += 1
if cnt - K < 0:
  print(0)
else:
  s = sorted(d.items(), key=lambda x:x[1])
  ans = 0
  for i in range(cnt - K):
    ans += s[i][1]
  print(ans)

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

Solution (Python):
import sys
import collections
input = sys.stdin.readline
n,k = map(int,input().split())

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

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

Solution (Python):
import sys
import collections







def main():
    n, k, *a = (int(x) for x in sys.stdin.read().split())

    c = collections.Counter(a)
    diffs = len(c)
    if diffs <= k: print(0); exit()
    remainder = diffs - k
    count = 0
    l = sorted(c.values())
    b = collections.Counter(l)
    for i, j in sorted(b.items()):
        if remainder - j > 0:
            count += j * i
            remainder -= j
        else:
            count += remainder * i
            break
    
    print(count)

if __name__ == "__main__":
    
    main()

Solution (Python):
import sys
import collections


import bisect




def main():
    n, k, *a = (int(x) for x in sys.stdin.read().split())

    c = collections.Counter(a)
    diffs = len(c)
    if diffs <= k: print(0); exit()
    remainder = diffs - k
    count = 0
    l = sorted(c.values())
    for i in range(1, n+1):
        b = bisect.bisect_right(l, i) - bisect.bisect_left(l, i)
        if remainder - b >= 0:
            count += b * i
            remainder -= b
        else:
            count += remainder * i
            break
    
    print(count)

if __name__ == "__main__":
    
    main()

Solution (Python):
import heapq

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

L = [0]*(N+1)
for i in range(N):
    L[A[i]] += 1
    
h = []
for i in range(N+1):
    if L[i] > 0:
        heapq.heappush(h, L[i])
        
ans = 0
while len(h) > K:
    ans += heapq.heappop(h)
    
print(ans)

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

b = [0] * n
for i in range(n):
    b[a[i] - 1] += 1

b.sort(reverse=True)

ans = 0

for i in range(k):
    ans +=b[i] 

if n - ans <= 0:
    print(0)
else:
    print(n - ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=[]
d,p=0,a[0]
for x in a:
  if p==x:
    d+=1
  else:
    c.append(d)
    d=1
    p=x
c.append(d)
c.sort(reverse=1)
k=min(k,len(c))
print(sum(c[k:]))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=[]
d,p=0,a[0]
for x in a:
  if p==x:
    d+=1
  else:
    c.append(d)
    d=1
    p=x
c.append(d)
c.sort(reverse=1)
k=min(k,len(c))
print(sum(c[k:]))

Solution (Python):
a,b=map(int,input().split())
n=list(map(int,input().split()))
import collections as c
lis=c.Counter(n).most_common()[b:]
ans=0
for i in lis:
    ans+=i[1]
print(ans)

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

Solution (Python):
import collections

N,K=map(int,input().split())
A=list(map(int,input().split()))
L=collections.Counter(A)
values,counts=zip(*L.most_common())
counts=list(counts)

Colors=len(counts)
Change=0
while Colors>K:
    Change+=counts[-1]
    counts.pop()
    Colors-=1

print(Change)

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

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

for i in A:
    L[i] += 1
    uniq.add(i)

if len(uniq) <= K:
    print(0)
else:
    L = sorted(L)
    count = 0
    ans = 0
    for i in L:
        if i != 0:
            count += 1
            ans += i
        if count == len(uniq)-K:
            break
    print(ans)

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

    cnt = [0] * N

    for ai in A:
        cnt[ai - 1] += 1

    cnt.sort()
    ans = sum(cnt[:N-K])
    print(ans)

if __name__ == "__main__":
    main()

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

    for ai in A:
        CNT[ai] += 1

    

    CNT2 = [i for i in CNT if i != 0]
    CNT2.sort()
    

    x = len(CNT2) - K
    print(sum(CNT2[:x]))
    

if __name__ == "__main__":
    main()

Solution (Python):
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
nums = {}
for a in A:
    if a in nums:
        nums[a] += 1
    else:
        nums[a] = 1
sorted_nums = list(sorted(nums.items(), key=lambda x: x[1]))
nums_len = len(sorted_nums)
ans = 0
if nums_len > K:
    for i in range(nums_len - K):
        ans += sorted_nums[i][1]
print(ans)

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

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

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

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

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

Solution (Python):
from collections import Counter

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

count = sorted(list(Counter(a).values()), reverse = True)

print(n - sum(count[:k]))

Solution (Python):
from collections import Counter

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

c = Counter(a) 
count = c.values() 

l_count = list(count) 
l_count.sort(reverse = True) 

print(n - sum(l_count[:k]))

Solution (Python):
from collections import Counter

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

count = []
c = Counter(a) 
for i in c:
    count.append(c[i])

count.sort(reverse = True)
print(n - sum(count[:k]))

Solution (Python):




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


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

li = sorted(li,reverse = True)

ttl = 0
for i in range(n+1):
    ttl += li[i]

    if i == k-1:
        break

ans = n-ttl

print(ans)

Solution (Python):
import sys
import collections
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    c = collections.Counter(input().split())
    c = sorted(c.values())
    k = len(c) - K
    if k <= 0:
        print(0)
    else:
        print(sum(c[:k]))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import collections
sys.setrecursionlimit(10 ** 7)


def main():
    N, K = map(int, input().split())
    c = collections.Counter(input().split())
    print(sum(sorted(c.values(), reverse=True)[K:]))


if __name__ == '__main__':
    main()

Solution (Python):
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
grps =[] 
from collections import Counter 
c=Counter(l)
l=[c[i] for i in c]
l.sort(reverse=1)
print(n-sum(l[:k]))

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

d={}
for Ai in A:
    if Ai not in d:
        d[Ai]=1
    else:
        d[Ai]+=1

l=sorted(list(d.values()))

print(sum(l[:max(len(l)-K,0)]))

Solution (Python):
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))
numMap = {}
ans = 0

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

if len(numMap) <= k:
    print(0)
    sys.exit()

cnts = []
for cnt in numMap.values():
    cnts.append(cnt)
cnts.sort()
temp = len(numMap)

for cnt in cnts:
    if temp == k:
        break
    ans += cnt
    temp -= 1



print(ans)

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

score = dict()

for i in range(N):
	if A[i] in score:
		score[A[i]] += 1
	else:
		score[A[i]] = 1
		
score_sorted = sorted(score.items(), key=lambda x:x[1])

ret = 0

if len(score_sorted) - K > 0:
	for i in range(len(score_sorted) - K):
		ret += score_sorted[i][1]
	print(ret)
else:
	print(0)

Solution (Python):
import collections
N,K=map(int,input().split())
li=list(map(int,input().split()))
li_count=collections.Counter(li)
li_count_most=li_count.most_common()[::-1]
change=0
S=max(len(li_count)-K,0)
for s in range(S):
    change+=li_count_most[s][1]
print(change)

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

M = max(A)

L = [0] * (M+1)

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

D = []    
for i in range(M+1):
    if L[i] > 0:
        D.append(L[i])

D.sort()

nn = len(D)

if nn <= K:
    print(0)

else:
    print(sum(D[:nn-K]))

Solution (Python):
n,k=map(lambda x: int(x), input().split())
a=list(map(lambda x: int(x), input().split()))
dic={}
for i in range(n):
    dic[a[i]]=dic.get(a[i],0)+1
count=list(dic.values())
count.sort(reverse=True)
if len(count) <= k:
    print(0)
else:
    print(sum(count[k:]))

Solution (Python):
import collections

def test():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    b = collections.Counter(a).most_common()
    ans = 0; i = -1
    c = len(b)
    while k < c:
        ans = ans + b[i][1]
        c = c - 1
        i = i - 1
    print(ans)


if __name__ == "__main__":
    test()

Solution (Python):

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


count = {}
for i in range(n):
    if a[i] not in count:
        count[a[i]] = 0
    count[a[i]] += 1
ans = 0
value = list(count.values())
value.sort()
for i in range(max(len(value) - k, 0)):
    ans += value[i]
print(ans)

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

import collections

c = collections.Counter(A)

cnt=0
res=0
for i in c.most_common():
        if cnt >= K:
                res+=i[1]
        else:
                cnt+=1


print(res)

Solution (Python):
N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
dic={}
for e in ls:
  if (e in dic):
    dic[e]+=1
  else:
    dic[e]=1
ls2=list(dic.items())
ls2=sorted(ls2, key=lambda x : -x[1])
ans=0
for i in range(K,len(ls2)):
  ans+=ls2[i][1]
print(ans)

Solution (Python):

import sys
import collections

def solve(N: int, K: int, A: "List[int]"):
    a_counter = collections.Counter(A)
    if len(a_counter) <= K:
        print(0)
        return 

    values = sorted(list(a_counter.values()))
    answer = 0
    for i in range(len(a_counter)-K):
        answer += values[i]
    print(answer)
    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)
NumA = list(c.values())
NumA.sort()
ans = 0

for i in range(len(set(A))-K):
    ans += NumA[i]
print(ans)

Solution (Python):
import sys


n,k = [int(_) for _ in input().split()]
l = [int(_) for _ in input().split()]
ans = 0
d = {}
for i in range(n):
    if l[i] in d:
        d[l[i]] += 1
    else:
        d[l[i]] = 1
d_sorted = sorted(d.items(), key = lambda x:x[1], reverse=True)
if len(d_sorted) <= k:
    ans = 0
    print(ans)
    sys.exit()
else:
    for j in range(k,len(d_sorted)):
        ans += d_sorted[j][1]
print(ans)

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

for i in range(k):
    ans += number[i]
ans = n-ans
print(ans)

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n, k = map(int, input().split())
    as_ = list(map(int, input().split()))
    counter_a = collections.Counter(as_)
    counter_a = sorted(counter_a.items(), key=lambda x: x[1])
    types = len(counter_a)
    ans = 0
    for num, count in counter_a:
        if types > k:
            ans += count
            types -= 1
        if types <= k:
            print(ans)
            break

if __name__ == '__main__':
    main()

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

List = collections.Counter(A)

cnt = list(List.values())
cnt.sort()

ans = 0
L = len(cnt)
for i in range(L):
    if L-i>K:
        ans += cnt[i]
    else:
        break
print(ans)

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

Solution (Python):
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = sorted(Counter(A).values(),reverse=True)
    ans = 0
    while K < len(c):
        ans += c.pop()
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import collections as col

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

cnt = col.Counter(li)
cnt2 = list(cnt.values())
cnt2 = sorted(cnt2)
cnt2 = list(reversed(cnt2))
print(max(0,n-sum(cnt2[0:k])))

Solution (Python):

N, K = map(int, input().split())
A = list(map(int, input().split()))
H = [0] * N
for i in range(N):
    H[A[i]-1] += 1
H.sort(reverse=True)
print(sum(H[K:]))

Solution (Python):

N, K = map(int, input().split())
A = list(map(int, input().split()))
H = [0] * N
for i in range(N):
    H[A[i]-1] += 1
H.sort(reverse=True)
print(sum(H[K:]))

Solution (Python):
import collections

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

A_count = collections.Counter(A)

_, counts = zip(*A_count.most_common()[::-1])

print(sum(counts[:len(counts)-K]))

Solution (Python):
import collections

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

A_count = collections.Counter(A)

_, counts = zip(*A_count.most_common()[::-1])

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

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

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

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

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

if len(d) <= k:
    print(0)
else:
    l = list(d.items())
    l = sorted(l, key=lambda x: x[1])
    res = 0
    for i in range(len(l) - k):
        res += l[i][1]
    print(res)

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

cnt=sorted(Counter(A).values())
print(sum(cnt[:-k]))

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

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

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

count = Counter(ali)
sortcount = sorted(count.items(), key=lambda x:x[1])

diverse = len(count)
erase = diverse - k
if erase <= 0:
    print(0)
    exit()

num = 0
for key, val in sortcount[:erase]:
    num += val
print(num)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = {}
for i in range(N):
    a = A[i]
    if a not in B:
        B[a] = 0
    B[a] += 1
B = list(B.items())
B = sorted(B,key= lambda x:x[1],reverse=True)
cnt = 0
for i in range(K,len(B)):
    cnt += B[i][1]
print(cnt)

Solution (Python):
N,K = map(int,input().split())
Data = list(map(int,input().split()))
Dic = {}
for d in Data:
    if d in Dic.keys():
        Dic[d]+=1
    else:
        Dic[d]= 1
kind = len(Dic)

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

ans = 0
cnt = kind-K
for k,v in sortedDic:
    if cnt <= 0:
        break
    else:
        cnt -= 1
        ans += v
print(ans)