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())
counter = Counter(int(x) for x in input().split())


i = len(counter) - K

if i < 1:
  print(0)
else:
  t = [(v, k) for k, v in counter.items()]
  t.sort()
  print(sum(v for v, k in t[:i]))

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

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

C = list(set(A))

B = len(C) 
x = B - K

d = {}

for i in A:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1

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

ans = 0
count = 0

if x<=0:
    print('0')
else:
    for key, value in d:
        ans = ans + value
        count = count + 1
        if count == x:
            print(ans)
            break

Solution (Python):
import collections

x, y = map(int,input().split())
li = list(map(int,input().split()))
c = collections.Counter(li)
ans = 0

count = c.most_common()
if len(count) > y:
    for i in range(y,len(count)):
        ans += count[i][1]

print(ans)

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

d = {}

for key in A:
    if key in d:
        d[key] += 1
        continue
    d[key] = 1

count = 0
d = sorted(d.items(), key=lambda x: x[1])
ans = 0
for key,data in d:
    if count<(len(A_set)-K):
        ans = ans + data
    count = count + 1
print(ans)

Solution (Python):
import sys
import collections
N, K = map(int, sys.stdin.readline().split(" "))
A = list(map(int, sys.stdin.readline().split(" ")))
C = sorted(list(collections.Counter(A).values()), reverse = True)
print(sum(C[K:]))

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
an = list(map(int, input().split()))
counts = Counter(an).most_common()
ans = 0
for i in range(max(0, len(set(an)) - k)):
    ans += counts[-(i+1)][1]
print(ans)

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

a_dic = {}

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

a_val = sorted(a_dic.values(),reverse = True)

print(sum(a_val[k:]))

Solution (Python):
from sys import stdin
import sys

[N, K] = list(map(int, stdin.readline().rstrip().split()))
A = list(map(int, stdin.readline().rstrip().split()))

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


count=0
num_of_items = len(h)

if num_of_items <= K:
    print(0)
    sys.exit()

for i in sorted(h.values()):
    if num_of_items > K:
        count += i
        num_of_items -= 1

print(count)

Solution (Python):
N,K=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
cnt=0
l=[]
l.append([A[0],0])
for i in range(len(A)):
  if A[i]==l[cnt][0]:
    l[cnt][1]+=1
  else:
    cnt+=1
    l.append([A[i],1])
if len(l) <= K:
  print(0)
else:
  l.sort(key=lambda x: x[1])
  sum=0
  for i in range(len(l)-K):
    sum+=l[i][1]
  print(sum)

Solution (Python):
import collections
N,K = map(int,(input().split()))
a = list(map(int,(input().split())))
f = collections.Counter(a)
c = f.most_common()[::-1]
ans = 0
for key in c[:max(0,len(c)-K)]:
    ans += key[1]
print(ans)

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

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

A_dict_sorted = sorted(A_dict.items(), key=lambda x:x[1])
result = 0
for i in range(len(A_dict)-K):
    result += A_dict_sorted[i][1]

print(result)

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

c = Counter(A)

c = sorted(c.values())


ans = sum(c[:-K])
print(ans)

Solution (Python):
import io

nim,mike=map(int,input().split())

A=list(map(int,input().split()))
from collections import Counter
A=Counter(A)
qwe=nim
for i in A.most_common(mike):
  qwe-=i[1]
print(qwe)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    a = list(map(int, readline().split()))

    from collections import Counter

    counter = Counter(a)
    u = len(counter)
    lcc = counter.most_common()[::-1]
    x = u - k

    ans = 0
    for i in range(x):
        ans += lcc[i][1]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
N, K = map(int,input().split())
A = list(map(int,input().split()))
count = Counter(A)
value = list(count.values())
value.sort()
ans = sum(value[:-K])
print(ans)

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

from collections import Counter
from operator import itemgetter


ac = Counter(a)
aci = list(ac.items())
aci = sorted(aci,key=itemgetter(1),reverse = False)  


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

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

Solution (Python):
from collections import Counter
n, k, *a = map(int, open(0).read().split())
_, c = zip(*Counter(a).most_common())
print(n - sum(c[:k]))

