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):
N, K = map(int, input().split())
A = map(int, input().split())
counter = 0
dic = {}

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

k = len(dic)
v = sorted(dic.values())
if k > K:
  change_n = k -K
  for i in range(change_n):
    min_k = v[i]
    counter += min_k

print(counter)

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

nums = Counter(A)

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

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

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

v = sorted(mem.values())
if len(v) > K:
    print(sum(v[:len(v)-K]))
else:
    print(0)

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

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


v = sorted(list(cnt_a.values()), reverse=True)


ans = sum(v[k:])
print(ans)

Solution (Python):
import sys
from collections import Counter

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

c = Counter(A)

num = len(c)

if num <= K:
    print(0)
else:
    ans = 0
    c = list(c.items())
    c.sort(key=lambda x: x[1])
    for i in c:
        ans += i[1]
        num -= 1
        if num <= K:
            print(ans)
            sys.exit()

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

cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1
    
    
v = sorted(list(cnt_a.values()), reverse=True)
ans = sum(v[k:])
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):
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())
count = len(kinds)
if K < count:
    mini = 0
    for i in kinds:
        mini += i
        count -= 1
        if count <= K:
            break
    print(mini)
else:
    print(0)

Solution (Python):
import re
import collections

a = input()
a = re.split(" ",a)
b = input()
b = re.split(" ",b)

c = collections.Counter(b)

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

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


from collections import Counter
c = Counter(A)
leng = len(c.keys())
if leng > K:
    print(sum(sorted(c.values())[:leng-K]))
else:
    print(0)

Solution (Python):
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



N, K = mi()
A = lmi()
numcnt = [0]*(2*10**5)
for i in A:
    numcnt[i] += 1
numcnt.sort()
print(len(A)-sum(numcnt[-1:-K-1:-1]))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    n, a, b = LI()
    print(min(n*a,b))
    return


def B():
    a = S()
    print(a.count("1"))
    return


def C():
    n = II()
    a = list(str(n))
    a = list(map(int,a))
    if not n % sum(a):
        print("Yes")
    else:
        print("No")
    return


def D():
    n = II()
    a = LI()
    ans = 0
    while True:
        for i in range(n):
            if a[i] % 2:
                print(ans)
                return    
            a[i] /= 2
        ans += 1
    print(ans)
    return


def E():
    return


def F():
    n, k = LI()
    a = LI()
    dic = defaultdict(int)
    for a_ in a:
        dic[a_] += 1
    dic = sorted(dic.values(),reverse = True)
    l = 0
    ans = 0
    for j in dic:
        l += 1
        ans += j
        if l == k:
            break
    print(n-ans)
    

    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    F()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,a,b = LI()
    print(min(n*a,b))
    return


def B():
    s = S()
    print(s.count("1"))
    return


def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return


def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return


def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return


def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return


def G():
    return


def H():
    return


def I_():
    return


def J():
    return


if __name__ == "__main__":
    F()

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

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

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

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

Solution (Python):



from collections import Counter

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

s = list(set(l))
num = range(len(s))
if len(s) <= K: print 0
else:
    counter = Counter(l)
    nums = counter.values()
    sousa = len(s)-K
    nums.sort()
    print sum(nums[:sousa])

Solution (Python):
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
n,k=map(int,input().split())
a=sorted(ecount(sorted(list(map(int,input().split())))))
ans=0
for i in range(max(0,len(a)-k)):ans+=a[i]
print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.append(10**9+7)
exnum_list=[]
ctr=0
for i in range(n):
    if a[i]==a[i+1]:
        ctr+=1
    else:
        exnum_list.append(ctr+1)
        ctr=0
exnum_list.sort()
en=len(exnum_list)
if en<=k:
    print(0)
else:
    print(sum(exnum_list[:en-k]))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
sa=len(set(A))-K
if sa>0:
    As={}
    for i in range(N):
        if A[i] in As:
            As[A[i]]+=1
        else:
            As[A[i]]=1
    Ass=sorted(As.values())
    print(sum(Ass[:sa]))
else:
    print(0)

Solution (Python):
import collections as C
n,k=map(int,input().split())
x=list(C.Counter([int(i) for i in input().split()]).values())
shu=len(x)
if shu<=k:
    print(0)
else:
    x.sort()
    print(sum(x[:shu-k]))

Solution (Python):
import collections
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
cnt=collections.Counter(a)
shu=len(cnt.values())
ans=0
if shu<=k:
    print(ans)
