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 = list(map(int,input().split()))
C = {}
for i in range(N):
    if A[i] not in C:
        C[A[i]] = 0
    C[A[i]] += 1
C = sorted(list(C.items()),key=lambda x:x[1],reverse=True)
n = len(C)
if n<=K:
    cnt = 0
else:
    cnt = 0
    for i in range(K,n):
        cnt += C[i][1]
print(cnt)

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 a in A:
    d[a] += 1

kinds = len(d)
d = sorted(d.items(), key=lambda x: x[1])
ans = 0

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

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()]
ans = dict(Counter(a))
n = len(ans)
ans = list(ans.values())
ans = sorted(ans)
print(sum(ans[:n-k]))

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
*A, = map(int, input().split())
# n, k = 10, 3
# A = [5, 1, 3, 2, 4, 1, 1, 2, 3, 4]
# n, k = 4, 4
# A = [1, 1, 2, 2]
D = {}
for a in A:
    try:
        D[a] += 1
    except:
        D[a] = 1
D = sorted(D.values())
print(sum(D[:len(D)-k]))

Submission status: Accepted

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

Submission status: Accepted

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

import collections

C = collections.Counter(A).most_common()


# print(C)

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

n, k, *a = map(int, read().split())
counter = sorted(Counter(a).values())
ans = 0
for i in range(len(counter) - k):
    ans += counter[i]
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)

ans = 0
balls = []
for i in c.items():
    balls.append(i)

balls.sort(key= lambda x:x[1], reverse=True)
cnt = 0
for i in range(len(balls)):
    cnt += 1
    if cnt <= k:
        continue
    else:
        ans += balls[i][1]

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    v = sorted(c.values())
    ans = 0
    if len(c.keys()) <= K:
        pass
    else:
        ans += sum(v[:len(v) - K])
    print(ans)


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()))
c = Counter(A).most_common()[::-1]

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

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).most_common()


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
from collections import Counter
ctr = Counter(A)
if len(ctr) <= K:
    print(0)
    exit()

l = len(ctr) - K
ans = sum(sorted(ctr.values())[:l])
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/arc086/tasks/arc086_a
N, K = read_ints()
A = read_ints()
# 個数をカウント ソート、sum
cnt = Counter(A)
v = sorted(cnt.values(), reverse=True)
if len(v) <= K:
    print(0)
else:
    print(N - sum(v[:K]))

Submission status: Accepted

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

from collections import Counter, OrderedDict

a=Counter(a)

if len(a) <= k:
    print(0)
else:
    b = sorted(a.items(), key=lambda pair: pair[1], reverse=True)
    
    ans = 0
    
    for i in b[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()))

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

if len(c) <= k:
    print(0)
    exit()

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

Submission status: Accepted

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

numbers = [0] * max(N,max(A))
for i in range(N):
    numbers[A[i]-1] += 1

numbers.sort(reverse=True)

ans = 0
for i in range(N):
    if numbers[i] == 0:
        break
    if i > K-1:
        ans += numbers[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)
p = c.most_common()
s = len(p)
if s <= k:
    print(0)
    exit()

ans = 0
for i in range(s-k):
    ans += p[-(i+1)][1]

print(ans)

Submission status: Accepted

Solution code:
import collections
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
acnt = collections.Counter(a)
acnt = sorted(acnt.items(), key=lambda x: x[1])
ans = 0
al = len(acnt)
for i in acnt:
    if al<=k:
        break
    al -= 1
    ans += i[1]

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
k = [[0,i] for i in range(1,N+1)]
for i in range(N):
  k[A[i]-1][0] += 1
B = set(A)
C = list(B)
k.sort()
if len(C) <= K:
  print(0)
else:
  now = len(C)-K
  ans = 0
  for i in range(len(k)):
    if k[i][0] == 0:
      continue
    else:
      now -= 1
      ans += k[i][0]
      if now == 0:
        print(ans)
        break

Submission status: Accepted

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

Submission status: Accepted

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

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

d = len(cnt) - K
ans = sum(list(sorted(cnt.values()))[:d])
print(ans)

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
A = inputlist()
from collections import Counter
c = Counter(A)
val = list(c.values())
val.sort()
if len(val)<= K:
    print(0)
    exit()
ans = 0
for i in range(len(val)-K):
    ans += val[i]
print(ans)

Submission status: Accepted

Solution code:
from time import time

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    a = [0 for i in range(N)]
    for i in A:
        a[i-1] += 1

    a.sort(reverse=True)
    a = a[K:]
    print(sum(a))

