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 sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,k = map(int,readline().split())
lst1 = list(map(int,readline().split()))

dic1 = dict()

for i in lst1:
    if i in dic1:
        dic1[i] += 1
    else:
        dic1[i] = 1

values = list(dic1.values())

values.sort()

values = deque(values)

ans = 0
while k < len(values):
    ans += values.popleft()

print(ans)

Solution (Python):
N, K = map(int,input().split())
A = list(map(int,input().split()))
li = {}
for i in A:
    c = li.setdefault(i,0)
    li[i] = c + 1
    
w = len(li.keys()) - K


ans = sorted(li.values())

if w > 0:
    print(sum(ans[:w]))
else:
    print(0)

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

import collections
c = collections.Counter(l)
c2=[i for i in c.items()]
c2.sort(key=lambda x: x[1])
ans=0
for i in range(len(c2)-k):
    ans+=c2[i][1]

print(ans)

Solution (Python):
N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
o = {}
for k in A:
    c = o.setdefault(k, 0)
    o[k] = c + 1
w = len(o.keys()) - K
ans = sorted(o.values())
print(sum(ans[:w]) if w > 0 else 0)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
li=c.most_common()
if len(li)<=k:
  print(0)
  exit()
li=li[k:]
ans=0
for i in li:
  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)
cs = sorted(c.items(), key=lambda x:x[1])
cnt = 0
for i in range(len(cs)-k):
    cnt += cs[i][1]
print(cnt)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
a_counter=collections.Counter(a)
a_count=a_counter.most_common()
answer = 0

for i in range(k, len(a_count)):
    
    answer += a_count[i][1]

print(answer)

Solution (Python):
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
cnt=[0 for i in range(N)]
for a in A:
  cnt[a-1]+=1
knd=[]
for i,c in enumerate(cnt):
  if c!=0:
    knd.append((i+1,c))
knd.sort(key=lambda x: x[1],reverse=True)
ans=0
while len(knd)>K:
  j,d=knd.pop()
  ans+=d
print(ans)

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

A_list = collections.Counter(A)
ok = A_list.most_common()[0:K]


ans2 = 0
for i in range(len(ok)):
  ans2 += ok[i][1]
  
print(N - ans2)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for i in a:
  d[i]+=1
if len(d)<=k:
  print(0)
else:
  print(sum(sorted(list(d.values()))[:len(d)-k]))

Solution (Python):
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
numberlist = dict()
for i in range(N):
    if A[i] in numberlist:
        numberlist[A[i]] += 1
    else:
        numberlist[A[i]] = 1
numberlist = sorted(numberlist.items(), key=lambda x: x[1])

ans = 0
index = 0
lenlist = len(numberlist)
while(1):
    if index >= lenlist - K:
        break
    ans += numberlist[index][1]
    index += 1
print(ans)

Solution (Python):
def solve(n, k, A):
    d = {}
    for a in A:
        d[a] = d.get(a, 0) + 1
    return sum(sorted(d.values())[:len(d) - k])

_n, _k = map(int, input().split())
_A = map(int, input().split())
print(solve(_n, _k, _A))

Solution (Python):
n,k = map(int,input().split())
a = list(map(int, input().split()))
s = dict()
for x in a:
  if x in s:
    s[x] += 1
  else:
    s[x] = 1
s_l = sorted(s.values())[0:max(0, len(s)-k)]
print(sum(s_l))

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for ai in a:
  if ai in d:
    d[ai] += 1
  else:
    d[ai] = 1
l = [d[key] for key in d]
l.sort(reverse = True)
if len(l) < k:
  print(0)
else:
  print(n - sum(l[:k]))

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline


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

    C = Counter(A)

    ans = 0
    if len(C) <= K:
        print(0)
        return
    else:
        mc = C.most_common()
        for i in range(len(C) - K):
            ans += mc[-i - 1][1]

    print(ans)


if __name__ == '__main__':
    main()

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

cnt = {}

for i in range(N):
    cnt.setdefault(A[i], 0)
    cnt[A[i]] += 1

cnt_val = sorted(cnt.values())
ans = sum(cnt_val[:len(cnt_val) - K])

print(ans)

Solution (Python):
dic = dict()

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

for ball in balls:
  if ball in dic:
    dic[ball] += 1
  else:
    dic[ball] = 1
    
nums = list(dic.values())
if len(nums) <= k:
  print(0)
