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

Solution (Python):



import sys

import collections as col



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(ALLNUM, KIND, ball_numbers):
    result = 0
    
    counter_result = col.Counter(ball_numbers)
    ball_num_len = len(counter_result)
    counter_result_sorted = sorted(counter_result.items(), key=lambda x: x[1])
    
    if ball_num_len <= KIND:
        return 0
    reduce_kind = ball_num_len - KIND
    
    for _, ballCount in counter_result_sorted:
        result += ballCount
        reduce_kind = reduce_kind - 1
        
        if reduce_kind <= 0:
            break
    return result


if __name__ == "__main__":
    N, K = MI()
    Ai = list(map(int, sys.stdin.readline().split()))
    
    print("{}".format(solver(N, K, Ai)))

Solution (Python):
import collections
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
col_A = collections.Counter(A)
lis_col_A=[]
for key,val in col_A.items():
    lis_col_A.append([key,val])
slcA = sorted(lis_col_A,key = lambda x:-x[1])
sumA = 0
for i in range(K,len(slcA)):
    sumA += slcA[i][1]
print(sumA)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
result = 0
cnt = Counter(a)
cnt_set = set(cnt.items())
cnt_sort = sorted(cnt.items(), key=lambda x:x[1])
for i in range(len(cnt_set) - k):
    result += cnt_sort[i][1]

print(result)

Solution (Python):
import sys
import math
import numpy as np
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N,K = I()
A = l()
c = Counter(A)
n = len(list(c))
if n <= K:
    print(0)
else:
    v = list(c.values())
    v.sort()
    print(sum(v[:n-K]))

Solution (Python):
N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[0]*(2*(10**5)+1)
for i in range(N):
  dp[A[i]]+=1
dp.sort(reverse=True)
bns=sum(dp[K:])
print(bns)

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

d=[0]*n
for i in range(n):
    d[a[i]-1]+=1

d.sort(reverse=True)

sm=0
for i in range(k):
    if i>=n:
        break
    sm+=d[i]

print(n-sm)

Solution (Python):
import sys
from collections import Counter

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, K = mi()
    A = list(mi())
    c = list(Counter(A).values())
    c.sort()
    print(sum(c[:-K]))


if __name__ == '__main__':
    main()

Solution (Python):


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

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

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

print(ans)

Solution (Python):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ball=[0]*n
s=set()
for i in range(n):
    ball[a[i]-1]+=1
    s.add(a[i]-1)
kind=len(s)
ans=0
ball.sort()
for i in range(n):
    if ball[i]==0:
        continue
    if kind>k:
        kind-=1
        ans+=ball[i]
print(ans)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import Counter

n, k, *a = map(int, read().split())
c = Counter(a)

l = list(c.items())
l.sort(key=lambda x: x[1])

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

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

Solution (Python):
import collections

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

check=collections.Counter(A).most_common()
ans=0
for i in range(K,len(check)):
  ans+=check[i][1]
print(ans)

Solution (Python):
from collections import Counter
N, K = map(int, input().split())
A = Counter(list(map(int,input().split()))).most_common()
repeat = len(set(A))-K
ans = 0
num = 0

while num < repeat:
    ans += A.pop(-1)[1]
    num += 1

print(ans)

Solution (Python):
import collections
a,b=map(int,input().split())
n=list(map(int,input().split()))
n=collections.Counter(n)
m,o=zip(*n.most_common())
o=list(o)
print(sum(o)-sum(o[:b]))

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

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

count={}

for i in range(N):
  if A[i] not in count:
    count[A[i]]=1
  else:
    count[A[i]]+=1

if(len(count)<=K):
  print(0)
else:
  x=len(count)-K 
  answer=0
  sorted_count=sorted(count.items(),key=lambda x:x[1])
  for i in range(x):
    answer+=int(sorted_count[i][1])
  
  print(answer)

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

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

Solution (Python):
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= 1
    q += s
    if p <= k:
        print(q)
        sys.exit()

