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:
import collections
n, k = map(int, input().split())
a = map(int, input().split())
c = collections.Counter(a)

if len(c) <= K:
  print(0)
else:
  c = c.most_common()
  print(sum(c[:K-1][0]))

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[a]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
if num<=k:
  print(0)
  exit()
for i in range(num-k):
  ans+=stack[p+i]
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
stack=[0]*(2*10**5+1)
a=list(map(int,input().split()))
num=len(set(a))
for i in a:
  stack[a]+=1
stack.sort()
def binarysearch():
  ng=-1
  ok=2*10**5+1
  while abs(ng-ok)>1:
    mid=(ng+ok)//2
    if stack[mid]==0:
      ng=mid
    else:
      ok=mid
  return ok
p=binarysearch()
ans=0
for i in range(num-k):
  ans+=stack[p+i]
print(ans)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
args = map(int, input().split())
count = len(set(args))
balls = {}
for ball in count:
    balls[ball] = 0

for i in args:
    balls[i] += 1
if count <= K:
    print (0)
else:
    print (sum(sorted(balls.values())[0:max(count-K, 0)]))

Submission status: Runtime Error

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

numAppeared = [0] * (N+1)

for i in A:
    numAppeared[i] += 1

numAppeared.sort( reverse=True )

# print( sum( numAppeared[i] for i in range(K,N) ) )
print( sum( numAppeared( range(K,N) ) ) )

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(str,input().split()))
a_c=collections.Counter(a)
l=sorted(a_c.values())
ans=0
for i in range(len(l)-k):
    ans+=l[i]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
B

