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

Solution code:
n,k=map(int,input().split())
l=list(map(int,input()))
f=[]
for i in range(0,n):
   a=l.count("i")
   f.append(a)

f.sort()
total=0
for j in range (0,n-k):
   total=total+f[j]

print(total)

Submission status: Runtime Error

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
B = [0]*20

for i in A:
    B[i] += 1
B.sort(reverse = True)

for i in range(K,N):
    ans += B[i]
print(ans)

Submission status: Runtime Error

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

b = [0]*200002

for a in A:
  b[a] += 1
b.sort(reverse = Ture)
print(n-sum(b[:k]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
setted_line = list(set(list(map(int,input().split()))))
origin_num = len(setted_line) 
pairs = {}
for i in range(len(setted_line)):
  count = line.count(setted_line[i])
  pairs[setted_line[i]] = count
sorted_pairs = sorted(pairs.items(), key = lambda x:x[1])
answer = 0
if origin_num <= k:
  answer = 0
else:
  gap = origin_num - k 
  for j in range(gap):
    answer += sorted_pairs[j][1]
print(answer)

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
setted_line = list(set(map(int,input().split())))
origin_num = len(setted_line) 
pairs = {}
for i in range(len(setted_line)):
  count = line.count(setted_line[i])
  pairs[setted_line[i]] = count
sorted_pairs = sorted(pairs.items(), key = lambda x:x[1])
answer = 0
if origin_num <= k:
  answer = 0
else:
  gap = origin_num - k 
  for j in range(gap):
    answer += sorted_pairs[j][1]
print(answer)

Submission status: Runtime Error

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

#print(N, K, A)
A2 = [0] * N
for i in range(len(A)):
    A2[A[i]] += 1

A2.sort(reverse = True)
print(A2)
count = 0
for i in range(K):
    count += A2[i]
print(N - count)

Submission status: Runtime Error

Solution code:

N,K = map(int,input().split()) 
numbers = list(map(int,input().split()))
num_set = set(numbers)
KindNum = len(num_set)

if KindNum < K:
    print(0)
else:
    numCount = []
    count = 0
    for num_kind in num_set:
        numCount.append(numbers.count(num_kind))
    numCount.sort()
    count = sum(numCount[:KindNum - K])
print(count)

Submission status: Runtime Error

Solution code:

N,K = map(int,input().split()) 
numbers = list(map(int,input().split()))
num_set = set(numbers)

if len(num_set) < K:
    print(0)
else:
    numCount = []
    count = 0
    KindNum = len(num_set)
    for num_kind in num_set:
        numCount.append(numbers.count(num_kind))
    numCount.sort()
    count = sum(numCount[:KindNum - K])
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
size=len(Counter(A).most_common())
if K >= size:
    print(0)
else:
    values, counts = zip(*Counter(A).most_common()[::-1])
    ans=0
    for i in range(size-K):
        ans += counts[i]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = collections.Counter(a_list)
d = b.most_common()[:k]
sum = 0
for i in d:
    sum += i
print(n-sum)

Submission status: Runtime Error

Solution code:
import collections
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = collections.Counter(a_list)
d = b.most_common()[:k]
sum = 0
for i in d:
    sum += i
print(n-i)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
d = b.most_common()[:k]
sum = 0
for i in d:
    sum += i
print(n-i)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
key, values = zip(*b.most_common())
sum=0
for i in values.range(k):
    d = sum + i
print(n-i)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
b_list = sorted(b.items(), key=lambda x:x[1])[:k]
d = sum(b_list.values())
print(n-d)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
b_list = sorted(b.items(), key=lambda x:x[1])[:k]
for i in b_list.values():
    d = sum(i)
print(n-d)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
b_list = sorted(b.items(), key=lambda x:x[1])
for i in b_list.values[:k]:
    d = sum(i)
print(n-d)

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b = Counter(a_list)
b_list = sorted(b.items(), key=lambda x:x[1])
for i in b_list.values[:k]:
    d = sum(i)
print(n-i)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []
for i in range(1,n+1):
    if i == a_list[i]:
        b_list[i] += 1
    else:
        b_list[i] = 1
b_list.sort(reverse = True)
f = sum(b_list[:k:])
print(n-f)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []
for i in range(n+1):
    if i == a_list[i]:
        b_list[i] += 1
    else:
        b_list[i] = 1
b_list.sort(reverse = True)
f = sum(b_list[:k:])
print(n-f)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
b_list = sorted([list(map(int, input().split())).count(i) for i in range(n+1)],reverse = True)[:k]
print(n-sum(b_list))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = sorted(a_list.count(i) for i in range(n+1),reverse = True)
print(n-sum(b_list[:k:]))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(sorted(a_list.count(i) for i in range(n+1),reverse = True))
print(n-sum(b_list[:k:]))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
ans = 0
while True:
    if len(set(a_list)) > k:
        if len(set(a_list)) == k+1:
            a_list.pop()
            ans += 1
        else:
            a_list = set(a_list).pop()
            ans += 1
            
print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = set(a)
c = [a.count(i) for i in b]
d = len(b)
ans = 0
for i in c:
  if K >= d:
    break
  ans += i
  d -= 1
  print(c[i])
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
for i in li:
    ans+=i[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
for i in li:
    ans+=li(i)[1]
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

a_counter=collections.Counter(a)
li=a_counter.most_common()[k:]
ans=0
ans+=li[1]
print(ans)

Submission status: Runtime Error

Solution code:
N, K = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = list(set(B))
D ={}
for i in C:
    D[i] = 0
    for j in B:
        if i == j:
            D[i] += 1
if len(D) <= K:
    print(0)
else:
    LLL = list(D.values())
    AA = len(D) - K
    bag = 0
    for i in range(-AA, 0):
    bag += LLL[i]
    print(bag)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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()))
number = [0]*n
for i in range(n):
    number[a[i]-1]+=1
number.sort(reversed=True)
ans = 0

for i in range(k):
    ans += number[i]
ans = n-ans
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
number = [0]*n
for i in range(n):
    number[a[i]-1]+=1
number.remove(0)
number.sort()
ans = 0

if len(number)<=k:
    print(0)
else:
    for i in range(len(number)-k):
        ans += number[i]
    print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
l = list(map(int, input().split()))
S = collections.Counter(l)
S = sorted(S.values())
print(sum(S[:len(S)-k]))

Submission status: Runtime Error

Solution code:
# ABC081C - Not so Diverse (ARC086C)
from collections import Counter


def main():
    N, K, *A = map(int, open(0).read().split())
    C = Counter(A).values()
    C.sort(reverse=1)
    ans = sum(C[K:])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

from collections import Counter

ac = Counter(A)
cnt = 0

if len(c) > K:
    for a in ac.most_common()[K:]:
        cnt += a[1]
        
print(cnt)

Submission status: Runtime Error

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

As_uni = np.unique(As)

if len(As_uni) <= K:
  ans = 0
else:
  for i,a in enumerate(As_uni):
    As_uni[i] = (As==a).sum()
  As_uni = np.sort(As_uni)
  ans = As_uni[:K2-K].sum()
  
print(int(ans))

Submission status: Runtime Error

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

S=[]
for i in range(1,N+1):
  S.append(A.count(i))

T=sorted(S)[::-1]

if U > K:
  ans = 0
  for j in range(0,K):
    ans+= T[j]
print(N-ans)

if U <= K:
  print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


sa = list(set(a))

if len(sa) > nk[1]:
	c = []
	for i in range(len(sa)):
		c.append(a.count(sa[i]))
		
	sortc = sorted(c, reverse = True)
	for i in range(nk[1]):
		m += sc[i]
	ans = n - m
else:
	ans = 0

print(ans)

Submission status: Runtime Error

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

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

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

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

Submission status: Runtime Error

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

A_dict = {str(i):0 for i in set(A)}
for a in A:
  A_dict[str(a)] += 1

def get_A_key_from_value(dic, value):
  keys = [i for i, j in dic.items() if j == value]
  if len(keys) != 1:
    keys = keys[0]
  return keys[0]
  
ans = 0
while True:
  if len(A_dict) <= K:
    break
  ans += min(A_dict.values())
  del A_dict[get_A_key_from_value(A_dict,min(A_dict.values()))]
print(ans)

Submission status: Runtime Error

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

count = {}

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

tmp = []
for k, v in count:
    tmp.appned(v)

tmp = sorted(tmp)

total = 0
for i in range(len(sorted_) - K):
    total += tmp[i]

print(total)

Submission status: Runtime Error

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

count = {}

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

tmp = []
for k, v in count:
    tmp.appned(v)

tmp = sorted(tmp)

total = 0
while K < len(sorted_):
    k, v = sorted_[0]
    sorted_ = sorted_[1:]
    total += v

print(total)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

c = [0] * N
for i in range(N):
    c[i] = A.count(i + 1)
c = sorted(c)

n = len(c)
if n - K > 0:
    cnt = sum(c[:n - K])
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=a[0]
cnt=1
x=[]
for i in range(1,n):
	if b==a[i]:
		cnt+=1
	else:
		x.append([a[i-1],cnt])
		cnt=1
		b=a[i]
x.append([a[-1],cnt])
x.sort(key=lambda x:-x[1])
y=0
for i in range(k):
	y+=x[i][1]
print(n-y)

Submission status: Runtime Error

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

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
binary = [0 for _ in range(n)]
ls = list(map(int, input().split()))
for i in ls:
    binary[i-1] += 1
binary = sorted(binary)
binary.pop(binary.index(0))

ans = 0
i = 0
while k < len(binary) - binary.count(0):
    if binary[i] != 0:
        ans += binary[i]
        binary.pop(i)
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
binary = [0 for _ in range(n)]
ls = list(map(int, input().split()))
for i in ls:
    binary[i-1] += 1
binary = sorted(binary)
binary.pop(binary.index(0))
print(binary)
ans = 0
i = 0
while k < len(binary) - binary.count(0):
    if binary[i] != 0:
        ans += binary[i]
        binary.pop(i)
    i+=1
print(ans)

Submission status: Runtime Error

Solution code:
,K = map(int,input().split())
a = list(map(int,input().split()))
adic = {}
for c in a:adic[c] = adic.get(c,0) + 1
alist = sorted([adic[c] for c in adic.keys()])
print(sum(alist[:len(alist)-K]))

Submission status: Runtime Error

Solution code:
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeSet;

class ball implements Comparable<ball>{
	int num, id;
	public ball(int n, int i) {
		num = n; id = i;
	}
	public int compareTo(ball o) {
		if(num == o.num) return id - o.id;
		return num - o.num;
	}
}
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) {
			int A = sc.nextInt();
			if(map.containsKey(A)) map.put(A, map.get(A) + 1);
			else map.put(A, 1);
		}
		/* 本質 */
		int ans = 0;
		TreeSet<ball> balls = new TreeSet<ball>();
		for(Entry<Integer, Integer> e : map.entrySet()) {
			balls.add(new ball(e.getValue(), e.getKey()));
		}
		while(balls.size() > K) {
			ans += balls.pollFirst().num;
		}
		System.out.println(ans);
	}
}

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
lst = list(map(int,input().split()))
lst_com = collections.Counter(lst).most_common()
if len(lst_com)<=k:
    print(0)
    exit()