if __name__ == '__main__':
    start = time()
    main()
    # print(time() - start)

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()
C.sort(key=lambda x:x[1])
if len(C)<=K:print(0)
else:
    ans = 0
    for i in range(len(C)-K):
        ans += C[i][1]
    print(ans)

Submission status: Accepted

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

a.sort()
count = []
c = 1
for i in range(n-1):
    if a[i] != a[i+1]:
        count.append(c)
        c = 1
    else:
        c += 1
    if i == n - 2:
        count.append(c)

l = len(count)
#print(a)
#print(count)
c = 0
if l <= k:
    print(0)
else:
    count.sort()
    for i in range(l):
        l -= 1
        c += count[i]
        if l <= k:
            print(c)
            quit()

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

V = sorted(C.values())
# print(V)
print(sum(V[:-K]))

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 key in A:
    d[key] += 1
ans = 0
for key, i in sorted(d.items(), key = lambda x:x[1])[:-K]:
    ans += 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()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)

Submission status: Accepted

Solution code:

from collections import Counter
n,k=map(int,input().split())
a=[int(i) for i in input().split()]

c=Counter(a).most_common()
c.sort(key=lambda x: x[1])
#print(c)
l=len(c)
print(sum(c[i][1] for i in range(l-k)))

Submission status: Accepted

Solution code:
from collections import Counter

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

ans = 0
if k < len(cnt):
  for k, v in cnt[:len(cnt) - k]:
    ans += v

print(ans)

Submission status: Accepted

Solution code:
import collections

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

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

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

Submission status: Accepted

Solution code:
import collections

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

if len(a)<=k:
    print("0")
    exit()

for i in range(k):
    ans+=a[i][1]

print(n-ans)

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
INF = 10**10+5
#入力
n,k = map(int,input().split())
a = list(map(int,input().split()))
#解答
maxa = max(a)
num = [0]*(maxa)
for i in range(len(a)):
    num[a[i]-1]+=1
cnt = len(set(a))
ans = 0

if cnt<k:
    print(ans)
else:
    for i in range(len(num)):
        if num[i] == 0:
            num[i] = INF
    num.sort()

    i = 0
    while True:
        if cnt == k:
            break
        ans += num[i]
        i+=1
        cnt -= 1

    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(n):
  cnt_dic[a[i]]+=1
v=len(cnt_dic.keys())
cnt_dic=sorted(cnt_dic.values())
if v<=k:
  print(0)
else:
  print(sum(cnt_dic[0:v-k]))

Submission status: Accepted

Solution code:
from collections import Counter
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
counts = dict(Counter(a))
counts = list(counts.values())
counts.sort()
count = 0

dev = len(counts)-k
for i in range(dev):
    count += counts[i]
        
print(count)

Submission status: Accepted

Solution code:
def main():
    from collections import Counter
    n, k, *a = map(int, open(0).read().split())
    b = Counter(a)
    l = len(b)
    if l <= k:
        ans = 0
    else:
        cnt = list(b.values())
        cnt.sort()
        ans = sum(cnt[:(l-k)])
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
suc = 1
suc_list = []
for i in range(N-1):
    if A[i] == A[i+1]:
        suc += 1
    else:
        suc_list.append(suc)
        suc = 1
suc_list.append(suc)

suc_list.sort()

kind = len(suc_list) - K

ans = sum(suc_list[0:kind])
print(ans)

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
get_string = lambda: sys.stdin.readline().strip()
get_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
get_int = lambda: int(sys.stdin.readline())

#----------------------------------------------------------------------#

n,k=get_list()
a=get_list()
freq_dict=Counter(a)
if len(freq_dict)<=k:
    print(0)
else:
    freq=[]
    for key in freq_dict:
        freq.append(freq_dict[key])
    freq.sort()
    ans=0
    for i in range(len(freq_dict)-k):
        ans+=freq[i]
    print(ans)

Submission status: Accepted

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

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

cnt = 0
numbers = []
for k in d.keys():
    cnt += 1
    numbers.append(d[k])
numbers.sort()
i = 0
ans = 0
while cnt > K:
    ans += numbers[i]
    cnt -= 1
    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()))

cnt=Counter(a)
cnt_len=len(cnt)
cnt=sorted(list(cnt.values()))
ans=0
if cnt_len<k:
    print(0)
    exit()
