Problem:


Score : 300 points

Problem Statement

Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.

He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.

Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

Already in the beginning, there are two different integers written on the balls, so we do not need to rewrite anything.

Sample Input 3

10 3
5 1 3 2 4 1 1 2 3 4

Sample Output 3

3



Sample input:
5 2
1 1 2 2 5


Sample output:
1

Submission status: Accepted

Solution code:
import collections

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

C = list(collections.Counter(A).values())
count = 0

if len(C) <= K:
    print(0)
else:
    C.sort()
    for i in range(len(C) - K):
        count += C[i]
    print(count)

Submission status: Accepted

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

from collections import Counter
import numpy as np
c = Counter(A)

no = len(c.most_common())
numlist = []
for label, num in c.most_common():
    numlist.append(num)

diff = no - K
ans = 0
if(diff > 0):
    ans = np.sum(numlist[-diff:])
    
print(ans)

Submission status: Accepted

Solution code:
import collections
n, k = map(int, raw_input().split())
num = map(int, raw_input().split())
n = int()
num = collections.Counter(num)
for t, v in sorted(num.items(), key=lambda x:x[1])[0:-k]:
    n += v
print n

Submission status: Accepted

Solution code:
import collections
import sys
N,K=map(int,raw_input().split())
a=[]
a=collections.Counter( map(int,raw_input().split()) )
b=sorted(a.items(), key=lambda x:x[1])

if len(b)=="K":
	print 0
	sys.exit()
else:
	sum=0
	for i in range(len(b)-K):
		sum+=b[i][1]
	else:
		print sum

Submission status: Accepted

Solution code:
import numpy as np

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

A = list(map(int, input().split()))
A.sort()
key = A[0]

B = []
cnt = 1

for i in range(1,N):
    if key == A[i]:
        cnt += 1
    else:
        key = A[i]
        B.append(cnt)
        cnt = 1

B.append(cnt)

B.sort(reverse=True)

print(sum(B[K:]))

Submission status: Accepted

Solution code:
list_ = [0]
n, min_count = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
kind = 1
tmp = a[0]
for i in range(n):
    if(tmp != a[i]):
        kind += 1
        tmp = a[i]
        list_.append(0)
    list_[kind - 1] += 1
ans = 0
list_.sort()
idx = 0
for i in range(kind - min_count):
    ans += list_[idx]
    idx += 1
print(ans)

Submission status: Accepted

Solution code:
import collections
from collections import  OrderedDict

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

count_dict = collections.Counter(val)

cant = 0

if len(count_dict) <= num[1]:
    print(0)
else:
    sort_dict = OrderedDict(sorted(count_dict.items(), key=lambda x:x[1], reverse= True))
    value_dict = sort_dict.values()
    print(sum(list(value_dict)[num[1]:]))

Submission status: Accepted

Solution code:
n,k = map(int,raw_input().split(" "))
a = raw_input().split(" ")

dic = {}
for x in a:
  if x not in dic:
    dic[x] = 1
  else:
    dic[x] += 1
z = len(dic)
if z <= k:
  print 0
  exit()
ans = 0
d = sorted(dic.items(), key=lambda x: x[1])
for a in range(z-k):
  ans += int(d[a][1])
print ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
a = list(map(str, input().split()))
dis = len(set(a)) - k
if dis > 0:
    dic = {}
    for i in range(n):
        if a[i] in dic:
            dic[a[i]] += 1
        else:
            dic[a[i]] = 1
    dic_v = sorted(dic.values())
    print(sum(dic_v[:dis]))
else:
    print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, K = line.rstrip("\n").split(" ", 2)
        N = int(N)
        K = int(K)
        A = map(
          lambda a: int(a), sys.stdin.readline().rstrip("\n").split(" "))
        
        histogram = {}
        for a in A:
            if a not in histogram:
                histogram[a] = 0
            histogram[a] += 1

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

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Accepted

Solution code:
from collections import OrderedDict, deque, Counter

def solve():
    N, K = list(map(int, input().split(" ")))
    A = list(map(int, input().split(" ")))
    counter = Counter(A)
    target = counter.most_common()
    l = len(target) - K
    target.reverse()
    ans = target[:l]
    summation = 0
    for word, cnt in ans:
        summation += cnt

    print(summation)


solve()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import Counter

N, K = sys.stdin.readline().split()
K = int(K)
line = sys.stdin.readline()
A = map(int, line.strip().split())
D = Counter(A)
diff = len(D) - K

if diff <= 0:
    print(0)
else:
    print( sum( i[1] for i in D.most_common()[-1*diff:]) )

Submission status: Accepted

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

