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

Solution (Python):
import collections


def calc(A, K):
    dist = {}
    tmp = collections.Counter(A)
    type_ = len(tmp)

    if type_ <= K:
        return 0

    for a, count in tmp.items():
        if count not in dist.keys():
            dist[count] = [a]
        else:
            dist[count].append(a)

    rewrite = 0
    i = 0
    for c in sorted(dist.keys()):
        for _ in dist[c]:
            i += 1
            rewrite += c
            if i == type_ - K:
                return rewrite


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = calc(A, K)
    print(ans)


if __name__ == "__main__":
    main()

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

table = {}
for _ in input().split():
    i = int(_)
    if i in table.keys():
        table[i] += 1
    else:
        table[i] = 1
nums = sorted(table.values())
print(sum(nums[0:len(nums)-K]))

Solution (Python):
import collections
N,K = [int(i) for i in input().split() ]
balls = [int(i) for i in input().split() ]

c = collections.Counter(balls)
common = c.most_common()
changed = 0

while len(common) > K :
	changed += common[-1][1]
	del common[-1]

print(changed)

Solution (Python):

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

A.sort()

counts = []
view = 0
cnt = 0
for i, Ai in enumerate(A):
    if i == 0: view = Ai
    elif Ai > view:
        counts.append(cnt)
        view = Ai
        cnt = 0
    cnt += 1
else:
    counts.append(cnt)

counts.sort()

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

Solution (Python):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
a.append(-1)
variation = []
target = a[0]
start = 0
for i in range(len(a)):
    if a[i] != target:
        variation.append(i-start)
        start = i
        target = a[i]
variation = sorted(variation)
cost = 0
for i in range(len(variation) - k):
    cost += variation[i]
print(cost)

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

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

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

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

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

Solution (Python):
import collections

N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ans = 0
con = collections.Counter(A).most_common()
if len(con) <= K:
    print(ans)
else:
    for a, b in con[K:]:
        ans += b
    print(ans)

Solution (Python):

"""
Created on Sun Nov 11 15:18:17 2018
ABC081C
@author: maezawa
"""
import collections as col
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

kinds = col.Counter(a)
commonk = kinds.most_common(k)

ans = n - sum([elem[1] for elem in commonk])
print(ans)

Solution (Python):
import collections

n, k = map(int, input().split())
a = input().split()
a = [int(m) for m in a]
a.sort()
c = collections.Counter(a)

values, counts = zip(*c.most_common()[::-1])

count = 0
i = 0

if len(c) <= k:
    print(0)
    exit()
else:
    for j in counts:
        if i >= 0 and i <= len(counts) - 1 - k:
            count += j
        i += 1

print(count)

"""for i, name in enumerate(l, 1):
    print('{:03}_{}'.format(i, name))"""

Solution (Python):
from collections import Counter, OrderedDict

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

ac = Counter(a)



ac.most_common()

tac = list(ac.values())
tac.sort()
v = len(tac)
if(k < v):
    print(sum(tac[:v-k]))
else:
    print(0)

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

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

s=collections.Counter(l)
s=s.most_common()

a=0
for i in range(k,len(s)):
    a+=s[i][1]
print(a)

Solution (Python):
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=len(set(a))
b=dict(Counter(a).most_common())
d=list(b.values())
d.sort()
if c<=k:
    print(0)
else:
    tmp=c-k
    ans=0
    for i in range(tmp):
        ans+=d[i]
    print(ans)

Solution (Python):
def 解():
    iN,iK = [int(_) for _ in input().split()]
    dA = {}
    def addD(d,a):
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    for a in [int(_) for _ in input().split()]:
        addD(dA,a)
    aV = dA.values()
    print(sum(sorted(aV)[0:len(aV)-iK]))
解()

Solution (Python):
def 解():
    iN,iK = [int(_) for _ in input().split()]
    aA = [0]*(iN+1)
    for a in [int(_) for _ in input().split()]:
        aA[a] += 1
    print(sum(sorted(aA)[0:iN-iK+1]))
解()

