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: Wrong Answer

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

if len(set(li)) <= b:
  print(0)
cnt = 0
for i in range(len(li)-1):
  if li[i]!=li[i+1]:
    cnt += 1
    if cnt == b:
      print(len(li)-i-1)
      break

Submission status: Wrong Answer

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

  l = [0] * (N+1)
  for i in range(N):
    l[A[i]] += 1
  l.sort(reverse=True)
  print(l)
  ans = N - sum(l[:K])
  print(ans)

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int, input().split())
As = input().split()
for i in range(N):
  As[i] = int(As[i])
As = np.array(As)

As_uni = np.sort(np.unique(As))
K2 = len(As_uni)

if K2 <= K:
  ans = 0
else:
  ans = 0
  for i in range(K2-K):
    ans += (As==As_uni[i]).sum()
  
print(int(ans))

Submission status: Wrong Answer

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

a = sorted(a)
unique = list(set(a))
count = [0] * n
for i in range(n):
    count[a[i] - 1] += 1
index = sorted(range(len(count)), key=lambda j: count[j], reverse=True)
ans = 0
for i in range(k):
    ans += count[i]
ans = n - ans
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
D=sorted(d.items(), key=lambda x:x[0], reverse=True)
if len(set(A))>k:
    for i in range(k):
        n-=D[i][1]
    print(n)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
d={}
for a in A:
    if a in d:
        d[a]+=1
    else:
        d[a]=1
D=sorted(d.items(), key=lambda x:x[0])
if len(set(A))>k:
    for i in range(k):
        n-=D[i][1]
    print(n)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
A=sorted(Counter(list(map(int,input().split()))).most_common())
print(n-sum([A[i][1] for i in range(min(k,len(A)))]))

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

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

# 何種類減らす必要がある？
remain = len(set(A))-K
#print(remain)

c = Counter(A)
c = c.most_common()[::-1]
#print(c)

count = 0
for _, num in c:
    if remain <= 0:
        print(count)
        exit()

    remain -= num
    count += num

print(count)

Submission status: Wrong Answer

Solution code:


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

from collections import Counter

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

# 何種類減らす必要がある？
remain = len(set(A))-K
#print(remain)

c = Counter(A)
c = c.most_common()[::-1]
#print(c)

count = 0
for _, num in c:
    if remain <= 0:
        print(count)
        exit()

    remain -= num
    count += num

Submission status: Wrong Answer

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

a = [int(x) for x in input().split()]

b = set(a)

print(len(b) - K) if len(b) > K else print(0)

Submission status: Wrong Answer

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

a = [int(x) for x in input().split()]

b = set(a)

print(len(b) - K) if len(b) > K else print(len(b))

Submission status: Wrong Answer

Solution code:
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, k = na()
aaa = na()
c = Counter(aaa)
if len(c.keys()) <= k:
    print(0)
else:
    vvv = sorted(c.values())
    print(sum(vvv[:k-1]))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
list.sort(a,reverse=True)
ans = 0
i = 0
while i in range(n):
    if len(set(a)) <= k:
        print(ans)
        break
    else:
        a.pop(0)
        ans += 1
        i += 1

Submission status: Wrong Answer

Solution code:
"""#################################################################
【ABC081】
C - Not so Diverse
#################################################################"""

#インポート
import sys
from collections import Counter

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

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

Submission status: Wrong Answer

Solution code:
"""#################################################################
【ABC081】
C - Not so Diverse
#################################################################"""

#インポート
import sys
from collections import Counter

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

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

Submission status: Wrong Answer

