Problem:
 Score : 300 points    Problem Statement Takahashi has N balls. Initially, an integer A_i is written on the i -th ball.  He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.  Find the minimum number of balls that Takahashi needs to rewrite the integers on them.      Constraints  1 \leq K \leq N \leq 200000  1 \leq A_i \leq N  All input values are integers.         Input Input is given from Standard Input in the following format:  N  K  A_1  A_2 ... A_N       Output Print the minimum number of balls that Takahashi needs to rewrite the integers on them.        Sample Input 1 5 2
1 1 2 2 5      Sample Output 1 1  For example, if we rewrite the integer on the fifth ball to 2 , there are two different integers written on the balls: 1 and 2 .
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1 .       Sample Input 2 4 4
1 1 2 2      Sample Output 2 0  Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.       Sample Input 3 10 3
5 1 3 2 4 1 1 2 3 4      Sample Output 3 3

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

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


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

print(ans)

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

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
if len(ctr) <= K:
    print(0)
    exit()

l = len(ctr) - K
ans = sum(sorted(ctr.values())[:l])
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  


N, K = read_ints()
A = read_ints()

cnt = Counter(A)
v = sorted(cnt.values(), reverse=True)
if len(v) <= K:
    print(0)
else:
    print(N - sum(v[:K]))

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

from collections import Counter, OrderedDict

a=Counter(a)

if len(a) <= k:
    print(0)
else:
    b = sorted(a.items(), key=lambda pair: pair[1], reverse=True)
    
    ans = 0
    
    for i in b[k:]:
        ans += i[1]

    print(ans)

Solution (Python):
import collections

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

c = collections.Counter(A)
c = sorted(c.values(),reverse=True)

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

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

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

numbers = [0] * max(N,max(A))
for i in range(N):
    numbers[A[i]-1] += 1

numbers.sort(reverse=True)

ans = 0
for i in range(N):
    if numbers[i] == 0:
        break
    if i > K-1:
        ans += numbers[i]
print(ans)

Solution (Python):
import collections
n , k= map(int,input().split())
a = list(map(int,input().split()))
c = collections.Counter(a)
p = c.most_common()
s = len(p)
if s <= k:
    print(0)
    exit()

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

print(ans)

Solution (Python):
import collections
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
acnt = collections.Counter(a)
acnt = sorted(acnt.items(), key=lambda x: x[1])
ans = 0
al = len(acnt)
for i in acnt:
    if al<=k:
        break
    al -= 1
    ans += i[1]

print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
k = [[0,i] for i in range(1,N+1)]
for i in range(N):
  k[A[i]-1][0] += 1
B = set(A)
C = list(B)
k.sort()
if len(C) <= K:
  print(0)
else:
  now = len(C)-K
  ans = 0
  for i in range(len(k)):
    if k[i][0] == 0:
      continue
    else:
      now -= 1
      ans += k[i][0]
      if now == 0:
        print(ans)
        break

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

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

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

d = len(cnt) - K
ans = sum(list(sorted(cnt.values()))[:d])
print(ans)

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,K = inputlist()
A = inputlist()
from collections import Counter
c = Counter(A)
val = list(c.values())
val.sort()
if len(val)<= K:
    print(0)
    exit()
ans = 0
for i in range(len(val)-K):
    ans += val[i]
print(ans)

Solution (Python):
from time import time

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    a = [0 for i in range(N)]
    for i in A:
        a[i-1] += 1

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

if __name__ == '__main__':
    start = time()
    main()

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])
if len(C)<=K:print(0)
else:
    ans = 0
    for i in range(len(C)-K):
        ans += C[i][1]
    print(ans)

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

a.sort()
count = []
c = 1
for i in range(n-1):
    if a[i] != a[i+1]:
        count.append(c)
        c = 1
    else:
        c += 1
    if i == n - 2:
        count.append(c)

l = len(count)


c = 0
if l <= k:
    print(0)
