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 Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnts = Counter(a).values()
print(sum(sorted(cnts, reverse=True)[k:]))

Submission status: Accepted

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

Submission status: Accepted

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

from collections import Counter
c = Counter(a)
cnts = []
for i, j in c.items():
  cnts.append(j)

print(sum(sorted(cnts)[:-k]))

Submission status: Accepted

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

from collections import Counter
c = Counter(a)
key = []
value = []
for i, j in sorted(c.items(), key=lambda x: x[1]):
  key.append(i)
  value.append(j)

print(sum(value[:(len(key)-k)]))

Submission status: Accepted

Solution code:
from collections import Counter
N,K=map(int, input().split())
v=sorted(Counter(map(int, input().split())).values())
if len(v) > K:
	print(sum(v[:len(v)-K]))
else:
	print(0)

Submission status: Accepted

Solution code:
from collections import Counter

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

length = len(a)
ans = 0

for i in range(length-k):
    ans += a[-1][1]
    a.pop(-1)
    
print(ans)

Submission status: Accepted

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

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

kinds = sorted(buckets.values(), reverse=True)
if K < len(kinds):
  mini = N-sum([kinds[i] for i in range(K)])
  print(mini)
else:
  print(0)

Submission status: Accepted

Solution code:

def read_input():
    n, k = map(int, input().split())
    alist = list(map(int, input().split()))
    return n, k, alist


def submit():
    n, k, alist = read_input()

    digits = [0] * n
    for a in alist:
        digits[a - 1] += 1

    digits.sort(reverse=True)
    truncate = sum(digits[k:])
    print(truncate)


if __name__ == '__main__':
    submit()

Submission status: Accepted

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


N, K = map(int, input().split())
A = list(map(int, input().split()))
A_count = Counter(A)
A_unique = list(set(A))
A_list = []
if len(A_unique) <= K:
    print(0)
    exit()
else:
    del_num = len(A_unique) - K
    for i in A_unique:
        A_list.append(A_count[i])
    A_list.sort()
    print(sum(A_list[:del_num]))

Submission status: Accepted

Solution code:
import collections

a, b = map(int, input().split())
l = collections.Counter(input().split(" ")).values()
print(sum(sorted(l, reverse=True)[b:]))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
ls=[0]*(n+1)
for i in a:
    ls[i]+=1
ls=sorted(ls,reverse=True)
for i in range(k,n+1):
    if ls[i]==0:
        break
    else:
        cnt+=ls[i]
print(cnt)

Submission status: Accepted

Solution code:
n, k = (int(i) for i in input().split())
balls = (int(i) for i in input().split())
freqs = {}
for ball in balls:
    freqs[ball] = freqs[ball] + 1 if ball in freqs else 1