Solution (Python):
def resolve():
    N, K = list(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
    d = sorted(list(d.items()), key=lambda x: x[1], reverse=True)
    res = 0
    while len(d) > K:
        num, cnt = d.pop()
        res += cnt
    print(res)


if '__main__' == __name__:
    resolve()

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

l = sorted(d.values(), reverse=True)

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()))

dic = {}

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

ks = list(dic.keys())
vs = list(dic.values())

vs.sort()

B = (len(ks))
cnt = 0

for i in range(len(vs)):
    if B > K:
        B -= 1
        cnt += vs[i]
    else:
        break

print(cnt)

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

Solution (Python):
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)

MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

N,K = MI()
a = LI()

d = {}
for i in range(N):
    d[a[i]] = d.get(a[i],0)+1
num = list(d.values())
num.sort()
n = len(num)
ans = 0
for i in range(n-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=a.most_common()[::-1]
x=len(A)-k

if x<=0:
  print("0")
else:
  ans=0
  for i in range(x):
    ans+=A[i][1]
  print(ans)

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

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

Solution (Python):
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))
d = defaultdict(int)
for a in A:
    d[a] += 1
kind = list(d.values())
kind = sorted(kind, reverse=True)
print(sum(kind[K:]))

Solution (Python):
import collections

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

AC = collections.Counter(A)

if K >= len(AC):
    print(0)
    exit(0)

delete_item_num = len(AC)-K
ans = 0
cnt = 0
for k, v in sorted(AC.items(), key=lambda x: x[1]):
    cnt += 1
    ans += v
    if cnt >= delete_item_num:
        print(ans)
        exit(0)

Solution (Python):
from collections import Counter
m,k=map(int,input().split())
A=list(map(int,input().split()))
d=Counter(A)
l=d.most_common()[::-1]
ans=0
i=0
while len(d)>k:
  ans+=l[i][1]
  del d[l[i][0]]
  i+=1
print(ans)

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

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

import collections
A_c = collections.Counter(A)
A_A = A_c.most_common()

ans = 0
for i in range(len(A_A)):
  if i >K-1:
    ans += list(A_A[i])[1]

if len(A_A)<=K:
  print(0)
else:
  print(ans)

Solution (Python):
import sys
from collections import Counter

n, k, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    res = sum(sorted(c.values())[:-k])
    print(res)

if __name__ ==  '__main__':
    main()

Solution (Python):
from collections import defaultdict

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = defaultdict(int)
for i in range(n):
    cnt[a[i]] += 1

cnt = sorted(cnt.items(), key = lambda x:x[1])
ans = 0
for i in range(len(cnt) - k):
    ans += cnt[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)
C = sorted(C.items(), key=lambda x:x[1])

if len(C) <= K:
  print(0)
else:
  print(sum([c[1] for c in C[:len(C)-K]]))

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

Solution (Python):
import collections


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n,k = readInts()
    A = readInts()
    A_qu = collections.Counter(A)
    ALL = []
    for i in A_qu:
        ALL.append(A_qu[i])
    ALL = sorted(ALL)
    ans = 0
    for i in range(len(ALL) - k):
        ans += ALL[i]
    print(ans)
if __name__ == '__main__':
  main()

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

aa = collections.Counter(a)
sub = []
for i in aa:
    sub.append(aa[i])

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

print(ans)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
ns = list(map(int, input().split()))
dic = Counter(ns)
result = 0
len_dic = len(dic)
for key, value in sorted(dic.items(), key=lambda x: x[1]):
    if len_dic <= k:
        break
    len_dic -= 1
    result += value
print(result)

Solution (Python):
url = "https://atcoder.jp/contests/abc081/tasks/arc086_a"
import copy
def main():
    n, m = list(map(int, input().split()))
    li = list(map(int, input().split()))
    dic = {}

    for v in li:
        dic.setdefault(v, 0)
        dic[v] += 1

    if len(dic) <= m:
        print(0)
        exit()

    count = 0
    vals = sorted(list(dic.values()), reverse=True)
    for i in range(len(dic) - m):
        count += vals.pop(-1)



    print(count)

if __name__ == '__main__':
    main()