for i in range(cnt_len-k):
    ans+=cnt[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*(n+1)
for i in range(n):
    x[a[i]]+=1
y=[]
for i in range(n+1):
    if x[i]>0: y.append(x[i])
y.sort()
print(sum(y[:-k]) if len(y)>k else 0)

Submission status: Accepted

Solution code:
import collections

n, k, *a = map(int, open(0).read().split())
c = collections.Counter(a)
print(n-sum([d[1]  for d in c.most_common()[:k]]))

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()
if len(C)<=K:
    print(0)
else:
    ans = 0
    for c in C[:K]:
        ans+=c[1]
    print(N-ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
l = list(map(int, input().split()))
c = Counter(l)
ans = len(l)
l2 = c.most_common(k)
for i in l2:
  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)

#ある数の個数が少ないものから順に数字を書き換えればよい
sort_by_nums = sorted(c.items(), key=lambda x: x[1])

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n, k, *A = map(int, open(0).read().split())
counter = Counter(A).most_common(n)
if len(counter) <= k:
    print(0)
else:
    print(sum(v for k, v in counter[k:]))

Submission status: Accepted

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

if n <= k:
    print(0)
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)

Submission status: Accepted

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

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

if n <= k:
    print(0)
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        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()))
d = Counter(A)

ls = sorted(d.values())
ans = 0
for v in ls[:len(ls)-k]:
    ans += v
print(ans)

Submission status: Accepted

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


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



ls = sorted(d.values())
ans = 0
for v in ls[:len(ls)-k]:
    ans += v
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
array = {}
ans = 0

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

array = sorted(array.values())

if len(set(A)) > k:
    num = len(array) - k
    for i in range(num):
        ans += array[i]

print(ans)

Submission status: Accepted

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

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

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        try:
            ans -= kv[i][1]
        except:
            pass
    print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
from collections import Counter as co
var=co(l).most_common()
en=len(var)
ans=0
while en>k :
    ans+=var[en-1][1]
    en-=1
print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
datas = {}
for i in l:
    if i in datas:
        datas[i] += 1
    else:
        datas[i] = 1

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

Submission status: Accepted

Solution code:
def main():
  n, k = input_list()
  a = list(input_list())
  kind = len(set(a[:]))
  if kind <= k:
    print(0)
    exit()
  need = kind - k
  ac = collections.Counter(list(a))
  ans = 0
  for v in sorted(ac.items(), key=lambda x: x[1]):
    if need == 0:
      break
    ans += v[1]
    need -= 1
  print(ans)
  
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

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

print(sum(a[:len(a) - K]))

Submission status: Accepted

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

A = [0] * n

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

for i in B:
    A[i-1] += 1

A = sorted(A)

t = 0
print(sum(A[:-k]))

Submission status: Accepted

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

a.sort()

ax = []
d = 0
for i in a:
    if(d != i):
        ax.append(1)
        d = i
    else:
        ax[-1] += 1

ax.sort()
#print(ax)

