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:
from collections import defaultdict
N, K = map(int, input().split())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

_sorted_nums = [[i] * j for i,
                j in sorted(num_freq.items(), key=lambda x:x[1])]
sorted_nums = []
for i in _sorted_nums:
    sorted_nums += i

borders = []
for i in range(1, N):
    if sorted_nums[i-1] != sorted_nums[i]:
        borders.append(i)

if len(num_freq) <= K:
    print(0)
else:
    border = borders[-K]
    print(len(sorted_nums[:border]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

N, K = map(int, input().split())
cntA = sorted(collections.Counter(list(map(int, input().split()))).items(), key=lambda x: x[1])

ans = 0
for i in range(max(0, len(cntA) - K)):
    ans += cntA[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)
print(sum(sorted(C.values())[:len(C)-K]) if len(C) > K else 0)

Submission status: Accepted

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

ball = [0]*N
count = 0
kind = 0

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

ball.sort(reverse=True)

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

print(count)

Submission status: Accepted

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

c=collections.Counter(a)
values = sorted(c.values())

ans=0
sum_values=len(values)
for i in range(len(values)):
    if sum_values<=k:
        break
    else:
        sum_values-=1
        ans+=values[i]
print(ans)

Submission status: Accepted

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

n_map = {}
for n in numbers:
    if n_map.get(n) is None:
        n_map[n] = 1
    else:
        n_map[n] += 1

sorted_map = sorted(n_map.values(), reverse=True)
max_num = sum(sorted_map)
min_num = sum(sorted_map[:K])
print(max_num - min_num)

Submission status: Accepted

Solution code:
from collections import Counter

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

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

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

print(answer)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=len(l)
        l.append(1)
ans=0
l.sort()
for i in range(len(l)-k):
    ans+=l[i]
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
d={}
l=[]
for i in range(n):
    try:
        l[d[a[i]]]+=1
    except:
        d[a[i]]=len(l)
        l.append(1)
ans=0
l.sort()
for i in range(len(l)-k):
    ans+=l[i]
print(ans)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    res = len(d)-k
    print(sum(d[:res]))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for i in li:
  d[i] += 1

newLi = []  
  
if len(d) <= K:
  print(0)
else:
  a = len(d) - K
  
  for i in d:
    newLi.append(d[i])

  newList = sorted(newLi)
  ans = 0
  
  for s in range(a):
    ans += newList[s]
  
  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)

keys, conts = zip(*A.most_common()[::-1])
ans = 0
x = len(set(a))

for cont in conts:
    if x > k:
        ans += cont
    x -= 1

print(ans)

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
B = [D[i] for i in D]
if len(B) <= K:
  print(0)
else:
  B.sort()
  print(sum(B[i] for i in range(len(B) - K)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
cnt=Counter(a)
mos=cnt.most_common()
"""print(mos)
print(mos[0][0])"""
ans=0
if len(cnt)>=k:
    for i in range(len(cnt)-k):
        ans+=mos[-i-1][1]
print(max(0,ans))

Submission status: Accepted

Solution code:

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

from collections import Counter

counter = Counter(A)
cnt = len(list(counter.keys())) - K 

if cnt <= 0:
  print(0)
  exit() 

ans = 0

C = counter.most_common()[::-1]
for i in range(cnt):
  ans += C[i][1]

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import heapq
n, k = map(int,input().split())
a = list(map(int,input().split()))
c = Counter(a)
heapc = list(c.values())
heapq.heapify(heapc)
l = len(c)
cnt = 0
if k < l:
    for _ in range(l-k):
        cnt += heapq.heappop(heapc)
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

dic = defaultdict(int)

for a in as_:
    dic[a] += 1

sorted_data = [(a, v) for a, v in dic.items()]
sorted_data = sorted(sorted_data, key=lambda d: d[1], reverse=True)

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

print(count)

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = Counter(A) 
key, value = zip(*A.most_common())
# 数が少ないものを変更する
print(sum(value[K:]))

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = Counter(A).most_common() # 降順 type=list

# 数が少ないものを変更する
cnt = A[K:]
print(sum([v for k, v in cnt]))

Submission status: Accepted

Solution code:
import sys


def solve(inp):
    (N, K) = map(int, inp.readline().split(' '))
    A = map(int, inp.readline().split(' '))

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

    values = sorted(nums.values())
    d = max(0, len(values) - K)
    s = sum(values[:d])

    return str(s)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
cost = sorted(Counter(a).values())
print(sum(cost[:max(len(cost) - k, 0)]))

Submission status: Accepted

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

def solve(N: int, K: int, A: "List[int]"):
    counter = list(Counter(A).values())
    counter.sort()

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

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import collections

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

c = collections.Counter(ls)
ls_s = c.most_common()

l = len(ls_s)
ans = 0

if l <= k:
	print(0)
else:
	for i in range(l - k):
		ans += ls_s[-1][1]
		del ls_s[-1]
	print(ans)

Submission status: Accepted

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

h = {}
for i in range(N):
    b = h.get(a[i], 0)
    h[a[i]] = b + 1

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

Submission status: Accepted

Solution code:
import collections

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

c=collections.Counter(a)

ans=0

all_balls = list(c.values())
all_balls.sort()

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

Submission status: Accepted

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

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

l = len(dct)
if l <= k:
    ans = 0
else:
    na = sorted([int(dct[key]) for key in dct])
    ans = sum(na[:l-k])

print(ans)

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()]

cou = sorted(Counter(A).items(), key=lambda x:x[1], reverse=True)
ans = [cou[i][1] for i in range(K, len(cou))]
print(sum(ans))

Submission status: Accepted

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

dic = {}
for i in A:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

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

ans = []
for i in range(K, len(dic_sort)):
    ans.append(dic_sort[i][1])

print(sum(ans))

Submission status: Accepted

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

cont=1
for i in range(n-1):
  if l[i]==l[i+1]:
    cont+=1
  else:
    ll.append(cont)
    cont=1
ll.append(l.count(l[-1]))
ll.sort()
ll.reverse()

print(sum(ll[k:]))

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    n,k=map(int,input().split())
    A=Counter(list(map(int,input().split())))
    # Aの重複元の個数を降順に並べてk番以降の和を数える.
    print(sum(sorted(A.values())[::-1][k:]))
main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, K = LI()
    A = LI()
    freq = collections.defaultdict(int)
    num = [0] * (N+1)
    for a in A:
        num[a] += 1
    num = sorted(num)[::-1]
    print(sum(num[K:]))

main()

Submission status: Accepted

Solution code:
import collections


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

if (k>=len(C)):
    ans = 0
else:
    ans = 0
    nums = sorted(C.values(),reverse=True)
    for i in range(k,len(nums)):
        ans += nums[i]
print(ans)

Submission status: Accepted

Solution code:
N_K = [int(i) for i in input().split()]

N = N_K[0]
K = N_K[1]

num_list = [int(i) for i in input().split()]
num_list.sort()

nums = [0] * (200001)

for i in range(0, N):
    nums[num_list[i]] += 1

nums.sort(reverse = True)

print(N - sum(nums[:K]))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
import collections
if K>=len(set(A)):
    print(0)
else:
    variety=len(set(A))
    c=collections.Counter(A)
    values, counts = zip(*c.most_common())
    counts=list(counts)
    counts.sort()
    summary=0
    for i in range(variety-K):
        summary+=counts[i]
    print(summary)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, k, *a = map(int, sys.stdin.read().split())

def main():
    c = Counter(a)
    l = len(c)
    if l <= k:
        return 0

    c = sorted(c.items(), key=lambda x: x[1])
    res = 0
    for i in range(l - k):
        res += c[i][1]

    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
B = [0]*200010

for i in A:
    B[i] += 1
B.sort(reverse = True)

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

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*200001
C=[]
p=0
for i in A:
  B[i]+=1
cnt=0
for i in range(N+1):
  if B[i]!=0:
    cnt+=1
    C.append(B[i])
C.sort()
if K>=cnt:
  print(0)
else:
  j=0
  while K<cnt:
    p=p+C[j]
    cnt=cnt-1
    j=j+1
  print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
import collections
c = collections.Counter(A)
d = sorted(c.values(), reverse=True)
ans = 0
while len(d) > K:
    ans += d.pop()
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import collections
N,K=map(int,input().split())
A=list(map(int,input().split()))
m=len(set(A))
ans=0
if K>=m:
    print(0)
else:
    c = collections.Counter(A)
    c_=c.most_common()
    for i in range(m-K):
        ans+=c_[m-1-i][1]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
n,k = map(int, input().split())
A = list(map(int, input().split()))
D = dict()
for a in A:
    if a in D:
        D[a] += 1
    else:
        D[a] = 1
D = sorted(D.items(), key=lambda x: x[1])
D = D[:len(D)-k]
total = sum([d[1] for d in D])
print(total)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
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:]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

A.sort()
num = len(list(set(A)))
c = [0] * A[-1]
for a in A:
    c[a - 1] += 1
c.sort()
ans = 0
if num > K:
    i = 0
    diff = 0
    while diff != num - K:
        if c[i] != 0:
            ans += c[i]
            i += 1
            diff += 1
        else:
            i += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

l = {}
for a in n:
    l[a] = l.get(a, 0) + 1
print(sum(sorted(l.values())[:-b]))

Submission status: Accepted

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

if len(set(balls)) <= k:
  print(0)
  exit(0)

import collections
c = collections.Counter(balls)
c = c.most_common()[::-1]

kc = len(c)
total = 0
for num, count in c:
  kc -= 1
  total += count
  if kc == k:
    print(total)
    exit(0)

print(0)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
cnt = [0] * (200000)
for i in range(n):
    cnt[a[i] - 1] += 1
cnt.sort(reverse=True)
kinds = 200000 - cnt.count(0)
if kinds <= k:
    print(0)
else:
    for i in range(kinds - k):
        ans += cnt[kinds - 1 - i]
    print(ans)

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = {}
for a in A:
  l[a] = l.get(a, 0) + 1
print(sum(sorted(l.values())[:-K]))

Submission status: Accepted

Solution code:
import collections
n,k = map(int,input().split())
line = list(input().split())
c = collections.Counter(line)
answer = 0
if k > len(c):
  answer = 0
else:
  gap = len(c) - k
  sorted_c = list(sorted(c.items(),key = lambda x:x[1]))
  for i in range(gap):
    answer += int(sorted_c[i][1])
print(answer)

Submission status: Accepted

Solution code:

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

b = [0] * N

for i in range(N):
    b[a[i]-1] += 1

b.sort(reverse = True)

count = 0
for i in range(K):
    count += b[i]

print(N-count)

Submission status: Accepted

Solution code:
import collections
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = collections.Counter(a)
v = list(d.values())
v = sorted(v)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=Counter(a)
als=list(c.values())
if len(als)<=m:
  print(0)
else:
  als.sort(reverse=True)
  print(sum(als[m:]))

Submission status: Accepted

Solution code:
import collections

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

B = collections.Counter(A)
V = []

for key, val in B.items():
    V.append(val)

V = sorted(V, reverse=True)

if len(V) <= k:
    ans = 0
else:
    ans = sum(V[k:])
print(ans)

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
key = a[0]
a_syurui = []
count = 1
for i in a[1:]:
    if key == i:
        count += 1
    else:
        a_syurui.append(count)
        count = 1
        key = i
a_syurui.append(count)
a_syurui.sort()
if len(a_syurui) <= k:
    print(0)
else:
    for i in range(len(a_syurui)-k):
        ans += a_syurui[i]
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
L=Counter(A).most_common()
sum_=0
for _,j in L[K:]:
    sum_+=j
print(sum_)

Submission status: Accepted

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

#print(N, K, A)
A2 = [0] * N
for i in range(len(A)):
    A2[A[i]-1] += 1

A2.sort(reverse = True)
#print(A2)
count = 0
for i in range(K):
    count += A2[i]
print(N - count)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

n,k=map(int,input().split())
A=list(map(int,input().split()))
c=collections.Counter(A)
s=sorted(c.values())
for i in range(max(0,len(s)-k)):
    # print(i)
    count+=s[i]
print(count)
# print(s)

Submission status: Accepted

Solution code:
from collections import Counter


def main()->None:
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(Counter(a).values(), reverse=True)
    print(sum(a[k:]))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(Counter(a).values(), reverse=True)

print(sum(a[k:]))

Submission status: Accepted

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

A_dic = dict()
for i in range(N):
    if A[i] in A_dic:
        A_dic[A[i]] += 1
    else:
        A_dic[A[i]] = 1
A_dic = sorted(A_dic.items(), key=lambda x:x[1])        

change_count = len(A_dic) - K
count = 0
for i in range(change_count):
    count += A_dic[i][1]
    

print(count)

Submission status: Accepted

Solution code:
import collections as c
import numpy as np

N,K = map(int,input().split()) 
A = list(map(int,input().split()))
A_c = c.Counter(A)
A_c = sorted(list(A_c.values()))
KindNum = len(A_c)
if KindNum < K:
    print(0)
else:
    ans = sum(A_c[:KindNum - K])
    print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=set(a)
l=[0]*(n+1)
for i in range(n):
    l[a[i]]+=1
l=[i for i in l if i>0]
l.sort()
le=len(s)
c=0
for i in range(len(l)):
    if le<=k:
        break
    else:
        c+=l[i]
        le-=1
print(c)

Submission status: Accepted

Solution code:
import collections
N,K = map(int, input().split())
lst = list(map(int, input().split()))
c = dict(collections.Counter(lst))
sorted_c = sorted(c.items(), key=lambda x:x[1], reverse=True)
ans = 0
if (len(sorted_c) > K):
  for i in sorted_c[K:]:
    ans += i[1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
import numpy as np
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
B=collections.Counter(A)
C=sorted(list(B.values()))
if len(C)<=K:
  answer=0
else:
  answer=np.cumsum(C)[len(C)-K-1]
print(answer)

Submission status: Accepted

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

print(sum(x[1] for x in c[k:]))

Submission status: Accepted

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

def solve(N: int, K: int, A: "List[int]"):
    a_counter = collections.Counter(A)
    if len(a_counter) <= K:
        print(0)
        return 

    values = sorted(list(a_counter.values()))
    answer = 0
    for i in range(len(a_counter)-K):
        answer += values[i]
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
import collections

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

ca = collections.Counter(a)
lk = ca.most_common(k)
sk = sum([lk[i][1] for i in range(len(lk))])
print(n-sk)

Submission status: Accepted

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

from collections import defaultdict
dic = defaultdict(int)
for a in al:
    dic[a] += 1

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

a = len(l) - k

ans = 0
for i in range(max(a,0)):
    ans += l[i]

print(ans)

Submission status: Accepted

Solution code:
dbflag=0
def debug(*args):
  if dbflag: print(*args)

result = 0


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

#リスト型
A = [int(i) for i in input().split(' ')]

bag = {}

for x in A:
	if 'x'+str(x) in bag:
		bag['x'+str(x)]+=1
	else:
		bag['x'+str(x)] = 1

debug(bag)
L = sorted(bag.items(),key= lambda x:x[1])
debug(L,len(L),K)
cnt = len(L) - K

if cnt > 0:
	result = sum(y[1] for y in L[0:cnt])
	debug([y[1] for y in L[0:cnt]])
else:
	result = 0


print(result)

Submission status: Accepted

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

values = Counter(A).values()
length = len(values)
values = sorted(values)
ANS = 0

for i in range(length - K):
  ANS += values[i]
print(ANS)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(A) #要素と出現回数の辞書

List=sorted(c.values())[::-1]
#print(List)

print(sum(List[K:]))

Submission status: Accepted

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

values = Counter(A).values()
length = len(values)
values = sorted(values)
ANS = 0

for i in range(length - K):
  ANS += values[i]
print(ANS)

Submission status: Accepted

Solution code:
from collections import Counter 

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

now_k=len(set(a))
d=now_k-k
arr=Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print(sum(b[:d]))

Submission status: Accepted

Solution code:
import collections

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

now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
b=sorted([arr[i][1] for i in range(now_k)])
print(sum(b[:d]))

Submission status: Accepted

Solution code:
import collections

n,k=map(int,input().split())
a=list(map(int,input().split()))
now_k=len(set(a))
d=now_k-k
arr=collections.Counter(a).most_common()
#print(arr)
b=sorted([arr[i][1] for i in range(now_k)])
#print(b)
cnt=now_k
cnt2=0
flg=0
for i in b:
  cnt-=1
  cnt2+=i
  if cnt==k:
    print(cnt2)
    flg=1
    break
if flg==0:
  print(0)

Submission status: Accepted

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

print(sum(sorted(list(D.values()))[:-K]))

Submission status: Accepted

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

Submission status: Accepted

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

b = [0]*n

if len(list(set(a))) <=k:
    print(0)
else:
    for i in a:
        b[i-1]+=1
    b.sort(reverse=True)
    del b[0:k]
    print(sum(b))

Submission status: Accepted

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

c = Counter(l)

ans = 0
for k,v in c.most_common()[k:]:
    ans += v
    
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
values = list(D.values())
values.sort()
print(sum(values[:len(values)-K]))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
balls = {}
for num in A:
  if num in balls:
    balls[num] += 1
  else:
    balls[num] = 1
# print(balls)
l = list(balls.values())
l.sort()
# print(l)
answer = 0
if K < len(l):
  for i in range(0, len(l) - K):
    answer += l[i]
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
size=len(Counter(A).most_common())
if K >= size:
    print(0)
else:
    values, counts = zip(*Counter(A).most_common()[::-1])
    ans=0
    for i in range(size-K):
        ans += counts[i]
    print(ans)

Submission status: Accepted

Solution code:
import collections
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = collections.Counter(a_list)
d = b.most_common()[k:]
sum = 0
for i in d:
    sum += i[1]
print(sum)

Submission status: Accepted

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

a_values = collections.Counter(a)

o = len(a_values) - k
values, counts = zip(*a_values.most_common()[::-1])

if o <= 0:
    print(0)
else:
    print(sum(counts[:o]))