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):
k,n=map(int,input().split())
a = list(map(int,input().split()))
a=sorted(a)
d=[]
cnt=1
for i in range(k-1):
  if a[i]==a[i+1]:
    cnt+=1
  else:
    d.append(cnt)
    cnt=1
d.append(cnt)
d=sorted(d)
ans=0
for i in range(len(d)-n):
  ans+=d[i]
print(ans)

Solution (Python):

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

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

dic = {}

for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

lis = []

for i in dic:

    lis.append(dic[i])

lis.sort()

ans = 0

num = len(lis) - K
if num < 0:
    num = 0

for i in range(num):
    ans += lis[i]

print (ans)

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
dic={}
for i in A:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
ans=0
for k,v in sorted(dic.items(),key=lambda x: x[1]):
    if K >= len(dic): break
    ans+=v
    K+=1
print(ans)

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

a.sort()

b = [0]*(len(set(a)))

ind = 0
for i in set(a):
    b[ind] = bisect.bisect_right(a,i)-bisect.bisect_left(a,i)
    ind += 1

b.sort()

print(sum(b[:max(0,len(b)-k)]))

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
*A, = map(int, input().split())
lst = sorted(Counter(A).values())
print(sum(lst[:len(lst)-K]))

Solution (Python):
from collections import Counter

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

a = Counter(A).most_common()

L = []
if K < len(a):
    need = len(a) - K
    for i in range(1, need+1):
        L.append(a[-i][1])

print(sum(L))

Solution (Python):
import collections

n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst_com = collections.Counter(lst).most_common()
if len(lst_com)<=k:
    print(0)
    exit()
ans=n
for i in range(k):
    ans -= lst_com[i][1]
print(ans)

Solution (Python):
from collections import defaultdict

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

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

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

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

print(ans)

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

a_hash = {}
for i in a:
    if i in a_hash:
        a_hash[i] += 1
    else:
        a_hash[i] = 1

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

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

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

c = collections.Counter(l)
c = c.most_common()
cnt = 0
if len(c) - K > 0:
    for i in range(1 , len(c) - K + 1):
        cnt += c[-i][1]

print(cnt)

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


c=collections.Counter(A)

a=(c.most_common()[K:])

ans=0
if a==[]:
  print(ans)
else:
  for i in range(len(a)):
    ans+=a[i][1]
  print(ans)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
A=Counter([int(i) for i in input().split()])
values,counts=zip(*A.most_common())
a=len(values)


if k<a:
    ans=0
    for i in range(k,a):

        ans+=counts[i]
    print(ans)
else:
    print(0)

Solution (Python):

import numpy as np
N,K = map(int,input().split())
A = np.array(input().split(), dtype=np.int32)
counter = np.bincount(A)
counter.sort()
counter = counter[::-1] 
no_change = counter[:K].sum()
answer = N - no_change
print(answer)

Solution (Python):
nk = input().split(" ");
n = int(nk[0]);
k = int(nk[1]);
a = input().split(" ");
num = 0;
for i in range(n) :
	a[i] = int(a[i]);
bucket = [0]*max(a);
for i in range(n) :
	bucket[a[i]-1] += 1;
	if bucket[a[i]-1] == 1 :
		num += 1;
bucket.sort();
ans = 0;
j = 0;
for i in range(max(a)) :
	if j >= num -k :
		break;
	if bucket[i] > 0 :
		ans += bucket[i];
		j += 1;
print(ans);

Solution (Python):

import sys
import collections


def solve(N: int, K: int, A: "List[int]"):
    C = collections.Counter(A)
    M = len(C) - K
    if M <= 0:
        print(0)
    else:
        print(sum([c[1] for c in reversed(C.most_common())][0:M]))



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 = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
from collections import Counter
counters = Counter(a)
b = sorted(counters.items(), key=lambda x: x[1])
left = len(b) - k
index = 0
ans = 0
while left > 0:
    ans += b[index][1]
    index += 1
    left -= 1
print(ans)

Solution (Python):
import collections

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

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

changenum = len(c) - k
if changenum <= 0:
    print(0)
    exit()

