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



Sample input:
5 2
1 1 2 2 5


Sample output:
1

Submission status: Accepted

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

from collections import Counter
dic = Counter(a)

v = len(dic) #種類数

l = [i for i in dic.values()]
l.sort()

ans = 0
for i in range(v-k):
    ans += l[i]

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc081/tasks/arc086_a
# 14:07-14:14 done


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

    cnt = {}
    for a in A:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1
    
    num_cnts = [[k, v] for k, v in cnt.items()]

    # if len(num_cnts) <= K:
    #     return 0

    num_cnts = sorted(num_cnts, key=lambda x: x[1], reverse=True)
    ans = sum([cnt for num, cnt in num_cnts[K:]])

    return ans


print(main())

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc081/tasks/arc086_a
# 14:07-14:14 done


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

    cnt = {}
    for a in A:
        if a in cnt:
            cnt[a] += 1
        else:
            cnt[a] = 1
    
    num_cnts = [[k, v] for k, v in cnt.items()]

    if len(num_cnts) <= K:
        return 0

    num_cnts = sorted(num_cnts, key=lambda x: x[1], reverse=True)
    ans = sum([cnt for num, cnt in num_cnts[K:]])

    return ans


print(main())

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
list_A = list(map(int, input().split()))
l = Counter(list_A)
l = sorted(l.values())
ans = 0
if len(l) > k:
    ans += sum(l[:len(l)-k])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
c = Counter(A)
if len(c) <= K:
    print(0)
else:
    n = len(c)
    c = sorted(c.items(), key=lambda x: x[1])
    ans = 0
    cnt = 0
    for k, v in c:
        cnt += 1
        ans += v
        if cnt == n - K:
            break
    print(ans)

Submission status: Accepted

Solution code:
import collections
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
c = collections.Counter(a_list)
v_list = []
c_v = c.values()
c_v = list(c_v)
c_v.sort()
if len(c_v)<k:
  print(0)
else:
  print(sum(c_v[:len(c_v) - k]))

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
A = list(map(int, input().split()))
counter = Counter(A)
result = 0
for el in sorted(list(counter.items()), key=lambda x:x[1], reverse=True)[k:]:
    result += el[1]
print(result)

Submission status: Accepted

Solution code:
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
if len(d) <= k:
  print(0)
else:
  d = sorted(d.values())
  ans = 0
  for i in range(len(d)-k):
    ans += d[i]
  print(ans)

Submission status: Accepted

Solution code:
import collections

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

if x<=0:
  print("0")
else:
  ans=0
  for i in range(x):
    ans+=A[i][1]
  print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n,k = map(int,input().split())
c = 0
list_A = Counter(list(map(int,input().split())))
t = len(list_A.keys())-k
if t<=0:
  print(0)
else:
  B =sorted(list_A.items(),key=lambda x:x[1])
  for j in range(t):
    c += B[j][1]
  print(c)

Submission status: Accepted

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

Ad = {key:0 for key in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    count = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x:x[1])
    for i in range(len(set(A))-K):
        count += Ad[i][1]
    print(count)

Submission status: Accepted

Solution code:
n,k = list(map(int, input().split()))
lst = list(map(int, input().split()))

count = {}
for i in lst:
    if i in count.keys():
        count[i]+=1
    else:
        count[i]=1
count_sorted = sorted(count.items(), key=lambda x:x[1])
# print(count_sorted)

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, A: "List[int]"):
    ctr = Counter(A)
    print(sum(sorted(ctr.values())[:-K]))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

cnt = [0]*n
for i,p in enumerate(a):
    cnt[p-1] += 1

cnt.sort()
ans = 0
for i in range(n-k):
    ans += cnt[i]

print(ans)

Submission status: Accepted

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

a_cnt = {}
for i in a:
    if i in a_cnt:
        a_cnt[i] += 1
    else:
        a_cnt[i] = 1
from  operator import itemgetter

a_cnt = sorted(a_cnt.items(), key=itemgetter(1))

from collections import deque
cnt_list = deque([])
for i, j in a_cnt:
    cnt_list.append(j)

ans = 0
while len(cnt_list) > K:
    ans += cnt_list[0]
    cnt_list.popleft()
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
from collections import Counter
cntr = sorted(Counter(a).items(), key=lambda x: x[1], reverse=True)
#print(cntr)
ans = 0
if len(cntr) > k:
  for i in range(k, len(cntr)):
    ans += cntr[i][1]
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int,input().split())
array = list(map(int,input().split()))

box = [0]*200000

for item in array:
  box[item-1] += 1
  
box.sort(reverse=True)

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