else:
  print(sum(sorted(nums, reverse = True)[k:]))

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

dic = dict()
for a in A:
    if dic.get(a) is not None:
        dic[a] += 1
    else:
        dic[a] = 1
sorted_dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)

ans = 0
for ind, (k, v) in enumerate(sorted_dic):
    if ind < K:
        continue
    else:
        ans += v
print(ans)

Solution (Python):
from collections import Counter

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

print(N - sum(x[1] for x in Counter(A).most_common(K)))

Solution (Python):
import collections

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

c = collections.Counter(A).most_common()
c = sorted(c, key=lambda x: x[1])

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

Solution (Python):




from collections import Counter

def solve():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    counter = Counter(A)
    L = len(counter)
    ret = 0
    if L > K:
        l = counter.most_common()
        
        ret += sum(map(lambda x:x[1],l[K:]))
    
    print(ret)
    
solve()

Solution (Python):
from collections import Counter
import heapq

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

C = Counter(A)
print(N - sum(heapq.nlargest(K, C.values())))

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
cnt = sorted(Counter(A).values())
print(sum(cnt[:-K]))

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

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

_sorted_nums = [[i] * j for i,
                j in sorted(num_freq.items(), key=lambda x:x[1])]
sorted_nums = []
for i in _sorted_nums:
    sorted_nums += i

borders = []
for i in range(1, N):
    if sorted_nums[i-1] != sorted_nums[i]:
        borders.append(i)

if len(num_freq) <= K:
    print(0)
else:
    print(borders[-K])

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

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

_sorted_nums = [[i] * j for i,
                j in sorted(num_freq.items(), key=lambda x:x[1])]
sorted_nums = []
for i in _sorted_nums:
    sorted_nums += i

borders = []
for i in range(1, N):
    if sorted_nums[i-1] != sorted_nums[i]:
        borders.append(i)

if len(num_freq) <= K:
    print(0)
else:
    border = borders[-K]
    print(len(sorted_nums[:border]))

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

Solution (Python):
import collections

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

ans = 0
for i in range(max(0, len(cntA) - K)):
    ans += cntA[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)
print(sum(sorted(C.values())[:len(C)-K]) if len(C) > K else 0)

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

ball = [0]*N
count = 0
kind = 0

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

ball.sort(reverse=True)

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

print(count)

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

c=collections.Counter(a)
values = sorted(c.values())

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

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

n_map = {}
for n in numbers:
    if n_map.get(n) is None:
        n_map[n] = 1
    else:
        n_map[n] += 1

sorted_map = sorted(n_map.values(), reverse=True)
max_num = sum(sorted_map)
min_num = sum(sorted_map[:K])
print(max_num - min_num)

Solution (Python):
from collections import Counter

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

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

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

print(answer)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=len(l)
        l.append(1)
ans=0
l.sort()
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={}
l=[]
for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=len(l)
        l.append(1)
ans=0
l.sort()
for i in range(len(l)-k):
    ans+=l[i]
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    res = len(d)-k
    print(sum(d[:res]))
    return


if __name__ == "__main__":
    solve()

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)

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

newLi = []  
  
if len(d) <= K:
  print(0)
else:
  a = len(d) - K
  
  for i in d:
    newLi.append(d[i])

  newList = sorted(newLi)
  ans = 0
  
  for s in range(a):
    ans += newList[s]
  
  print(ans)

Solution (Python):
import collections

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

keys, conts = zip(*A.most_common()[::-1])
ans = 0
x = len(set(a))

for cont in conts:
    if x > k:
        ans += cont
    x -= 1

print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
cnt=Counter(a)
mos=cnt.most_common()
"""print(mos)
print(mos[0][0])"""
ans=0
if len(cnt)>=k:
    for i in range(len(cnt)-k):
        ans+=mos[-i-1][1]
print(max(0,ans))

Solution (Python):

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

from collections import Counter

counter = Counter(A)
cnt = len(list(counter.keys())) - K 

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

ans = 0

C = counter.most_common()[::-1]
for i in range(cnt):
  ans += C[i][1]

print(ans)

Solution (Python):
from collections import Counter
import heapq
n, k = map(int,input().split())
a = list(map(int,input().split()))
c = Counter(a)
heapc = list(c.values())
heapq.heapify(heapc)
l = len(c)
cnt = 0
if k < l:
    for _ in range(l-k):
        cnt += heapq.heappop(heapc)