else:
    count.sort()
    for i in range(l):
        l -= 1
        c += count[i]
        if l <= k:
            print(c)
            quit()

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

V = sorted(C.values())

print(sum(V[:-K]))

Solution (Python):
from collections import defaultdict

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

d = defaultdict(int)
for key in A:
    d[key] += 1
ans = 0
for key, i in sorted(d.items(), key = lambda x:x[1])[:-K]:
    ans += i
print(ans)

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)

Solution (Python):

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

c=Counter(a).most_common()
c.sort(key=lambda x: x[1])

l=len(c)
print(sum(c[i][1] for i in range(l-k)))

Solution (Python):
from collections import Counter

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

ans = 0
if k < len(cnt):
  for k, v in cnt[:len(cnt) - k]:
    ans += v

print(ans)

Solution (Python):
import collections

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

c = collections.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=collections.Counter(a).most_common()
ans=0

if len(a)<=k:
    print("0")
    exit()

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

print(n-ans)

Solution (Python):
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
INF = 10**10+5

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

maxa = max(a)
num = [0]*(maxa)
for i in range(len(a)):
    num[a[i]-1]+=1
cnt = len(set(a))
ans = 0

if cnt<k:
    print(ans)
else:
    for i in range(len(num)):
        if num[i] == 0:
            num[i] = INF
    num.sort()

    i = 0
    while True:
        if cnt == k:
            break
        ans += num[i]
        i+=1
        cnt -= 1

    print(ans)

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

Solution (Python):
from collections import Counter
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)

Solution (Python):
def main():
    from collections import Counter
    n, k, *a = map(int, open(0).read().split())
    b = Counter(a)
    l = len(b)
    if l <= k:
        ans = 0
    else:
        cnt = list(b.values())
        cnt.sort()
        ans = sum(cnt[:(l-k)])
    print(ans)
if __name__ == '__main__':
    main()

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

suc_list.sort()

kind = len(suc_list) - K

ans = sum(suc_list[0:kind])
print(ans)

Solution (Python):
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())



n,k=get_list()
a=get_list()
freq_dict=Counter(a)
if len(freq_dict)<=k:
    print(0)
else:
    freq=[]
    for key in freq_dict:
        freq.append(freq_dict[key])
    freq.sort()
    ans=0
    for i in range(len(freq_dict)-k):
        ans+=freq[i]
    print(ans)

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

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

cnt = 0
numbers = []
for k in d.keys():
    cnt += 1
    numbers.append(d[k])
numbers.sort()
i = 0
ans = 0
while cnt > K:
    ans += numbers[i]
    cnt -= 1
    i += 1
print(ans)

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

cnt=Counter(a)
cnt_len=len(cnt)
cnt=sorted(list(cnt.values()))
ans=0
if cnt_len<k:
    print(0)
    exit()
for i in range(cnt_len-k):
    ans+=cnt[i]
print(ans)

Solution (Python):
from collections import defaultdict
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*(n+1)
for i in range(n):
    x[a[i]]+=1
y=[]
for i in range(n+1):
    if x[i]>0: y.append(x[i])
y.sort()
print(sum(y[:-k]) if len(y)>k else 0)

Solution (Python):
import collections

n, k, *a = map(int, open(0).read().split())
c = collections.Counter(a)
print(n-sum([d[1]  for d in c.most_common()[:k]]))

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

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
l = list(map(int, input().split()))
c = Counter(l)
ans = len(l)
l2 = c.most_common(k)
for i in l2:
  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)


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

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

print(ans)

Solution (Python):
from collections import Counter
n, k, *A = map(int, open(0).read().split())
counter = Counter(A).most_common(n)
if len(counter) <= k:
    print(0)
else:
    print(sum(v for k, v in counter[k:]))

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

if n <= k:
    print(0)
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)

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

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)

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

ls = sorted(d.values())
ans = 0
for v in ls[:len(ls)-k]:
    ans += v
print(ans)

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


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



