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

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, k = map(int, input().split())
    aa = list(map(int, input().split()))
    ac = Counter(aa)
    now = len(ac)
    del_n = now - k
    ans = 0
    for v in sorted(ac.values()):
        if del_n <= 0:
            break
        ans += v
        del_n -= 1
    print(ans)

main()

Solution (Python):
from collections import Counter


def main(n: int, k: int, a: list):
    calc = Counter(a)
    calc = sorted(calc.values())

    print(sum(calc[:len(calc) - k]))


if __name__ == '__main__':
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    main(n, k, a)

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

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

ans = 0
if len(c) - k > 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()))

s = len(set(a))
m = s - k
if m <= 0:
    print(0)
    exit()
    
a.sort()
l = [0] * (a[-1] + 1)
for i in a:
    l[i] += 1

l.sort()
ans = 0
for x in l:
    if x == 0:
        pass
    else:
        ans += x
        m -=1
        if m == 0:
            print(ans)
            exit()

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

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

Solution (Python):
from collections import defaultdict

n, k = map(int, input().split())
d = defaultdict(int)
for key in input().split():
  d[key] += 1
  
l = len(d)
print(sum(sorted(d.values())[:l-k]))

Solution (Python):
import math
import heapq
from collections import Counter




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

S=Counter(A)
s= S.most_common(K)

print(N-[sum(x) for x in zip(*s)][1])

Solution (Python):
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

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

b = list()
cn = 1

for i in range(1,n+1):
    if(a[i]==a[i-1]):
        cn += 1
    else:
        b.append((a[i-1],cn))
        cn = 1
        
sn = 0        
    
b.sort(key = lambda x : (x[1],x[0]),reverse = True)    
    
if(len(b)<=k):
    print(0)
else:
    for i in range(len(b)-1,k-1,-1):
        sn += b[i][1]
    print(sn)

Solution (Python):
n,k = map(int,input().split())	
a = list(map(int,input().split()))
cnt={}
for i in a:
    if i not in cnt:
        cnt[i]=1
    else:
        cnt[i]+=1
num=[]
for i in cnt:
    num.append(cnt[i])
num.sort()
num_l=len(num)
ans=i=0
while num_l > k:
    ans+=num[i]
    i+=1
    num_l-=1
print(ans)