b=[]
counter = Counter(a)
for word, cnt in counter.most_common():
    b.append(int(cnt))
    
b.reverse()

x=0
if len(b)-s > 0:
  for i in range(len(b)-s):
    x+=b[i]
print(x)

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline().strip()
N, K = [int(x) for x in line.split()]

line = sys.stdin.readline().strip()
A = [int(x) for x in line.split()]

X = {}
for i in A:
    X[i] = X.get(i, 0) + 1

vs = sorted(list(X.values()))

r = 0

if len(vs) < K:
    r = 0
else:
    r = sum(vs[:-K])

print(r)

Submission status: Accepted

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

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

L = list(d.values())

if len(L) <= K:
    print(0)
else:
    L.sort()
    print(sum(L[:-K]))

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

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

ans = 0
count = 1
for k, v in sorted(d.items(), key=lambda x: -x[1]):
    if count > K:
        ans += v
    count += 1        
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
s = input().split()
N = int(s[0])
K = int(s[1])
s = input().split()
s = [int(i) for i in s]

dic = {}
for i in range(N): 
    if s[i] in dic : 
        dic[s[i]] += 1
    else :
        dic[s[i]] = 1

L = len(dic)
if K >= L : 
    print(0)
else :
    okikae = L - K
    x = sorted(dic.items(), key=lambda x: x[1])
    rst = 0
    for i in range(okikae) : 
        rst += x[i][1]
    print(rst)

Submission status: Accepted

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

freq=[0 for i in range(N+1)]
for i in range(N):
    freq[A[i]]+=1
# print(freq)

sorted_freq=sorted(freq)
# print(sorted_freq)

count=0
for i in range(1,N-K+1):
    count+=sorted_freq[i]
print(count)

Submission status: Accepted

Solution code:
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
c = collections.Counter(a)
c = sorted(c.items(), key=lambda k: k[1],
           reverse=True)

size = len(c)
if size > k:
    ans = sum([v for _, v in c[k:]])
    print(ans)

else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, input().split())
A = map(int, input().split())
C = Counter(A)
if len(C.keys()) <= K:
    print(0)
else:
    n = len(C.keys()) - K
    print(sum(map(lambda x:x[1],C.most_common()[-n:])))

Submission status: Accepted

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

for e in a:
    d[e] += 1

cnts = sorted(d.values())
print(sum(cnts[:-k]))

Submission status: Accepted

Solution code:
[n, k] = map(int, raw_input().split())
xs = map(int, raw_input().split())
d = dict()
for x in xs:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1
v = d.values()
v.sort()
if len(v) <= k:
    r = []
else:
    r = v[:len(v)-k]
print sum(r)

Submission status: Accepted

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

ans = 0
num = {}
key = 0
for i in A:
	if i in num:
		num[i] += 1
	else:
		num[i] = 1
		key += 1

if key - K <= 0:
	print("0")
	exit(0)

num2 = sorted(num.items(), key=lambda x:x[1])
for i in range(key-K):
	ans += num2[i][1]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

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

num = Counter(s)

if len(num) <= k:
    print(0)
else:
    cnt = len(num) - k
    ans = 0
    i = 0
    for v in sorted(num.values()):
        if cnt == i:
            break
        ans += v
        i += 1

print(ans)

Submission status: Runtime Error

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

a = collections.Counter(A)
V = list(a.values())
V = sorted(V)


if N <= K:
    print(0)
    exit()
    
    
L = len(V)
if L <= K:
    print(0)
    exit()


cn = 0

for i in range(L):
    cn = cn + V[i]
    del V[0]
    if len(V) == K:
        print(cn)
        break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

d={}

for n in range(N):
    if d.get(A[n])==None:
        d[A[n]]=1
    else:
        d[A[n]]+=1

dn=sorted(d.items(),key=lambda x:x[1])

if K>=len(d):
    print(0)
else:
    cnt=0
    ans=0
    for n in range(len(dn)):
        ans+=dn[n][1]
        cnt+=1
        if cnt==len(d)-K:
            break
print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
# B = [0 for i in range(N + 1)]
B=[]
for a in A:
    B[a] += 1