ls = sorted(d.values())
ans = 0
for v in ls[:len(ls)-k]:
    ans += v
print(ans)

Solution (Python):
n, k = map(int, input().split())
A = list(map(int, input().split()))
array = {}
ans = 0

for a in A:
    if a in array.keys():
        array[a] += 1
    else:
        array[a] = 1

array = sorted(array.values())

if len(set(A)) > k:
    num = len(array) - k
    for i in range(num):
        ans += array[i]

print(ans)

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

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        try:
            ans -= kv[i][1]
        except:
            pass
    print(ans)

Solution (Python):
n,k=map(int,input().split())
l=list(map(int,input().split()))
from collections import Counter as co
var=co(l).most_common()
en=len(var)
ans=0
while en>k :
    ans+=var[en-1][1]
    en-=1
print(ans)

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

a = sorted(datas.items(), key=lambda x: x[1], reverse=True)
if len(a) < k + 1:
    print(0)
else:
    ans = 0
    for i in a[k:]:
        ans += i[1]
    print(ans)

Solution (Python):
def main():
  n, k = input_list()
  a = list(input_list())
  kind = len(set(a[:]))
  if kind <= k:
    print(0)
    exit()
  need = kind - k
  ac = collections.Counter(list(a))
  ans = 0
  for v in sorted(ac.items(), key=lambda x: x[1]):
    if need == 0:
      break
    ans += v[1]
    need -= 1
  print(ans)
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

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

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

Solution (Python):
from collections import Counter

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

a = list(Counter(A).values())
a.sort()

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

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

A = [0] * n

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

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

A = sorted(A)

t = 0
print(sum(A[:-k]))

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

a.sort()

ax = []
d = 0
for i in a:
    if(d != i):
        ax.append(1)
        d = i
    else:
        ax[-1] += 1

ax.sort()


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

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

Solution (Python):

n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cnt = []
tmp = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        tmp += 1
    else:
        cnt.append(tmp)
        tmp = 1
cnt.append(tmp)


cnt.sort()
if len(cnt) > k:
    ans = sum(cnt[-k:])
else: ans = n
print(n-ans)

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

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

Solution (Python):
N, K = map(int, input().split())
X = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
for x in X:
    d[x] += 1

l = sorted(list(d.values()))
print(sum(l[:max(0, len(l)-K)]))

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

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

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

l = collections.Counter(a)
x = l.most_common(k)

for i in range(len(x)):
    t += x[i][1]

ans -= t
if ans < 0:
    ans = 0
print(ans)

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

list.sort(a)
    
count=1
size=0
b=[]
for p in range (N-1):
  if a[p]==a[p+1]:
    count+=1
  else:
    b.append(count)
    count=1
    size+=1

b.append(count)
size+=1
  
list.sort(b,reverse=True)

s=0
if K<size:
  for u in range (K):
    s+=b[u]
else:
  s=N
print(N-s)

Solution (Python):
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
d = {}
for a_i in a:
    if a_i not in d.keys():
        d[a_i] = 0
    d[a_i] += 1
d = list(sorted(d.items(), key=lambda x:x[1])[::-1])
if len(d) <= k: print(0)
else: print(sum([v[1] for v in d[k:]]))

Solution (Python):
import collections

N,K = map(int,input().split())
A = list(map(int,input().split()))
type = len(set(A))
con = 0

if K >= type:
  print(0)
  
else:
  C = collections.Counter(A)
  C = C.most_common()
  
  for i in range(1,type - K + 1):
    con += C[-i][1]
  
  print(con)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
A = list(map(int, input().split()))
cA = sorted(Counter(A).values())
dk = len(set(A))-k
r = 0
for i in range(n):
    if dk<1:
        break
    else:
        dk -= 1
        r += cA[i]
print(r)

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = Counter(map(int, input().split()))
if len(A) <= K:
    print(0)
    exit(0)
ans = 0
Y = list(sorted(A.items(), key=lambda x: x[1]))
for i in range(0, len(A)-K):
    ans += Y[i][1]