Solution (Python):
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    a = collections.Counter(a).most_common()[:k]
    cnt = 0
    for k, v in a:
        cnt += v
    print(n - cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

Solution (Python):
import collections as c

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

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



if len(A)<=K:
  print(0)
else:
  print(N-sum([A[i][1] for i in range(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):
from collections import defaultdict

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

d = defaultdict(int)

for a in A:
    d[a] += 1

L = len(d.keys())
if L <= K:
    print(0)
    exit()

diff = L - K
ans = 0
for k, v in sorted([x for x in d.items()], key=lambda x: x[1])[:diff]:
    ans += v

print(ans)

Solution (Python):

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

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda:0)
    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 B():

    return


def C():

    return


def D():

    return


def E():

    return


if __name__ == "__main__":
    A()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    import collections
    a = collections.Counter(a).most_common()
    if len(a) < k:
        print(0)
    else:
        cnt = 0
        for i in range(k, len(a)):
            cnt += a[i][1]
        print(cnt)


if __name__ == '__main__':
    main()

Solution (Python):
import os,re,sys,operator,math
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)
n,k=map(int,stdin.readline().rstrip().split())
a=[int(i) for i in stdin.readline().rstrip().split()]
t=deque(Counter(a).most_common())
ans=0
while len(t)>k:
    now=t.pop()
    ans+=now[1]
print(ans)

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

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

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

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

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

counts = {}
for a in A:
    if a not in counts:
        counts[a] = 1
    else:
        counts[a] += 1
        
count_pairs = []
for key,val in counts.items():
    count_pairs.append((val, key))
    
    
count_pairs.sort()
count_pairs.reverse()
if len(count_pairs) <= K:
    print(0)
else:
    non_change_num = 0
    for i in range(K):
        val, _ = count_pairs[i]
        non_change_num += val
    print(N - non_change_num)

Solution (Python):
import collections

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

c = collections.Counter(a)
vs = []
for v in c.values():
  vs.append(v)
vs.sort(reverse=True)

i = 0
if len(vs) <= k:
  print(i)
  exit()
else:
  while len(vs) > k:
    i += vs[-1]
    vs.pop()
  else:
    print(i)
    exit()

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

dic = defaultdict(int)
for a in A:
    dic[a] += 1

key_n = len(dic)

ans = 0
if key_n > K:
    dic2 = sorted(dic.items(), key=lambda x:x[1])
    for i in range(key_n - K):
        ans += dic2[i][1]
print(ans)

Solution (Python):
import collections

N, k = map(int, input().split())
S = list(map(int, input().split()))
S_unique_count = list(collections.Counter(S).values())

S_unique_count.sort()

ans = sum(S_unique_count[0:len(S_unique_count)-k])
print(ans)

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

Solution (Python):
from collections import defaultdict
n,k = map(int,input().split())
nums = input().split()
count_per_nums = defaultdict(int)
for n in nums:
  count_per_nums[n] += 1
count_per_nums = sorted(count_per_nums.items(), key=lambda x:x[1])
ans = 0
for i in range(len(count_per_nums)-k):
  ans += count_per_nums[i][1]
print(ans)

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

Solution (Python):

from collections import Counter

n, k = map(int, input().split(' '))
A = [int(el) for el in input().split(' ')]

c = Counter(A)
if len(c) < k:
    print(0)
else:
    total = 0
    for a, b in c.most_common()[k:]:
        total += b
    print(total)

Solution (Python):

from collections import Counter


def main():
    n, k = map(int, input().rstrip().split())
    A = sorted(Counter(input().split()).values(), reverse=True)
    print(sum(A[k:]))


if __name__ == "__main__":
    main()

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

Solution (Python):
from collections import Counter
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=Counter(a)
value=sorted(list(count.values()))[::-1]
print(sum(value[k:]))

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

d = {}
ans = 0

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

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

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

print(ans)

Solution (Python):

n, k = map(int, input().split())
arr = list(map(int, input().split()))
hash = dict()
for ai in arr:
    if ai in hash:
        hash[ai] += 1
    else:
        hash[ai] = 1
hash = list(sorted(hash.items(), key=lambda x: x[1]))
ans = 0
for i in range(len(hash) - k):
    ans += hash[i][1]
print(ans)

Solution (Python):

from collections import Counter


def main():
    _, k, *a = map(int, open(0).read().split())
    print(sum(sorted(Counter(a).values(), reverse=True)[k:]))


if __name__ == "__main__":
    main()

Solution (Python):

from collections import Counter


def main():
    n, k = list(map(int, input().rstrip().split()))
    lst = list(map(int, input().rstrip().split()))
    cnt = sorted(Counter(lst).values(), reverse=True)
    print(sum(cnt[k:]))


if __name__ == "__main__":
    main()

Solution (Python):
import collections
a,b =map(int,input().split())
c = input().split()
t = collections.Counter(c)
values, counts = zip(*t.most_common()[::-1])
print(sum(counts[0:len(counts)-b]))

Solution (Python):
import collections
n, k = map(int, input().split())
dat_a = list(map(int,input().split()))
d = collections.Counter(dat_a)
r_num =  len(d)- k
res = 0
r = d.most_common()[::-1]
for i in range(r_num):
    res += r[i][1]
print(res)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
A = sorted(Counter(list(map(int, input().split()))).most_common(), key=lambda x:x[1])
cnt = 0
if len(A) > k:
    for i in range(len(A)-k):
        cnt += A[i][1]
print(cnt)

Solution (Python):
n,k=map(int,input().split())
al=list(map(int,input().split()))
al.sort()
tl=[]
pv=al[0]
cnt=0
for i in al:
    if i==pv:
        cnt+=1
    else:
        tl.append(cnt)
        pv=i
        cnt=1
tl.append(cnt)
tl.sort()
if len(tl)<=k:
    print(0)
else:
    print(sum(tl[:len(tl)-k]))

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

n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
set_a = set(a)
count_a = collections.Counter(a).most_common()[::-1]
if len(set_a)-k > 0:
    for i in range(len(set_a)-k):
        ans += count_a[i][1]
print(ans)

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

Solution (Python):
from collections import Counter

n, k = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
cnt = sorted(Counter(lst).values(), reverse=True)
print(sum(cnt[k:]))

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)
print(sum(cnt[k:]))

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)
print(n - sum(cnt[:k]))

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 Counter