Solution (Python):
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
d = dict()
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

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

if len(cs) <= k:
    print(0)
else:
    c = 0
    print(sum(cs[:-k]))

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = input().split()
d = sorted(Counter(a).values())
ans = 0

for i in range(len(d) - k):
    ans += d[i]

print(ans)

Solution (Python):
from collections import Counter

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

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

print(ans)

Solution (Python):
from collections import defaultdict
n, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print(sum(sorted(d.values(), reverse=True)[k:]))

Solution (Python):
from collections import defaultdict
n, k = [int(x) for x in input().split()]
a_list = [int(x) for x in input().split()]
d = defaultdict(int)
for a in a_list:
    d[a] += 1
print(sum(sorted(d.values())[:-k]))

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
a = input().split()
c = sorted(Counter(a).values(), reverse=True)

print(max(0, sum(c[k:])))

Solution (Python):
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
b = set(a)
if k >= len(b):
    print(0)
else:
    d = {}
    for i in a:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    c = list(d.values())
    c.sort()
    e = 0
    for i in range(len(b) - k):
        e += c[i]
    print(e)

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

Solution (Python):
from collections import Counter
import sys

N, K = map(int, input().split())
A = list(input().split())
ball = [int(A[i]) for i in range(N)]
kinds = len(set(ball))
Cou = list(Counter(ball).most_common())
dele = [int(Cou[i][1]) for i in range(len(Cou) - kinds + K, len(Cou))]
print(sum(dele))

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

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

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

Solution (Python):
from collections import Counter

N,K,*a = map(int, open(0).read().split())
c = Counter(a)
v = sorted([x for x in c.values()])
if len(v) - K > 0:
    print(sum(v[:len(v)-K]))
else:
    print(0)

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

N,K = list(map(int,input().split()))
A = list(Counter(map(int,input().split())).items())
A = sorted(A,key=itemgetter(1),reverse = True)

ans = 0
B = A[K:]
for i in range(len(B)):
    ans += B[i][1]
print(ans)

Solution (Python):
n,k = map(int,input().split())
from collections import defaultdict
d = defaultdict(int)
num_list = list(map(int,input().split()))
for tmp in num_list:
	d[tmp] += 1
    
v_list = sorted(list(d.values()) ,reverse=True)

print(n - sum(v_list[:k]))

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
D = {}
for a in A:
    if a not in D:
        D[a] = 1
    else:
        D[a] += 1

D_list = sorted(D.items(), key=lambda x: x[1])
N = len(D_list)
ANS = 0
for t in D_list:
    if N <= K:
        break
    ANS += t[1]
    N -= 1

print(ANS)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) == k:
    print(0)
    exit()

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

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

print(ans)

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

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


import collections

c = collections.Counter(al)

l = len(c)
cc = sorted(c.items(), key=lambda x:x[1])

res = 0

if l <= k:
    pass

else:
    for i in range(l-k):
       res += cc[i][1] 

print(res)

Solution (Python):
from collections import OrderedDict

N, K =map(int, input().split())
a = list(map(int, input().split()))
p = OrderedDict()
for i in a:
  if i not in p:
    p[i] = 1
  else:
    p[i] +=1

p_rev = OrderedDict(
    sorted(p.items(), key=lambda x: x[1])
)


count = 0
sum = 0
for i in p_rev.values():
  if len(p_rev) - count > K:
    sum += i
    count += 1
  else:
    break
print(sum)

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

ans = 0
c = collections.Counter(A_list)
if K >= len(c):
    ans = 0
else:
    foo = len(c)-K
    bar_list = list(c.values())
    bar_list.sort()
    for i in range(foo):
        ans += bar_list[i]

print(ans)

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

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

base = np.zeros(n)
for i in range(n):
  base[a[i]-1] += 1
  
seen = np.where(base>0,1,0)
num = np.sum(seen) - k

if num <= 0:
  ans = 0