print(sum(ax[0:len(ax)-k]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cnt = []
tmp = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        tmp += 1
    else:
        cnt.append(tmp)
        tmp = 1
cnt.append(tmp)
#最終の時も必ず追加する

cnt.sort()
if len(cnt) > k:
    ans = sum(cnt[-k:])
else: ans = n
print(n-ans)

Submission status: Accepted

Solution code:
from collections import Counter
n,k = map(int,input().split())
L = list( map(int,input().split()))
l = len(L)
L = Counter(L)
L = sorted(list(L.most_common(k)))

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
X = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
for x in X:
    d[x] += 1

l = sorted(list(d.values()))
print(sum(l[:max(0, len(l)-K)]))

Submission status: Accepted

Solution code:
from collections import Counter
n,k = map(int,input().split())
L = list( map(int,input().split()))
l = len(L)
L = Counter(L)
L = sorted(list(L.most_common(k)))

ans = 0
for i in range(len(L)):
    ans += L[i][1]
if l >= ans:
    print(l - ans)
else:
    print(0)

Submission status: Accepted

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

l = collections.Counter(a)
x = l.most_common(k)

for i in range(len(x)):
    t += x[i][1]

ans -= t
if ans < 0:
    ans = 0
print(ans)

Submission status: Accepted

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

list.sort(a)#小さい順に並び替える
    
count=1#各数字が何回出てくるか
size=0#何種類の数字が出てくるか
b=[]#各数字が何回出てきたかを入れる箱
for p in range (N-1):
  if a[p]==a[p+1]:
    count+=1
  else:
    b.append(count)
    count=1
    size+=1

b.append(count)
size+=1
  
list.sort(b,reverse=True)#大きい順に並び替える

s=0
if K<size:
  for u in range (K):
    s+=b[u]#大きい方からK個分の個数の合計
else:
  s=N#出てくる数の個数が少なければ変える必要はない
print(N-s)

Submission status: Accepted

Solution code:
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
d = {}
for a_i in a:
    if a_i not in d.keys():
        d[a_i] = 0
    d[a_i] += 1
d = list(sorted(d.items(), key=lambda x:x[1])[::-1])
if len(d) <= k: print(0)
else: print(sum([v[1] for v in d[k:]]))

Submission status: Accepted

Solution code:
import collections

N,K = map(int,input().split())
A = list(map(int,input().split()))
type = len(set(A))
con = 0

if K >= type:
  print(0)
  
else:
  C = collections.Counter(A)
  C = C.most_common()
  
  for i in range(1,type - K + 1):
    con += C[-i][1]
  
  print(con)

Submission status: Accepted

Solution code:
from collections import Counter
n, k = map(int, input().split())
A = list(map(int, input().split()))
cA = sorted(Counter(A).values())
dk = len(set(A))-k
r = 0
for i in range(n):
    if dk<1:
        break
    else:
        dk -= 1
        r += cA[i]
print(r)

Submission status: Accepted

Solution code:
from collections import Counter

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

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, k = map(int, input().split())
    As = list(map(int, input().split()))

    dic = defaultdict(int)
    for i in range(n):
        dic[As[i]] += 1
    
    ls = sorted(dic.values())
    
    if len(ls) <= k:
        print(0)
        return
    
    cnt = 0
    for i in range(len(ls) - k):
        cnt += ls[i]
    
    print(cnt)

            

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
"""
#solution:
#潜 影 蛇 手 ! !
N,K=pin()
A=list(pin())
b=[0]*N#for backet
for i in range(N):
    b[A[i]-1]+=1
b.sort()
ans=0
x=N
for j in range(N):
    if b[j]==0:
        x-=1
    else:
        if x>K:
            x-=1
            ans+=b[j]
print(ans)

Submission status: Accepted

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

dict = {}
for i in range(n):
  if a[i] in dict:
    dict[a[i]] += 1
  else:
    dict[a[i]] = 1
ans = sorted(dict.items(), key=lambda x:x[1])
if len(ans) <= k:
  print(0)
else:
  tmp = 0
  s = 0
  for i in ans:
    tmp += i[1]
    s+=1
    if s == len(dict) - k:
      break
  print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter
a=Counter(a)
a=a.most_common()

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

Submission status: Accepted

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

B=[0]*(N+1)
for i in range(0,N):
    B[A[i]]=B[A[i]]+1
C=[]
for i in range(0,N+1):
    if B[i]!=0:
        C.append(B[i])
C.sort()
if K>=len(C):
    print(0)
else:
    s=0
    for i in range(0,len(C)-K):
        s=s+C[i]
    print(s)

Submission status: Accepted

Solution code:
n,k = map(int, input().split( ))
import sys
from collections import Counter
input = sys.stdin.readline
a = list(map(int,input().split( )))

ac = Counter(a)
cnt = []
for ke in ac:
    cnt.append(ac[ke])
cnt.sort()
if len(cnt)<=k:
    print(0)
else:
    print(sum(cnt[:-k]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    S = Counter(A)
    V = sorted(list(S.values()), reverse=True)
    print(sum(V) - sum(V[:K]))
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(a)
b = list(sorted(c.values(), reverse=True))
sum = 0

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

for i in range(0, k):
    sum = sum + b[i]

print(max(len(a)-sum, 0))

Submission status: Accepted

Solution code:
import collections
import sys

N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
cnt = 0
if len(c)<= K:
    print(0)
    sys.exit()

for i in c.most_common(K):
    cnt += i[1]

print(N-cnt)

Submission status: Accepted

Solution code:
import collections as co

n, k = map(int,input().split())
a = list(map(int,input().split()))
cnt = co.Counter(a)
ans = 0
initial = len(cnt)
if initial <= k:
    print(0)
    exit()
else:
    cnt = sorted(cnt.values())
    for i in range(initial-k):
        ans += cnt[i]
    print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N,K = map(int,input().split())
A_list = list(map(int,input().split()))
dic = defaultdict(lambda: 0)

for key in A_list:
    dic[key] += 1

change = len(dic) -K

if change <= 0:
  print(0)
else:
  sorted_list = sorted(list(dic.values()))
  Answer = sum(sorted_list[:change])
  print(Answer)