Solution (Python):
N,k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
count = [0] * N
for i in range(N):
  count[a[i]-1] += 1
count.sort(reverse = True)
ans = N
for i in range(k):
  ans -= count[i]
print(ans)

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

from collections import Counter
dic = Counter(a)

v = len(dic) 

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

ans = 0
for i in range(v-k):
    ans += l[i]

print(ans)

Solution (Python):






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

    cnt = {}
    for a in A:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1
    
    num_cnts = [[k, v] for k, v in cnt.items()]

    
    

    num_cnts = sorted(num_cnts, key=lambda x: x[1], reverse=True)
    ans = sum([cnt for num, cnt in num_cnts[K:]])

    return ans


print(main())

Solution (Python):






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

    cnt = {}
    for a in A:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1
    
    num_cnts = [[k, v] for k, v in cnt.items()]

    if len(num_cnts) <= K:
        return 0

    num_cnts = sorted(num_cnts, key=lambda x: x[1], reverse=True)
    ans = sum([cnt for num, cnt in num_cnts[K:]])

    return ans


print(main())

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
list_A = list(map(int, input().split()))
l = Counter(list_A)
l = sorted(l.values())
ans = 0
if len(l) > k:
    ans += sum(l[:len(l)-k])
print(ans)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)
if len(c) <= K:
    print(0)
else:
    n = len(c)
    c = sorted(c.items(), key=lambda x: x[1])
    ans = 0
    cnt = 0
    for k, v in c:
        cnt += 1
        ans += v
        if cnt == n - K:
            break
    print(ans)

Solution (Python):
import collections
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
c = collections.Counter(a_list)
v_list = []
c_v = c.values()
c_v = list(c_v)
c_v.sort()
if len(c_v)<k:
  print(0)
else:
  print(sum(c_v[:len(c_v) - k]))

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
A = list(map(int, input().split()))
counter = Counter(A)
result = 0
for el in sorted(list(counter.items()), key=lambda x:x[1], reverse=True)[k:]:
    result += el[1]
print(result)

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
if len(d) <= k:
  print(0)
else:
  d = sorted(d.values())
  ans = 0
  for i in range(len(d)-k):
    ans += d[i]
  print(ans)

Solution (Python):
import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))
a=collections.Counter(a)
A=a.most_common()[::-1]
x=len(A)-k

if x<=0:
  print("0")
else:
  ans=0
  for i in range(x):
    ans+=A[i][1]
  print(ans)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
c = 0
list_A = Counter(list(map(int,input().split())))
t = len(list_A.keys())-k
if t<=0:
  print(0)
else:
  B =sorted(list_A.items(),key=lambda x:x[1])
  for j in range(t):
    c += B[j][1]
  print(c)

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

Ad = {key:0 for key in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)

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

count = {}
for i in lst:
    if i in count.keys():
        count[i]+=1
    else:
        count[i]=1
count_sorted = sorted(count.items(), key=lambda x:x[1])


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

Solution (Python):

from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, A: "List[int]"):
    ctr = Counter(A)
    print(sum(sorted(ctr.values())[:-K]))


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

cnt = [0]*n
for i,p in enumerate(a):
    cnt[p-1] += 1

cnt.sort()
ans = 0
for i in range(n-k):
    ans += cnt[i]

print(ans)

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

a_cnt = {}
for i in a:
    if i in a_cnt:
        a_cnt[i] += 1
    else:
        a_cnt[i] = 1
from  operator import itemgetter

a_cnt = sorted(a_cnt.items(), key=itemgetter(1))

from collections import deque
cnt_list = deque([])
for i, j in a_cnt:
    cnt_list.append(j)

ans = 0
while len(cnt_list) > K:
    ans += cnt_list[0]
    cnt_list.popleft()
print(ans)

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

ans = 0
if len(cntr) > k:
  for i in range(k, len(cntr)):
    ans += cntr[i][1]
print(ans)

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

box = [0]*200000

for item in array:
  box[item-1] += 1
  
box.sort(reverse=True)

cnt = 0
for i in range(k):
  cnt += box[i]
  
print(n-cnt)

Solution (Python):
from collections import Counter