elif num > 0:
  base.sort()
  count = 0
  ans = 0
  for i in range(n):
    if base[i] != 0:
      ans += base[i]
      count += 1
      
    if count == num:
      break
    
print(int(ans))

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

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

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

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

Solution (Python):
import collections

n, k = map(int,input().split())
a = input().split()
a = sorted(collections.Counter(a).values(), reverse=True)
s = sum(a[:k])

print(0 if s == n else n - s)

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

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

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

tmp = 0

for i in range(min(k, len(d_sorted))):
    tmp += d_sorted[i][1]

print(n - tmp)

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

C=Counter(a)
ans=0

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

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

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

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

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

b=sorted(c(a).items(),key=lambda x:x[1])
kind=len(c(a))
i=0
ans=0
while k<kind:
    ans+=b[i][1]
    kind-=1
    i+=1
print(ans)

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

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

Solution (Python):

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

Solution (Python):
import collections

N, K = map(int, input().split())
A = sorted(collections.Counter(list(map(int, input().split()))).items(), key=lambda x: x[1], reverse = True)
if len(A) <= K:
    print(0)
else:
    print(sum([x[1] for x in A[K:]]))

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7


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

C = Counter(A)

n = sorted(list(C.values()))
print(sum(n[:len(n)-K]))

Solution (Python):
__DEUBG__ = 0


from collections import Counter

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

balls = Counter(balls)
b2 = sorted(balls.items(), key=lambda item: item[1], reverse=True)

uniq_num = len(balls)

if __DEUBG__:
    print('\n'*2)
    print(len(balls))
    print(balls)
    print(b2)

if uniq_num <= K:
    print(0)
else:
    total = 0
    for i in range(uniq_num-K):
        tmp = b2.pop()
        if __DEUBG__:
            print(tmp)
        total += tmp[-1]
    print(total)

Solution (Python):
from collections import Counter
n, k = map(int, input().split())
a = map(int, input().split())
ca = Counter(a)
print(sum(sorted([w for q, w in ca.items()])[:-k]))

Solution (Python):
n, k = map(int, input().split())
a = map(int, input().split())
ball_count = {}
for num in a:
    if num in ball_count:
        ball_count[num] += 1
    else:
        ball_count[num] = 1
ball_kinds = len(ball_count.keys())
ball_count_list = sorted(ball_count.values(), reverse=True)
ans = 0
for _ in range(ball_kinds - k):
    ans += ball_count_list.pop()

print(ans)

Solution (Python):
from collections import Counter

n, k = map(int, input().split())
L = list(map(int, input().split()))
cnt = Counter(L)
if len(cnt.keys()) <= k:
  print(0)
else:
  rewrite_groups = len(cnt.keys()) - k
  print(sum(sorted(cnt.values())[:rewrite_groups]))

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

Solution (Python):
import sys
import collections

input = sys.stdin.readline

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

B = set(A)

cnt = len(B)





li = list(collections.Counter(A).values())
li = sorted(li)

if cnt - K > 0:
    for x in range(cnt - K):
        ans += li[x]
    print(ans)

else :
    print(ans)

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

import collections
A_tuple = collections.Counter(A).most_common()[::-1]

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

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

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

num = list(d.values())
num.sort(reverse=True)
print(sum(num[K:]))

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

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

kind = len(dict)-k
if kind <=0:
  print(0)
  exit()

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

for i in range(kind):
  sum += dic[i][1]
  
print(sum)

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

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

m = len(set(A))

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

Solution (Python):
import sys
from collections import Counter
def main():
    n, k = map(int, input().split())
    a = tuple(map(int, input().split()))

    col = max(0, len(set(a)) - k)
    if col == 0:
        print(0)
        sys.exit()

    ac = Counter(a)
    acl = ac.most_common()[::-1]
    acll = [ace[1] for ace in acl[:col]]

    r = sum(acll)
    print(r)

if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import Counter