Submission status: Accepted

Solution code:
from collections import Counter

x, y = map(int, input().split())
l = list(map(int, input().split()))
l2 = []
d = Counter(l)
l2 = list(d.values())
l2.sort(reverse=True)

print(sum(l2[y:]))

Submission status: Accepted

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

d = {i:0 for i in set(A)}
for a in A:
    d[a] += 1
ans = list(d.values())
ans.sort(reverse = True)
print(sum(ans[k:]))

Submission status: Accepted

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

if len(set(A))<=k:
    print(0)
else:
    d = {i:0 for i in set(A)}
    for a in A:
        d[a] += 1
    ans = list(d.values())
    ans.sort(reverse = True)
    print(sum(ans[k:]))

Submission status: Accepted

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

import collections
c=collections.Counter(A)
lst=c.most_common()[::-1]
val_lst=[el[1] for el in lst]
#print(val_lst)
print(sum(val_lst[:(len(lst)-K)]))

Submission status: Accepted

Solution code:
import collections
n,k = map(int,input().split())
line = list(map(int,input().split()))
num = len(set(line))
nums = collections.Counter(line)
snums = sorted(nums.values())
if num <= k:
  print(0)
else:
  require = num - k
  answer = 0
  for j in range(require):
    answer += snums[j]
  print(answer)

Submission status: Accepted

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

from collections import Counter
print(sum(sorted(list(dict(Counter(a)).values()))[:-k]))

Submission status: Accepted

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

num = collections.defaultdict(int)

for elem in a:
    num[elem] += 1

count = 0
if len(num) <= k:
    print(count)
else:
    # sort使う発想なかった(出現頻度の昇順にソート)
    sorted_num = sorted(num.items(), key=lambda x:x[1])
    # 減らさなければいけない種類数だけ繰り返す
    for i in range(len(num) - k):
        # 出現頻度の少ない数から順に，その頻度を加えていく
	    count += sorted_num[i][1]

    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

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

    AA = Counter(A).most_common()

    num=len(AA)-K
    ans=0
    for i in range(1,num+1):
        ans+=AA[-i][1]
    print(ans)

resolve()

Submission status: Accepted

Solution code:
import collections

n,k = map(int,input().split())
s = list(map(int,input().split()))
c = collections.Counter(s)
tap = c.most_common()

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from collections import Counter


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

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

    result = 0
    for i in range(max(0, len(A) - K)):
        result += A[i][1]

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import Counter


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