Solution (Python):
def 解():
    iN,iK = [int(_) for _ in input().split()]
    
    dA = {}
    def addD(d,a):
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    for a in [int(_) for _ in input().split()]:
        addD(dA,a)
    aList = sorted(list(dA.items()),key=lambda x:x[1])
    print(sum(map(lambda x:x[1],aList[0:len(aList)-iK])))
解()

Solution (Python):
def 解():
    iN,iK = [int(_) for _ in input().split()]
    aA = [int(_) for _ in input().split()]
    dA = {}
    def addD(d,a):
        if a in d:
            d[a] += 1
        else:
            d[a] = 1
    for a in aA:
        addD(dA,a)
    aList = sorted(list(dA.items()),key=lambda x:x[1])
    print(sum(map(lambda x:x[1],aList[0:len(aList)-iK])))
解()

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

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

mapa = {}
for i in range(n):
    if a[i] in mapa:
        mapa[a[i]] += 1
    else:
        mapa[a[i]] = 1

mapsa = sorted(mapa.items(), key=lambda x: x[1])
count = 0
if len(mapsa) > k:
    for i in range(len(mapsa) - k):
        count += mapsa[i][1]
print(count)

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

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

dict = {}

for a in A:
	try:
		dict[a] += 1
	except KeyError:
		dict[a] = 1

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

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

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

dict = {}

for a in A:
	try:
		dict[a] += 1
	except KeyError:
		dict[a] = 1

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

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

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

for i in range(N):
    D[A[i]] += 1

over = max(0, len(D) - K)
Dkey = sorted(D.items(), key = lambda x:x[1])

change = 0
current = 0
while over > 0:
    change += Dkey[current][1]
    over -= 1
    current += 1
print(change)

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

count = 0
b = [0] * 200000

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

b.sort()

for i in range(len(b)):
    if b[i] == 0:
        count += 1

del b[:count]

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

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

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

count = 0
result = sorted(result.items(), key=lambda x: x[1])
if len(result) > K:
    for key, val in result[:len(result) - K]:
        count += val

print(count)

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

keys = num_map.keys()
nums = list(num_map.values())
sum_kind = len(keys)
nums.sort()

cnt = sum_kind
ans = 0
for num in nums:
    if cnt <= K:
        break
    else:
        ans += num
        cnt -= 1
print(ans)

Solution (Python):
n,k=map(int,input().split())
A=list(map(int,input().strip().split(" ")))
dict={}

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

X=[]
sorted_A = sorted(dict.items(), key=lambda x: x[1], reverse=True)
for i,v in sorted_A:
    X.append(v)

ans=0
if len(X)>k:
    for i in X[k:]:
        ans+=i
print(ans)

Solution (Python):

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

dict = {}
for a in an:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

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

print(ans)

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

import collections
s_c=collections.Counter(a)


key, value=zip(*s_c.most_common())
value = list(value)
value.sort()
ans = 0
if len(key) - k >0:
	ans = sum(value[:(len(key)-k)])
print(ans)

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

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

Solution (Python):
N, K = map(int, input().split())
A_list = list(map(int,input().split()))
A_dict = dict()
for elem in A_list:
    if not elem in A_dict:
        A_dict[elem] = 1
    else:
        A_dict[elem] += 1
total = 0
A_dict = sorted(A_dict.items(), key=lambda x: x[1])
for i in range(len(A_dict) - K):
    total += A_dict[i][1]
print(total)

Solution (Python):
import collections

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

count = collections.Counter(A)
if len(count) <= K:
    print(0)
else:
    num_cnt = 0
    for _, c in count.most_common()[K:]:
        num_cnt += c

    print(num_cnt)

Solution (Python):
from collections import Counter

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

count = Counter(A)
same = sum([v[1] for v in count.most_common(K)])

print(N - same)

Solution (Python):
def getN():
    return int(input())


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


def getList():
    return list(map(int, input().split()))

n, k = getNM()
nums = getList()

bucket = [0 for i in range(200001)]
for num in nums:
    bucket[num] += 1

bucket.sort()
print(sum(bucket[:-k]))

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
L = list(D.values())
L = sorted(L)
ans = 0
counter = 0
for i in range(len(L)) :
    if len(L) - counter > K :
        ans += L[i]
        counter += 1
    else :
        print(ans)
        break

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n,k = li()
a = list(li())