changecount=0
for changeidx in range(changenum):
    index = -1 - changeidx
    changecount += c[index][1]
print(changecount)

Solution (Python):
n, k = map(int, input().split())
from collections import defaultdict
dic = defaultdict(lambda : 0)
for a in input().split():
    a = int(a)
    dic[a] += 1
diff = len(dic.keys()) - k
if n == k or diff <= 0:
    print(0)
else:
    count = sum(sorted(dic.values())[:diff])
    print(count)

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

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

a.sort()
key = 0
cnt = 0
b = []
for i in range(n):
    if a[i] != key:
        key = a[i]
        b.append(cnt)
        cnt = 1
    else:
        cnt += 1
b.append(cnt)
del b[0]

b.sort()
if len(b) < k:
    print(0)
else:
    print(sum(b[:len(b)-k]))

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

    id2count = {}
    for x in A:
        if x not in id2count:
            id2count[x] = 1
        else:
            id2count[x] += 1

    sorted_items = sorted(id2count.items(), key=lambda x: x[1])
    total = 0
    for (key, count) in sorted_items[:len(sorted_items)-int(K)]:
        total += count
    print(total)


if __name__ == '__main__':
    main()

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

from collections import Counter

cnt = Counter(a)

value = sorted(cnt.values(),reverse=True)

flg = 0
if len(value)<=k:
    print(0)
else:
    for i in range(k):
        flg += value[i]

    print(n-flg)

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
V = []
for v in A.values():
    V.append(v)
V.sort(reverse = 1)
print(sum(V[K:]))

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = Counter(list(map(int,input().split())))
V = []
for v in A.values():
    V.append(v)
V.sort(reverse = 1)
print(sum(V[K:]))

Solution (Python):

N, K = map(int, raw_input().split())
a_arr = map(int, raw_input().split())

a_dic = {}

for idx in range(0, N):
  if str(a_arr[idx]) in a_dic:
    a_dic[str(a_arr[idx])] += 1
  else:
    a_dic[str(a_arr[idx])] = 1

a_len = len(a_dic.keys())


counter = 0
sum_val = 0
for k, v in sorted(a_dic.items(), key=lambda x: x[1]):
  if a_len - counter <= K:
    break
  sum_val += v
  counter += 1

print(sum_val)

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

Solution (Python):
from collections import Counter

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

a_count = Counter(a)

a_c = []
for i in a_count:
    a_c.append([int(i),a_count[i]])

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

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

Solution (Python):
import collections

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

a = collections.Counter(A)

del_num = len(a)-K
print (sum(sorted(a.values())[:del_num]))

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

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
temp = list(dic.values())
ans = 0
temp.sort()
for i in range(len(temp)-k):
    ans += temp[i]
    
print(ans)

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

dic = dict()
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])

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

print (ans)

Solution (Python):

n, k = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())))
dic = {}
for i in lst:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

cnt = sorted([i for i in dic.values()], reverse=True)
ans = 0
for i in range(len(cnt)):
    if k > 0:
        k -= 1
        continue
    ans += cnt[i]
print(ans)

Solution (Python):
from collections import defaultdict

N,K=map(int,input().split())
A=list(map(int,input().split()))
C=defaultdict(int)
B=[]
for a in A:
    C[a]+=1
ans=0
for i,v in C.items():
    B.append(v)
B.sort(reverse=True)
p=0
for i in range(len(B)):
    if i<K:
        continue
    ans+=B[i]
print(ans)

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

a_set = set(a)
a_counts = {}

for elem in a:
    if not elem in a_counts:
        a_counts[elem] = 0
    a_counts[elem] += 1

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

ball_to_replace = len(a_set) - k

result = 0
if ball_to_replace > 0:
    for i in range(ball_to_replace):
        result += a_counts[i][1]
print(result)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()
  l=LI()

  l.sort()
  a=l[0]
  l2=[]
  c=1
  for x in l[1:]:
    if a==x:
      c+=1
    else:
      l2.append([a,c])
      c=1
      a=x
  l2.append([a,c])

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

  ans=0
  for i in range(len(l2)-m):
    ans+=l2[i][1]

  return ans

