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:
import collections as c
N,K,*A= map(int,open(0).read().split())
ans=0
C=c.Counter(A)
C=sorted(C.values(),key=lambda x:x)

for i in C:
  if len(C)<=K:
    break
  _c = C.pop(0)
  ans+=_c
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 0
countA = collections.Counter(A)
sortA = list(countA.values())
sortA.sort(reverse=True)
n = len(sortA)

if n <= K:
    print("0")
else:
    for i in range(n):
        ans += sortA[i]
        lenA = n-i
        if lenA <= K:
            break
    print(N-ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

N, K = map(int, input().split())
A = list(map(int, input().split()))
s = len(set(A))
t = s-K

c = Counter(A)
num = list(c)
num.sort()

print(sum(num[:t])) if t>0 else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

N, K = map(int, input().split())
A = list(map(int, input().split()))
s = len(set(A))
t = s-K

c = Counter(A)
num = list(c)
num.sort()
print(num,t)
print(sum(num[:t])) if t>0 else print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

N, K = map(int, input().split())
A = list(map(int, input().split()))
s = len(set(A))
t = s-K

c = Counter(A)
num = list(c)
num.sort()

print(sum(num[:t]))

Submission status: Wrong Answer

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
D = sorted(D.values())
ans = 0
if len(D)<=K:
  print(ans)
else:
    print(sum(D[:K]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
Q=list(C.values())
Q=sorted(Q,reverse=1)
if len(Q)>k:
    print(0);exit()
print(n-sum(Q[:k]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
Q=list(C.values())
Q=sorted(Q)
print(sum(Q[:n-k]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
Q=list(C.values())
Q=sorted(Q,reverse=1)
print(sum(Q[:n-k]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal as D  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as F  #F(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
Q=list(C.values())
Q=sorted(Q,reverse=1)
print(sum(Q[:k]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

#n,k=map(int,input().split())
#l=list(map(int,input().split()))
n,k=10, 3
l=[5, 1, 3, 2, 4, 1, 1, 2, 3, 4]

l=Counter(l)

if len(l) > k:
  ans=0
else:
  sl=sorted(list(l.values()))
  num=k-len(l)
  print(sl[:num-1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

#n,k=map(int,input().split())
#l=list(map(int,input().split()))
n,k=10, 3
l=[5, 1, 3, 2, 4, 1, 1, 2, 3, 4]

l=Counter(l)
num=len(l)
cnt=0

print(l)

Submission status: Wrong Answer

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

ans = 0

for a in A:
    if K < a:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

A = collections.Counter(A)
cnt = 0
for _ in range(K):
    if len(A.keys()) <= K:
        break
    k, v = min(A.items(), key=lambda x: x[1])
    cnt += v
    del A[k]
    
print(cnt)

Submission status: Wrong Answer

Solution code:
#24 C - Not so Diverse
import collections 
N,K = map(int,input().split())
A = list(map(int,input().split()))

cnt = collections.Counter(A)
print(cnt)

diff = len(cnt.keys()) - K
# 個数が少ないボールを diff 種類書き換える
values = sorted(list(cnt.values()),reverse = False)
ans = values[:diff]
print(sum(ans))

Submission status: Wrong Answer

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

ans = 0
for c in C[len(C) - 1:len(C) - K:-1]:
    ans += c[1]
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import heapq
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = Counter(A)
dif = len(l) - K
if dif <= 0:
    print(0)
    exit()
l = list(l.values())
heapq.heapify(l)
#print(l)
print(sum(l[:dif]))

Submission status: Wrong Answer

Solution code:
import heapq
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = Counter(A)
dif = len(l) - K
l = list(l.values())
heapq.heapify(l)
#print(l)
print(sum(l[:dif]))

Submission status: Wrong Answer

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

for i in range(n):
    if not a[i] in kaburi:
        kaburi.append(a[i])

kaisu = 0

while True:
    global p,q
    p = n
    q = 0
    if k >= len(kaburi):
        print(kaisu)
        break
    else:
        for j in range(len(kaburi)):
            p = min(p,a.count(kaburi[j]))
            if p > a.count(kaburi[j]):
                q = kaburi[j]
        kaisu += p
        print(p,q,kaisu,len(kaburi))
        kaburi.pop(q)

Submission status: Wrong Answer

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

for i in range(n):
    if not a[i] in kaburi:
        kaburi.append(a[i])

kaisu = 0

while True:
    p = n
    q = 0
    if k >= len(kaburi):
        print(kaisu)
        break
    else:
        for j in range(len(kaburi)):
            p = min(p,a.count(kaburi[j]))
            if p > a.count(kaburi[j]):
                q = kaburi[j]
        kaisu += p
        kaburi.pop(q)

Submission status: Wrong Answer

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

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

li = [0] * (N + 1)

#  li[i] = j  i:ボールの数 j:種類

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

ans = 0
k = len(dic)

for i in range(N):
    if li[i] > 0:
        if k - li[i] >= K:
            ans += i * li[i]
            k -= li[i]
        else:
            ans += i * (K - k)
            k -= li[i]

    if k <= K:
        break

print(ans)

Submission status: Wrong Answer

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

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

li = [0] * (N + 1)

#  li[i] = j  i:ボールの数 j:種類

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

ans = 0
k = len(dic)

for i in range(N):
    if li[i] > 0:
        if k - li[i] >= K:
            ans += i * li[i]
            k -= li[i]
        else:
            ans += i * (li[i] - k)
            k -= li[i]

    if k <= K:
        break

print(ans)

Submission status: Wrong Answer

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

c = collections.Counter(a).most_common()[::-1]
p = len(c) - k
if p <= 0:
  print(0)
else:
  print(sum(list(map(lambda x:x[1], c[:k-1]))))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

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

B = []
for i in set(A):
    B.append(A.count(i))

ans = 0
kazu = len(set(A)) - K
for i in sorted(B):
    if kazu <= 0:
        break
    kazu -= i
    ans += i

print(ans)

Submission status: Wrong Answer

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

cnt_l = [0]*(2*(10**5))
num = []
ans = 0

for i in A:
    cnt_l[i] += 1
    if i not in num:
        num.append(i)

cnt_l.sort()

cnt_l = cnt_l[2*(10**5)-len(num):]

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

cnt_l = cnt_l[:k-1]

print(sum(cnt_l))

Submission status: Wrong Answer

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

cnt_l = [0]*(2*10**5)
num = []
ans = 0

for i in A:
    cnt_l[i] += 1
    if i not in num:
        num.append(i)

cnt_l.sort()

cnt_l = cnt_l[10**5-len(num):]

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

cnt_l = cnt_l[:k-1]

print(sum(cnt_l))

Submission status: Wrong Answer

Solution code:
import math
import sys
import collections
n,k = map(int, input().split())
A = list(map(int, input().split()))
count=len(A)
Adel=list(set(A))
ans=len(Adel)-k
#print(Adel)
if ans<0:
    ans=0
    print(ans)
    sys.exit()
newA=collections.Counter(A)
count=list(newA.values())
count.sort()
#print(count)
ans=sum(count[:k-1])
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, k = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    d = defaultdict(int)
    for e in a:
        d[e] += 1
    b = [k for k in d]
    b.sort()
    ans = 0
    i = 0
    m = len(b)
    while m - i > k:
        ans += b[i]
        i += 1
    print(ans)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,K=map(int,input().split())
N=list(map(int,input().split()))
A=Counter(N)
C=list(A.values())
if len(C)<=K:
    print(0)
else:
    ans=sum(C[-(len(C)-K):])
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
num = [0] * 200000
an = list(map(int, input().split()))
for i in range(len(an)):
    num[an[i]] += 1
Ans = 0
num2 = [s for s in num if s != 0]
num2.sort()
length = len(num2)
for i in range(length):
    Ans += num2[i]
    length = length - 1
    if length == k:
        break
print(Ans)

Submission status: Wrong Answer

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

import collections

c = collections.Counter(a)
c2=sorted(c)
b=[0]*len(c)

sum=0
if K>=len(c):
    print(0)
else:
    for i in range(len(c)):
        b[i] = c[c2[i]]
    for i in range(K,len(b)):
        sum+=b[i]
    print(sum)

Submission status: Wrong Answer

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

Aset =list(set(A))
B=[0]*len(A)
cnt =0

check = len(Aset)
dff = check - K
if dff <= 0:
  print(0)
  exit(0)

A=sorted(A)

for i in range(1,len(A)):
    if A[i] != A[i-1]:
        cnt +=1
    B[i]=cnt
    cnt =0

B[0] =1

cnt2=0
i =0

if K >=sum(B):
    print(0)
elif len(B) >2:
    while cnt2 <= K:
        cnt2 += B[i]
        i +=1
    print(N-i+1)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N,K= map(int, input().split())
A =list(map(int, input().split()))
 
Aset =list(set(A))
B=[0]*len(A)
cnt =0
 
A=sorted(A)
 
for i in range(1,len(A)):
    if A[i] != A[i-1]:
        cnt +=1
    B[i]=cnt
    cnt =0
 
B[0] =1
 
cnt2=0
i =0
 
if K >=sum(B):
    print(0)
elif len(B) >2:
    while cnt2 <= K:
        cnt2 += B[i]
        i +=1
    print(N-i+1)
else:
    print(0)

Submission status: Wrong Answer

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

Aset =list(set(A))
B=[0]*len(A)
cnt =0

A=sorted(A)

for i in range(1,len(A)):
    if A[i] != A[i-1]:
        cnt +=1
    B[i]=cnt
    cnt =0

B[0] =1

cnt2=0
i =0

if K >=sum(B):
    print(0)
else:
    while cnt2 <= K:
        cnt2 += B[i]
        i +=1
    print(N-i+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,K=map(int,input().split())
a=list(map(int,input().split()))
print(max(0,len(set(a))))

Submission status: Wrong Answer

Solution code:
N, K=map(int, input().split())
A=list(map(int, input().split()))
sa=set(A)
if len(sa)<=K:
  print(0)
else:
  # 書き換える要素の種類数
  sub=len(sa)-K
  # 少ないやつを書き換えたい
  A.sort()
  A.append(A[-1])
  a=[0]*len(sa)
  j=0
  for i in range(N):
    a[j]+=1
    if A[i]!=A[i+1]:
      j+=1
  
  a.sort()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from bisect import bisect_left
from itertools import accumulate


def read():
    N, K = map(int, input().strip().split())
    A = map(int, input().strip().split())
    return N, K, A


def solve(N, K, A, NMAX=200000):
    bucket = [0 for i in range(NMAX)]
    for a in A:
        bucket[a-1] += 1
    bucket.sort()
    S = list(accumulate(bucket))
    l = bisect_left(bucket, 1)
    r = NMAX - K
    return S[r-1] - S[l-1]


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(n)]

for i in a:
    r[i-1] += 1

u = []

for i in r:
    if i:
        u.append(i)

u.sort()
print(sum(u[:k-1]))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
if len(set(a)) <= k:
    print(0)
else:
    r = [0 for _ in range(n)]

    for i in a:
        r[i-1] += 1

    u = []

    for i in r:
        if i:
            u.append(i)
    
    u.sort()
    print(sum(u[:k-1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

now_cnt = len(list(set(A)))

if (now_cnt <= k):
    print(0)
    exit()

c = Counter(A)
c_sorted = sorted(c.items(), key=lambda x: x[1])
dec = now_cnt - k
cnt = 0
L = []

for (i, v) in c_sorted:
    L.append([i, v])
for _ in range(len(L)):
    if (dec != 0):
        L[0][1] -= 1
        L[-1][1] += 1
        cnt += 1
    else:
        print(cnt)
        exit()

    if (L[0][1] == 0):
        L.pop(0)
        dec -= 1

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


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

dictNum = defaultdict(int)
for a in A:
    dictNum[a] += 1

listNum = sorted(list(dictNum.values()))
if len(listNum) <= K:
    print(0)
else:
    print(sum(listNum[:K-1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

sum(li[:max(len(li) - K, 0)])

Submission status: Wrong Answer

Solution code:
import bisect
n, m = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()

res = bisect.bisect_right(lis, m)
print(len(lis)-res)

Submission status: Wrong Answer

Solution code:
import bisect
n, m = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()

res = bisect.bisect_left(lis, m + 1)
print(len(lis)-res)

Submission status: Wrong Answer

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

for i in a:
    if i in cnt.keys():
        cnt[i] += 1
    else:
        cnt[i] = 1

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

a.sort()
cnt = dict(Counter(a))
cnt = sorted(cnt.items(), key = lambda x : x[1])

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

n, k = map(int, input().split())
s = map(int, input().split())
d = {}

for i in s:
    d.setdefault(i, 0)
    d[i] = d[i] + 1

if k >= len(d):
    print(0)
else:
    c = len(d) - k
    t = list(d.keys())
    t.sort()
    print(sum(t[0:c]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))
    count = Counter(A)
    L = len(count)
    print(L)
    if L<=K:
        print(0)
    else:
        B = list(count.values())
        B.sort()
        print(sum(B[:L-K]))



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(len(A) - K)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations
import math
import bisect
import numpy as np
from collections import defaultdict, deque
from operator import itemgetter
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n, k = map(int, input().split())
    A = len(set(list(map(int, input().split()))))
    print(max(A - k, 0))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

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

c_list = len(c)
cnt = 0
if len(c) <= k:
    print(0)
else:
    for i in c:
        cnt += i
        if c_list-cnt<=k:
            print(cnt)
            exit()

Submission status: Wrong Answer

Solution code:
import collections

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

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

cnt = 0
if len(c) <= k:
    print(0)
else:
    for i in c:
        cnt += i
        if len(c)-cnt<=k:
            print(cnt)
            exit()

Submission status: Wrong Answer

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[0], reverse=True)[:-K]:
    ans += i
print(ans)

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)
cnt_len=len(cnt)
cnt=sorted(list(cnt))
ans=0
if cnt_len<k:
    print(0)
    exit()
for i in range(cnt_len-k):
    ans+=cnt[i]
print(ans)

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)
cnt_len=len(cnt)
cnt=sorted(list(cnt))
ans=0
for i in range(cnt_len-k):
    ans+=cnt[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

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

Submission status: Wrong Answer

Solution code:
import collections

n, k, *a = map(int, open(0).read().split())
c = collections.Counter(a)

a_l = len(set(a))
if a_l -k > 0:
    print(sum([d[1]  for d in c.most_common()[:a_l-k:-1]]))
else:
    print(0)

Submission status: Wrong Answer

Solution code:
s, t  = map(int, input().split())
u = list(map(int,input().split()))
from collections import Counter
v = Counter(u)
w = 0
for i in range(s):
    if len(v) <= t:
        print(w)
        break
    else:
        w += min(v.values())
        v.popitem()

Submission status: Wrong Answer

Solution code:
s, t  = map(int, input().split())
u = list(map(int,input().split()))
from collections import Counter
v = Counter(u)
w = 0
for i in range(s):
    if len(v) <= t:
        print(w)
        break
    else:
        w += min(v.values())
        v = v.popitem()

Submission status: Wrong Answer

Solution code:
s, t  = map(int, input().split())
u = list(map(int,input().split()))
from collections import Counter
v = Counter(u)
w = 0
for i in range(s):
    if len(v) <= t:
        print(w)
        break
    else:
        del v[min(v, key = v.get)]
        w += 1

Submission status: Wrong Answer

Solution code:
s, t  = map(int, input().split())
u = list(input())
from collections import Counter
v = Counter(u)
w = 0
for i in range(s):
    if len(v) <= t:
        print(w)
        break
    else:
        del v[min(v, key = v.get)]
        w += 1

Submission status: Wrong Answer

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

L = Counter(L)
if len(L) > k-1:
    L = sorted(list(L.most_common()))[len(L)-k+1:]
else:
    print(0)
    exit()

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
L = list( map(int,input().split()))
#L = np.array(L)
L = Counter(L)
L = sorted(list(L.most_common()))[::-1]

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

Submission status: Wrong Answer

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
  
print(b)
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: Wrong Answer

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

if a[N-2]!=a[N-1]:#一番少ない数が一回だった時
  b.append(1)
  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: Wrong Answer

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

if a[N-2]!=a[N-1]:
  b.append(1)
  size+=1
  
list.sort(b,reverse=True)

s=0
if K<size:
  for u in range (K):
    s+=b[u]
else:
  s=N
print(N-s)

Submission status: Wrong Answer

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

list.sort(b,reverse=True)

s=0
if K<size:
  for u in range (K):
    s+=b[u]
else:
  s=N
print(N-s)

Submission status: Wrong Answer

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

for i in range (N):
  for j in range (N-1):
    if a[j]>a[j+1]:
      g=a[j]
      a[j]=a[j+1]
      a[j+1]=g
    
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

for q in range (size):
  for r in range (size-1):
    if b[r]<b[r+1]:
      g=b[r]
      b[r]=b[r+1]
      b[r+1]=g

s=0
if K<size:
  for u in range (K):
    s+=b[u]
else:
  s=N
print(N-s)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Submission status: Wrong Answer

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

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

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

print(al)
print(sum(al[k:]))

Submission status: Wrong Answer

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

if len(al_s) <= k:
    print(0)
else:
    tmp = []
    for a in al_s:
        tmp.append(al.count(a))
    ball = sum(sorted(al_s)[:len(al_s) - k])
    print(ball)

Submission status: Wrong Answer

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])
print(C)
C.sort()
print(C)
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: Wrong Answer

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)<=2:
    print(0)
else:
    print(sum(cnt[:-2]))

Submission status: Wrong Answer

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 k in ac:
    cnt.append(ac[k])
cnt.sort()
if len(cnt)<=2:
    print(0)
else:
    print(sum(cnt[:-2]))