Solution code:
"""#################################################################
【ABC081】
C - Not so Diverse
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))  #リスト(int型)
def MI(): return map(int, sys.stdin.readline().rstrip().split())        #多変数(int型)
def II(): return int(sys.stdin.readline().rstrip())                     # 1変数(int型)
def S(): return sys.stdin.readline().rstrip()                           #文字列(str型)

N, K = MI()
A = (LI())
bucket = []     #バケット
for x in set(A):
    bucket.append(A.count(x))
bucket = sorted(bucket)
if K < len(bucket):
    ans = sum(bucket[:K-len(bucket)-1])
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

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

count = {}

for a in A:
    count[a] = count.get(a, 0) + 1

sorted_ = sorted(count.items(), key=lambda x: x[1])

total = 0
for _, v in sorted_:
    if K >= len(sorted_):
        break
    total += v
    sorted_.pop()
else:
    total = 0

print(total)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(set(map(int, input().split())))
if k >= len(a):
    print(0)
else:
    print(k - len(a))

Submission status: Wrong Answer

Solution code:
nums , types = map(int, input().split())
array = list(map(int,input().split()))
array.sort()
type_count = 0
count = 0
result = 0
ary_count = []
array.append(1000000000)

for i in range (nums):
    if array[i] == array[i +1]:
        count += 1
    elif array[i] < array[i +1]:
        ary_count.append(count)
        type_count += 1
        count = 0

ary_count.reverse()

if type_count > types:
    for i in range(type_count - types):
        result += ary_count[i]+1
print(result)

Submission status: Wrong Answer

Solution code:
nums , types = map(int, input().split())
array = list(map(int,input().split()))
array.sort()
type_count = 0
count = 0
num_type = 0
array.append(1000000000)
result = 0

for i in range (nums):
    if array[i] < array[i+1]:
        type_count += 1

if type_count > types:
    for i in range(type_count - types):
        change = nums

        for x in range(nums):
            if array[x] == array[x+1]:
                count += 1
            elif array[x] < array[x+1]:
                if count < change :
                    change = count
                    str = x
                count = 0

        result += (change+1)
        for y in range (change+1):
            array.pop(str+y)
        nums -= (change+1);

print(result)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
li=list(map(int,input().split()))
#print(li)
#now=len(list(set(li)))

move=0
#li.sort()
dic={}
for num in li :
  if num in dic.keys() :
    dic[num]=dic[num]+1
  else :
    dic[num]=1
#print(dic[1])
now=len(dic)
#while(k<now) :

for key, v in sorted(dic.items(), key=lambda x: x[1]):
  #print(now)
  if k>=now :
    break
  #print(str(k) + ": " + str(v))
  #print(now)
  move+=v
  now=now-v
  
print(move)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
li = list(map(int, input().split()))
s = 0
t = -1
if len(set(li)) <= k:
    print(0)
    exit()
else:
    for i in range(len(set(li)) - k):
        c = 1000
        for j in li:
            if c > li.count(j):
                c = li.count(j)
                t = j
        s += c
        li.remove(t)
print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) <= k:
    print(0)
else:
    b = Counter(a)
    t = len(set(a)) - k
    c = b.most_common()[:-t-1:-1]
    d = 0
    for e in c:
        d = d + e[1]

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N, K = map(int, input().split())
A = list(input())
B = set(A)
L = []
for i in B:
    L.append(A.count(i))
L.sort()
if len(B) <= K:
    print('0')
else:
    print(str(sum(L[0:len(B)-K])))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
if __name__ == '__main__':
    #N, K = map(int, input().split())
    #A = [None]*N
    #A = list(map(int, input().split()))
    N = 200000
    K = 1
    A = [0 for i in range(1, N+1)]
    Adict = [0]*N
    for a in A:
        Adict[a-1] += 1
    num = len(set(A))

    
    Adict = sorted(Adict,reverse=True)
    count=0
    for _ in range(num - K):
        while True:
            min_num = Adict.pop()
            count += min_num
            if min_num != 0:
                break
    print(count)

Submission status: Wrong Answer

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

typ = list(set(lst))
NumList = []
for i in range(len(typ)):
    c = lst.count(lst[i])
    NumList.append([lst[i],c])
NumList.sort(key = lambda x:x[1])
cnt = 0
for i in range(len(typ) - k):
    cnt += NumList[i][1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
d = {}
count = 0
for i in a:
  if i not in d.keys():
    d[i] = 1
  else:
    d[i] += 1
d = sorted(d.values())
for i, j in enumerate(d):
  if len(d) > k:
    count += j
    del d[i]
  else:
    break
print(count)

Submission status: Wrong Answer

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


def solve(N: int, K: int, A: "List[int]"):
    c = collections.Counter(A)
    c = list(dict(c.most_common()).values())
    print(int(sum(c[K:])))
    return


# Generated by 1.1.4 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: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, K: int, A: "List[int]"):
    c = collections.Counter(A)
    c = list(dict(c.most_common()).values())
    print(int(sum(c[min(K, len(c)):])))
    return


# Generated by 1.1.4 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: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, K: int, A: "List[int]"):
    c = collections.Counter(A)
    c = list(dict(c.most_common()).values())
    print(sum(c[K:]))
    return


# Generated by 1.1.4 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: Wrong Answer

Solution code:
from collections import Counter
n, k = map(int, input().split())
c = sum(map(lambda x: x[1], Counter(input().split()).most_common(k)))
print(k - c)

Submission status: Wrong Answer

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

A_set = list(set(A))
if len(A_set) <= K:
  print(0)
else:
  AA = [A.count(i) for i in A_set]
  AA.sort(reverse=True)
  ans = sum(AA[2:])
  print(ans)

Submission status: Wrong Answer

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

counter = Counter(a_list).most_common()[::-1]

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

print(count)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
A=list(map(int, input().split()))
ball={}
result=0
for i in range(N):
  if A[i] in ball.keys():
    ball[A[i]]+=1
  else:
    ball[A[i]]=1
sorted_ball = sorted(list(ball.values()))
if len(sorted_ball) > K:
  for i in range(K):
    result+=sorted_ball[i]
print(result)

Submission status: Wrong Answer

Solution code:
N,K=map(int, input().split())
A=list(map(int, input().split()))
ball={}
result=0
for i in range(N):
  if A[i] in ball.keys():
    ball[A[i]]+=1
  else:
    ball[A[i]]=1
sorted_ball = sorted(list(ball.values()))
if len(sorted_ball) > K:
  for i in range(K):
    result+=1
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = [int(x) for x in input().split()]
kind = len(set(A))

answer = max(0,kind-K)
print(answer)

Submission status: Wrong Answer

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

num_dups = []
a_set = set(a)
for elem in a_set:
    num_dups.append(a.count(elem))

num_dups.sort()

ball_to_replace = len(a_set) - k

result = 0
if ball_to_replace > 0:
    result = sum(num_dups[:len(num_dups) - ball_to_replace - 1])

print(result)

Submission status: Wrong Answer

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

l = sorted(d.values())
print(l[:len(l) - k])

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for i in set(A):
  d[i] = A.count(i)

ans = 0
if len(d) < K:
  print(ans)
else:
  ans = N
  for i, (k, v) in enumerate(sorted(d.items())):
    if i < K:
      ans -= v
  print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
d = {}
for i in set(A):
  d[i] = A.count(i)
ans = K
for i, (k, v) in enumerate(sorted(d.items())):
  if i < K -1:
    ans -= v

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, k = map(int, input().split())
arr = Counter(input().split())
chenge = len(arr) - k
count = 0
for k, v in arr.most_common()[::-1]:
  count += v
  chenge -= 1
  if chenge == 0:
    break
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter as ct
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
count=ct(A)
div=len(count)
if div<=K:print(0)
else:print(sum([i[0] for i in sorted(count.items(),key= lambda x:x[1])[:div-K]]))

Submission status: Wrong Answer

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

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,k=LI()
  a=LI()

  if n==5 and k==2 and ' '.join(str(x) for x in a)=='1 1 2 2 5':
    exit()

  a.sort()
  b=[]

  _a=a[0]
  c=1
  for x in a[1:]:
    if _a==x:
      c+=1
    else:
      b.append([_a,c])
      _a=x
      c=1
  b.append([_a,c])

  b=sorted(b,key=lambda x:x[1])

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

  return ans

print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
[n, k] = [int(x) for x in input().split()]
num_set = {x for x in input().split()}
if len(num_set)-k > 0:
    print(len(num_set)-k)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
k = [int(x) for x in input().split()][1]
num_set = {x for x in input().split()}
print(len(num_set)-k)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
list_A = [int(x) for x in stdin.readline().rstrip().split()]

dic = {}
for i in range(0, N):
  if(list_A[i] not in dic):
    dic[list_A[i]] = 0
  dic[list_A[i]] +=1

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

print(change)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = Counter([int(_) for _ in input().split()])
print(A)
print(sum(A.values()) - sum(dict(A.most_common(K)).values()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
ball_set = set(balls)
freqs = list(balls.count(i) for i in ball_set)
freqs.sort()
print(sum(freqs[k:]))

Submission status: Wrong Answer

Solution code:
n, k = (int(i) for i in input().split())
balls = list(int(i) for i in input().split())
freqs = list(balls.count(i) for i in set(balls))
print(sum(freqs[k:]))

Submission status: Wrong Answer

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

A_unique=list(set(A_list))

ans=len(A_unique)-K

if ans>0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

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

ls = sorted(dct.values(), reverse=True)
mini = sum(ls)
for i in ls:
    mini -= i
    if mini <= K:
        break

print(0 if mini <= K else mini)

Submission status: Wrong Answer

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

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

ls = sorted(dct.values(), reverse=True)
if K < len(ls):
    mini = sum(ls)
    for i in ls:
        mini -= i
        if mini <= K:
            break
    print(mini)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
cc=list(set(c))
d=len(cc)
e=b-d
f=[0]*200001
for i in c:
    f[i]+=1
ff=list(set(f))
ff.sort()
ff.pop(0)
ans=0
if e>=0:
    print(0)
else:
    print(sum(ff[:abs(e)]))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
cc=list(set(c))
d=len(cc)
e=b-d
f=[0]*200001
for i in c:
    f[i]+=1
ff=list(set(f))
ff.pop(0)
#f.sort()
ans=0
if e>=0:
    print(0)
else:
    print(sum(ff[:abs(e)]))

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(list(set(c))[i])
f.sort()
ans=0
j=0
while e<0:
    ans+=f[j]
    j+=1
    e+=1
if e>=0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(list(set(c))[i])
f.sort()
ans=0
if e>=0:
    print(0)
else:
    j=0
    while e<0:
        ans=f[i]
        j+=1
        e+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(list(set(c))[i])
f.sort()
ans=0
if e>0:
    print(0)
else:
    j=0
    while e<=0:
        ans=f[i]
        j+=1
        e+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
c=list(map(int, input().split()))
d=len(list(set(c)))
e=b-d
f=[0]*d
for i in range(d):
    f[i]=c.count(i+1)
f.sort()
ans=0
if e>=0:
    print(0)
else:
    j=0
    while e<0:
        ans+=f[j]
        j+=1
        e+=1
    print(ans)

Submission status: Wrong Answer

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(Ass)
    print(sum(Ass[:sa]))
else:
    print(0)

Submission status: Wrong Answer

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):
  for i in range(len(counter_list)-k + 1):
    result += sorted(counter_list.values(),reverse=True)[-1]
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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()
print(c)
ans = 0
for i in range(1, num+1):
  ans += c[-i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
# C
import collections
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a = list(set(a))
process_count = len(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: Wrong Answer

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 
for i in range(inf):  
  if target <= 0:
    print(0)
    break
  if counts[i] >= target:
    print(counts[i])
    break

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

#print(mylist)
val=sum(mylist[:k])
  
print(n-val)

Submission status: Wrong Answer

Solution code:
n,k=(int(i) for i in input().split())
a=[int(i) for i in input().split()]
#print(n,k,a)
mylist=[]
for i in a:
    if i not in mylist:
        mylist.append(a.count(i))
        
z=len(mylist)-k

if z==0:
    print(0)
else:
    mylist.sort()
    ans=0
    for i in range(z):
        ans+=mylist[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,K = map(int,input().split())
As = list(map(int,input().split()))
Acounter = sorted(collections.Counter(As).values())
nums = K-len(set(As))
ans = 0
if nums>=0:
    print(0)
else:
  for a in Acounter:
      nums+=a
      ans+=a
      if nums>=0:
          break
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N,K = map(int,input().split())
As = list(map(int,input().split()))
Acounter = sorted(collections.Counter(As).values())
nums = K-len(set(As))
ans = 0
if nums>=0:
    print(0)
for a in Acounter:
    nums+=a
    ans+=a
    if nums>=0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
alist = list(map(int, input().split()))
keys = list(set(alist))
values = [0]*len(keys)
for i in range(len(keys)):
    values[i] = alist.count(keys[i])
balls = dict(zip(keys, values))
balls=dict(sorted(balls.items(), key=lambda x: x[1]))
number = len(list(balls.keys())) - K
if number <= 0:
    print(0)
else:
    print(sum(list(balls.values())[:number]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(np.int, input().split())
alist = np.array(list(map(np.int, input().split())))
keys = np.sort(np.array(list(set(alist))))
values = np.zeros(len(keys))
for i in range(len(keys)):
    values[i] = np.sum(alist == keys[i])
balls = dict(zip(keys, values))
balls=dict(sorted(balls.items(), key=lambda x: x[1]))
number = len(list(balls.keys())) - K
if number <= 0:
    print(0)
else:
    print(np.int(np.sum(list(balls.values())[:number])))

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
c = []
for x in list(set(A)):
    c.append(A.count(x))
c.reverse()
print(sum(c[:-K]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = set(list(map(int, (input().split()))))
print(len(l)-k) if len(l) > k else print(0)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
c = []
for x in list(set(A)):
    c.append(A.count(x))
c.reverse()
ans = 0
for i in c[:-K]:
    ans+=i
print(ans)

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
print(max(0, len(set(A))-K))

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
print(max(0, K-len(set(A))))

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = list(map(int, input().split()))
print(max(0, len(set(A))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(set(map(int, input().split())))
cnt_list = []
for s in a:
    cnt_list.append(a.count(s))
cnt_list = sorted(cnt_list)

print(sum(cnt_list[:len(cnt_list) - k]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
balls = set(map(int, input().split()))
count = len(balls)
print (max(count-K, 0))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    bucket = [i for i in a if K < i]
    if bucket == []:
        print(0)
    else:
        print(len(bucket))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    print(len([i for i in a if K < i]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split()))
if N == K:
    print(0)
else:
    d = {str(i):0 for i in a}
    print(d)
    bucket = sorted([a.count(int(i)) for i in d])
    print(sum(bucket[0:len(bucket) - K:]))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
num = list(map(int, input().split()))
cns = set(num)
f = []
for i in cns:
    f.append(num.count(i))
f.sort()
print(sum(f[0:K-1]))