ans=n
for i in range(k):
    ans -= lst_com[i][1]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
seta = set(a)
dic = {}
for i in seta:
  dic[i] = a.count(i)

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
cnt = 0
for i in range(k):
  cnt = cnt + dic[i][1]

print(n - cnt)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
seta = set(a)
dic = {}
for i in seta:
  dic[i] = a.count(i)

dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
print(dic)
cnt = 0
for i in range(k):
  cnt = cnt + dic[i][1]

print(n - cnt)

Submission status: Runtime Error

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

print(sum(B[::-1][:K][i][1] for i in range(len(B[K:]))))

Submission status: Runtime Error

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

print(sum(B[::-1][:K][i][1] for i in range(len(B)-K)))

Submission status: Runtime Error

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

TMP = [0] * N

for i in A:
    TMP[i-1] += 1

filter_TMP = sorted([i for i in TMP if i > 0])

n = sum( x > 0 for x in filter_TMP)

cnt = 0
ans = 0
while n > K:
    ans += filter_TMP[cnt]
    del filter_TMP[cnt]
    cnt += 1
    n -= 1

print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
    break
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
nums = list(map(int,input().split()))
nums.sort()
dif = []
cnt=[]
for i in range(N-1):
  if nums[i] != nums[i+1]:
    dif.append(i+1) #玉の番号の変わり目を記録する