�����j\_������������������@���s����d�dl�Z�d�dlmZ�eee������\ZZdd��e�����D��Z	e
e��e	��Ze
e�ekr`ed���nJee���ed�d�Zd�Zx(ee
e�e��D�]Zeee�d�7�Zq�W�ee��dS�)�����N)�
itemgetterc�������������C���s���g�|�]}t�|��qS���)�int)�.0�jr���r����
ABC081C.py�
<listcomp>���s����r�������)�key)�collections�operatorr����mapr����input�split�N�KZball�dict�Counter�kind�len�print�sorted�itemsZskindZsumNum�range�ir���r���r���r����<module>���s���


Submission status: Runtime Error

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

count.sort(reverse=True)
print(sum(count[K:]))

Submission status: Runtime Error

Solution code:
import collections

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

import collections 
def solve():
  c = list(collections.Counter(a).values())
  c.sort()
  if(len(c)<=k):
    print(0)
  else:
    print(sum(c[:len(c)-k]))
 
solve()

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
a = list(map(int, input().split())
import collections 
def solve():
  c = list(collections.Counter(a).values())
  c.sort()
  if(len(c)<=k):
    print(0)
  else:
    print(sum(c[:len(c)-k]))
 
solve()

Submission status: Runtime Error

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

def solve():
  a.sort()
  c = [a.count(i) for i in range(1,n+1) if a.count(i)>0]
  c.sort()
  if(len(count)<=k):
    print(0)
  else:
    print(sum(count[:len(c)-k]))

solve()

Submission status: Runtime Error

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

a = [A.count(A_unique[i]) for i in range(N_unique)]
a_sort = sorted(a)

M = A_unique-K
if M <= 0:
	print(0)
	exit()

ans = 0
for i in range(0,M):
	ans += a_sort[i]
print(ans)

Submission status: Runtime Error

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

a = [A.count(A_unique[i]) for i in range(N_unique)]
a_sort = sorted(a)

M = N-K
if M <= 0:
	print(0)
	exit()

ans = 0
for i in range(0,M):
	ans += a_sort[i]
print(ans)

Submission status: Runtime Error

Solution code:
import sys
# A,B,C = [int(n) for n in input().split()]
N,K = [int(n) for n in input().split()]
# S = str(input())
# T = str(input())
bucket = [0]*(N+1)
A = [int(n) for n in input().split()]
s = set(A)
for a in A:
    bucket[a]+=1
bucket = [n for n in bucket if n != 0]
rc = len(s) - K
ans = 0
for r in range(rc):
    tminid = bucket.index(min(bucket))
    ans += bucklet[tminid]
    bucket[tminid]=200006
print(ans if ans >=0 else 0)

Submission status: Runtime Error

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

summary = {}
for a in A:
    if a not in summary.keys():
        summary[a] = 1
    else:
        summary[a] += 1
s_list = list(summary.values())
s_list.sort()
res = 0
i = 0
while len(s_list) > K:
    res += s_list.pop(i)
    i += 1
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

count = 0;

def cnt_uniq(li):
    ret = []
    for i in li:
        if i not in ret:
            ret.append(i)
    return ret

uniq = sorted(cnt_uniq(a))
while k < len(uniq):
    count += uniq[0]
    uniq.pop[0]

print(count)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
#print(l)
s=collections.Counter(l)
s=s.most_common()
#print(s)
a=0
for i in range(k,len(s)):
    a+=s[i][1]
print(a)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>

using namespace std;

int a[2000010];

int main(){
    int l=100000,r=0;
    int n,k;
    cin>>n>>k;
    int d;
    for(int i=1;i<=k;i++)
    {
        cin>>d;
        a[d]++;
        l=min(l,d);
        r=max(r,d);
    }
    if(r-i+1<=k) {
        cout<<0;
        return 0;
    }
    sort(a+l,a+r+1);
    int ans=0;
    while(r-l+1>k)
    {
        ans+=a[l];
        l++;
    }
    cout<<ans;
    return 0;
}

Submission status: Runtime Error

Solution code:
import sys
N, K = map(int, input().split())
A_list = sorted(map(int,input().split()))
A_index = list(set(A_list))
A_len = len(A_index)
if K >= A_len:
  print(0)
  sys.exit()
ANumDict = {}
i = 0
num = 0
for A in A_list:
  if A == A_index[i]:
    num += 1
  else:
    ANumDict[A_index[i]] = num
    num = 1
    i += 1
ANumDict[A_index[i]] = num
A_count = sorted(ANumDict.values())
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A_list = sorted(map(int,input().split()))
A_index = list(set(A_list))
ANumDict = {}
i = 0
num = 0
for A in A_list:
  if A == A_index[i]:
    num += 1
  else:
    ANumDict[A_index[i]] = num
    num = 1
    i += 1
ANumDict[A_index[i]] = num
A_count = sorted(ANumDict.values())
A_len = len(A_count)
print(sum([A_count[i] for i in range(A_len - K)]))

Submission status: Runtime Error

Solution code:
import collections

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


a = collections.Counter(a)

a = a.most_common()
if k<len(a):
	x = 0
	for i in range(k,len(a)):
		x += a[i][1]

	print(x)
else:
	print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K=map(int,input().split())
A=list(map(int,input().split()))
x=Counter(A)
l=x.most_common(K)
s=0
for i in range(K):
  s+=l[i][1]
  
print(N-s)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=[]
B=set(A)
for i in B:
  x=A.count(i)
  L.append(x)
L.sort(reverse=True)
S=0
for i in range(K):
  S+=L[i]
print(N-S)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=[]
A.sort()
A.append(200001)
for i in range(N):
  if A[i]==A[i+1]:
    continue
  else:
    x=A.count(A[i])
    L.append(x)
L.sort(reverse=True)
S=0
for i in range(K):
  S+=L[i]
print(N-S)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
L=[]
A.sort()
A.append(200001)
for i in range(N):
  if A[i]==A[i+1] or i==N-1:
    continue
  else:
    x=A.count(A[i])
    L.append(x)
L.sort(reverse=True)
S=0
for i in range(K):
  S+=L[i]
print(N-S)

Submission status: Runtime Error

Solution code:
N , K = map(int, input().split())
A = list(map(int, input().split()))
syurui = set(A)
ans = 0
if len(syurui) > K:
    ans = sum(sorted([A.count(i) for i in syurui])[:n_syurui-K])
print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
import collections
c = collections.Counter(A)
ans = N
for k in range(K):
    n = c.most_common()[k][0]
    ans -= c[n]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N, K =map(int,input().split())
a=list(map(int,input().split()))
c = collections.Counter(a)
c_=c.most_common()
c__=np.array(c_)
ans=0
for i in range (K,c__.shape[0]):
    ans+=c__[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split())
ans = 0
dic = {}
for i in a:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
dic = sorted(dic.items(), key=lambda x: x[1])
while len(dic) > k:
    ans += dic[0][1]    
    del dic[0]
print(ans)

Submission status: Runtime Error

Solution code:
# vim: set fileencoding=utf-8 :
from collections import Counter

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
c = Counter(a).values().sort(reverse=True)
print(sum(c[:k]))

Submission status: Runtime Error

Solution code:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[:len(d.items())-K]
for i in e:
  c+=i[1]
print(c)

Submission status: Runtime Error

Solution code:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[len(d.items())-K:]
for i in e:
  c+=i[1]
print(c)

Submission status: Runtime Error

Solution code:
N,K=map(int,raw_input().split())
d={}
l=map(int,raw_input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=sorted(d.items(),key=lambda x:x[1])[len(d.items())-K:]
for i in e:
  c+=i[1]
print(c)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
d={}
l=map(int,input().split())
for i in l:
  if not i in d:
    d[i]=1
  else:
    d[i]+=1
c=0
e=list(sorted(d.items(),key=lambda x:x[1]))[len(d)-K:]
for i in e:
  c+=e[1]

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K = map(int,input().split())
a = list(map(int,input().split()))
matome = set(a)
counter =0
ctr = Counter(a)
kensyo = ctr.values()
print(N - sum(kensyo[:K]))

Submission status: Runtime Error

Solution code:
/*
g++ -std=c++11 -o2 -Wall ABC081C.cpp -o ./out/ABC081C.out
./out/ABC081C.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

constexpr ll INF = 10000000000000000;

int aa[200005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  map<int, int> m;
  int a;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    ++m[a];
  }
  int key, value;
  int index = 0;
  for (auto& kv : m) {
    key = kv.first;
    value = kv.second;
    aa[index++] = value;
  }
  int types = m.size();
  sort(aa, aa + types);
  int ans = 0;
  for (int i = 0; i < min(max(types - k, 0), types); ++i) {
      ans += aa[i];
  }
  cout << ans << "\n";
}

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

dict_A = {i: 0 for i in range(1, n+1)}
for a in A:
    dict_A[a] += 1

num_list = [[] for _ in range(n)]
for key in dict_A.keys():
    num_list[dict_A[key]].append(key)

ans = 0
count = len(dict_A.keys())
pointer = 1
while count > k:
    if len(num_list[pointer]) == 0:
        pointer += 1
        continue
    ans += pointer
    count -= 1
    del num_list[pointer][0]
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

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

dict_A = {}
for a in A:
    if a not in dict_A:
        dict_A[a] = 1
    else:
        dict_A[a] += 1

num_list = [[] for _ in range(n)]
for key in dict_A.keys():
    num_list[dict_A[key]].append(key)

ans = 0
count = len(dict_A.keys())
pointer = 1
while count > k:
    if len(num_list[pointer]) == 0:
        pointer += 1
        continue
    ans += pointer
    count -= 1
    del num_list[pointer][0]
print(ans)

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
  int N, K;
	cin >> N >> K;
  vector<int> c(N);
	REP(i,N) {
		int a; cin >> a; c[--a]++;
	}
	sort(c.begin(), c.end(), greater<int>());
	int s = N;
	REP(i,K) s -= c[i];
	cout << s << endl;
	return 0;
}

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
B = [0]*N
for i in input().split():
  B[int(i)] += 1
print(sum(sorted(B)[:-K]))

Submission status: Runtime Error

Solution code:
from collections import Counter
n, k = map(int, input().split())
a = Counter((i for i in input().split()))

sort_count = sorted(a.items(), key=lambda x: x[1])

total = 0
for i in range(k):
    total += sort_count[i][1]

print(n-total)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.keys())
kesu = 0
sortv = list(sorted(dics.values()))

if len(sortv) > k:
    for i in range(n-k-1):
        kesu = kesu + sortv[i]
print(kesu)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.values())
kesu = 0
sortv = list(sorted(dics.values()))

if len(sortv) > k:
    for i in range(n-k):
        kesu = kesu + sortv[i]
print(kesu)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.values())
kesu = 0
sortv = list(sorted(dics.values()))

#while len(sortv) > k:
#    kesu = kesu + sortv[0]
#    sortv.remove(sortv[0])

if len(sortv) > k:
    for i in range(n-k+1):
        kesu = kesu + sortv[i]
print(kesu)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.values())
kesu = 0
sortv = list(sorted(list((dics.values()))))

#while len(sortv) > k:
#    kesu = kesu + sortv[0]
#    sortv.remove(sortv[0])

if len(sortv) > k:
    for i in range(n-k):
        kesu = kesu + sortv[i]
print(kesu)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.values())
kesu = 0
sortv = list(sorted(list((dics.values()))))

#while len(sortv) > k:
#    kesu = kesu + sortv[0]
#    sortv.remove(sortv[0])

if len(sortv) > k:
    for i in range(n-k):
        kesu = kesu + sortv[i]
print(kesu)

Submission status: Runtime Error

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

for i in range(n):
    if al[i] in dics:
        dics[al[i]] = dics[al[i]] + 1
    else:
        dics.update({al[i]:1})
        
counts = len(dics.values())
kesu = 0
sortv = dics.values()
while len(sortv) > k:
    kesu = kesu + min(sortv)
    sortv.remove(min(sortv))
print(kesu)

Submission status: Runtime Error

Solution code:
n, k = input().split()
a = {}
for i in [int(j) for j in input().split()]:
  if i in a:
    a[i] += 1
   else:
    a[i] = 1
if len(a) <= k:
  print(0)
else:
	print(sum(sorted(a.values())[len(a) - k]))

Submission status: Runtime Error

Solution code:
# 5 2
# 1 1 2 2 5
n, k = map(int, input().split())
a = list(map(int, input().split()))
countup = [0 for x in range(n)]
for i in a:
  countup[i] += 1

result = 0
f = list(filter(lambda x: x != 0, countup.sort()))

for i, v in enumerate(f):
 if i >= len(f) - k:
    print(result)
    break
 result += v

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
kind=[]
count=1
for i in range(len(a)-1):
  if(a[i]==a[i+1]):count+=1
  else:
    kind.append(count)
    count=1
kind.append(count)
kind.sort()
change=0
for i in range(k):change+=kind.pop()
print(n-change)

Submission status: Runtime Error

Solution code:
from collections import Counter
n,k=map(int,input().split())
cnt=list(sorted(Counter(map(int,input().split().values()))))
num=len(cnt)
ans=0
for v in cnt:
    if num<=k:
        break
    ans+=v
    num-=1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N, dtype=int)
    dp[0,:] = 0 
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:                           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])                          
                                                        
N, K = map(int, raw_input().split())                            
A = map(int, raw_input().split())                                           
print solve(N, K, A)

Submission status: Runtime Error

Solution code:
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N, dtype=in
    dp[0,:] = 0 
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:                           
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])                          
                                                        
N, K = map(int, raw_input().split())                            
A = map(int, raw_input().split())                                           
print solve(N, K, A)

Submission status: Runtime Error

Solution code:
import numpy as np
def solve(N, K, A):
    numbers = {}
    for a in A:
        numbers[a] = numbers.get(a, 0) + 1
    M = len(numbers)
    if M <= K:
        return 0
    dp = np.full((M+1, M+1), N)
    dp[0,:] = 0
    for i, n in enumerate(numbers.values()):
        for j in range(M+1):
            if j > 0:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
            else:
                dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
    return min(dp[M,:K+1])

if __name__ == "__main__":
    N, K = map(int, raw_input().split())
    A = map(int, raw_input().split())
    print solve(N, K, A)

Submission status: Runtime Error

Solution code:
import numpy as np
N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
numbers = {}
for a in A:
    numbers[a] = numbers.get(a, 0) + 1
M = len(numbers)
dp = np.full((M+1, M+1), N)
dp[0,:] = 0
for i, n in enumerate(numbers.values()):
    for j in range(M+1):
        if j > 0:
            dp[i+1,j] = min(dp[i+1,j], dp[i,j-1], dp[i,j] + n)
        else:
            dp[i+1,j] = min(dp[i+1,j], dp[i,j] + n)
print min(dp[M,:K+1])

Submission status: Runtime Error

Solution code:
import math

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

#keyはA[i]、valueは登場回数
A_unique = {}
 
for i in range(0,len(A)):
    if A[i] in A_unique:
        A_unique[A[i]] += 1
    else:
        A_unique[A[i]] = 1
v = list(A_unique.values())
v.sort() #登場回数が少ない順に書き換えていく
A_length = len(A_unique.keys()) #元々のAの長さ
d = 0

for k in v:
    if  A_length - d < K:
        print(d)
        break
    else:
        d += A_unique[k]

Submission status: Runtime Error

Solution code:
import collections

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
A_dict = collections.Counter(A)
A_common = A_dict.most_common(K)
result = N

for i in range(K): result -= A_common[i][1]

print result

Submission status: Runtime Error

Solution code:
#N個のボールを持ち，K個以下の整数にする
#順当に考えるならば，種類が少ないやつから変更していけばいい
#番号の列をリストで表現
#押し付けきれるとは限らない

counter = 0

condition = list(map(int, input().split()))
A_list = list(map(int, input().split()))

zero_line = [0 for _ in range(condition[0])]

for i in A_list:
    if zero_line[i] == 0:
        counter += 1
    zero_line[i] += 1

zero_line.sort()
zero_line.reverse()

if counter <= condition[1]:
    print(0)
else:
    print(sum(zero_line[counter-condition[1]+1 :counter]))

Submission status: Runtime Error

Solution code:
from collections import defaultdict

parameter = list(map(int, input().split()))
n, k = parameter[0], parameter[1]

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

numbers = defaultdict(lambda: 0)
for b in balls:
    numbers[b] += 1

if len(numbers) == k:
    print(0)

else:
    sort_number = sorted(numbers.items(), key=lambda x:x[1], reverse=True)
    answer = n - sum([sort_number[i][1] for i in range(k)])
    print(answer)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

parameter = list(map(int, input().split()))
n, k = parameter[0], parameter[1]

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

numbers = defaultdict(lambda: 0)
for b in balls:
    numbers[b] += 1

sort_number = sorted(numbers.items(), key=lambda x:x[1], reverse=True)
answer = n - sum([sort_number[i][1] for i in range(k)])
print(answer)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 20 12:35:48 2017

"""
 
from collections import Counter

NKList = list(map(int,input().split()))
N = NKList[0]
K = NKList[1]

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

countDict = Counter(AList)
soretedList = sorted(countDict.values())

rewrite = 0
l = len(soretedList)

while l > K:
    head = soretedList.pop(0)
    rewrite += head
    
print(rewrite)

Submission status: Runtime Error

Solution code:
#abc081c
import collections
import sys

n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
if n==k:
 print 0
 sys.exit()
cnt=collections.Counter(a)
l=[]
for k1,v in cnt.items():
 l.append(v)
l2=sorted(l,reverse=True)
temp=0
for i in xrange(k):
 temp+=l2[i]
print n-temp

Submission status: Runtime Error

Solution code:
n, k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
d=sorted([a.count(i) for i in set(a)])[::-1]
ans=0
for i in range(k):
  ans+=d[i]
print(n-ans)

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a =list(map(int, input().split()))
ball = 0
count = [0]*(n+1)
for i in range(n):
    count[a[i]] += 1

count = count.sorted(reverse=True)
for i in range(k):
    ball += count[i]

print(n - ball)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# coding:utf-8
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
default_A = A.copy()
counted = list(map(lambda x:x*0, list(range(10))))


counted2 = [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9]]
for a in A:
    counted2[a-1][0] += 1
count2 = 0
for i in range(10):
    if counted2[i][0]>0:
        count2 += 1

iranai = count2-K
min_2 = 1<<15
min_number = []
for i in range(len(counted2)):
    for j in range(len(counted2)-1, i, -1):
        if counted2[j][0] < counted2[j-1][0]:
            counted2[j], counted2[j-1] = counted2[j-1], counted2[j]

for i in range(10):
    if len(counted2)>1:
        if counted2[0][0] == 0:
            counted2.pop(0)

last_min = 0
if iranai > 0 and len(counted2) > iranai-1:
    for i in range(iranai):
        last_min += counted2[i][0]
    print(last_min)
else:
    print(0)

Submission status: Runtime Error

Solution code:
# coding:utf-8
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
default_A = A.copy()
counted = list(map(lambda x:x*0, list(range(10))))


counted2 = [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9]]
for a in A:
    counted2[a-1][0] += 1
count2 = 0
for i in range(10):
    if counted2[i][0]>0:
        count2 += 1

iranai = count2-K
min_2 = 1<<15
min_number = []
for i in range(len(counted2)):
    for j in range(len(counted2)-1, i, -1):
        if counted2[j][0] < counted2[j-1][0]:
            counted2[j], counted2[j-1] = counted2[j-1], counted2[j]

for i in range(10):
    if counted2[0][0] == 0:
        counted2.pop(0)

last_min = 0
if iranai > 0:
    for i in range(iranai):
        last_min += counted2[i][0]
    print(last_min)
else:
    print(0)

Submission status: Runtime Error

Solution code:
# coding:utf-8
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
default_A = A
#counted = list(map(lambda x:x*0, list(range(10))))
counted2 = [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9]]
for a in A:
    counted2[a-1][0] += 1
count2 = 0
for i in range(10):
    if counted2[i][0]>0:
        count2 += 1

iranai = count2-K
min_2 = 1<<15
min_number = []
for i in range(len(counted2)):
    for j in range(len(counted2)-1, i, -1):
        if counted2[j][0] < counted2[j-1][0]:
            counted2[j], counted2[j-1] = counted2[j-1], counted2[j]

for i in range(10):
    if counted2[0][0] == 0:
        counted2.pop(0)

last_min = 0
if iranai > 0:
    for i in range(iranai):
        last_min += counted2[i][0]
    print(last_min)
else:
    print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
from pandas import Series, DataFrame
 
N,K=map(int,input().split())
A=list(map(int,input().split()))
count=0
S=set(A)
c=Counter(A)
L=c.most_common(len(S))
 
x=len(S)-1
for _ in range(len(S)-K):
    count=count+int(L[x][1])
    x=x-1
 
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
from pandas import Series
 
N,K=map(int,input().split())
A=list(map(int,input().split()))
count=0
S=set(A)
c=Counter(A)
L=c.most_common(len(S))
 
x=len(S)-1
for _ in range(len(S)-K):
    count=count+int(L[x][1])
    x=x-1
 
print(count)

Submission status: Runtime Error

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
default_A = A.copy()
counted = list(map(lambda x:x*0, list(range(10))))
counted2 = [[0,0],[0,1],[0,2],[0,3],[0,4],[0,5],[0,6],[0,7],[0,8],[0,9]]
for a in A:
    counted2[a-1][0] += 1
count2 = 0
for i in range(10):
    if counted2[i][0]>0:
        count2 += 1

iranai = count2-K
min_2 = 1<<15
min_number = []
for i in range(len(counted2)):
    for j in range(len(counted2)-1, i, -1):
        if counted2[j][0] < counted2[j-1][0]:
            counted2[j], counted2[j-1] = counted2[j-1], counted2[j]

for i in range(10):
    if counted2[0][0] == 0:
        counted2.pop(0)

last_min = 0
if iranai > 0:
    for i in range(iranai):
        last_min += counted2[i][0]
    print(last_min)
else:
    print(0)

Submission status: Runtime Error

Solution code:
def solve():
	N,K = input().split(' ')
	N,K = [int(N),int(K)]
	A=list(int(_) for _ in input().split()) 

	list=[]
	cnt = 0
	ans = 0

	for n in range(N+1):
		if (A.count(n)) > 0:
			cnt += 1
			list.append(A.count(n))

	list.sort()

	if cnt > K:
		for n in range(cnt-K): ans += list[n] 

	print(ans)

if __name__ == '__main__':
	solve()

Submission status: Runtime Error

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


t = list(s.values())
t.sort()
a = 0

while len(t) > k:
    a += t.pop(0)[1]

print(a)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
l = list(map(int, input().split()))
count = 0

hoge = [0] * N

for i in range(N - 1):
    hoge[l[i]] += 1

for j in range(len(hoge)):
    if hoge[j] <= 1:
        count += 1

if count - K <= 0:
    print(0)
else:
    print(count - K)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
l = list(map(int, input().split()))
count = 0

hoge = [0] * N

for i in range(N - 1):
    hoge[l[i]] += 1

for j in range(len(hoge)):
    if hoge[j] <= 1:
        count += 1

if count - K <= 0:
    print(0)
else:
    print(count - K)