n, k = map(int, input().split())
A = sorted(Counter(list(map(int, input().split()))).most_common(), key=lambda x:x[1])
cnt = 0
if len(A) > k:
    for i in range(len(A)-k):
        cnt += A[i][1]
print(cnt)

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

Solution (Python):
from collections import Counter

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

print(ans)

Solution (Python):
n, k = map(int, input().split())
balls = sorted(input().split())
kinds = len(set(balls))
amo = [1] * kinds

balls.append(0)
j = 0
for i in range(n):
    if balls[i] == balls[i+1]:
        amo[j] += 1
    else:
        j += 1
amo.sort()
print(sum(amo[:max(0, kinds-k)]))

Solution (Python):


from collections import Counter
N, K = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]

counter = Counter()
for a in As:
    counter[a]+=1

B = sorted([(v, k) for k, v in counter.items()])

print(sum(v for v, k in B[:max(0, len(counter)-K)]))

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)



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







a.sort()
cnum = a[0]
ct =1
st = []
for i in range(1,n):
    if a[i] != cnum:
        cnum = a[i]
        st.append(ct)
        ct = 1
    else:ct+=1
st.append(ct)
st.sort(reverse=True)
total = 0
for i in range(min(k,len(st))):
    total+=st[i]
print(n-total)

Solution (Python):
import collections

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

A_cou = collections.Counter(A)
B = A_cou.most_common()
l = len(B)
count = 0

if K >= l:
    print(0)
else:
    for i in range(l - K):
        count += B[-i-1][1]
    print(count)

Solution (Python):
from collections import Counter
N,K = (int(i) for i in input().split())
d = Counter([int(i) for i in input().split()])
if len(d) <= K:
    print(0)
    exit()

tmp = 0
for _,p in d.most_common(K):
    tmp += p
print(N-tmp)

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

Solution (Python):
n,k=map(int,input().split())
a_list=[int(i) for i in input().split()]
count={}
for a in a_list:
    count[a]=count.get(a,0)+1
val=list(count.values())
val.sort(reverse=True)
print(sum(val[k:]))

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

for i in a:
    if i in cnt:
        cnt[i] += 1
    else:
        cnt[i] = 1

item = cnt.items()
item_srt = sorted(item, key=lambda x: x[1])
l = len(item_srt)
for j in item_srt:
    if l <= k:
        break
    ans += j[1]
    l -= 1
print(ans)

Solution (Python):
from collections import Counter

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

Solution (Python):
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=[0]*n
for i in a:
    count[i-1]+=1