else:
    x=list(cnt.values())
    x.sort()
    for i in range(shu-k):
        ans+=x[i]
    print(ans)

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

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

Solution (Python):
import sys
from collections import Counter
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

N,K = na()
A=Counter(na())
c=0
ans=0
for i in A.most_common():
    ans+=i[1]
    c+=1
    if(c>=K):
        break
print(N-ans)

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

counter = sorted(Counter(a).values())
if len(counter) <= k:
    print(0)
else:
    print(sum(counter[:len(counter)-k]))

Solution (Python):
n,k=map(int,input().split())
num=list(map(int,input().split()))
a=[0]*n
for x in num:
    a[x-1]+=1
a=sorted(a)
for i in range(n):
    if a[i]!=0:
        del a[:i]
        break
ans=0
i=0
while len(a)-i>k:
    ans+=a[i]
    i+=1
print(ans)

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)

N, K=LI()
A=LI()

counts = collections.Counter(A)
counts = counts.values()
counts = sorted(counts, reverse=True)
result = 0
while len(counts) > K:
    result+=counts.pop()
    
print(result)

Solution (Python):
N,K=map(int,input().split())
from collections import defaultdict
cnt=defaultdict(int)
for a in map(int,input().split()):
    cnt[a]+=1
res=[]
for a in cnt.keys():
    res.append(cnt[a])
res.sort()
if len(res)>K:
    ans=sum(res[0:-1*K])
else:
    ans=0
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
a = list(map(int, input().split()))
c = list(Counter(a).values())
c.sort()
ans = 0
print(sum(c[:max(0, len(c) - K)]))

Solution (Python):
import collections

result = 0
n,k = map(int,input().split())
input_list = input().split()
counter_list = collections.Counter(input_list)
if k < len(counter_list):
  length = len(counter_list)-k
  sort_list = sorted(counter_list.values())
  for i in range(length):
    result += sort_list[i]
print(result)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)
if len(c.keys()) <= k:
    print(0)
    exit()
else:
    ans = 0
    lis = list(c.values())
    lis.sort()
    l = len(lis) - k
    for i in range(l):
        ans += lis[i]
print(ans)

Solution (Python):
import collections

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

Solution (Python):
N, K = map(int, input().split())
L = list(map(int, input().split()))
dic = {}
for i in range(N):
    dic.setdefault(L[i], 0)
    dic[L[i]] += 1

cnt = len(dic.keys())
tmp = 0
if cnt <= K:
    print(0)
else:
    for k, v in sorted(dic.items(), key = lambda x:x[1]):
        tmp += v
        cnt -= 1
        if cnt <= K:
            break
    print(tmp)

Solution (Python):
from collections import defaultdict

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

counter = defaultdict(int)
for a in A:
    counter[a] += 1
n = list(counter.values())
n.sort(reverse=True)
print(sum(n[K:]))

Solution (Python):


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

def arraycount(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a.sort()
a = arraycount(a)


for i in range(len(a)):
    a[i][0],a[i][1] = a[i][1],a[i][0]

a.sort()

need = len(a) - k
answer = 0

for i in range(need):
    answer += a[i][0]

print(answer)

Solution (Python):
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[i]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)

Solution (Python):
from collections import Counter