freq_hist = list(freqs.values())
freq_hist.sort(reverse=True)
print(sum(freq_hist[k:]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

init_data = list(map(int, input().split(' ')))
data = list(map(int, input().split(' ')))

c = Counter(data)

result = c.most_common()


print(sum(x[1] for x in result[init_data[1]:]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
A = map(int, input().split())
counter = 0
dic = {}

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

k = len(dic)
v = sorted(dic.values())
if k > K:
  change_n = k -K
  for i in range(change_n):
    min_k = v[i]
    counter += min_k

print(counter)

Submission status: Accepted

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

nums = Counter(A)

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

Submission status: Accepted

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

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

v = sorted(mem.values())
if len(v) > K:
    print(sum(v[:len(v)-K]))
else:
    print(0)

Submission status: Accepted

Solution code:
n,k = map(int, input().split())
ans = 0
a = list(map(int, input().split()))
 
#各数字が何個あるかの辞書{}
cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1

#含まれている文字数を大きい順にソート    
v = sorted(list(cnt_a.values()), reverse=True)

# K+1番目以降の文字数を変更する必要があるので数える
ans = sum(v[k:])
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter

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

c = Counter(A)

num = len(c)

if num <= K:
    print(0)
else:
    ans = 0
    c = list(c.items())
    c.sort(key=lambda x: x[1])
    for i in c:
        ans += i[1]
        num -= 1
        if num <= K:
            print(ans)
            sys.exit()

Submission status: Accepted

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

cnt_a = {}
for i in a:
  if i in cnt_a:
    cnt_a[i] += 1
  else:
    cnt_a[i] = 1
    
    
v = sorted(list(cnt_a.values()), reverse=True)
ans = sum(v[k:])
print(ans)

Submission status: Accepted

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

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

kinds = sorted(buckets.values(), reverse=True)
if K < len(kinds):
    mini = N-sum([kinds[i] for i in range(K)])
    print(mini)
else:
    print(0)

Submission status: Accepted

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

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

kinds = sorted(buckets.values())
count = len(kinds)
if K < count:
    mini = 0
    for i in kinds:
        mini += i
        count -= 1
        if count <= K:
            break
    print(mini)
else:
    print(0)

Submission status: Accepted

Solution code:
import re
import collections

a = input()
a = re.split(" ",a)
b = input()
b = re.split(" ",b)

c = collections.Counter(b)

c = sorted(c.items(), key=lambda x: x[1])
ans = 0
for i in range(len(c)-int(a[1])):
    ans += c[i][1]
print(ans)

Submission status: Accepted

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


from collections import Counter
c = Counter(A)
leng = len(c.keys())
if leng > K:
    print(sum(sorted(c.values())[:leng-K]))
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N, K = mi()
A = lmi()
numcnt = [0]*(2*10**5)
for i in A:
    numcnt[i] += 1
numcnt.sort()
print(len(A)-sum(numcnt[-1:-K-1:-1]))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n, a, b = LI()
    print(min(n*a,b))
    return

#B
def B():
    a = S()
    print(a.count("1"))
    return

#C
def C():
    n = II()
    a = list(str(n))
    a = list(map(int,a))
    if not n % sum(a):
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = II()
    a = LI()
    ans = 0
    while True:
        for i in range(n):
            if a[i] % 2:
                print(ans)
                return    
            a[i] /= 2
        ans += 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    n, k = LI()
    a = LI()
    dic = defaultdict(int)
    for a_ in a:
        dic[a_] += 1
    dic = sorted(dic.values(),reverse = True)
    l = 0
    ans = 0
    for j in dic:
        l += 1
        ans += j
        if l == k:
            break
    print(n-ans)
    

    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    F()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print(min(n*a,b))
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return

#E
def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return

#F
def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#G
def G():
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

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

Submission status: Accepted

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

ans = {}
for i in a:
    if i in ans:
        ans[i] += 1
    else:
        ans[i] = 1
#print(ans)
ans = sorted(ans.items(), key=lambda x: x[1])
#print(ans)
answer = 0
for i in range(len(ans)-k):
    answer += ans[i][1]
print(answer)

Submission status: Accepted

Solution code:
#!/usr/bin/python
#coding: utf-8

from collections import Counter

N, K = map(int, raw_input().split())
l = map(int, raw_input().split())

s = list(set(l))
num = range(len(s))
if len(s) <= K: print 0
else:
    counter = Counter(l)
    nums = counter.values()
    sousa = len(s)-K
    nums.sort()
    print sum(nums[:sousa])

Submission status: Accepted

Solution code:
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
n,k=map(int,input().split())
a=sorted(ecount(sorted(list(map(int,input().split())))))
ans=0
for i in range(max(0,len(a)-k)):ans+=a[i]
print(ans)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.append(10**9+7)
exnum_list=[]
ctr=0
for i in range(n):
    if a[i]==a[i+1]:
        ctr+=1
    else:
        exnum_list.append(ctr+1)
        ctr=0
exnum_list.sort()
en=len(exnum_list)
if en<=k:
    print(0)
else:
    print(sum(exnum_list[:en-k]))

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
sa=len(set(A))-K
if sa>0:
    As={}
    for i in range(N):
        if A[i] in As:
            As[A[i]]+=1
        else:
            As[A[i]]=1
    Ass=sorted(As.values())
    print(sum(Ass[:sa]))
else:
    print(0)

Submission status: Accepted

Solution code:
import collections as C
n,k=map(int,input().split())
x=list(C.Counter([int(i) for i in input().split()]).values())
shu=len(x)
if shu<=k:
    print(0)
else:
    x.sort()
    print(sum(x[:shu-k]))

Submission status: Accepted

Solution code:
import collections
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
cnt=collections.Counter(a)
shu=len(cnt.values())
ans=0
if shu<=k:
    print(ans)
else:
    x=list(cnt.values())
    x.sort()
    for i in range(shu-k):
        ans+=x[i]
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N , K = map(int,input().split())
an= list(map(int,input().split()))
ac = Counter(an)
la = list(ac.items())
la.sort(key=lambda x:x[1])
ans = 0
if len(la) <= K:
    print(0)
else:
    for i in range(len(la)-K):
        ans += la[i][1]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

N,K = na()
A=Counter(na())
c=0
ans=0
for i in A.most_common():
    ans+=i[1]
    c+=1
    if(c>=K):
        break
print(N-ans)

Submission status: Accepted

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

counter = sorted(Counter(a).values())
if len(counter) <= k:
    print(0)
else:
    print(sum(counter[:len(counter)-k]))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
num=list(map(int,input().split()))
a=[0]*n
for x in num:
    a[x-1]+=1
a=sorted(a)
for i in range(n):
    if a[i]!=0:
        del a[:i]
        break
ans=0
i=0
while len(a)-i>k:
    ans+=a[i]
    i+=1
print(ans)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)

N, K=LI()
A=LI()

counts = collections.Counter(A)
counts = counts.values()
counts = sorted(counts, reverse=True)
result = 0
while len(counts) > K:
    result+=counts.pop()
    
print(result)

Submission status: Accepted

Solution code:
N,K=map(int,input().split())
from collections import defaultdict
cnt=defaultdict(int)
for a in map(int,input().split()):
    cnt[a]+=1
res=[]
for a in cnt.keys():
    res.append(cnt[a])
res.sort()
if len(res)>K:
    ans=sum(res[0:-1*K])
else:
    ans=0
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
a = list(map(int, input().split()))
c = list(Counter(a).values())
c.sort()
ans = 0
print(sum(c[:max(0, len(c) - K)]))

Submission status: Accepted

Solution code:
import collections

result = 0
n,k = map(int,input().split())
input_list = input().split()
counter_list = collections.Counter(input_list)
if k < len(counter_list):
  length = len(counter_list)-k
  sort_list = sorted(counter_list.values())
  for i in range(length):
    result += sort_list[i]
print(result)

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.keys()) <= k:
    print(0)
    exit()
else:
    ans = 0
    lis = list(c.values())
    lis.sort()
    l = len(lis) - k
    for i in range(l):
        ans += lis[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)
print(sum(sorted(c.values(), reverse=True)[K:]))

Submission status: Accepted

Solution code:
N, K = map(int, input().split())
L = list(map(int, input().split()))
dic = {}
for i in range(N):
    dic.setdefault(L[i], 0)
    dic[L[i]] += 1

cnt = len(dic.keys())
tmp = 0
if cnt <= K:
    print(0)
else:
    for k, v in sorted(dic.items(), key = lambda x:x[1]):
        tmp += v
        cnt -= 1
        if cnt <= K:
            break
    print(tmp)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

counter = defaultdict(int)
for a in A:
    counter[a] += 1
n = list(counter.values())
n.sort(reverse=True)
print(sum(n[K:]))

Submission status: Accepted

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

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

def arraycount(arr):
    arr_target = [[]]
    cnt = 1
    for i in range(1,len(arr)):
        if arr[i] == arr[i-1]:
            cnt += 1
        else:
            arr_target.append([arr[i-1],cnt])
            cnt = 1
    arr_target.append([arr[len(arr)-1],cnt])
    del arr_target[0]
    return arr_target

a.sort()
a = arraycount(a)


for i in range(len(a)):
    a[i][0],a[i][1] = a[i][1],a[i][0]

a.sort()

need = len(a) - k
answer = 0

for i in range(need):
    answer += a[i][0]

print(answer)

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[i]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter


def solve(string):
    n, k, *a = map(int, string.split())
    count = Counter(a)
    return str(sum(sorted(count.values(), reverse=True)[k:]))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

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

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

d = dict()

for item in data:
    if d.__contains__(item):
        d[item]+=1
    else:
        d[item]=1

l = list(d.values())

l.sort()

i = 0
res = 0

if len(l)>k:
    res += sum(l[:len(l)-k])

print(res)

Submission status: Accepted

Solution code:
import collections
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
l = collections.Counter(a)
l_ = sorted(l.values())
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()))