count=list(reversed(sorted(count)))
print(sum(count[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 = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

li = {}
for i in A:
    if(not i in li):
        li[i]=1
    else:
        li[i]+=1

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

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

d = {}
for i in a:
    d[i] = d.get(i, 0) + 1

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

if k >= len(d):
    ans = 0
else:
    ans = sum([ v for k, v in d[:len(d)-k]])

print(ans)

Solution (Python):
n,k=map(int,input().split())
arr=list(map(int,input().split()))
cnt=[0]*(n+1)
cnt2=[]
for i in range(n):
  cnt[arr[i]]+=1
for i in range(1,n+1):
  if cnt[i]!=0:
    cnt2.append(cnt[i])
cnt2=sorted(cnt2)
if len(cnt2)<=k:
  print(0)
else:
  print(sum(cnt2[:len(cnt2)-k]))

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

count = {}
for i in A:
    if i not in count:
        count[i] = 0
    count[i] += 1

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

Solution (Python):
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
c = collections.Counter(A)
a = list(c.values())
if len(a) <= K:
  print(0)
else:
  a.sort(reverse=True)
  print(N-sum(a[:K]))

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

from collections import Counter
b = Counter(a)
counter = []
for key in b.keys():
    counter.append(b[key])
counter.sort()
print(sum(counter[:len(counter) - nk[1]]))

Solution (Python):
from collections import Counter

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

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

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

Solution (Python):
from collections import Counter

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

print(sum(v for _, v in Counter(A).most_common()[K:]))

Solution (Python):
import collections as col

N, K = map(int,input().split())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()
ans = 0

if len(L) <= K:
    print('0')
    exit()

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

print(ans)

Solution (Python):
N,K=map(int,input().split())
A=input().split()
from collections import defaultdict
d = defaultdict(int)
for i in A:
    d[i]+=1
var = len(d.keys())
l = list(d.values())
l.sort()
print(sum(l[:max(var-K,0)]))

Solution (Python):
import collections

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

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

print(sum(B[K::]))

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,k = f()
    a = f()

    cnt = {}
    for i in a:
        if i in cnt:
            cnt[i] += 1
        else:
            cnt[i] = 1
    
    items = sorted(cnt.items(), key = lambda x: x[1], reverse = True)

    print(n - sum([i[1] for i in items[:k]]))

solve()

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):
import sys
import bisect
import math
input = sys.stdin.readline

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

m = {}
for v in l:
    if m.get(v) != None:
        m[v] += 1
    else:
        m[v] = 1
        
m = list(m.values())
m.sort()
t = len(m) - k
if t < 0:
    t = 0
print(sum(m[:t]))

Solution (Python):
from collections import Counter

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

key, val = zip(*Counter(A).most_common())
k = len(val)

for i in range(len(val)):
    if k <= K:
        break
    count += val[len(val)-i-1]
    k -= 1

print(count)

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

num = {}
for i in A:
	if not i in num.keys():
		num[i] = 1
	else:
		num[i] += 1

cnt = list(num.values())
cnt.sort()
print(sum(cnt[:len(cnt)-K]))

Solution (Python):
from collections import Counter

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

c = Counter(A).most_common()

ans = 0

for i in range(K,len(c)):
    ans += c[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).most_common()

ans = 0

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

print(ans)

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

counter = [0]*(N+1)
integers = 0
for a in A:
    if counter[a] == 0:
        integers += 1
    counter[a] += 1
counter = sorted(counter)
ans = 0
for c in counter:
    if c > 0:
        ans += c
        integers -= 1
    if integers <= K:
        break
print(ans)

Solution (Python):


import sys
import math



N,K = map(int, sys.stdin.readline().rstrip().split())
An = list(map(int, sys.stdin.readline().rstrip().split()))

amap = {}
for a in An:
  if a not in amap:
    amap[a] = 1
  else:
    amap[a] += 1

nl = []
for i in list(amap.values()):
  nl.append(i)
nl = sorted(nl)

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

Solution (Python):
from collections import defaultdict

N,K = map(int, input().split())
a = list(map(int, input().split()))
cnt_d = defaultdict(lambda: 0)
for ai in a:
    cnt_d[ai] += 1

cnt_v = sorted([v for k,v in cnt_d.items()])
print(sum(cnt_v[:-K]))

Solution (Python):
from collections import defaultdict
from operator import itemgetter

N,K = map(int, input().split())
a = list(map(int, input().split()))
cnt_d = defaultdict(lambda: 0)
for ai in a:
    cnt_d[ai] += 1

cnt_l = sorted(cnt_d.items(), key=itemgetter(1))
ans = sum([v for k,v in cnt_l[:-K]])
print(ans)

Solution (Python):
import collections
n,k=map(int,input().split())
A=list(map(int,input().split()))
c=collections.Counter(A)
tot=0
for i in c.most_common(min(k,len(set(A)))):
  tot+=i[1]
print(n-tot)

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

o = []
v = A[0]
z = 0
for i in range(1,N):
    if v != A[i]:
        o.append(i-z)
        v = A[i]
        z = i
o.append(N-z)
o.sort()
print(sum(o[:-K]))

Solution (Python):
n,m=map(int,input().split())
l=list(map(int,input().split()))
d={}

c=0
for i in l:
  if i in d:
    d[i]+=1
  else:
    d[i]=1
l1=d.values()
if m>=len(l1):
  print(0)
else:
  l1=sorted(l1)
  for i in range(len(l1)-m):
    c+=l1[i]
  print(c)

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

Solution (Python):
n,k=map(int,input().split())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
m=list(d.values())
m.sort()
a=len(m)-k
ans=0
for i in m:
  if a<=0:
    break
  a-=1
  ans+=i
print(ans)

Solution (Python):
from collections import Counter
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
A = Counter([int(_) for _ in stdin.readline().rstrip().split()])
print(sum((i[1] for i in A.most_common()[K:])))

Solution (Python):
n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
c = [0] * (n + 1)

for i in a:
    c[i] += 1
    
c.sort(reverse=True)
print(sum(c[k:]))

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

Solution (Python):
import collections

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

dict = collections.Counter(a_n)

v_list = list(dict.values())
v_list_s = sorted(v_list)

cnt = 0
if len(v_list_s) <= K:
    print(0)
else:
    x = len(v_list_s) - K
    for i in range(x):
        cnt += v_list_s[i]
    print(cnt)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=collections.Counter(a)
cm=c.most_common()[::-1]
cml=len(cm)
count=0
for i in range(cml):
    if cml<=k:
        break
    else:
        cml-=1
        count+=cm[i][1]
print(count)

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

Solution (Python):
from collections import defaultdict

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

counts = defaultdict(int)
for a in As:
    counts[a] += 1

counts = sorted(counts.values())

if len(counts) <= K:
    print(0)
else:
    total = 0
    for i in range(len(counts) - K):
        total += counts[i]
    print(total)

Solution (Python):
import bisect

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

data = []
i = 0

while i < len(A):
    x = A[i]
    a = bisect.bisect_left(A, x)
    b = bisect.bisect_right(A, x)
    data.append([x, b - a])
    i = b
    
data = sorted(data, key = lambda x: x[1])
m = len(data) - K
ans = 0

for i in range(0, m):
    ans += data[i][1]
    
print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A.copy()
B = list(set(B))
n = len(B)

def counter(A):
 counter = {}
 for a in A:
  if(a in counter):
   counter[a] += 1
  else:
   counter[a] = 1
 return counter

ans = 0
if(n > K):
  dict = counter(A)
  count = 1
  
  for k, v in sorted(dict.items(), key=lambda x: -x[1]):
    if(count > K):
     ans += v
    count += 1
    
print(ans)

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

dic = {}                
for a in A:
    dic[a] = dic.get(a,0) + 1
    
C = []
for k in dic:
    C.append([k,dic[k]])
    
C.sort(key = lambda x: x[1])

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

Solution (Python):
N, K = map(int, input().split())
A = [int(_) for _ in input().split()]
num = len(set(A))
cnt = [0]*(N+1)
ans = 0

for i in A:
    cnt[i] += 1

for i in range(N+1):
    if cnt[i] == 0:
        cnt[i] = N+1
        
cnt = sorted(cnt)
for i in range(max(0, num-K)):
    ans += cnt[i]

print(ans)

Solution (Python):
from collections import Counter

if __name__ == '__main__':
    n, k = map(int, input().split())
    a = sorted(Counter(int(s) for s in input().split()).values())
    print(sum(a[:len(a) - k]))

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    input_raw = read_func().strip().split()
    A = {}
    for i in range(N):
        if int(input_raw[i]) not in A:
            A[int(input_raw[i])] = 1
        else:
            A[int(input_raw[i])] += 1
    A_val = A.values()

    A_val.sort(reverse = True)

    count = 0L
    for i in range(K, len(A_val)):
        count += A_val[i]
    print count


if __name__ == '__main__':
    main()