print(cnt)

Solution (Python):
from collections import defaultdict

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

dic = defaultdict(int)

for a in as_:
    dic[a] += 1

sorted_data = [(a, v) for a, v in dic.items()]
sorted_data = sorted(sorted_data, key=lambda d: d[1], reverse=True)

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

print(count)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = Counter(A) 
key, value = zip(*A.most_common())

print(sum(value[K:]))

Solution (Python):
from collections import Counter

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


cnt = A[K:]
print(sum([v for k, v in cnt]))

Solution (Python):
import sys


def solve(inp):
    (N, K) = map(int, inp.readline().split(' '))
    A = map(int, inp.readline().split(' '))

    nums = {}
    num_kinds = 0
    for a in A:
        if a not in nums:
            num_kinds += 1
            nums[a] = 0
        nums[a] += 1

    values = sorted(nums.values())
    d = max(0, len(values) - K)
    s = sum(values[:d])

    return str(s)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

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

Solution (Python):

import sys
from collections import Counter

def solve(N: int, K: int, A: "List[int]"):
    counter = list(Counter(A).values())
    counter.sort()

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

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

c = collections.Counter(ls)
ls_s = c.most_common()

l = len(ls_s)
ans = 0

if l <= k:
	print(0)
else:
	for i in range(l - k):
		ans += ls_s[-1][1]
		del ls_s[-1]
	print(ans)

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

h = {}
for i in range(N):
    b = h.get(a[i], 0)
    h[a[i]] = b + 1

if len(h.keys()) <= K:
    print(0)
else:
    ans = 0
    keys = sorted(h.keys(), key=lambda x: h[x])
    for i in range(len(keys) - K):
        ans += h[keys[i]]
    print(ans)

Solution (Python):
import collections

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

c=collections.Counter(a)

ans=0

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

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

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

dct = {}
for i in range(n):
    if a[i] not in dct:
        dct[a[i]] = 1
    else:
        dct[a[i]] += 1

l = len(dct)
if l <= k:
    ans = 0
else:
    na = sorted([int(dct[key]) for key in dct])
    ans = sum(na[:l-k])

print(ans)

Solution (Python):
from collections import Counter

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

cou = sorted(Counter(A).items(), key=lambda x:x[1], reverse=True)
ans = [cou[i][1] for i in range(K, len(cou))]
print(sum(ans))

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

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

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

ans = []
for i in range(K, len(dic_sort)):
    ans.append(dic_sort[i][1])

print(sum(ans))

Solution (Python):
n,k=map(int, input().split())
l=sorted(list(map(int, input().split())))
ll=[]

cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    cont=1
ll.append(l.count(l[-1]))
ll.sort()
ll.reverse()

print(sum(ll[k:]))

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

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    A = LI()
    freq = collections.defaultdict(int)
    num = [0] * (N+1)
    for a in A:
        num[a] += 1
    num = sorted(num)[::-1]
    print(sum(num[K:]))

main()

Solution (Python):
import collections


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

if (k>=len(C)):
    ans = 0
else:
    ans = 0
    nums = sorted(C.values(),reverse=True)
    for i in range(k,len(nums)):
        ans += nums[i]
print(ans)

Solution (Python):
N_K = [int(i) for i in input().split()]

N = N_K[0]
K = N_K[1]

num_list = [int(i) for i in input().split()]
num_list.sort()

nums = [0] * (200001)

for i in range(0, N):
    nums[num_list[i]] += 1

nums.sort(reverse = True)

print(N - sum(nums[:K]))

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

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

Solution (Python):
import sys
from collections import Counter

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

def main():
    c = Counter(a)
    l = len(c)
    if l <= k:
        return 0

    c = sorted(c.items(), key=lambda x: x[1])
    res = 0
    for i in range(l - k):
        res += c[i][1]

    return res

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

Solution (Python):
N, K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
B = [0]*200010

for i in A:
    B[i] += 1
B.sort(reverse = True)

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

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*200001
C=[]
p=0
for i in A:
  B[i]+=1
cnt=0
for i in range(N+1):
  if B[i]!=0:
    cnt+=1
    C.append(B[i])
C.sort()
if K>=cnt:
  print(0)