B = set(a) #ユニークな要素のリスト
d = Counter(a)

num = len(B) - k #消すべき要素の種類

c = d.most_common()
ans = 0
for i in range(1, num+1):
  ans += c[-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()]
B = set(A)
d = Counter(A)
num = len(B) - K
ans = 0
c = d.most_common()
for i in range(1, num+1):
    ans += c[-i][1]
print(ans)

Submission status: Accepted

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
numbers = {}
for a in A:
    if not a in numbers:
        numbers[a] = 1
    else:
        numbers[a] += 1
numbers = sorted(numbers.items(),key=lambda x: -x[1])
sum = 0
for i,k in enumerate(numbers):
    if i < K:
        continue
    sum += numbers[i][1]
print(sum)

Submission status: Accepted

Solution code:
N,K = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
L = [0 for i in range(N)]
for i in range(N):
  L[A[i]-1] +=1

L.sort()

ans = 0
for i in range(N-K):
  ans += L[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)
c = len(A)
#print(a.most_common(K))
S = a.most_common(K)
for i in range(K):
    try:
        c -= S[i][1]
    except IndexError:
        print(c)
        exit()
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C
import collections
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
unique_a = list(set(a))
process_count = len(unique_a) - k
c = collections.Counter(a)
values, counts = zip(*c.most_common())