print(main())

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N, K = MI()
    A = LI()
    c = Counter(A).most_common()
    c = [j for i, j in c]
    ans=0
    for val in c[K:]:
        ans += val
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):











import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from collections import Counter
    N, K = MI()
    A = LI()
    c = Counter(A)
    c = [j for i, j in c.items()]
    c.sort()
    change_num = len(c) - K
    ans=0
    for C in c:
        if change_num <= 0:
            break
        ans += C
        change_num -= 1
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
from collections import defaultdict

def main():
    num, k = map(int, input().split())
    data = list(map(int, input().split()))
    dic = defaultdict(int)
    for i in range(num):
        dic[data[i]] += 1

    dic = sorted(dic.items(), key=lambda x: -x[1])
    ans = 0
    for i in range(min(k, len(dic)), len(dic)):
        ans += dic[i][1]
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
countlist = []
tmp = 0
for i in range(0, N):
	if tmp != A[i]:
		countlist.append([A[i], 0])
		tmp = A[i]
	countlist[-1][1] += 1
countlist.sort(key = lambda v: v[1])
sum = 0
for i in range(0, len(countlist)-K):
	sum += countlist[i][1]
print(sum)

Solution (Python):
from collections import Counter


n, k = map(int, input().split())
lst_A = list(map(int, input().split()))
ctr_A = Counter(lst_A)


keep = 0
for _, val in ctr_A.most_common(k):
    keep += val


print(n - keep)

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
A1 = set(A)
AN = {}
for a in A:
    if not a in AN:
        AN[a] = 0
    AN[a] += 1
AN = sorted(AN.items(), key=lambda x: x[1])
ans = 0
K1 = len(A1) - K
if K1 > 0:
    for k in range(K1):
        ans += AN[k][1]
    print(ans)
else:
    print('0')

Solution (Python):
from collections import Counter


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


set_A = set(lst_A)
cnt_A = sorted(Counter(lst_A).items(), key=lambda x:x[1])
num_change = len(set_A) - k
ans = 0
if num_change > 0:
    for i in range(num_change):
        ans += cnt_A[i][1]


print(ans)

Solution (Python):
from collections import Counter


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


set_A = set(lst_A)
cnt_A = sorted(Counter(lst_A).items(), key=lambda x:x[1])
num_change = len(set_A) - k
ans = 0
if num_change > 0:
    for i in range(num_change):
        ans += cnt_A[i][1]


print(ans)

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

a = sorted(Counter(a).items(), key=lambda x: -x[1])
if len(a) <= k:
    print(0)
else:
    ans = 0
    for l in range(k,len(a)):
        ans += a[l][1]
    print(ans)

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

l = sorted(d.values())
print(sum(l[:len(l) - k]))

Solution (Python):
N,K = list(map(int,input().split(" ")))
d={}
for i in input().split(" "):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
print(sum(sorted(d.values())[:len(d.keys())-K:]))

Solution (Python):
from collections import Counter

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

c = Counter(a)

arr = c.most_common()[k:]

print(sum(x[1] for x in arr))

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
arr = Counter(input().split())
chenge = len(arr) - k
count = 0
for k, v in arr.most_common()[::-1]:
  if chenge > 0:
    count += v
    chenge -= 1
print(count)

Solution (Python):
from collections import Counter

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

c = Counter(a)

arr = c.most_common()[k:]

print(sum(x[1] for x in arr))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
S=set(a)
dic={i:0 for i in S}
for i in a:
    dic[i]+=1
cnt=0
l=sorted(dic.values())
if len(l)>k:cnt+=sum(l[:len(l)-k])
print(cnt)

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

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0], reverse=True)

max_ball = 0
cnt = 1
for i in filter_TMP:
    if cnt <= K:
        max_ball += i
        cnt += 1
    else:
        break
    

print(N - max_ball)

Solution (Python):
n,k,*a=map(int,open(0).read().split())
d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(sorted(d.values())[:-k]))

Solution (Python):
n,k,*a=map(int,open(0).read().split())
d={}
for i in a:d[i]=d.get(i,0)+1
print(sum(sorted(d.values())[:-k]))

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