# nums = [b for b in B if b > 0]
nums=B.sort()
n = len(nums)
print(0 if n<=K else sum(nums[:n - K]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

V.append(temp)
V.sort() 
ans = N- sum(V[-k:])
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
l = list(map(int, input().split()))
freq = [0]*n+1
for i in l:
    freq[i]+=1
freq.sort()
vf = len(freq) - k if len(freq)> k else 0
print(sum(freq[:vf]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
l = list(map(int, input().split()))
freq = [0]*n
for i in l:
    freq[i]+=1
freq.sort()
vf = len(freq) - k if len(freq)> k else 0
print(sum(freq[:vf]))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
l = 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: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0 for i in range(n)]
y=[]
s=0
for i in range(n):
  if a[i] in a:
    x[a[i]-1]+=1
    
for i in range(n):
  if x[i]:
    y.append(x[i])
y.sort()
i=0
while(len(y)>k):
  s+=y[i]
  y.pop(i)
  i+=1
print(s)

Submission status: Runtime Error

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

num_counts = dict()
if len(set(num_lists)) <= k:
  ans = 0
else:
  for i in set(num_lists):
    num_counts[i] = num_lists.count(i)
    numbers = [num_counts.values()]
    numbers.sort()
    ans = 0
  for i in range(len(set(num_lists)) - k):
    ans += numbers[i]

print(ans)

Submission status: Runtime Error

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

if len(set(num_lists)) <= k:
  ans = 0
else:
  num_counts = {}
  for i in set(num_lists):
    num_counts[i] = num_lists.count(i)
  
  numbers = list(num_counts.values())
  numbers.sort()
  ans = 0
  for i in range(k - len(set(num_lists)):
    ans += numbers[i]
print(ans)

Submission status: Runtime Error

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

if len(set(num_lists)) <= k:
  ans = 0
else:
  num_counts = {}
  for i in set(num_lists):
    num_counts[i] = num_lists.count(i)
  
  numbers = list(num_counts.values)
  numbers.sort()
  ans = 0
  for i in range(k - len(set(num_lists)):
    ans += numbers[i]
print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
from collections import defaultdict

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

d = defaultdict(int)
for x in a:
  d[x] += 1

av = reverse(sorted(d.values()))
ks = 0
idx = 0
while ks < k:
  ks += av[idx]
  idx += 1
print(idx)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
kind=1
A.sort()
for i in range(N-1):
    if A[i]!=A[i+1]:
        kind+=1
if N!=1:
    if A[0]!=A[1]:
        kind+=1
else:
    kind=1
if kind>K:
    flood_kind=kind-K
else:
    flood_kind=0
import collections
c=collections.Counter(A)
li=c.most_common()
ans=0
for k in range(flood_kind):
    ans+=li[kind-k-1][1]
print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
kind=1
A.sort()
for i in range(N-1):
    if A[i]!=A[i+1]:
        kind+=1
if N!=1:
    if A[0]!=A[1]:
        kind+=1
if kind>K:
    flood_kind=kind-K
else:
    flood_kind=0
import collections
c=collections.Counter(A)
li=c.most_common()
ans=0
for k in range(flood_kind):
    ans+=li[kind-k-1][1]
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
li = [0]*10**5
for i in range(N):
    li[A[i]] += 1
# print(li)
li.sort(reverse=True)
# print(li)
print(sum(li[K:]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

B = []
for i in C:
    B.append(C.count(i))
print(sum(sorted(B)[:len(C) - k]))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
A = set(map(int, input().split()))
B = []
for i in A:
    B.append(A.count(i))
print(sum(sorted(B)[:len(A) - k]))

Submission status: Runtime Error

Solution code:
    n, k = map(int, input().split())
    A = set(map(int, input().split()))
    B = []
    for i in A:
        B.append(A.count(i))
    print(sum(sorted(B)[:len(A) - k]))

Submission status: Runtime Error

Solution code:
10 3
5 1 3 2 4 1 1 2 3 4

Submission status: Runtime Error

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

import collections

a = collections.Counter(A)

d = 0

for i in range(K):
    d += a.most_common()[i][1]

ans = len(A) - d

if ans <= 0:
    print('0')
else:
    print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
A = Counter(list(map(int,input().split())))
print(sum(sorted(A.values(),reverse = True)[k:]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
from collections import defaultdict
d = defaultdict(int)
for i in range(5):
    tmp = input()
    d[tmp] += 1
    
v_list = sorted(list(d.values()))
while len(v_list) > k:
    v_list.pop(0)
print(n - sum(v_list))

Submission status: Runtime Error

Solution code:
n,k=MI()
lis=LI()
cou=Counter(lis)
u=cou.most_common()
#print(u)
ans=0
for i in range(len(u)-k):
    j=len(u)-i-1
    #print(j)
    ans+=u[j][1]
    #print(cou.most_common()[j][1])
print(ans)

Submission status: Runtime Error

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

    res = 0
    balls = {}

    for ball in A:
        if ball in balls:
            balls[ball] += 1
        else:
            balls[ball] = 1

    while True:
        
        minValue = 200000
        maxValue = 0

        for key, value in balls.items():
            if value < minValue and value > 0:
                minValue = value
                minKey = key
        
            if value > maxValue:
                maxValue = value
                maxKey = key
        
        balls[maxKey] += minValue
        balls.pop(minKey)

        res += minValue

        if len(balls.keys()) == k:
            break
    
    print(res)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(A)

for i in range(len(A)-K):
    ans += c.most_common()[i][1]

print(ans)

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
import collections

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

readline = sys.stdin.readline

n, k = map(int, input().split())
a = np.array(readline().split(), dtype=np.int64)
b = np.sort(np.array(np.unique(a, return_counts=True))[1])
ans = np.sum(b[:-k])
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l = list(map(int,input().split()))
if set(l)<=k:
    print(0)
    break

Submission status: Runtime Error

Solution code:
m,k=map(int,input().split())
A=list(map(int,input().split()))
d=Counter(A)
l=d.most_common()[::-1]
s=set(A)
ans=0
i=0
while len(s)>k:
  ans+=l[i][1]
  del d[l[i]]
  s=len(d)
  i+=1
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N,K = map(int , input().split())
c=collections.Counter(list(input().split()))
result = N
for i in range(K):
    result = result - c.most_common(K)[i][1]
print(result)

Submission status: Runtime Error

Solution code:
import collections

N,K = map(int , input().split())
c=collections.Counter(list(input().split()))
result = K
for i in range(K):
    result = result - c.most_common(K)[i][1]
print(result)

Submission status: Runtime Error

Solution code:
import collections

N,K = map(int , input().split())
c=collections.Counter(list(input().split()))
result = 0
for i in range(K):
    result = result - c.most_common(K)[i][1]
print(result)

Submission status: Runtime Error

Solution code:
import collections

N,K = map(int , input().split())
c=collections.Counter(list(input().split()))
  
R1=c.most_common(2)[0][1]
R2=c.most_common(2)[1][1]
print(N-R1-R2)

Submission status: Runtime Error

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

import collections
A_c = collections.Counter(A)
A_A = A_c.most_common()

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

if A_A<=K:
  print(0)
else:
  print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
d = collections.defaultdict(int)
b = map(int, input().split())
for e in b:
    d[e] += 1
ret = 0
a = sorted([v for v in d.values()], reverse = True)
while len(a) > k:
    ret  += a.pop()
print(ret)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
array = list(map(int, input().split()))
count = [0] * n
from collections import Counter
lis = sorted((Counter(array)).items(), key = lambda x: x[1])
count2 = 0
for i in range(len(lis)):
    if len(lis) > k:
        count2 += lis[i][1]
        lis.remove(lis[i])
print(count2)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
array = list(map(int, input().split()))
count = [0] * n
from collections import Counter
lis = sorted((Counter(array)).items(), key = lambda x: x[1])[:n]
count2 = 0
for i in range(len(lis)):
    if len(lis) > k:
        count2 += lis[i][1]
        lis.remove(lis[i])
print(count2)

Submission status: Runtime Error

Solution code:
N, K = [int(x) for x in input().split(" ")]
lst = [int(x) for x in input().split(" ")]

dic= {}
cnt = 0 
swap = 0
prep = len(set(lst))-K

for i in range(1,N+1):
	dic["{}".format(i)] = 0
	dic["{}".format(lst[i-1])] += 1

sorted_dic = sorted(dic.items(), key = lambda x : x[1])
    
for i in range(0,N):
  swap += sorted_dic[i][1]
  if sorted_dic[i][1] != 0:
    cnt +=1
  if cnt >= prep:
    break
      
print(swap)

Submission status: Runtime Error

Solution code:
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
k, v = zip(*collections.Counter(a).most_common()[::-1])
v_list = [i for i in v]
diff = max(0, len(v_list - k))
ans = sum(v_list[:diff])
print(ans)

Submission status: Runtime Error

Solution code:
def NotsoDiverse(n , k , al):

    lis = [0]*n

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

    lis.sort(reverse=True)

    ans = sum(lis[k:])
    return ans

def main():
    n , k = map(int , input().split())
    al = list(map(int , input().split()))
    print(NotsoDiverse(n , k , al))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    c = sorted(b.items(),key=lambda x:x[1])
    for i in range(len(c)):
        num_keys -= c[i][1]
        c[-1][1] += c[i][1] 
        ans += c[i][1]
        if num_keys <= k:
            break
            
print(ans)

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    if k != 0:
        c = sorted(b.items(),key=lambda x:x[1])
        for i in range(len(c)):
            num_keys -= c[i][1]
            ans += c[i][1]
            if num_keys <= k:
                break
    else:
        ans += k
            
print(ans)

Submission status: Runtime Error

Solution code:
from collections import OrderedDict
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = collections.Counter(a)
ans = 0
num_keys = len(b.keys())

if num_keys > k:
    if k != 0:
        c = sorted(b.items(),key=lambda x:x[1])
        for i in range(len(c)):
            num_keys -= c[i][1]
#           c[-1][1] += c[i][1] 
            ans += c[i][1]
            if num_keys <= k:
                break
    else:
        ans += k
            
print(ans)

Submission status: Runtime Error

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

d = {}
for i in a:
  if i in d:
    d[a] += 1
  else:
    d[a] = 1
    
    
d = sorted(d,values())
if len(d) > k:
  ans = 0
  for i in range(len(d)-k):
    ans += d[i]
  print(ans)
else:
  print(0)

Submission status: Runtime Error

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

c=collections.Counter(a)
num_kind=len(set(a)) #種類の数
diff = num_kind-k #変更すべき数
values, counts = zip(*c.most_common()[::-1]) #少ない順
print(sum(counts[:diff]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
A = [int(x) for x in input().split()]
d = {}
for a in A:
  if a in d:
    d[a] +=1
  eles:
    d[a] =1
    
d =sorted(d.values())

if len(d) > K:
  ans = 0
  for i in range(len(d)-K):
    ans += d[i]
  print(ans)
else:
  print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
aList = list(map(int, input().split()))
num = [0 for _ in range(n)]
for i in aList:
    num[i] += 1
num.sort()
num = num[:-k]
print(sum(num))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
hash = [0 for i in range(n+1)]
#dic = {a[i]:count}
if len(set(a))<=k:
  print(0)
  exit()
else:
  ans=0
  for i in a:
    hash[i]+=1
  L = list(set(hash))
  x = len(set(a)) - k
  for i in range(x+1):
    ans+=L[i]
  print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = list(map(int, input().split()))
A = list(map(int, input().split()))
kinds = []
for i in A:
    if i not in kinds:
        kinds.append(i)

print(kinds)

if len(kinds) >= K:
    moves = len(kinds) - K
    moves = 5 - 3
    print(moves)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n, k = input().split()
n, k = int(n), int(k)
balls = input().split()
dic = {}
for x in balls:
	if x not in dic:
		dic[x] = 1
	else:
		dic[x] += 1
change = 0
qnt = list(dic.values())
qnt.sort()
dif = len(qnt) - k
while dif:
	change += qnt[0]
	qnt.pop(0)
	dif -= 1
print(change)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
cnt=[0 for i in range(N)]
for a in A:
  cnt[a-1]+=1
knd=[]
for i,c in enumerate(cnt):
  if c!=0:
    knd.append((i+1,c))
knd.sort(key=lambda x: x[1],reverse=True)
ans=0
while len(knd)<=K:
  j,d=knd.pop()
  ans+=d
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int, input().split()))
s = set()
for x in a:
  if x in s:
    s[x] += 1
  else:
    s[x] = 1
s_l = sorted(s.values())[0:max(0, len(s)-k)]
print(sum(s_l))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
## 種類数の求め方
# 1. A内の要素を取り出して、それがA内に存在するとき：種類＋１
# 2. その要素を重複数だけAから削除してループ

kinds = 0
A = sorted(A)
duplicatedList = []
while len(A) > 0:
    if A[0] in A:
        kinds += 1
        duplicatedList.append(A.count(A[0]))
        for j in range(A.count(A[0])):
            A.remove(A[0])

if kinds <= K:
    print('0')
elif kinds > K:
    duplicatedList = sorted(duplicatedList)
    tmp = 0
    for i in range(kinds-K):
        tmp += duplicatedList[i]
    print(tmp)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
A = [int(input() for _ in range(N))]
## 種類数の求め方
# 1. A内の要素を取り出して、それがA内に存在するとき：種類＋１
# 2. その要素を重複数だけAから削除してループ

kinds = 0
A = sorted(A)
duplicatedList = []
while len(A) > 0:
    if A[0] in A:
        kinds += 1
        duplicatedList.append(A.count(A[0]))
        for j in range(A.count(A[0])):
            A.remove(A[0])

if kinds <= K:
    print('0')
elif kinds > K:
    duplicatedList = sorted(duplicatedList)
    tmp = 0
    for i in range(kinds-K):
        tmp += duplicatedList[i]
    print(tmp)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
f=[l.count(i) for i in range(0,n)].sort()
print(sum(f[0:n-k]))