cnt = Counter(a)

al = cnt.most_common()

if len(al) <= k:
    print(0)
else:
    ans = 0
    for _, v in al[k:]:
        ans += v
        
    print(ans)

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(D.items(),key=lambda x:x[1])
counter = 0
answer = 0
for j in range(len(D)) :
    if len(D) - counter > K :
        counter += 1
        answer += D[j][1]
    else :
        print(answer)
        break

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

c = Counter(a)
c_most = c.most_common()
count = 0
for i in range(min(len(c_most), k)):
    count += c_most[i][1]

print(n - count)

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

from collections import Counter
counter=Counter(A)

counter=counter.most_common()

ANS=0
for i in range(K,len(counter)):
    ANS+=counter[i][1]

print(ANS)

Solution (Python):
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
ctr = Counter(A)
stay = 0
for k,v in ctr.most_common(K):
    stay += v
print(N - stay)

Solution (Python):
s=0
R=[]
N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
import collections
c=collections.Counter(A).most_common()


if len(c)>K:
    for i in range(K):
        s+=c[i][1]
    print(N-s)
else:
    print("0")

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

c=collections.Counter(a)
l=[]

for i,j in c.most_common():
    l.append(j)

l.sort()
l.reverse()
ans=n


for i in range(k):
    ans-=l[i]
    if ans==0:
        break
print(ans)

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

seisuu.sort()
seisuu.reverse()
for i in range(K, N):
    ans += seisuu[i]
print(ans)

Solution (Python):
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print(0)

Solution (Python):
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print(0)

Solution (Python):
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print(0)

Solution (Python):

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

if N==1:
    print(0)
    exit()

A_sorted=sorted(A)

BallCount=[N+1]*N
BallCount_order=0   
BallCount_count=1   

for i in range(N-1):
    if A_sorted[i]==A_sorted[i+1]:
        BallCount_count+=1
    else:
        BallCount[BallCount_order]=BallCount_count
        BallCount_order+=1
        BallCount_count=1
    
    if i == N - 2:
        BallCount[BallCount_order] = BallCount_count

BallCount_sorted=sorted(BallCount)

remains=BallCount_order+1-K

act_count=0     
i=0     
while remains>0:
    act_count+=BallCount_sorted[i]
    remains-=1
    i+=1
print(act_count)

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

d = dict()
for x in a:
    d[x] = d.get(x, 0) + 1
d2L = [(k, v) for k, v in d.items()]
d2L = sorted(d2L, key = lambda x: x[1])

ans = 0
i = 0
while len(d2L) - k - i > 0:
    ans += d2L[i][1]
    i += 1
print(ans)

Solution (Python):
n, k = map(int, input().split())
listA = list(map(int, input().split()))
listA.sort()
countL =[]

index=0
beforeN=0
count=0
while index < len(listA):
    if index ==0:
        beforeN = listA[index]
        count+=1
    else:
        if listA[index] == beforeN:
            count+=1
        else:
            countL.append(count)
            beforeN = listA[index]
            count=1
    index+=1
countL.append(count)

if len(countL)== k:
    print(0)
else:     
    countL.sort()
    index2 =0
    sum =0
    while index2 < len(countL)-k:
        sum+=countL[index2]
        index2+=1
    print(sum)

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(D.items(),key=lambda x:x[1])
counter = 0
answer = 0
for j in range(len(D)) :
    if len(D) - counter > K :
        counter += 1
        answer += D[j][1]
    else :
        print(answer)
        break

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

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

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

if K >= len(set(ball)):
  print("0")
  exit()

for i in ball:
  if not i in d:
    d[i] = 1
  else:
    d[i] += 1

d_val = sorted(d.values(),reverse=True)
print(N - sum(d_val[:K]))

Solution (Python):
from collections import Counter

N, K = map(int, input().split())
A = input().split()
cnt = Counter(A)
del_num = len(cnt) - K

print(sum(sorted(cnt.values())[:del_num]))

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

for x in input().split():
    dic[x] = dic.get(x,0) + 1

sort_d = sorted(dic.values())

ans = 0
el = len(dic) -K
for i,x in enumerate(sort_d):
    if i >= el:
        break
    else:
        ans += x