x, y = map(int, input().split())
l = list(map(int, input().split()))
l2 = []
d = Counter(l)
l2 = list(d.values())
l2.sort(reverse=True)

print(sum(l2[y:]))

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

d = {i:0 for i in set(A)}
for a in A:
    d[a] += 1
ans = list(d.values())
ans.sort(reverse = True)
print(sum(ans[k:]))

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

if len(set(A))<=k:
    print(0)
else:
    d = {i:0 for i in set(A)}
    for a in A:
        d[a] += 1
    ans = list(d.values())
    ans.sort(reverse = True)
    print(sum(ans[k:]))

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

import collections
c=collections.Counter(A)
lst=c.most_common()[::-1]
val_lst=[el[1] for el in lst]

print(sum(val_lst[:(len(lst)-K)]))

Solution (Python):
import collections
n,k = map(int,input().split())
line = list(map(int,input().split()))
num = len(set(line))
nums = collections.Counter(line)
snums = sorted(nums.values())
if num <= k:
  print(0)
else:
  require = num - k
  answer = 0
  for j in range(require):
    answer += snums[j]
  print(answer)

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

from collections import Counter
print(sum(sorted(list(dict(Counter(a)).values()))[:-k]))

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

num = collections.defaultdict(int)

for elem in a:
    num[elem] += 1

count = 0
if len(num) <= k:
    print(count)
else:
    
    sorted_num = sorted(num.items(), key=lambda x:x[1])
    
    for i in range(len(num) - k):
        
	    count += sorted_num[i][1]

    print(count)

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

Solution (Python):

from collections import Counter, deque






import sys

sys.setrecursionlimit(10 ** 5 + 10)




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

    AA = Counter(A).most_common()

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

resolve()

Solution (Python):
import collections

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

ans = 0
while len(tap) > k:
    ans += tap[-1][1]
    tap.pop(-1)

print(ans)

Solution (Python):


from collections import Counter


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

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

    result = 0
    for i in range(max(0, len(A) - K)):
        result += A[i][1]

    print(result)


if __name__ == "__main__":
    main()

Solution (Python):
from collections import Counter


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

C = Counter(A)
V = list(C.values())
V.sort()
ans = sum(V[:len(V) - K])

print(ans)

Solution (Python):
from collections import Counter
n,k,*a=map(int,open(0).read().split())
l=Counter(a).most_common()
ans=0
for i in l[k:]:
  ans+=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)

ball = []
for k, v in C.items():
    ball.append([v, k])
ball.sort(key=lambda x: -x[0])

ans = 0
for i in range(len(ball)):
    if i>=K:
        ans += ball[i][0]

print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
cc=Counter(a)
l=[]
for i in cc:
    l.append([cc[i],i])
l.sort(key=lambda x: -x[0] )

su=0
for i in range(min(k,len(l))):
    su+=l[i][0]
print(n-su)

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

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

Solution (Python):
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
def groupby():
    global a
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby()
b.sort(key=lambda x:x[1],reverse=True)
l=len(b)
ans=0
for i in range(k,l):
    ans+=b[i][1]
print(ans)

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = Counter(A)
values, counts = zip(*A.most_common())
counts = list(counts)
ans = 0

while K < len(counts):
  ans += counts[-1]
  counts.pop(-1)

print(ans)

Solution (Python):
N,K=map(int, input().split())
int_dict={}
for a in map(int, input().split()):
	int_dict.setdefault(a,0)
	int_dict[a]+=1
diff=len(int_dict) - K
if diff <= 0:
	print("0")
else:
	print(sum(sorted(int_dict.values())[:diff]))

Solution (Python):
from collections import Counter

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

C = Counter(A).most_common()

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

print(ans)

Solution (Python):
from collections import Counter
def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    counter = Counter(A)
    sorted_cnter = sorted(list(counter.items()), key=lambda x: x[1])
    will_rewrite = sorted_cnter[:-K]

    ans = 0
    for t in will_rewrite:
        ans += t[1]
    
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):

S = input().split(" ")
N = int(S[0])
K = int(S[1])
ARR = [int(s) for s in input().split(" ")]