def solve(string):
    n, k, *a = map(int, string.split())
    count = Counter(a)
    return str(sum(sorted(count.values(), reverse=True)[k:]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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

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

d = dict()

for item in data:
    if d.__contains__(item):
        d[item]+=1
    else:
        d[item]=1

l = list(d.values())

l.sort()

i = 0
res = 0

if len(l)>k:
    res += sum(l[:len(l)-k])

print(res)

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

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

B = set(a) 
d = Counter(a)

num = len(B) - k 

c = d.most_common()
ans = 0
for i in range(1, num+1):
  ans += c[-i][1]
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
c = d.most_common()
for i in range(1, num+1):
    ans += c[-i][1]
print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
numbers = {}
for a in A:
    if not a in numbers:
        numbers[a] = 1
    else:
        numbers[a] += 1
numbers = sorted(numbers.items(),key=lambda x: -x[1])
sum = 0
for i,k in enumerate(numbers):
    if i < K:
        continue
    sum += numbers[i][1]
print(sum)

Solution (Python):
N,K = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
L = [0 for i in range(N)]
for i in range(N):
  L[A[i]-1] +=1

L.sort()

ans = 0
for i in range(N-K):
  ans += L[i]

print(ans)

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

S = a.most_common(K)
for i in range(K):
    try:
        c -= S[i][1]
    except IndexError:
        print(c)
        exit()
print(c)

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

Solution (Python):

import collections
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
unique_a = list(set(a))
process_count = len(unique_a) - k
c = collections.Counter(a)
values, counts = zip(*c.most_common())

counts = list(counts)
counts.sort()
ans = 0

for i in range(process_count):
    ans += counts[i]
print(ans)

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

from collections import Counter
c = Counter()
for A in An:
    c[A] += 1

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

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

from collections import Counter

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

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

if len(firstA)<=K:
    print(0)
    exit()
count = [0 for i in range(max(firstA)+1)]
for i in range(N):
    count[A[i]] += 1
count.sort()
for i,x in enumerate(count):
    if x > 0:
        count = count[i:]
        break
print(sum(count[:len(count)-K]))

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

import collections
from itertools import accumulate

c = collections.Counter(A)
_, counts = zip(*c.most_common()[::-1])
counts = list(accumulate(counts))
cnt = 0
inf = 10 ** 18

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

Solution (Python):
from collections import Counter

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

D = Counter(A)
V = sorted(D.values(),reverse=True)
print(max(n-sum(V[:k]),0))

Solution (Python):
from collections import Counter

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

D = Counter(A)
V = []
for v in D.values():
    V.append(v)
V.sort(reverse=True)
print(max(n-sum(V[:k]),0))

Solution (Python):
from collections import Counter

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

D = Counter(A)
K = []
for key in D.keys():
    K.append(key)
if len(set(K)) <= k:
    print(0)
else:
    V = []
    for v in D.values():
        V.append(v)
    V.sort(reverse=True)
    print(n-sum(V[:k]))

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

c = sorted(c.values())[:-K]

print(sum(c))

Solution (Python):
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = collections.Counter(A)
c = sorted(c.values())
print(sum(c[:(len(c) - K)]))

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

Solution (Python):


"""
Created on 2019/3/16
Solved on 2019/3/
@author: shinjisu
"""






def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]

def zeros2(n, m): return [zeros(m) for i in range(n)] 

def getIntMat(n, m):  
    
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N, K = getIntList()
    d.dmp((N, K), 'N, K')
    A = getIntList()
    d.dmp((A), 'A')
    dic = {}
    for e in A:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    d.dmp(dic,'dic')
    val = list(dic.values())
    count = 0
    val.sort()
    d.dmp(val,'val')
    for i in range(len(val)-K):
        count += val[i]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Solution (Python):
import collections

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

mydata=collections.Counter(a)
mylist=list(mydata.values())
mylist.sort(reverse=True)


if len(mylist)<k:
  print(0)
else:
  val=sum(mylist[:k])
  print(n-val)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
lst=[int(i) for i in input().split()]
L=list(Counter(lst).values())
L.sort()
l=len(L)
ans=0
a=0
if l>k:
  while l>k:
    ans+=L[a]
    l-=1
    a+=1
print(ans)

Solution (Python):
import collections
N,K = map(int,input().split())
As = list(map(int,input().split()))
Acounter = sorted(collections.Counter(As).values())
ans = 0
for i in range(0,len(Acounter)-K):
  ans+=Acounter[i]
print(ans)

Solution (Python):
from collections import Counter

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

An = Counter(input().split())


def main():
    
    
    
    print(sum(sorted(An.values())[:len(An) - K]))

    return


main()

Solution (Python):
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter(input().split())


def main():
    
    
    
    print(sum(sorted(An.values())[:len(An) - K]))

    return


main()

Solution (Python):
import collections

N, K = map(int, input().split())
alist = collections.Counter(map(int, input().split()))
number = max(0,len(alist) - K )
answer = 0
if number == 0:
    print(0)
else:
    for a in alist.most_common()[-number:]:
        answer += a[1]
    print(answer)

Solution (Python):
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter([int(i) for i in input().split()])


def main():
    
    
    
    print(sum([v for k, v in An.most_common()[K:]]))

    return


main()

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

Solution (Python):


import itertools
import collections
import bisect

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    C = collections.Counter(A)
    need_rewrite = max(0, len(C.keys()) - K)
    if need_rewrite:
        ans = 0
        for kv in C.most_common()[-need_rewrite:]:
            ans += kv[1]
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()

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

Solution (Python):
n,k = map(int,input().split())
n_lst = list(map(int,input().split())) 
cnt_lst = [0 for _ in range(n+1)]

for x in n_lst:
    cnt_lst[x] += 1
cnt_lst.sort(reverse=True)
print(sum(cnt_lst[k:]))

Solution (Python):
from collections import Counter

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

cnt_lst = Counter(n_lst).most_common()[k:]
ans = 0
for x in cnt_lst:
    ans += x[1]
print(ans)

Solution (Python):
def not_so_diverse(N: int, K: int, A: int) -> int:
    freq = [0] * N
    for a in A:
        freq[a - 1] += 1

    return sum(sorted(freq, reverse=True)[K:])


if __name__ == "__main__":
    N, K = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = not_so_diverse(N, K, A)
    print(ans)

Solution (Python):
from collections import Counter

def main():
    n, k = map(int, input().split())
    a = [int(s) for s in input().split()]
    print(solve(n, k, a))

def solve(n, k, a):
    counter = Counter(a)
    s = 0
    for _, m in counter.most_common(k):
        s += m

    return n - s

main()

Solution (Python):
import collections

n, k = map(int, input().split())
l = list(map(int, (input().split())))
count = 0
c = collections.Counter(l)
c = c.most_common()[::-1]


if len(c) > k:
    for i in range(len(c)-k):
        count += c[i][1]
print(count)

Solution (Python):
N, K = map(int, raw_input().split())
A = [int(a)-1 for a in raw_input().split()]

T = [0]*N
for a in A:
  T[a] += 1
T.sort()
print sum(T[:N-K])

Solution (Python):
import sys

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

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

    num = []
    for key in d:
        num.append(d[key])

    if len(num) <= K:
        ans = 0
    else:
        num = sorted(num, key=lambda x: -x)
        ans = sum(num[K:])

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
cnt=dict(Counter(a))
if len(cnt)<=k:
    print(0)
else:
    value=list(reversed(sorted(cnt.values())))
    print(sum(value[k:]))

Solution (Python):
n, k=map(int, input().split())
a=list(map(int, input().split()))
ans=0
d={}
for ai in a:
    if ai in d:
        d[ai]+=1
    else:
        d[ai]=1
cnt=sorted(list(d.values()), reverse=True)
print(sum(cnt[k:]))

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

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n,k=IL()
A=IL()
Ad={}
for a in A:
    if a in Ad:
        Ad[a]+=1
    else:
        Ad[a]=1
Add=sorted(Ad.items(), key=lambda x: x[1])
ans=0
for i in range(len(Add)-k):
    ans+=Add[i][1]
print(ans)

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

import collections
c = collections.Counter(a)
values, counts = zip(*c.most_common(k))
print(n-sum(counts))

Solution (Python):
N, K = map(int, input().split())
k2num = {}
for k in map(int, input().split()):
    if k in k2num:
        k2num[k] += 1
        continue
    k2num[k] = 1

ans = 0
num_ball = sorted(k2num.values(), key=lambda x: x)
for i, num in enumerate(num_ball):
    if len(num_ball)-i <= K:
        break
    ans += num
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter(list(map(int, input().split())))
A = sorted(A.items(), key=lambda x: x[1], reverse=True)
print(sum([a[1] for a in A[K:]]))

Solution (Python):

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


D = {}
for i in range(N):  
  if A[i] in D:
    D[A[i]] += 1
  else:
    D[A[i]] = 1
    
L = list(D.values())[:]  


L.sort()  

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


print(ans)

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

Solution (Python):
from collections import defaultdict

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

ddict = defaultdict(int)
li_a = list(input().split())

for a in li_a:
    ddict[a] += 1

counter = 0
for w in sorted(ddict, key=lambda x: ddict[x], reverse=True)[k:]:
    counter += ddict[w]

print(counter)

Solution (Python):
from collections import Counter

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

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

Solution (Python):
def main():
    N, K = map(int, input().split())
    A = map(int, input().split())
    cnt = {}
    for a in A:
        if a not in cnt:
            cnt[a] = 0
        cnt[a] += 1
    n = max(len(cnt) - K, 0)
    x = list(cnt.values())
    x.sort()
    print(sum(x[:n]))


if __name__ == "__main__":
    main()

Solution (Python):
import collections
import sys

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

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

a.sort()

l = collections.Counter()

for i in a:
    l[i] += 1

co = 0
su = 0
l = l.most_common(m)
for i in l:
    if co < m:
        co += 1
        n -= i[1]

print(n)

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

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

l=len(set(A))

mycounter=Counter(A)
X=mycounter.most_common()[::-1]
cnt=0
if l<=k:
    print(0)
else:
    for i in range(l-k):
        cnt+=X[i][1]
    print(cnt)

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

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

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

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

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