print(ans)

Solution (Python):
n, k = map(int, input().split())
a = list(input().split()) 
 
cnt = {} 
for a_i in a:
    if a_i not in cnt.keys(): 
        cnt[a_i] = 1
    else:
        cnt[a_i] += 1
        
cnts = sorted(cnt.values())
print(sum(cnts[:len(cnts) - k]))

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

num_balls = [0]*(n+1)
for i in range(n):
    num_balls[a[i]] += 1
num_balls = sorted(num_balls, reverse = True)


print(sum(num_balls[k:]))

Solution (Python):
from collections import Counter

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

cnt_a = Counter(a).most_common()

ans = 0
while len(cnt_a) > k:
    last = cnt_a.pop()
    ans += last[1]

print(ans)

Solution (Python):
from collections import defaultdict
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
C = defaultdict(int)
for a in A:
  C[a] += 1
print(sum(sorted(C.values())[:-K]))

Solution (Python):
N, K = map(int, input().split())
A = list(map(int, input().split()))
from collections import Counter
c = Counter(A).most_common()[::-1]
rewrite = len(c) - K
count = 0
for k, v in c[:rewrite]:
    count += v
print(count)

Solution (Python):


def zehnpaard():
    from collections import Counter

    n, k = map(int, input().split())
    c = Counter(int(x) for x in input().split())
    print(sum(val for key, val in c.most_common()[k:]))

def main():
    """WA"""
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    import collections
    c_dict = collections.Counter(a_list)
    diff = len(c_dict) - K
    if diff <= 0:
        print(0)
        exit()

    
    ans = 0
    c_list = sorted(c_dict.items(), key=lambda x: x[1])
    for i in range(diff):
        ans += c_list[i][1]
    print(ans)

def main2():
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    import collections
    c_dict = collections.Counter(a_list)
    print(sum(value for key, value in c_dict.most_common()[K:]))

if __name__ == "__main__":
    main()

Solution (Python):


def zehnpaard():
    from collections import Counter

    n, k = map(int, input().split())
    c = Counter(int(x) for x in input().split())
    print(sum(val for key, val in c.most_common()[k:]))

def main():
    """WA"""
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    import collections
    c_dict = collections.Counter(a_list)
    diff = len(c_dict) - K
    if diff <= 0:
        print(0)
        exit()

    
    ans = 0
    c_list = sorted(c_dict.items(), key=lambda x: x[1])
    for i in range(diff):
        ans += c_list[i][1]
    print(ans)

def main2():
    N, K = list(map(int, input().split()))
    a_list = list(map(int, input().split()))

    import collections
    c_dict = collections.Counter(a_list)
    print(sum(value for key, value in c_dict.most_common()[K:]))

if __name__ == "__main__":
    main2()

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

a_list = list(map(int, input().split()))
a_set = set(a_list)
if len(a_set) <= K:
    print(0)
else:
    a_map = {}
    for a in a_list:
        if a in a_map:
            a_map[a] += 1
        else:
            a_map[a] = 1
    margin = len(a_set) - K
    a_map = sorted(a_map.items(), key=lambda x:x[1])
    count = 0
    for i in range(margin):
        count += a_map[i][1]
    print(count)

Solution (Python):
from collections import Counter
n,k =map(int, input().split())
a=list(map(int, input().split()))
count=Counter(a)
ans=0
for l,(i,j) in enumerate(count.most_common()):
    if l<k:continue
    ans+=j
print(ans)

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

Solution (Python):
import collections

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

cnt_list = []

c = collections.Counter(A)
values, counts = zip(*c.most_common())
counts = list(counts)
counts.reverse()

answer=0

if len(counts) > K:
    for i in range(len(counts)-K):
        answer += counts[i]
        
print(answer)

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

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

ball_dict = {}
uni_A = list(set(A))

if len(uni_A) <= k:
    print(0)

else:
    for uni_a in uni_A:
        ball_dict[uni_a] = 0

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

    val = sorted(ball_dict.values())

    

    print(sum(val[:-k]))

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, K = map(int, input().split())
    c = Counter(list(map(int, input().split())))
    total = len(c)
    ans = 0
    for v in sorted(c.values()):
        if total - K > 0:
            ans += v
            total -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import collections