counts = list(counts)
counts.sort()
ans = 0

for i in range(process_count):
    ans += counts[i]
print(ans)

Submission status: Accepted

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

from collections import Counter
c = Counter()
for A in An:
    c[A] += 1

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

Submission status: Accepted

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

from collections import Counter

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

Submission status: Accepted

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

if len(firstA)<=K:
    print(0)
    exit()
count = [0 for i in range(max(firstA)+1)]
for i in range(N):
    count[A[i]] += 1
count.sort()
for i,x in enumerate(count):
    if x > 0:
        count = count[i:]
        break
print(sum(count[:len(count)-K]))

Submission status: Accepted

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

import collections
from itertools import accumulate

c = collections.Counter(A)
_, counts = zip(*c.most_common()[::-1])
counts = list(accumulate(counts))
cnt = 0
inf = 10 ** 18

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

Submission status: Accepted

Solution code:
from collections import Counter

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

D = Counter(A)
V = sorted(D.values(),reverse=True)
print(max(n-sum(V[:k]),0))

Submission status: Accepted

Solution code:
from collections import Counter

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

D = Counter(A)
V = []
for v in D.values():
    V.append(v)
V.sort(reverse=True)
print(max(n-sum(V[:k]),0))

Submission status: Accepted

Solution code:
from collections import Counter

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

D = Counter(A)
K = []
for key in D.keys():
    K.append(key)