C = Counter(A)
V = list(C.values())
V.sort()
ans = sum(V[:len(V) - K])

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n,k,*a=map(int,open(0).read().split())
l=Counter(a).most_common()
ans=0
for i in l[k:]:
  ans+=i[1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

ball = []
for k, v in C.items():
    ball.append([v, k])
ball.sort(key=lambda x: -x[0])

ans = 0
for i in range(len(ball)):
    if i>=K:
        ans += ball[i][0]

print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
cc=Counter(a)
l=[]
for i in cc:
    l.append([cc[i],i])
l.sort(key=lambda x: -x[0] )
#print(l)
su=0
for i in range(min(k,len(l))):
    su+=l[i][0]
print(n-su)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
def groupby():
    global a
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby()
b.sort(key=lambda x:x[1],reverse=True)
l=len(b)
ans=0
for i in range(k,l):
    ans+=b[i][1]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = Counter(A)
values, counts = zip(*A.most_common())
counts = list(counts)
ans = 0

while K < len(counts):
  ans += counts[-1]
  counts.pop(-1)

print(ans)

Submission status: Accepted

Solution code:
N,K=map(int, input().split())
int_dict={}
for a in map(int, input().split()):
	int_dict.setdefault(a,0)
	int_dict[a]+=1
diff=len(int_dict) - K
if diff <= 0:
	print("0")
else:
	print(sum(sorted(int_dict.values())[:diff]))

Submission status: Accepted

Solution code:
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(len(C)):
    if i >= K:
        ans += C[i][1]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    counter = Counter(A)
    sorted_cnter = sorted(list(counter.items()), key=lambda x: x[1])
    will_rewrite = sorted_cnter[:-K]

    ans = 0
    for t in will_rewrite:
        ans += t[1]
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:

S = input().split(" ")
N = int(S[0])
K = int(S[1])
ARR = [int(s) for s in input().split(" ")]

def calculate(n, k, arr):
    dict = {}

    for ar in arr:
        if dict.get(ar) == None:
            dict.__setitem__(ar,1)
        else:
            tmp = dict.get(ar)
            tmp = tmp + 1
            dict.__setitem__(ar,tmp)

    sortedDict = sorted(dict.items(),key=lambda k:-k[1])


    sum = 0
    for i in sortedDict[k:]:
        sum = sum + i[1]


    print(sum)


calculate(N, K, ARR)

Submission status: Accepted

Solution code:
from collections import Counter
N,K=map(int,input().split(' '))
A=(Counter(list(map(int,input().split(' ')))))
A=sorted(A.items(),key=lambda x:x[1])
ans = 0
if len(A)>K:
    for i in A[:len(A)-K]:
        ans += i[1]
print(ans)

Submission status: Accepted

Solution code:
import collections

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

number = len(set(A))

c = collections.Counter(A)
values,counts=zip(*c.most_common())
count = 0
for i in range(number):
    if number <= K:
        print(count)
        break
    count += counts[-(i+1)]
    number -= 1

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
Ad = {a:0 for a in set(A)}
if len(set(A)) <= K:
    print(0)
else:
    cnt = 0
    for a in A:
        Ad[a] += 1
    Ad = sorted(Ad.items(), key=lambda x: x[1])
    for i in range(len(set(A))-K):
        cnt += Ad[i][1]
    print(cnt)

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    n, k = MI()
    a_list = MI()

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

    for l in c.most_common()[k:]:
        sum += l[1]
    print(sum)
    pass


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(l)
ans = 0
if K >= len(c):
    pass
elif len(c) > K:
    p = [s[1] for s in c.most_common()[::-1][:(len(c)-K)]]
    ans = sum(p)
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N,K = map(int,input().split())
A = sorted(Counter(map(int, input().split())).items(), key=lambda x:x[1], reverse=False)
s = len(A) - K
c = 0
if s > 0:
    for i in range(s):
        c += A[i][1]
print(c)

Submission status: Accepted

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

a.sort()

s=[]
ai=a[0]
acnt=-1
for i in range(n):
    if a[i]>ai:
        s.append([acnt+1,ai])
        acnt=0
        ai=a[i]
    else:
        acnt=acnt+1
s.append([acnt+1,ai])
        

if len(s)<=k:
    print(0)
else:
    s.sort()
#    print(s)
    ssum=0
    for i in range(len(s)-k):
        ssum=ssum+s[i][0]
    print(ssum)

Submission status: Accepted

Solution code:
n,k,*l=map(int,open(0).read().split());from collections import*;print(sum(sorted(Counter(l).values())[:-k]))

Submission status: Accepted

Solution code:
from collections import*;f=lambda:map(int,input().split());_,k=f();print(sum(sorted(Counter(f()).values())[:-k]))

Submission status: Accepted

Solution code:
from collections import *
f=lambda:map(int,input().split())
_,k=f()
c=Counter(f())
print(sum(sorted(c.values())[~k::-1]))

Submission status: Accepted

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

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

if len(d.keys()) <= k:
    print(0)
else:
    a = list(d.values())
    b = sorted(d.values())[-k:]
    for i in b:
        if i in a:
            a.remove(i)
    print(sum(a))

Submission status: Accepted

Solution code:
import sys

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

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

num_flag = [0 for i in range(n)]

for item in a:
    num_flag[item - 1] += 1

# while 0 in num_flag:
#     num_flag.remove(0)

# num_flag.sort()

# cnt = 0
# while len(num_flag) > k:
#     print(len(num_flag))
#     cnt += num_flag[0]
#     num_flag.pop(0)

num_flag.sort(reverse=True)

cnt = 0
for i in range(k):
    cnt += num_flag[i]

print("{}".format(n - cnt))

Submission status: Accepted

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=Counter(a).most_common()
ans=0
idx=1
m=len(c)
while m>k:
  m-=1
  ans+=c[-idx][1]
  idx+=1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def solve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    counter = defaultdict(int)
    for ai in A:
        counter[ai] += 1
    
    sorted_c = sorted(counter.values())
    ans = 0
    for i in range(len(counter) - K):
        ans += sorted_c[i]
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(a).most_common()[::-1]
res = 0
for i in range(len(c)-k):
    res += c[i][1]

print(res)

Submission status: Accepted

Solution code:
from collections import Counter

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

rep_n = len(A)-k

if rep_n<=0:
  print(0)
else:
  ans = 0
  for k, v in A.most_common()[::-1]:
    ans += v
    rep_n -= 1
    if rep_n==0:
      break
  print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

d = defaultdict(int)
for i in range(N):
  d[A[i]] += 1
  
cnt = len(d.keys()) - K
d = sorted(d.items(), key=lambda x:x[1])
ans = 0
for val in d:
  if cnt <= 0:
    print(ans)
    exit()
  ans += val[1]
  cnt -= 1

Submission status: Accepted

Solution code:
from collections import Counter
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
ans2=0
A1=Counter(A)
A2=A1.most_common()
for i in range(K,len(A1)):
    ans2+=A2[i][1]
print(ans2)

Submission status: Accepted

Solution code:
from collections import Counter

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

c = Counter(balls)

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

Submission status: Accepted

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

t = list(map(int,input().split()))
c = collections.Counter(t)
score_sorted = sorted(c.items(), key=lambda x:-x[1])
count = 0
memo = 0
for i,j in score_sorted:
    memo += j
    count += 1
    if count == k:
        break
print(n-memo)

Submission status: Accepted

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

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

ans = 0
i = 0 
for _,v in C:
  if len(C)-K <= i:
    break
  ans += v
  i += 1
print(ans)

Submission status: Accepted

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

s=len(set(l))

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

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

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = sorted(list(map(str,input().split())))
def runlength(S):
    ans = []
    for s in S:
        if len(ans) == 0 or ans[-1][0] != s:
            ans.append([s,1])
        else:
            ans[-1][1] += 1
    return ans
a = runlength(a)
a.sort(key = lambda x:x[1],reverse = True)
b = a[k:]
ans = 0
for i in range(len(b)):
  ans += b[i][1]
print(ans)

Submission status: Accepted

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

A = Counter(a)

if len(A.keys()) <= k:
    print(0)
else:
    lst = A.most_common()
    cnt = 0
    for i in range(k, len(lst)):
        cnt += lst[i][1]
    print(cnt)

Submission status: Accepted

Solution code:
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
count = 1
chk = []
p = 1
if n == 1:
  print(0)
  exit()
else:
  for i in range(n-1):
    if a[i] != a[i+1]:
      count += 1
      chk.append(p)
      p = 1
    else:
      p += 1
  if a[-1] == a[-2]:
    chk.append(p)
  else:
    chk.append(1)
  chk.sort()
  #print(chk)
  #print(count)
  if count <= k:
    print(0)
    exit()
  else:
    print(sum(chk[:count-k]))
    exit()

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=input().split()
balls=[int(a) for a in A]
answers=[0]*200000
for a in balls:
    answers[a-1]+=1
list=[a for a in answers if a!=0]
newlist=sorted(list)
n=len(newlist)-K
answer=0
for a in range(n):
    answer+=newlist[a]
print(answer)

Submission status: Accepted

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

counter = collections.Counter(A)
counter = sorted( list(counter.items()), key= lambda x: x[1])

print(sum( [i[1] for i in counter[:-K]]))

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = list(map(int,input().split()))
B = set(A)
C = Counter(A).most_common()[::-1]
pre_color = len(B)
ans = 0
if pre_color <= K:
    print(0)
    exit()
else:
    dec = pre_color - K
    for i in range(dec):
        ans += C[i][1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
d=Counter(a)
g=len(d)
cnt=0
d=sorted(d.items(),key=lambda x:x[1])
for i , j in d:
    if g<=k:
        print(cnt)
        break
    else:
        g-=1
        cnt+=j

Submission status: Accepted

Solution code:
#081_C
from collections import Counter
n,k=map(int,input().split())
a=Counter(input().split())

if len(a)<=k:
    print(0)
else:
    c=a.most_common()[::-1]
    print(sum([c[i][1] for i in range(len(a)-k)]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter

def main():
    N,K = map(int,input().split())
    array = list(map(int,input().split()))
    cnt = 0
    diff = 0

    #array.sort()
    CUNT = Counter(array)
    #print(CUNT)

    array = sorted(CUNT.values(),reverse=True)
    #print(array)

    ans = sum(array[K:])
    print(ans)

main()

Submission status: Accepted

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

import collections

count = collections.Counter(a_L)
c = count.most_common()

if len(set(a_L)) >= k:
    print(0)
    exit()

ans = 0
tmp = 0

for _,v in c:
    if tmp >= k:
        ans += v
    tmp += 1


print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
bucket = {}
for ai in A:
    if bucket.get(ai) == None:
        bucket[ai] = 1
    else:
        bucket[ai] += 1
if len(bucket) <= K:
    print(0)
else:
    bucket_sorted = sorted(bucket.items(), key=lambda x:x[1], reverse=True)
    ans = 0
    for k, v in bucket_sorted[K:]:
        ans += v
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[]
c=Counter(A)
value=list(c.values())
key=list(c.keys())
count=0
for i in range(len(key)):
    l.append([key[i],value[i]])
l.sort(key=lambda x:x[1])
#print(l)
for i in range(len(key)-K):
    count=count+l[i][1]
print(count)

Submission status: Accepted

Solution code:
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])
ans = 0
for i in range(len(B)-k):
    ans += B[i][1]
print(ans)

Submission status: Accepted

Solution code:
import collections
n, k = map(int, input().split())
d = collections.defaultdict(int)
b = map(int, input().split())
for e in b:
    d[e] += 1
ret = 0
a = sorted([v for v in d.values()], reverse = True)
while len(a) > k:
    ret  += a.pop()
print(ret)

Submission status: Accepted

Solution code:
from collections import Counter

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

aa = Counter(a)
ans = 0

if len(aa) > k:
	value = sorted(aa.values())
	ans = sum(value[:len(aa)-k])

print(ans)

Submission status: Accepted

Solution code:
import collections
N,K = map(int,input().split())
d = collections.defaultdict(int)
b = map(int,input().split())
for e in b:
  d[e]+=1
ret = 0
a = sorted([v for v in d.values()],reverse=True)
while len(a) > K:
  ret += a.pop()
print(ret)

Submission status: Accepted

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
#print(N, K)
#print(A)

A_dict = {}
for a in A:
  if a not in A_dict:
    A_dict[a] = 0
  A_dict[a] += 1

sorted_A = sorted(A_dict.items(), key=lambda x:x[1])
#print(sorted_A)

num_A = len(sorted_A)

cnt=0

for item in sorted_A:
  if num_A > K:
    cnt += item[1]
    num_A -= 1
  else:
    break
print(cnt)

Submission status: Accepted

Solution code:
import collections

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

list_a = list(collections.Counter(a).values())
dic = dict(zip(collections.Counter(a), list_a))
dic_sorted = sorted(dic.items(), key=lambda x: x[1])
del_num = dic_sorted[:len(dic_sorted)-k]

for i in del_num:
    ans += i[1]

print(ans)

Submission status: Accepted

Solution code:
import collections
def main():
  N, K = map(int, input().split())
  A =list(map(int, input().split()))
  LA = list(collections.Counter(A).values())
  LA.sort(reverse = True)
  Ans = N-sum(LA[0:K])
  if Ans > 0:
    print(Ans)
  else:
    print(0)

main()

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = [int(x) for x in input().split(" ")]
lst = [int(x) for x in input().split(" ")]

dic= {}
cnt = 0 
swap = 0
prep = len(set(lst))-K

for i in range(1,N+1):
	dic["{}".format(i)] = 0

for i in range(0,N):
	dic["{}".format(lst[i])] += 1

sorted_dic = sorted(dic.items(), key = lambda x : x[1])
    
for i in range(0,N):
  swap += sorted_dic[i][1]
  if sorted_dic[i][1] != 0:
    cnt +=1
  if cnt >= prep:
    break
      
print(swap)

Submission status: Accepted

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

Asort = sorted(A)

from collections import Counter
c = Counter(A)
keys, values = zip(*c.most_common())

ans = 0
N = len(keys)

for i in range(K,N):
    ans += values[i]
    
print(ans)

Submission status: Accepted

Solution code:
import collections

n, k = map(int, input().split())
values = list(map(int, input().split()))
obj, cnt = zip(*collections.Counter(values).most_common()[::-1])
cnt = list(cnt)
diff = max(0, len(cnt) - k)
ans = sum(cnt[:diff])
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = list(Counter(a).items())
count.sort(key=lambda x:x[1])

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

Submission status: Accepted

Solution code:
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
a_cnt = collections.Counter(a).most_common()[::-1]
ans = 0
n = len(list(set(a)))
if n <= k:
    print(0)
    exit()
for v in range(n):
    ans += a_cnt[v][1]
    n -= 1
    if n <= k:
        print(ans)
        exit()

Submission status: Accepted

Solution code:
def NotsoDiverse(n , k , al):

    lis = [0]*(n + 1)

    for i in range(n):
        lis[al[i]] += 1

    lis.sort(reverse=True)

    ans = sum(lis[k:])
    return ans

def main():
    n , k = map(int , input().split())
    al = list(map(int , input().split()))
    print(NotsoDiverse(n , k , al))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, k = [int(e) for e in input().split()]
a = list(map(str, input().split()))
elem_dict = {}
ans = 0
for i in a:
    if i not in elem_dict:
        elem_dict[i] = 1
    else:
        elem_dict[i] += 1
elem_sorted = sorted(elem_dict.items(), key=lambda x:x[1])
for i in range(len(elem_sorted)-k):
    ans = ans + elem_sorted[i][1]
print(ans)