else:
  j=0
  while K<cnt:
    p=p+C[j]
    cnt=cnt-1
    j=j+1
  print(p)

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = sorted(c.values(), reverse=True)
ans = 0
while len(d) > K:
    ans += d.pop()
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
m=len(set(A))
ans=0
if K>=m:
    print(0)
else:
    c = collections.Counter(A)
    c_=c.most_common()
    for i in range(m-K):
        ans+=c_[m-1-i][1]
    print(ans)

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

Solution (Python):

n,k = map(int, input().split())
A = list(map(int, input().split()))
D = dict()
for a in A:
    if a in D:
        D[a] += 1
    else:
        D[a] = 1
D = sorted(D.items(), key=lambda x: x[1])
D = D[:len(D)-k]
total = sum([d[1] for d in D])
print(total)

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

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

Solution (Python):


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

A.sort()
num = len(list(set(A)))
c = [0] * A[-1]
for a in A:
    c[a - 1] += 1
c.sort()
ans = 0
if num > K:
    i = 0
    diff = 0
    while diff != num - K:
        if c[i] != 0:
            ans += c[i]
            i += 1
            diff += 1
        else:
            i += 1

print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
ball = [0] * (N + 1)
for i in A:
        ball[i] += 1
ball.sort()
print(sum(ball[:-K]))

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

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

l = {}
for a in n:
    l[a] = l.get(a, 0) + 1
print(sum(sorted(l.values())[:-b]))

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

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

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

kc = len(c)
total = 0
for num, count in c:
  kc -= 1
  total += count
  if kc == k:
    print(total)
    exit(0)

print(0)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
cnt = [0] * (200000)
for i in range(n):
    cnt[a[i] - 1] += 1
cnt.sort(reverse=True)
kinds = 200000 - cnt.count(0)
if kinds <= k:
    print(0)
else:
    for i in range(kinds - k):
        ans += cnt[kinds - 1 - i]
    print(ans)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = {}
for a in A:
  l[a] = l.get(a, 0) + 1
print(sum(sorted(l.values())[:-K]))

Solution (Python):
import collections
n,k = map(int,input().split())
line = list(input().split())
c = collections.Counter(line)
answer = 0
if k > len(c):
  answer = 0
else:
  gap = len(c) - k
  sorted_c = list(sorted(c.items(),key = lambda x:x[1]))
  for i in range(gap):
    answer += int(sorted_c[i][1])
print(answer)

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)

count = 0
for i in range(K):
    count += b[i]

print(N-count)

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

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

ans = 0
i = 0
while len(v) - i > k:
    ans += v[i]
    i += 1

print(ans)

Solution (Python):
from collections import Counter
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=Counter(a)
als=list(c.values())
if len(als)<=m:
  print(0)
else:
  als.sort(reverse=True)
  print(sum(als[m:]))

Solution (Python):
import collections

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

B = collections.Counter(A)
V = []

for key, val in B.items():
    V.append(val)

V = sorted(V, reverse=True)

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

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

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

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


A2 = [0] * N
for i in range(len(A)):
    A2[A[i]-1] += 1

A2.sort(reverse = True)

count = 0
for i in range(K):
    count += A2[i]
print(N - count)

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

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

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

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

Solution (Python):

import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

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

Solution (Python):
from collections import Counter


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

if __name__ == "__main__":
    main()

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

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

print(sum(a[k:]))

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

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

change_count = len(A_dic) - K
count = 0
for i in range(change_count):
    count += A_dic[i][1]
    

print(count)

Solution (Python):
import collections as c
import numpy as np

N,K = map(int,input().split()) 
A = list(map(int,input().split()))
A_c = c.Counter(A)
A_c = sorted(list(A_c.values()))
KindNum = len(A_c)
if KindNum < K:
    print(0)
else:
    ans = sum(A_c[:KindNum - K])
    print(ans)

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

Solution (Python):
import collections
N,K = map(int, input().split())
lst = list(map(int, input().split()))
c = dict(collections.Counter(lst))
sorted_c = sorted(c.items(), key=lambda x:x[1], reverse=True)
ans = 0
if (len(sorted_c) > K):
  for i in sorted_c[K:]:
    ans += i[1]
print(ans)

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

Solution (Python):
import collections
import numpy as np
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
B=collections.Counter(A)
C=sorted(list(B.values()))
if len(C)<=K:
  answer=0
else:
  answer=np.cumsum(C)[len(C)-K-1]
print(answer)

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

print(sum(x[1] for x in c[k:]))

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