if len(set(K)) <= k:
    print(0)
else:
    V = []
    for v in D.values():
        V.append(v)
    V.sort(reverse=True)
    print(n-sum(V[:k]))

Submission status: Accepted

Solution code:
import collections
N, K = map(int, input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
# print(c)
c = sorted(c.values())[:-K]
# -K番目(1番最後)の数値を数える
print(sum(c))

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())
print(sum(c[:(len(c) - K)]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/16
Solved on 2019/3/
@author: shinjisu
"""


# ABC 081 C Not so Diverse
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    N, K = getIntList()
    d.dmp((N, K), 'N, K')
    A = getIntList()
    d.dmp((A), 'A')
    dic = {}
    for e in A:
        if e in dic:
            dic[e] += 1
        else:
            dic[e] = 1
    d.dmp(dic,'dic')
    val = list(dic.values())
    count = 0
    val.sort()
    d.dmp(val,'val')
    for i in range(len(val)-K):
        count += val[i]
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Accepted

Solution code:
import collections

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

mydata=collections.Counter(a)
mylist=list(mydata.values())
mylist.sort(reverse=True)
#print(mylist)

if len(mylist)<k:
  print(0)
else:
  val=sum(mylist[:k])
  print(n-val)

Submission status: Accepted

Solution code:
from collections import Counter
n,k=map(int,input().split())
lst=[int(i) for i in input().split()]
L=list(Counter(lst).values())
L.sort()
l=len(L)
ans=0
a=0
if l>k:
  while l>k:
    ans+=L[a]
    l-=1
    a+=1
print(ans)

Submission status: Accepted

Solution code:
import collections
N,K = map(int,input().split())
As = list(map(int,input().split()))
Acounter = sorted(collections.Counter(As).values())
ans = 0
for i in range(0,len(Acounter)-K):
  ans+=Acounter[i]
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

An = Counter(input().split())


def main():
    # 要素数(v) 昇順
    # 先頭 から インデックス len(An) - K - 1 まで
    # 要素数(v) 合計
    print(sum(sorted(An.values())[:len(An) - K]))

    return


main()

Submission status: Accepted

Solution code:
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter(input().split())


def main():
    # 要素数(v) 昇順
    # 先頭 から インデックス len(An) - K - 1 まで
    # 要素数(v) 合計
    print(sum(sorted(An.values())[:len(An) - K]))

    return


main()

Submission status: Accepted

Solution code:
import collections

N, K = map(int, input().split())
alist = collections.Counter(map(int, input().split()))
number = max(0,len(alist) - K )
answer = 0
if number == 0:
    print(0)
else:
    for a in alist.most_common()[-number:]:
        answer += a[1]
    print(answer)

Submission status: Accepted

Solution code:
from collections import Counter

from sys import stdin

input = stdin.readline

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

An = Counter([int(i) for i in input().split()])


def main():
    # 要素数(v) 多い順 インデックス K 含んでそれよりも後ろ
    # 先頭 K + 1 個目から 末尾 まで
    # 要素数(v) 合計
    print(sum([v for k, v in An.most_common()[K:]]))

    return


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
for i in range(len(C) - K):
    ans += C[i][1]
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc081/tasks/arc086_a

import itertools
import collections
import bisect

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    C = collections.Counter(A)
    need_rewrite = max(0, len(C.keys()) - K)
    if need_rewrite:
        ans = 0
        for kv in C.most_common()[-need_rewrite:]:
            ans += kv[1]
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()

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()
print(sum(c[:N-K]))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
n_lst = list(map(int,input().split())) 
cnt_lst = [0 for _ in range(n+1)]

for x in n_lst:
    cnt_lst[x] += 1
cnt_lst.sort(reverse=True)
print(sum(cnt_lst[k:]))

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt_lst = Counter(n_lst).most_common()[k:]
ans = 0
for x in cnt_lst:
    ans += x[1]
print(ans)