def main():
    N, K = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    counter = Counter(A)
    n_kind = len(counter.keys())
    if n_kind <= K:
        print(0)
    else:
        counts = list(counter.values())
        counts.sort()
        print(sum(counts[:(n_kind - K)]))



if __name__ == '__main__':
    main()

Solution (Python):
import collections
def solve(n, k, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    tmp = sorted(counter.values(), reverse=True)
    ans = n - sum(tmp[:k])
    
    return ans

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print(solve(n, k, a_list))

Solution (Python):
import collections
def solve(n, k, a_list):

    counter = collections.Counter()

    for i in a_list:
        counter[i] += 1

    key_num = len(counter.keys())
    if key_num > k:
        tmp = sorted(counter.items(), key=lambda x: x[1])
        ans = sum([v for k, v in tmp[: key_num - k]])
    else:
        ans = 0

    return ans

if __name__ == "__main__":
    n, k = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print(solve(n, k, a_list))

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

from collections import Counter

AL=Counter(A)
AL= sorted(AL.items(), key=lambda x:x[1])
n=len(set(A))-K

sum=0
for i in range(n):
  sum+=AL[i][1]
print(sum)

Solution (Python):



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
lis=LI()
cou=Counter(lis)
u=cou.most_common()

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

Solution (Python):
from collections import Counter

n,k=map(int,input().split())
l=[int(i) for i in input().split()]
c=Counter(l).most_common()
if len(c)<=k:
    ans=0
else:
    sum=0
    for i in range(0,k):
        sum+=c[i][1]
        ans=n-sum

print(ans)

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

nndict = {}
nnlist = []
for i in range(1, N+1):
  if ndict[i] >= 1:
    if ndict[i] not in nndict:
      nndict[ndict[i]] = 1
      nnlist.append(ndict[i])
    else:
      nndict[ndict[i]] += 1
      
nnlist.sort(reverse=True)


ki = K
for i in range(len(nnlist)):
  if ki > nndict[nnlist[i]]:
    ki -= nndict[nnlist[i]]
  else:
    nndict[nnlist[i]] -= ki
    inow = i
    break
else:
  print(0)
  exit()

ans = 0
for i in range(i, len(nnlist)):
  ans += nndict[nnlist[i]] * nnlist[i]
print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1





N,K = IL()
A = IL()
d = DD(int)
for a in A:
  d[a] += 1
  
d = [(d[k])for k in d]
d.sort()
n = len(d)
P(sum(d[:max(0,n-K)]))

Solution (Python):


from collections import defaultdict
N, K = map(int, input().split())
balls = defaultdict(int)
for b in input().split():
    balls[b] += 1
balls = sorted(balls.values())
print(N - sum(balls[-K:]))

Solution (Python):
from collections import defaultdict
N, K = map(int, input().split())
balls = defaultdict(int)
for b in input().split():
    balls[b] += 1
types = len(balls.keys())
balls = sorted(balls.values(), reverse=True)
ans = 0
while types > K:
    ans += balls.pop()
    types -= 1
print(ans)

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

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

c = Counter(a).most_common()
ans = 0
tmp = 0
for i,cnt in c:
    tmp += cnt
    k-=1
    if k == 0:
        ans = n-tmp
        break
print(ans)

Solution (Python):
import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=collections.Counter(a)
values,counts=zip(*a.most_common())
l=len(values)
ans=0
i=0
while l>k:
  ans=ans+counts[len(values)-i-1]
  i=i+1
  l=l-1

print(ans)

Solution (Python):
N,K = map(int,input().split())
A = list(map(int,input().split()))
X = dict()
for i in A:
    if i in X:
        X[i] += 1
    else:
        X[i] = 1
Y = [] 
for i in X.keys():
    Y.append(X[i])
Y.sort()

if len(Y) <= K:
    ans = 0
else:
    ans = sum(Y[:len(Y)-K])
print(ans)

Solution (Python):
import collections
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
count = c.most_common()[::-1]

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

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

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