Solution (Python):

n, k =  [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]

count_list = [ 0 for i in range(n) ]
for i in num_list:
	count_list[i-1] += 1
count_list.sort(reverse = True)
print(n-sum(count_list[:k]))

Solution (Python):
from collections import Counter as ct
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
count=ct(A)
div=len(count)
if div<=K:print(0)
else:print(sum([i[1] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))

Solution (Python):

import sys
from collections import Counter
import heapq
INF = float("inf")


def solve(N: int, K: int, A: "List[int]"):
    counter = Counter(A)
    
    values = sorted(counter.values())
    
    if len(values) < K:
        print(0)
    else:
        print(sum(values[:len(values)-K]))
    return


def main():

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


if __name__ == '__main__':
    main()

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  a=LI()

  a.sort()
  b=[]

  _a=a[0]
  c=1
  for x in a[1:]:
    if _a==x:
      c+=1
    else:
      b.append([_a,c])
      _a=x
      c=1
  b.append([_a,c])

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

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

  return ans

print(main())

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

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

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

max_n = 200000

ball_counts = [0]*max_n

for ball in balls:
    ball_counts[ball-1] += 1


counts = []

for n in ball_counts:
    if n !=0:
        counts.append(n)
        
counts = sorted(counts)

print(sum(counts[0:len(counts)-k]))

Solution (Python):
from collections import Counter
N, K = 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())
A = list(map(int, input().split()))

c = Counter(A).most_common()
c.sort(key=lambda x: -x[1])
ans = 0
while len(c) > K:
    ans += c.pop()[1]
print(ans)

Solution (Python):
[n, k] = [int(x) for x in input().split()]
num_list = [int(x) for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
sorted_count = sorted(num_dict.values())
if len(sorted_count) - k > 0:
    print(sum(sorted_count[:len(sorted_count)-k]))
else:
    print(0)

Solution (Python):
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) 
if len(dif)==0:
  print(0)
else:
  for i in range(len(dif)+1):
    if i == 0:
      cnt.append(dif[0])
    if i == len(dif):
      cnt.append(N-dif[-1])
      break
    cnt.append(dif[i]-dif[i-1])
  cnt.sort(reverse=True)
  n = 0
  if len(cnt)<=K:
    print(0)
  else:
    for i in range(K):
      n+=cnt[i]
    print(N-n)

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

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

Solution (Python):







from operator import itemgetter

def numcount(in_list):
    wkdict = dict()
    for i in range(len(in_list)):
        if wkdict.get(in_list[i]) == None:
            wkdict[in_list[i]] = 1
        else:
            wkdict[in_list[i]] += 1
    numlist = list()
    for x in wkdict.keys():
        wlst = list()
        wlst.append(x)
        wlst.append(wkdict[x])
        numlist.append(wlst)
    return numlist


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


acnt = numcount(a)


acnt.sort(key=itemgetter(1))


idx = 0
acm = 0
while(len(acnt) - idx > k):
    acm += acnt[idx][1]
    idx += 1


print(acm)

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

nlist = [0] * N
for i in A:
    nlist[i-1] += 1

nlist.sort(reverse = True)
cnt = 0
for i in range(K,N):
    if nlist[i] == 0: break
    cnt += nlist[i]

print(cnt)

Solution (Python):
from collections import Counter

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

cnt_dict = Counter(A)
cnt_common = cnt_dict.most_common()

if len(cnt_common) <= K:
  ans = 0
else:
  n_asis = 0
  for i in range(K):
    n_asis += cnt_common[i][1]
  ans = N - n_asis

print(ans)

Solution (Python):
from collections import Counter


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

    c = Counter()
    for a in A: c[a] += 1

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

    print(res)


if __name__ == '__main__':
    main()

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

var = [0] * (N+1)


for i in A:
    var[i] += 1
    