for i in range(len(dif)+1):
  if i == 0:
    cnt.append(dif[0])
  if i == len(dif):
    cnt.append(N-dif[-1])
  cnt.append(dif[i]-dif[i-1])
cnt.sort(reverse=True)#それぞれの球が何個ずつあるかのリスト作成
n = 0
if len(cnt)<=K:
  print(0)
else:
  for i in range(K):
    n+=cnt[i]
  print(N-n)

Submission status: Runtime Error

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

nlist = [0] * N
for i in A:
    nlist[i] += 1

nlist.sort(reverse = True)
cnt = 0
for i in range(K,N):
    if nlist[i] == 0: break
    cnt += nlist[i]

print(cnt)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print(0)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * N+1


for i in A:
    var[i] += 1
    
var = sorted(var,  reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * N+1


for i in A:
    var[i] += 1
    
var.sort( reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * 21000


for i in range(N):
    var[A[i]] += 1
    
var.sort( reverse = True )


count = 0
for j in range( K, N ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Submission status: Runtime Error

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

nums=[0] * 21000
var = [0] * 21000

for i in range(N):
    nums[A[i]] += 1
    var[A[i]] = 1
    
VAR = sum(var)
s_nums = sorted(nums, reverse = True)
ans = 0
# flag = 0
# for j in range(N):
if VAR <= K:
    print(0)
        
        
if VAR > K:
    for k in range(K):
        ans += s_nums[k]
    print(N - ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if s_nums[j] != 0 and count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print("0")

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if s_nums[j] != 0 and count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print(0)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
c = Counter(A)
ans = 0

for w, v in sorted(c.items(), key=lambda x: x[1]):
    if k < len(set(a)):
        while w in a:
            aIndex = a.index(w)
            a.pop(aIndex)
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
c = Counter(A)
ans = 0


for w, v in sorted(c.items(), key=lambda x: x[1]):
    if k < len(set(a)):
        while w in a:
            aIndex = a.index(w)
            a.pop(aIndex)
            ans+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

Solution code:
s = list(set(l))
num = range(len(s))
if len(s) <= K: print 0
else:
    for i in range(len(s)):
        num[i] = len([j for j in l if j == s[i]])
    sousa = len(s)-K
    num.sort()
    print sum(num[:sousa])

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    exit
else:
    count=[0]*len(As)
    for i in As:
        count[i]=A.count(i)
    num=sorted(count)
    ans=0
    for i in range(sa):
        ans+=num[i]
    print(ans)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
As=list(set(A))
sa=max(0,len(As)-K)
if sa==0:
    print(0)
    break
else:
    count=[]
    for i in As:
        count.append(A.count(i))
    num=sorted(count)
    ans=0
    for i in range(sa):
        ans+=num[i]
    print(ans)

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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

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

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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

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

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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

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

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

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

counts = collections.Counter(A)

result = 0
while len(counts) != K:
    result=counts.pop()[1]
    
print(result)