def calculate(n, k, arr):
    dict = {}

    for ar in arr:
        if dict.get(ar) == None:
            dict.__setitem__(ar,1)
        else:
            tmp = dict.get(ar)
            tmp = tmp + 1
            dict.__setitem__(ar,tmp)

    sortedDict = sorted(dict.items(),key=lambda k:-k[1])


    sum = 0
    for i in sortedDict[k:]:
        sum = sum + i[1]


    print(sum)


calculate(N, K, ARR)

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

Solution (Python):
import collections

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

number = len(set(A))

c = collections.Counter(A)
values,counts=zip(*c.most_common())
count = 0
for i in range(number):
    if number <= K:
        print(count)
        break
    count += counts[-(i+1)]
    number -= 1

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

Solution (Python):
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, k = MI()
    a_list = MI()

    c = Counter(a_list)
    sum = 0
    if len(c) <= k:
        print("0")
        exit()

    for l in c.most_common()[k:]:
        sum += l[1]
    print(sum)
    pass


if __name__ == "__main__":
    main()

Solution (Python):
import collections

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

c = collections.Counter(l)
ans = 0
if K >= len(c):
    pass
elif len(c) > K:
    p = [s[1] for s in c.most_common()[::-1][:(len(c)-K)]]
    ans = sum(p)
print(ans)

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

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

a.sort()

s=[]
ai=a[0]
acnt=-1
for i in range(n):
    if a[i]>ai:
        s.append([acnt+1,ai])
        acnt=0
        ai=a[i]
    else:
        acnt=acnt+1
s.append([acnt+1,ai])
        

if len(s)<=k:
    print(0)
else:
    s.sort()

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

Solution (Python):
n,k,*l=map(int,open(0).read().split());from collections import*;print(sum(sorted(Counter(l).values())[:-k]))

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

Solution (Python):
from collections import *
f=lambda:map(int,input().split())
_,k=f()
c=Counter(f())
print(sum(sorted(c.values())[~k::-1]))

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

if len(d.keys()) <= k:
    print(0)
else:
    a = list(d.values())
    b = sorted(d.values())[-k:]
    for i in b:
        if i in a:
            a.remove(i)
    print(sum(a))

Solution (Python):
import sys

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

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

num_flag = [0 for i in range(n)]

for item in a:
    num_flag[item - 1] += 1












num_flag.sort(reverse=True)

cnt = 0
for i in range(k):
    cnt += num_flag[i]

print("{}".format(n - cnt))

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

Solution (Python):
from collections import defaultdict


def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    
    sorted_c = sorted(counter.values())
    ans = 0
    for i in range(len(counter) - K):
        ans += sorted_c[i]
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
from collections import Counter

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

c = Counter(a).most_common()[::-1]
res = 0
for i in range(len(c)-k):
    res += c[i][1]

print(res)

Solution (Python):
from collections import Counter

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

rep_n = len(A)-k

if rep_n<=0:
  print(0)
else:
  ans = 0
  for k, v in A.most_common()[::-1]:
    ans += v
    rep_n -= 1
    if rep_n==0:
      break
  print(ans)

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
  
cnt = max(len(d.keys()) - K, 0)
d = sorted(d.items(), key=lambda x:x[1])
ans = 0
for i in range(cnt):
  ans += d[i][1]
print(ans)

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
  
cnt = len(d.keys()) - K
d = sorted(d.items(), key=lambda x:x[1])
ans = 0
for val in d:
  if cnt <= 0:
    print(ans)
    exit()
  ans += val[1]
  cnt -= 1

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

Solution (Python):
from collections import Counter

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

c = Counter(balls)

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

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

t = list(map(int,input().split()))
c = collections.Counter(t)
score_sorted = sorted(c.items(), key=lambda x:-x[1])
count = 0
memo = 0
for i,j in score_sorted:
    memo += j
    count += 1
    if count == k:
        break
print(n-memo)

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

C = {}
for a in A:
  if a in C:
    C[a] += 1
  else:
    C[a] = 1
C = sorted(C.items(), key=lambda x:x[1])

ans = 0
i = 0 
for _,v in C:
  if len(C)-K <= i:
    break
  ans += v
  i += 1
print(ans)