print(ans)

Solution (Python):
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, k = map(int, input().split())
    As = list(map(int, input().split()))

    dic = defaultdict(int)
    for i in range(n):
        dic[As[i]] += 1
    
    ls = sorted(dic.values())
    
    if len(ls) <= k:
        print(0)
        return
    
    cnt = 0
    for i in range(len(ls) - k):
        cnt += ls[i]
    
    print(cnt)

            

    return

if __name__ == '__main__':
    main()

Solution (Python):

def pin(type=int):
    return map(type,input().split())

"""
"""


N,K=pin()
A=list(pin())
b=[0]*N
for i in range(N):
    b[A[i]-1]+=1
b.sort()
ans=0
x=N
for j in range(N):
    if b[j]==0:
        x-=1
    else:
        if x>K:
            x-=1
            ans+=b[j]
print(ans)

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

dict = {}
for i in range(n):
  if a[i] in dict:
    dict[a[i]] += 1
  else:
    dict[a[i]] = 1
ans = sorted(dict.items(), key=lambda x:x[1])
if len(ans) <= k:
  print(0)
else:
  tmp = 0
  s = 0
  for i in ans:
    tmp += i[1]
    s+=1
    if s == len(dict) - k:
      break
  print(tmp)

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

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

from collections import Counter
a=Counter(a)
a=a.most_common()

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

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

B=[0]*(N+1)
for i in range(0,N):
    B[A[i]]=B[A[i]]+1
C=[]
for i in range(0,N+1):
    if B[i]!=0:
        C.append(B[i])
C.sort()
if K>=len(C):
    print(0)
else:
    s=0
    for i in range(0,len(C)-K):
        s=s+C[i]
    print(s)

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

ac = Counter(a)
cnt = []
for ke in ac:
    cnt.append(ac[ke])
cnt.sort()
if len(cnt)<=k:
    print(0)
else:
    print(sum(cnt[:-k]))

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    S = Counter(A)
    V = sorted(list(S.values()), reverse=True)
    print(sum(V) - sum(V[:K]))
    return


if __name__ == "__main__":
    main()

Solution (Python):
import collections

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

c = collections.Counter(a)
b = list(sorted(c.values(), reverse=True))
sum = 0

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

for i in range(0, k):
    sum = sum + b[i]

print(max(len(a)-sum, 0))

Solution (Python):
import collections
import sys

N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
cnt = 0
if len(c)<= K:
    print(0)
    sys.exit()

for i in c.most_common(K):
    cnt += i[1]

print(N-cnt)

Solution (Python):
import collections as co

n, k = map(int,input().split())
a = list(map(int,input().split()))
cnt = co.Counter(a)
ans = 0
initial = len(cnt)
if initial <= k:
    print(0)
    exit()
else:
    cnt = sorted(cnt.values())
    for i in range(initial-k):
        ans += cnt[i]
    print(ans)

Solution (Python):
from collections import defaultdict
N,K = map(int,input().split())
A_list = list(map(int,input().split()))
dic = defaultdict(lambda: 0)

for key in A_list:
    dic[key] += 1

change = len(dic) -K

if change <= 0:
  print(0)
else:
  sorted_list = sorted(list(dic.values()))
  Answer = sum(sorted_list[:change])
  print(Answer)

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = Counter(A)
if K >= len(count):
    print(0)
else:
    values = sorted(list(count.values()),reverse = True)
    del values[:K]
    print(sum(values))

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

c = Counter(A)
kv = c.most_common()

count = 0
ans = 0
if len(kv) <= K:
    print(0)
    sys.exit(0)

for l in kv[::-1]:
    count += 1
    ans += l[1]
    if count == (len(kv) - K):
        break

print(ans)

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

from collections import Counter
cnt=0

a=Counter(A)
b=list(a.values())
b.sort()
leng=len(b)

for item in b:
  if leng>K:
    cnt+=item
    leng-=1
    
