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:
N,K = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
counter_list = []
for i in range(N):
    if a_list.count(i) > 0:
        counter_list.append(a_list.count(i))

counter_list.sort()

count = 0
for i in range(len(counter_list) - K):
    count += i

print(count)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in a:
  if i>k:
    c+=1;
    
print(c)

Submission status: Wrong Answer

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

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 a > k:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

num = Counter(s)

ans = 0
i = 0
if len(num) <= k:
    print(0)
else:
    cnt = len(num) - k

    for v in sorted(num.values()):
        if cnt == i:
            break
        ans += v
        i += 1

print(ans)

Submission status: Wrong Answer

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

a_dict = {}

for i in range(N):
    if a[i] not in a_dict.keys():
        a_dict[a[i]] = 1
    else:
        a_dict[a[i]] += 1

ans = 0
if len(a_dict) <= K:
    print(ans)
else:
    sort_a_dict_list = sorted(a_dict.items(), reverse=True)
    for j in range(len(a_dict) - K):
        ans += sort_a_dict_list[j][1]
    print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
*A, = map(int, input().split())
d = [0]*(N+1)
for a in A:
    d[a] += 1
    d.sort()
    d.reverse()

print(sum(d[K:]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
*A, = map(int, input().split())
d = [0]*(N+1)
for a in A:
    d[a] += 1
    d.sort()
    d.reverse()
    print(sum(d[K:]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
*A, = map(int, input().split())
d = [0]*(N+1)
for a in A:
        d[a] += 1
        d.sort()
        d.reverse()

print(sum(d[K:]))

Submission status: Wrong Answer

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

for a in A:
  B[a] += 1

nums = [b for b in B if b > 0]
nums.sort()
n = len(nums)
if n <= K:
  print(0)
else:
  print(sum(nums[:K-n]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = {}
for i in range(n):
    s[i] = a.count(i)
for i in range(n):
    if s[i] == 0:
        s.pop(i)
    else:
        continue
cnt = 0
while len(s) > k:
    cnt = cnt + min(s.values())
    s.pop(min(s, key=s.get))
print(cnt)

Submission status: Wrong Answer

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

print(s)
cnt = 0
while len(s) > k:
    cnt = cnt + min(s.values())
    s.pop(min(s, key=s.get))
print(cnt)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = len(set(a))
ans = 0
l = collections.Counter(a)
for i, v in l.most_common()[::-1]:
    if k < cnt:
        cnt -= v
        ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
_, K = map(int, input().split())
A = list(Counter(input().split()).values())[::-1]
print(sum(A[:len(A)-K]))

Submission status: Wrong Answer

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

d={}

for x in range(n):
  if a[x] not in d:
    d[a[x]]=0
  d[a[x]]+=1
  
ans=0
ans1=[]
for g in d:
  ans1.append(d[g])
  
if len(ans1)<k:
  print(k)
  
else:
  ans1.sort()
  r=len(ans1)-k
  for t in range(r):
    ans+=ans1[t]
    
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

N=input().split()

list1=input().split()

list1=[int(i) for i in list1]

X=int(N[0])

Y=int(N[1])

aaa=[]

#print(len(set(list1)))

int1=len(set(list1))

if int1<=Y:
    print(0)
    sys.exit()

c = collections.Counter(list1)

CCC=sorted(c.items(), key=lambda x:x[1])

print(CCC)

#print(int1)

int2=0

for i in CCC:
    #print(i)
    if int1>Y:
        int2=int2+i[1]
        int1=int1-1
    else:
        break

print(int2)

Submission status: Wrong Answer

Solution code:

import sys
import collections

N=input().split()

list1=input().split()

list1=[int(i) for i in list1]

print(list1)

X=int(N[0])

Y=int(N[1])

#print(Y)

aaa=[]

print(len(set(list1)))

int1=len(set(list1))

if int1<=Y:
    print(0)
    sys.exit()

c = collections.Counter(list1)

print(min(c))

print(c)

#c.pop(min(c))

print(c)

Submission status: Wrong Answer

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

Chou_List = collections.Counter(N_List)
if len(Chou_List) <= K:
    print(0)
else:
    Chou_List = list(Chou_List.values())
    print(sum(Chou_List[K:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n, k = map(int, input().split())
a = [int(an) for an in input().split()]
ans = 0
set_a = set(a)
num_of_types = len(set_a)
if num_of_types > k:
  cnt = Counter(set_a)
  ans = sum(sorted(cnt.values())[: num_of_types - k])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count = 0
aa = Counter(a).most_common()
x = []

for i in aa:
    x.append(i[1])

x.sort()
l = len(x)

if l > k:
    for i in range(1, l - k + 1):
        count += i
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

count = 0
aa = Counter(a).most_common()
x = []

for i in aa:
    x.append(i[1])

x.sort()
l = len(x)

if l > k:
    for i in range(l - k + 1):
        count += i
    else:
        pass

print(count)

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split())
    inlis = list(map(int, input().split()))
    indic = dict()
    cnt = 0
    for i in range(n):
        num = inlis[i]
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
            cnt += 1
    if cnt <= k:
        print(0)
    else:
        indic_sort = sorted(indic.items(), key=lambda x:x[1])
        print(indic_sort)
        sa = cnt - k
        tmp = 0
        ans = 0
        for j in range(n):
            tmp += 1
            ans += indic_sort[j][1]
            if tmp == sa:
                break
        print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
l = list(map(int, input().split()))
def counter(l):
    count = {}
    for i in l:
        count[i] = l.count(i)
    return sorted(count.values())

freq = counter(l)
print(len(freq) - k if len(freq)> k else 0)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int, input().split()))
A=list(map(int, input().split()))
S=set(A)
B=[]
for i in S:
  k=A.count(i)
  B.append(k)
B.sort()
print(B)
C=B[:len(S)-K]
print(sum(C))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=[int(i)for i in input().split()]
d=[0 for i in range(max(a))]
for i in a:
    d[i-1]+=1
ans=sum(sorted(d)[:k-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()))
syurui = len(set(a))
#print(syurui)
c = Counter(a)
ans = 0
c_sort = c.most_common()
print(c_sort)
for i in range(1, syurui-k + 1):
    ans += c_sort[-i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
r,k = map(int,input().split())
b = [i for i in map(int,input().split())]
s = set(b)

if len(s) <= k:
    print(0)
else:
    n = [b.count(i) for i in s]
    n.sort()
    ans = 0
    for i in range(len(s)-k):
        ans += n[i]
        print(n[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
r,k = map(int,input().split())
b = input().split()
s = set(b)
n = [b.count(i) for i in s]
n.sort()
ans = 0
for i in range(len(s)-k):
    ans += n[i]
    print(n[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
array = list(map(int,input().split()))
dup = len(set(array))
if dup<=K:
    print('0')
else:
    print(dup-K)

Submission status: Wrong Answer

Solution code:

def calcPattern(N, Y):
    for i in range(0, N+1):
        for j in range(0, N+1):
            if i == ((Y - 1000*N - 4000*j) / 9000):
                if (N-i-j) >= 0: return (str(i) + " " + str(j) + " " +str(N-i-j))
    return ("-1 -1 -1")

n,y = map(int, input().split())
print(calcPattern(n,y))

Submission status: Wrong Answer

Solution code:
import collections

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
c = sorted(b.items(), key=lambda x:x[1])
ans = 0
d = len(c)
i = 0
while d >= k:
    d -= c[i][1]
    ans += c[i][1]
    i +=1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
c = sorted(b.items(), key=lambda x:x[1])
ans = 0
d = len(c)
i = 0
while d > k:
    d -= c[i][1]
    ans += c[i][1]
    i +=1
print(ans)

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:
    dic_a = {x:0 for x in set(a)}
    for i in a:
        dic_a[i] += 1
    sum = 0
    af = sorted(dic_a.items(), key=lambda x: x[0])
    for i in range(k,len(set(a))):
        sum += af[i][1]
    print(sum)

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:
    dic_a = {x:0 for x in set(a)}
    for i in a:
        dic_a[i] += 1
    sum = 0
    a = sorted(dic_a.items(), key=lambda x: x[0])
    for i in range(k,len(a)):
        sum += a[i][1]
    print(sum)

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:
    dic_a = {}
    for i in set(a):
        dic_a[i] =a.count(i)
    sum = 0
    a = sorted(dic_a.items(), key=lambda x: x[0])
    for i in range(k,len(a)):
        sum += a[i][1]
    print(sum)

Submission status: Wrong Answer

Solution code:
# arc086_a.py
import collections
N, K = map(int, input().split())
A = list(map(int, input().split()))
C = collections.Counter(A)
C = sorted(C.values())

lenght = len(C)
print(lenght, K, C)
print(sum(C[:(lenght-K)]))

Submission status: Wrong Answer

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

a.sort()
ans = 0
a.append(-1)
x = []
tmp = 0
for i in range(n):
  if a[i] != a[i+1]:
    tmp += 1
    x.append(tmp)
    tmp = 0
  else:
    tmp += 1
    
print(sum(x[k:]))

Submission status: Wrong Answer

Solution code:
import copy
from collections import Counter

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

count = [0]*(n+1)

for i in range(n):
    count[lis[i]] += 1

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

cnt = sorted(count)
nlis = []
for i in range(n+1):
    if cnt[i] != 0:
        nlis.append(cnt[i])

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for x in range(max(len(set(A)) - k, 0)):
    cnt = 200001
    for i in A:
        cnt = min(cnt, A.count(i))
        if cnt == A.count(i):
            rmv = i
    ans += cnt
    A.remove(rmv)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
a,b=map(int,input().split())
n=list(map(int,input().split()))
n=collections.Counter(n)
m,o=zip(*n.most_common())
o=list(o)
if len(m)<=b:
    print(0)
elif b==1:
    print(sum(o[1:]))
else:
    print(sum(o[-b+1:]))

Submission status: Wrong Answer

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

count=0
for a in A:
  if a>K:
    count+=1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
p = len(list(set(ls)))
if p <= k:
    print(0)
    sys.exit()
di=[float("inf")]*n
for i in range(n):
    if di[ls[i]-1] == float("inf"):
        di[ls[i]-1] = 1
    else:
        di[ls[i]-1] += 1
di.sort(reverse=True)
q = 0 
while True:
    s = di.pop()
    p -= s
    q += s
    if p <= k:
        print(q)
        sys.exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
if len(a) > k:
    di = [0]*(len(a))
    new = c.most_common()[::-1]
    for i in range(len(a)):
        di[i] = new[i][1]
    import numpy 
    new_ls = numpy.cumsum(numpy.array(di))
    for j in range(len(a)):
        if len(a) - k <=new_ls[j]:
            print(new_ls[j])
            sys.exit()
else:
    print(0)

Submission status: Wrong Answer

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

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

res =0
for i in range(n):
    if al[i] > k:
        res +=1
        
print(res)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict

N, K =map(int, input().split())
a = list(map(int, input().split()))
p = OrderedDict()
for i in a:
  if i not in p:
    p[i] = 1
  else:
    p[i] +=1
#print(p)
p_rev = OrderedDict(
    sorted(p.items(), key=lambda x: x[1])
)
#print(p_rev)
#print(len(p_rev))
count = 0
sum = 0
for i in p_rev.values():
  if len(p_rev) - count >= K:
    sum += i
    count += 1
  else:
    break
print(sum)

Submission status: Wrong Answer

Solution code:
from collections import OrderedDict

N, K =map(int, input().split())
a = list(map(int, input().split()))
p = OrderedDict()
for i in a:
  if i not in p:
    p[i] = 1
  else:
    p[i] +=1
#print(p)
p_rev = OrderedDict(
    sorted(p.items(), key=lambda x: x[1])
)
#print(p_rev)
#print(len(p_rev))
count = 0
sum = 0
for i in p_rev.values():
  sum += i
  count += 1
  if len(p_rev) - count >= K:
    break
print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=False)
ans = 0
while len(Counter(a)) > k:
  x = a.count(a[0])
  a = a[x:]
  ans += x
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=False)
ans = 0
while len(Counter(a)) > k:
  a = a[2:]
  ans += 1
print(ans)

Submission status: Wrong Answer

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

import collections
A_tuple = collections.Counter(A).most_common()[::-1]
print(len(A_tuple))
if len(A_tuple) < K:
    print(0)
else:
    ans = 0
    for i in range(len(A_tuple)-K):
        ans += A_tuple[i][1]
    print(ans)

Submission status: Wrong Answer

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

    col = max(0, len(set(a)) - k)
    ac = Counter(a)
    acl = ac.most_common()[::-1]
    acll = [ace[1] for ace in acl[:col]]
    r = sum(acll)
    print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k =list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
ans = 0
tmp = a[0]
for i in range(n):
    if tmp != a[i]:
        tmp += 1
    if tmp > k:
        ans = n-i
        break
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)
values,counts=zip(*a.most_common())
l=len(values)
ans=0
i=0
while l>k:
  ans=ans+values[i]
  i=i+1
  l=l-1

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
X = dict()
for i in A:
    if i in X:
        X[i] += 1
    else:
        X[i] = 1
Y = [] 
for i in X.keys():
    Y.append(i)
Y.sort()
#print(Y)
if len(Y) <= K:
    ans = 0
else:
    ans = sum(Y[:len(Y)-K])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# AtCoder
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
u = list(set(A))[K:]
c = Counter(A)
ans = 0
for e in c.items():
    if e[0] in u:
        ans += e[1]

print(ans)

Submission status: Wrong Answer

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
print(sum(sorted(c[k:], reverse=True)))

Submission status: Wrong Answer

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

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 not in D:
        D[a] = 1
    else:
        D[a] += 1
E = sorted(D.values(), reverse=True)
c = 0
i = 0
l = len(D)
while l > K:
    if (K - l) in D.values():
        c += K - c
        l -= K - c
    else:
        c += E[-1 -i]
        l -= E[-1 -i]
        i += 1
print(c)

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 not in D:
        D[a] = 1
    else:
        D[a] += 1
E = sorted(D.items())
c = 0
i = 0
l = len(D)
while l > K:
    if (K - l) in D.values():
        c += K - c
        l -= K - c
    else:
        c += E[-1 -i][1]
        l -= E[-1 -i][1]
        i += 1
print(c)

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 not in D:
        D[a] = 1
    else:
        D[a] += 1
D = sorted(D.items())
c = 0
i = 0
l = len(D)
while l > K:
    c += D[-1 -i][1]
    l -= D[-1 -i][1]
    i += 1
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
if n<=k:
    print(0)
else:    
    c = Counter(a)
    l = sorted(list(c.values()))
    print(sum(l[:k-1]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
if n<=k:
    print(0)
else:    
    c = Counter(a)
    cv = sorted(c.values())
    ans+=sum(cv[:k-1])
    print(ans)

Submission status: Wrong Answer

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

#n,k = 10,3
#a = [5,1,3,2,4,1,1,2,3,4]

count = [0] * (n+1)
for i in a:
  count[i] += 1

count2=[]
for i in count:
  if i:
    count2.append(i)
count2 = sorted(count2)

#何種類減らせばいいか
x = len(set(a))
y = x - k
y = max(0,y)

ans = 0
if not y:
  print(ans)
else:
  for i in range(y+1):
    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 = len(set(A)) - K
d = Counter(A)
l = sorted(d.keys(),reverse=True)
res = 0
if len(d) <=K:
    print(0)
else:
    for i in range(cnt):
        res += d[l[i]]
    print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N,K = map(int,input().split())
A = list(map(int,input().split()))
cnt = len(set(A)) - K
d = Counter(A)
l = sorted(d.keys(),reverse=True)
res = 0
for i in range(cnt):
    res += d[l[i]]
print(res)

Submission status: Wrong Answer

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

l = set(A)
d = list(set(A))[-(len(l)-K):]
res = 0
for i in d:
    res += A.count(i)
print(res)

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=[int(a) for a in input().split()]
B=[b for b in set(A)]
X=[[A.count(B[i]),B[i]] for i in range(len(B))]
X=sorted(X)
if len(X)<=K:
    print(0)
else:
    q=len(X)-K
    ans=0
    for i in range(q):
        ans+=X[i][0]
    print(ans)
print(X)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def resolve():
	n, k = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	lc = len(c.keys())
	if lc > k:
		v = 0
		sc = sorted(c.values())
		for i in range(k-1):
			v += sc[i]
		print(v)
	else:
		print(0)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def resolve():
	n, k = map(int, input().split())
	a = list(map(int, input().split()))
	c = Counter(a)
	lc = len(c.keys())
	if lc > k:
		v = sum(sorted(c.values())[:k-1])
		print(v)
	else:
		print(0)
resolve()

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
n,k = ma()
A = list(ma())
import collections
co = collections.Counter(A)
print(max(0,len(co.items()) -k))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
"""this is python work script"""
def return_count_list(input_list):
    input_set = set(input_list)
    answer_list = []

    for num in input_set:
        answer_list.append(input_list.count(num))
    sorted(answer_list)

    return answer_list

def solve(k, input_list):
    list_uniq = set(input_list)
    count_uniq = len(list_uniq)
    count_diff = count_uniq - k
    return count_diff

def main():
    """main function"""
    N, K = list(map(int, input().split()))
    list_input = list(map(int, input().split()))
    answer = 0

    diff = solve(K, list_input)
    count_list = return_count_list(list_input)
    if diff > 0:
        answer = sum(count_list[-diff:])

    print(answer)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
a=list(map(int,input().split()))
d=[0]*N
ans=0
for i in range(N):
    d[a[i]-1]+=1
d.sort(reverse=True)
if len(d)>K:
    ans =sum(d[K:-1])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n,k = map(int,input().split())
ls = list(map(int,input().split()))
a = list(set(ls))
c = collections.Counter(ls)
p = 0
i = 0
if len(a) > k:
    q = len(a) - k
    while p < q:
        p += c.most_common()[-1-i][1]
        i += 1
    print(p)
    sys.exit()    
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()))
ans=len(a)
a=dict(Counter(a))
count=0
a = sorted(a.items(), key=lambda x:x[1], reverse=True)
print(a)
for i,j in a:
  count+=1
  ans-=j
  if count==k:
    break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    A = collections.Counter(il())
    ret = sorted([v for v in A.values()])
    print(0 if K >= len(ret) else sum(ret[:K-len(ret)-1]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = [0]*9
for i in range(1,10):
    cnt[i-1] = al.count(i)
cnt.sort()
cnt = cnt[cnt.count(0):]

print(sum(cnt[:-k]))

Submission status: Wrong Answer

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

cnt = [0]*9
for i in range(1,10):
    cnt[i-1] = al.count(i)
cnt.sort(reverse=True)

print(sum(cnt[k:]))

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
INIT_VAL = 0
def DD2(d1,d2): return [[INIT_VAL]*d2 for _ in range(d1)]
def DD3(d1,d2,d3): return [DD2(d2,d3) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n, k = MII()
    aa = Counter(MII())
    c = aa.most_common()[-(len(aa)-k):]
    print(sum([ci[1] for ci in c]))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
Are = list(set(A))
if len(Are) <= K:
  print(0)
  exit()
else:
  B = []
  for i in range(len(Are)):
    B.append(A.count(Are[i]))
  B.sort()
  for i in range(len(B)):
    if i+1 >= len(Are)-K:
      print(sum(B[:i+1]))
      break
print(B)

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
if len(set(A)) >= K:
  print(len(set(A))-K)
else: print(0)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
tmp = [0]*N
tmp_2 = [0]*N
Cnt=0
result = 0
for i in range(N):
  tmp[A[i]-1]+= 1
  tmp_2[A[i]-1] = 1

m = sum(tmp_2)-K
tmp = sorted(tmp)
for i in range(N):
	if tmp[i]!=0:
		result += tmp[i]
		Cnt +=1
	if Cnt == m:
		break
    
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N,K=map(int,input().split())
    A=[int(x) for x in input().split()]
    
    dictionary={}
    for num in A:
        if num in dictionary:
            dictionary[num]+=1
        else:
            dictionary[num]=1
    
    ans=0  
    i=0
    
    if len(A)<=K:
        ans=0
    else:
        for value in sorted(dictionary.values()):
            if (i==len(dictionary)-K):
                break
            else:
                ans+=value
                i+=1
    print(ans)


if __name__ == "__main__":
    main()