import numpy as np
N, K =map(int,input().split())
a=list(map(int,input().split()))
c = collections.Counter(a)
c_=c.most_common()
c__=np.array(c_)
ans=0
for i in range (K,c__.shape[0]):
    ans+=c__[i][1]
print(ans)

Solution (Python):
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])



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

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

Cn = [0] * (N+1)
Uq = set()
for a in A:
  Cn[a] += 1
  Uq.add(a)

Cn.sort(reverse=True)

if len(Uq) <= K:
  print(0)
else:
  print(sum(Cn[K:]))

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

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

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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N, K = li_input()
    A = li_input()

    D = collections.defaultdict(lambda: 0)
    C = []

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

    for v in D.values():
        C.append(v)

    C.sort(reverse=True)

    print(sum(C[K:]))


main()

Solution (Python):

from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = sorted(Counter(a).values(), reverse=True)
print(sum(c[k:]))

Solution (Python):

from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = sorted(Counter(a).values())
print(sum(c[:-k]))

Solution (Python):

from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = Counter(a)
v = sorted(c.values())
print(sum(v[:-k]))

Solution (Python):
from collections import Counter

tmp = input().split(" ")
N = int(tmp[0])
K = int(tmp[1])
a = input().split(" ")

a.sort()
c = Counter(a)
m = len(c)
min = c.most_common()[::-1]
p = 0
ans = 0
while(m > K):
  ans += min[p][1]
  m -= 1
  p += 1
    
print(ans)

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

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

import itertools
import collections
cnt = collections.Counter(A)
print(sum(itertools.islice(sorted(cnt.values()), max(0, len(cnt) - K))))

Solution (Python):
import itertools
n,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
c = []
g = itertools.groupby(a)
for m,v in g:
    c.append(len(list(v)))
c = sorted(c)
print(sum(c[:-k]))

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,K = inpl()
aa = inpl()
ed = set()
dd = defaultdict(int)

for a in aa:
	ed.add(a)
	dd[a] += 1

CNTs = []
for i in ed:
	CNTs.append(dd[i])

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

print(ans)

Solution (Python):
import collections

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

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

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

Solution (Python):
import collections
from collections import OrderedDict
count=0
N,K=map(int,input().split())
ball=list(map(str,input().split()))
c=sorted(collections.Counter(ball).values())
n=len(c)-K
if n==0:
    print(count)
else:
    for i in range(n):
        count+=c[i]
    print(count)

Solution (Python):
from collections import Counter

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

cnt = Counter(A)

vl = list(cnt.values())
vl.sort(reverse=True)

if len(vl) <= K:
    print(0)
else:
    print(N-sum(vl[:K]))

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

d = {}

for i in range(N):
    d[A[i]] = 0

for i in range(N):
    d[A[i]] += 1

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

c = len(d)
ret = 0
for i in range(N):
    if c <= K:
        break
    c -= 1
    ret += dd[i][1]
print(ret)

Solution (Python):
import bisect
n,k = map(int,input().split())
a= list(map(int,input().split()))
a.sort()
c = []
d = 0

while d <= n-1:
    s = bisect.bisect_right(a,a[d])
    c.append(s-d)
    d = s
c.sort()



l = len(c)
d = c[:l-k:]



print(sum(d))

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


for j in range(K):
    list1[j]=0
    
print(sum(list1))

Solution (Python):
from collections import Counter

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

keys = [li[0] for li in A.most_common()][K:]
ans = sum(A[key] for key in keys)
print(ans)

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

a = tuple(map(int, input().split(" ")))

a_count = dict()
for a_i in a:
	if a_i not in a_count:
		a_count[a_i] = 0
	a_count[a_i] += 1

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

Solution (Python):
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)

Solution (Python):
N, K = map(int, input().split())
a = [int(x) for x in input().split()]
d = {}

for i in a :
    if i in d.keys() :
        d[i] += 1
    else :
        d[i] = 1
    
    
sb = sorted(d.items(), key = lambda x : x[1])
types = len(sb)
cnt = 0

for k in sb :
    if types > K :
        types -= 1
        cnt += k[1]
    else: 
        break
        
print(cnt)