print(cnt)

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

import sys
import collections
c = collections.Counter(t)
c=sorted(list(c.values()))
ans=0
delete_count=len(c)-k
if delete_count<=0:
    print(0)
    sys.exit()
else:
    for i in range(delete_count):
        if len(c)>k:
            ans+=c[i]
            
print(ans)
sys.exit()

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

a=collections.Counter(A).most_common()
print(sum([a[-i-1][1] for i in range(len(a)-K)]))

Solution (Python):
import sys
from collections import Counter
n, k = [int(i) for i in sys.stdin.readline().split()]
a_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(a_ls)
variety = len(ct.keys())

cnt = 0
ans = 0
for key, v in sorted(ct.items(), key=lambda x:x[1]):
    if cnt >= variety - k:
        break
    ans += v
    cnt += 1
print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(n)]
z=set(a)
y=len(z)
for x in a:
    s[x-1]+=1
b=sorted(s)
f=0
ans=0
for x in b:
    if x!=0:
        f+=1
        ans+=x
    if f>=y-k:
      	break
print(ans)

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

from collections import Counter
s=Counter(a)
l=s.most_common(k)

ans=0
for (i,j) in l:
  ans+=j
  
print(n-ans)

Solution (Python):
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = collections.Counter(a)
cnt = 0
c = b.most_common()
s = 0
for i in range(len(c)):
	cnt += 1
	if cnt > k:
		for j in range(i,len(c)):
			s += c[j][1]
		break
print (s)

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()
p = len(a)
ans = 0
for i in range(-1,-n-1,-1):
    if p <=k:break
    ans += a[i][1]
    p-=1

print(ans)

Solution (Python):
from collections import Counter as c
N, K = map(int, input().split())
A = tuple(map(int, input().split()))
s = dict(c(A))
if len(s) > K:
	s_s = sorted(s.items(), key=lambda x: x[1])
	l = len(s)
	i = 0
	cnt = 0
	while l > K:
		l -= 1
		cnt += s_s[i][1]
		i += 1
	print(cnt)
else:
	print(0)

Solution (Python):
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, K = map(int, input().split())
a = list(map(int, input().split()))
d = dd(int)
for i in range(N):
  d[a[i]] += 1
ks = list(d.keys())
l = []
for k in ks:
  l.append(d[k])
l.sort(reverse = True)
res = 0
for _ in range(len(ks) - K): res += l.pop()
print(res)

Solution (Python):
from collections import *
_,k,*a = map(int,open(0).read().split())
print(sum(sorted(Counter(a).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
b=list(d.values())
b.sort()
print(sum(b[:-k]))

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

Solution (Python):
import collections
import heapq

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

c = collections.Counter(A)
value_list = list(c.values())
heapq.heapify(value_list)


ans = 0
for i in range(len(value_list) - K):
    ans += heapq.heappop(value_list)

print(ans)

Solution (Python):
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A).most_common()[::-1]
k = len(c)
if k<=K:print(0)
else: print(sum([e[1] for e in c[:k-K]]))

Solution (Python):
import collections as cl
N, K, *A = map(int, open(0).read().split())
c = sorted(cl.Counter(A).values())
print(sum(c[:-K]))

Solution (Python):
import collections

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

print(sum([x[1] for x in collections.Counter(a).most_common()[k:]]))

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

d = dict()
for i in range(n):
    d[a[i]] = d.get(a[i], 0) + 1

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

Solution (Python):

import sys
import collections


def solve(N: int, K: int, A):
    c = collections.Counter(A).most_common()
    z = 0
    m = len(c)
    for i in range(m - K):
        z += c[m - i -1][1]
    print(z)


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):
from collections import defaultdict

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

d = defaultdict(int)

for key in a_li:
    d[key] += 1
d = sorted(d.items(), key=lambda x:x[1])
    
s = len(d) - k
ans = 0

for i in range(s):
    ans += d[i][1]
    
print(ans)