var = sorted(var,  reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Solution (Python):
from collections import Counter

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

C = Counter(A)

for i,c in enumerate(sorted(C.items(), key=lambda x: -x[1])):
	total += c[1]
	if i == K-1:
		break
print(N-total)

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

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

a=[int(i) for i in input().split()]
d=Counter(a)
a=sorted(list(d.items()),key=lambda x:x[1],reverse=True)
if len(a)<=k:
    print(0)
else:
    ans=0
    for i in range(k,len(a)):
        ans+=a[i][1]
    print(ans)

Solution (Python):
from functools import reduce
import math
import collections
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N, K = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())
    d = collections.defaultdict(int)
    for a in A:
        d[a] +=1
    d = sorted(d.items(),key=lambda x:x[1])
    V = []
    for k,v in d:
        V.append(v)
    ans = 0
    for i in range(len(V)-K):
        ans += V[i]
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter([int(_) for _ in input().split()])
print(sum(A.values()) - sum(dict(A.most_common(K)).values()))

Solution (Python):
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Solution (Python):
import collections


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


main()

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

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

keys = sorted(m, key=lambda x:m[x])

msum = 0
for i in range(len(m) - K):
	msum += m[keys[i]]

print(msum)

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

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

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter(list(map(int, input().split()))).most_common()
l = len(A)
ans = 0
for _ in range(N):
	if l > K:
		ans += A[-1][1]
		del A[-1]
		l = len(A)
	else:
		print(ans)
		exit()

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = Counter(A)
D = []
for c in C:
    D.append(C[c])
D.sort(reverse=True)
print(sum(D[K:]))

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

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

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

from collections import Counter
c = Counter(a)
cnts = []
for i, j in c.items():
  cnts.append(j)

print(sum(sorted(cnts)[:-k]))

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

from collections import Counter
c = Counter(a)
key = []
value = []
for i, j in sorted(c.items(), key=lambda x: x[1]):
  key.append(i)
  value.append(j)

print(sum(value[:(len(key)-k)]))

Solution (Python):
from collections import Counter
N,K=map(int, input().split())
v=sorted(Counter(map(int, input().split())).values())
if len(v) > K:
	print(sum(v[:len(v)-K]))
else:
	print(0)

Solution (Python):
from collections import Counter

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

length = len(a)
ans = 0

for i in range(length-k):
    ans += a[-1][1]
    a.pop(-1)
    
print(ans)

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

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

kinds = sorted(buckets.values(), reverse=True)
if K < len(kinds):
  mini = N-sum([kinds[i] for i in range(K)])
  print(mini)
else:
  print(0)

Solution (Python):

def read_input():
    n, k = map(int, input().split())
    alist = list(map(int, input().split()))
    return n, k, alist


def submit():
    n, k, alist = read_input()

    digits = [0] * n
    for a in alist:
        digits[a - 1] += 1

    digits.sort(reverse=True)
    truncate = sum(digits[k:])
    print(truncate)


if __name__ == '__main__':
    submit()

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


N, K = map(int, input().split())
A = list(map(int, input().split()))
A_count = Counter(A)
A_unique = list(set(A))
A_list = []
if len(A_unique) <= K:
    print(0)
    exit()
else:
    del_num = len(A_unique) - K
    for i in A_unique:
        A_list.append(A_count[i])
    A_list.sort()
    print(sum(A_list[:del_num]))

Solution (Python):
import collections

a, b = map(int, input().split())
l = collections.Counter(input().split(" ")).values()
print(sum(sorted(l, reverse=True)[b:]))

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
ls=[0]*(n+1)
for i in a:
    ls[i]+=1
ls=sorted(ls,reverse=True)
for i in range(k,n+1):
    if ls[i]==0:
        break
    else:
        cnt+=ls[i]
print(cnt)

Solution (Python):
n, k = (int(i) for i in input().split())
balls = (int(i) for i in input().split())
freqs = {}
for ball in balls:
    freqs[ball] = freqs[ball] + 1 if ball in freqs else 1
freq_hist = list(freqs.values())
freq_hist.sort(reverse=True)
print(sum(freq_hist[k:]))

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

Solution (Python):
from collections import Counter

init_data = list(map(int, input().split(' ')))
data = list(map(int, input().split(' ')))

c = Counter(data)

result = c.most_common()


print(sum(x[1] for x in result[init_data[1]:]))

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