Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

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

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

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

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

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

Sample Input 3

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

Sample Output 3

3



Sample input:
5 2
1 1 2 2 5


Sample output:
1

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
n = [0 for i in range(N + 1)]
count = 1
for i in range(1, N):
    if A[i] != A[i - 1]: count += 1
    n[A[i]] += 1
n.sort()
if count <= K:
    print(0)
else:
    for i in range(N + 1):
        if n[i] != 0:
            key = i
            break
    print(sum(n[key:key + count - K]))

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
n = [0 for i in range(N + 1)]
count = 1
for i in range(1, N):
    if A[i] != A[i - 1]: count += 1
    n[A[i]] += 1
n.sort()
if count <= K:
    print(0)
else:
    for i in range(N):
        if n[i] != 0:
            key = i
            break
    print(sum(n[key:key + count - K]))

Submission status: Wrong Answer

Solution code:
import os
import sys

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

d = {}
for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i] = 1

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

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

tmp = len(d)
ans = 0

for i in d.keys():
    tmp-=1
    ans += d[i]
    if(tmp==k):
        break

print(ans)
exit(0)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = sorted(list(map(int, input().split())))
counts = []
now = l[0]
count = 1
for i in range(1, n):
  if l[i] == now:
    count += 1
  else:
    counts.append(count)
    now = l[i]
    count = 1
  
  if i == n-1 and count == 1:
    counts.append(count)
counts = sorted(counts)
if len(counts) <= k:
  print(0)
else:
  print(sum(counts[:len(set(l))-k]))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
l = sorted(list(map(int, input().split())))
counts = []
if len(set(l)) <= k:
  print(0)
else:
  now = l[0]
  count = 1
  for i in range(1, n):
    if l[i] == now:
      count += 1
    else:
      counts.append(count)
      now = l[i]
      count = 1
    
    if i == n-1 and count == 1:
      counts.append(count)
  counts = sorted(counts)
  
  if len(counts) <= k:
    print(0)
  else:
    print(sum(counts[:-k]))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=len(set(a))
from collections import Counter
data=Counter(a)
data=sorted(data.items(),key=lambda x:-x[1])
data_cnt=len(data)#ボールの種類数
ans=0
if cnt<=k:
    print(0)
else:
    for i in range(k,data_cnt):
        ans+=data[i][1]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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((dics.values()))
for i in range(len(sortv)):
    minj = i
    for j in range(i,len(sortv)):
        if sortv[j] < sortv[minj]:
            minj = j
    p = sortv[i]
    q = sortv[minj]
    sortv[i] = q
    sortvminj = p
while len(sortv) > k:
    kesu = kesu + sortv[0]
    sortv.remove(sortv[0])
print(kesu)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
dic = defaultdict(int)
for i in range(n):
    dic[a[i]] += 1

s = sorted(dic.values())
if len(dic) <= k:
    print(0)
else:
    print(sum(s[:k - len(dic) - 1]))

Submission status: Wrong Answer

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
while(len(kind)>k):
  change+=kind.pop()
print(n-change)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0] * (N + 1)
    MAX = 9999999
    for a in A:
        B[a] += 1
    kinds = 0
    for b in B:
        if b != 0:
            kinds +=1
    if kinds <= K:
        return 0
    diff = kinds - K
    ans = 0
    for d in range(diff):
        m = 9999999
        index = 0
        for i, v in enumerate(B):
            if v == 0:
                continue
            m = min(m, v)
            index = i
        B[index] = 9999999
        ans += m
    return ans


print(main())

Submission status: Wrong Answer

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

import sys

u"""
最初にdictにいれ、key=number, value=count
それを元に (count, number)のリストをつくり、昇順にソート
リストの長さがK以下になるまでリストをたどる
"""

n, k = [int(e) for e in raw_input().split()]
al = [int(e) for e in raw_input().split()]

d = {}
for a in al:
    d[a] = d.get(a, 0) + 1
# print d

l = []
for dk, dv in d.iteritems():
    # l.append((dv, dk))
    l.append(dv)
l.sort()
# print l

i = 0
b = 0
ll  = len(l)
llc = ll
while llc > k:
    if i >= ll:
        break
    c = l[i]
    llc -= c
    b += c
    i += 1
    
sys.stdout.write('%d\n' % b)
sys.stdout.flush()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
data=Counter(a).values()
count=0
p=len(list(data))
if p<=k:
    print(count)
else:
    for c in data:
        if k<p:
            p-=1
            count+=c
        else:
            break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
counter=Counter(a)
ans=[]
for i in counter.values():
    ans.append(i)
v=sum(ans[0:k])
print(n-v)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=list(set(a))
ans=[]
data=Counter(a)
if len(c)<k:
    print(0)
else:
    for i in data.values():
        ans.append(i)
    ans.reverse()
    print(sum(ans[0:len(c)-k]))

Submission status: Wrong Answer

Solution code:
balls, target = [int(i) for i in input().split()]
num_dict = {}
count = 0

for i in input().split():
    if i in num_dict.keys():
        num_dict[i] += 1
    else:
        num_dict[i] = 1

while target < len(num_dict):
    # for key, value in sorted(num_dict.items(), key = lambda x: x[1]):
    #     count += value
    #     del(num_dict[key])
    #     break
    min_key = min(num_dict, key=(lambda x: num_dict[x]))
    count += num_dict[min_key]
    del(num_dict[min_key])
    break
print(count)

Submission status: Wrong Answer

Solution code:
balls, target = [int(i) for i in input().split()]
num_dict = {}
count = 0

for i in input().split():
    if i in num_dict.keys():
        num_dict[i] += 1
    else:
        num_dict[i] = 1

while target < len(num_dict):
    key = sorted(num_dict.keys())[0]
    count += num_dict[key]
    del(num_dict[key])
    break

print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
cnt=sorted(Counter(input().split()).most_common(),reverse=True)
count=0
p=len(cnt)
if p<=k:
    print(count)
else:
    for num,c in cnt:
        if p>k:
            p-=1
            count+=c
        else:break
    print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int,input().split())
cnt=sorted(Counter(input().split()).most_common(),reverse=True)
count=0
p=len(cnt)
if p<=k:
    print(count)
else:
    for num,c in cnt:
        if p>k:
            p-=1
            count+=c
        else:break
    
    print(count)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A_list = list(map(int,input().split()))
counter = [0]*(N+1) 
for i in A_list:
    counter[i] += 1
print(counter)
zeronashi = [i for i in counter if i != 0]
zeronashi.sort()
length = len(zeronashi)
x = length - K
y = 0
if x < 1:
    print(0)
else:
    for i in range(x):
        y += zeronashi[i]
    print(y)

Submission status: Wrong Answer

Solution code:
# C - Not so Diverse
# coding: utf-8

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)

if len(A_common) <= K:
  result = 0
else:
  result = N
  for i in range(K): result -= A_common[i][1]

print result

Submission status: Wrong Answer

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(200001)]

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

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(200000)]

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

Solution code:
import numpy as np
import sys

b=[int(x) for x in input().split()]
n=b[0]
m=b[1]
a=[int(x) for x in input().split()]

# find number of integers
count=0
for i in range(n):
    flag=0
    for k in range(i):
        if a[k]==a[i]:
            flag+=1
#    print(flag)
    if flag==0:
        count+=1
#    print("count=",count)

#print(count)

# sort by the number of integers
c=np.zeros((2,n))
#c=np.zeros((2,count))
#for i in range(count):
#    c[i]=0

#c[0,0]=a[0]
#c[1,0]+=1

for i in range(n):
    flag=0
    for k in range(i):
        if c[0,k]==a[i]: #c[0,k]:
            flag+=1
            c[1,k]+=1
#            print(c)
    if flag==0:
        c[0,i]=a[i]
        c[1,i]+=1
#        print(c)
#print(c)    

e=c
if count-m<0:
    print(0)
    sys.exit()

d=np.zeros(count-m)
for l in range(count-m):
    for k in range(n):
#for k in range(count-m):
        small=n
        for i in range(n):
#        for i in range(count):
            if small > e[1,i] and e[1,i]!=0:
                small = e[1,i]
#            print(c[1,i])
    d[l] = small
    for i in range(count):
        if e[1,i]==d[l]:
            e[1,i]=0
#            print('a')
            continue
    
#print(d)

ans=0
for i in range(count-m):
    ans+=d[i]
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

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

l = sorted(d.items(), key=lambda p: p[1])
x = len(l)
ans = 0
for e in l:
    if x <= K:
        break
    x -= e[1]
    ans += e[1]
print(ans)

Submission status: Wrong Answer

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

def make_group(list):
    list.sort()
    group = []
    g_count = 0
    prev = list[0]
    for i in range(N):
        current = list[i]
        if prev != current:
            group.append(g_count)
            g_count = 0
        g_count += 1
        prev = current
        if i == N - 1:
            group.append(g_count)
    return sorted(group)

def calc_moving_count(group):
    group_length = len(group)
    length = max(group_length - K, 0)
    should_move_group = group[:length]
    count = sum(should_move_group)
    return count

def main():
    group = make_group(A)
    print(group)
    count = calc_moving_count(group)
    print(count)

if __name__  == '__main__':
    main()

Submission status: Wrong Answer

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

def make_group(list):
    list.sort()
    group = []
    g_count = 0
    prev = None
    for i in range(N):
        current = list[i]
        g_count += 1
        if prev != current:
            group.append(g_count)
            g_count = 0
        prev = current
    return sorted(group)

def calc_moving_count(group):
    group_length = len(group)
    length = max(group_length - K, 0)
    should_move_group = group[:length]
    count = sum(should_move_group)
    return count

def main():
    group = make_group(A)
    count = calc_moving_count(group)
    print(count)

if __name__  == '__main__':
    main()

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
#abc081c
import collections

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

Submission status: Wrong Answer

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

def make_group(list):
    list.sort()
    group = []
    g_count = 0
    prev = None
    for i in range(N):
        current = list[i]
        g_count += 1
        if prev != current or i == N - 1:
            group.append(g_count)
            g_count = 0
        prev = current
    return sorted(group)

def calc_moving_count(group):
    group_length = len(group)
    length = max(group_length - K, 0)
    should_move_group = group[:length]
    count = sum(should_move_group)
    return count

def main():
    group = make_group(A)
    count = calc_moving_count(group)
    print(count)

if __name__  == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, K = map(int, input().split())
A = list(map(int, input().split()))

num = [0] * 200001
for a in A:
    num[a] += 1

num = list(filter(lambda x: x != 0, num))
num.sort()
print(sum(num[:K - 1]) if (len(num) > K) else 0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, K = map(int, input().split())
A = list(map(int, input().split()))

num = [0] * 200001

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

num.sort()
num = list(filter(lambda x: x != 0, num))
print(sum(num[:K - 1]) if (len(num) > K) else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K >= len(li):
  print(0)
  exit()
for i in li :
  ind = np.take(c,np.where( c== i),axis = 0)
  print(ind)
  d = np.append(d,ind.shape[1])
d = np.sort(d)
for i in range(h):
  Num += d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K >= len(li):
  print(0)
  exit()
for i in li :
  ind = np.take(c,np.where( c== i),axis = 0)
  d = np.append(d,ind.shape[1])
print(d)
for i in range(h):
  Num += d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K >= len(li):
  print(0)
  exit()
for i in li :
  ind = np.take(c,np.where( c== i),axis = 0)
  d = np.append(d,ind.shape)
d = np.sort(d)
print(d)
for i in range(h):
  Num += d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K>len(li):
  print(0)
for i in li :
  ind = c[np.where( c== i)]
  d = np.append(d,ind.shape)
d = np.sort(d)
for i in range(h):
  Num += d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K>len(li):
  print(0)
for i in li :
  ind = c[np.where( c== i)]
  d = np.append(d,ind.shape)
d = np.sort(d)
print(d)
for i in range(h):
  Num += d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K>len(li):
  print(0)
for i in li :
  ind = c[np.where( c== i)]
  d = np.append(d,ind.shape)
d = np.sort(d)
print(d)
for i in range(h):
  Num += d[i]
print(Num)

Submission status: Wrong Answer

Solution code:
import numpy as np
a = list(map(int,input().split()))
N = a[0]
K = a[1]
b = list(map(int,input().split()))
li = list(set(b))
c = np.array(b)
d = np.array([])
h = len(li) -K
Num = 0
if K>len(li):
  print(0)
for i in li :
  ind = c[np.where( c== i)]
  d = np.append(d,ind.shape)
d = np.sort(d)
print(d)
for i in range(h):
  Num = d[i]
print(int(Num))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
mp={}
for e in a:
    if e in mp:
        mp[e]+=1
    else:
        mp[e]=1
l=len(mp)
ans=0
for e,cnt in sorted(mp.items(),key=lambda x:x[1]):
    if l == k:
        break
    ans+=cnt
    l-=1
print(ans)

Submission status: Wrong Answer

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

res = set(num)
while len(res) > k:
	num[num.index(max(num))]=min(num)
	a+=1
	res =set(num)
	
print(a)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
a = 0
b = 0
B = [A[0]]
s = 200001
t = 0
u = 0
for k in range(N):
    if not A[k] in B:
        B.append(A[k])
        a += 1
for i in range(N):
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]
while a >= K:
    a -= 1
    b += 1
    for i in range(N):
        for j in range(N):
            if A[j] == t:
                A[j] = s
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]
#for i in range(N):
print(b)

Submission status: Wrong Answer

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

A_count = dict()
for i in set(A):
	A_count.update({i:len([j for j in A if j == i])})

A_sort = sorted(A_count.values())
if len(A_sort) <= N[1]:
	print("0")
else:
	print(sum(A_sort[:N[1]-1]))

Submission status: Wrong Answer

Solution code:
N, K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
print(A)
a = 0
b = 0
B = [A[0]]
s = 200001
t = 0
u = 0
for k in range(N):
    if not A[k] in B:
        B.append(A[k])
        a += 1
for i in range(N):
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]
while a >= K:
    a -= 1
    b += 1
    for i in range(N):
        for j in range(N):
            if A[j] == t:
                A[j] = s
        if A.count(A[i]) > u:
            u = A.count(A[i])
            v = A[i]
        if A.count(A[i]) < s:
            s = A.count(A[i])
            t = A[i]

#for i in range(N):
print(b)

Submission status: Wrong Answer

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

A_count = dict()
for i in set(A):
	A_count.update({i:len([j for j in A if j == i])})

A_sort = sorted(A_count.values())
print(sum(A_sort[:N[1]-1]))

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))
m = [0 for k in range(n+1)]
ans = 0
for l in range(n):
    m[h[l]] += 1
s = set(m)
while True:
    try:
        m.pop(m.index(0))
    except:
        break
for i in range(len(s)-k):
    num = m.index(min(m))
    ans += num
    m.pop(num)
print(max(ans-1,0))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input())
del listA[" "]
# print(listA)
listA = list(listA.values())
listA.sort()
# print(listA)

num = 0
# print(listA)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        for _ in range(tmp):
            listA[len(listA)-1] += 1
            listA.sort()
        # print(listA)

print(num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N,K=map(int,input().split())
AS=[int(x) for x in input().split()]
nc=Counter(AS)
nckeys=len(nc)
sa=nckeys-K
if sa>0:
    ndch=[x[1] for x in nc.most_common(sa)]
    hw=sum(ndch)
else:
    hw=0
print(hw)

Submission status: Wrong Answer

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

import sys
def g():
    m_l = [0] * (n+1)

    for a in a_l:
        m_l[a] += 1

    print(m_l)

    r = 0
    for m in m_l:
        if m != 0: r+= 1


    if r <= k:
        print(0)
        sys.exit(0)

    mn = 0
    while True:
        mm = min(i for i in m_l if i > 0)

        for i in range(n):
            if mm == m_l[i]:
                mn += mm
                r -= 1
                m_l[i] = 0

                print(r, k, m_l)

                if r <= k: return mn
        
print(g())

Submission status: Wrong Answer

Solution code:
import collections

N,K=input().split(" ")
N = int(N)
K = int(K)
A = input().split(" ")
#temp_list = list(set(A))

test = collections.Counter(A)
test_key = list(test.keys())
#print(type(test_key))
temp = []
for i in test_key:
    temp.append(int(i))
tyouka = K - len(temp)
temp = sorted(temp)
ans = 0 
if tyouka >=0:
    print(0)
else:
    tyouka = -tyouka
    for i in range(tyouka):
        ans += int(temp[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
N,K=map(int,input().split())
AS=[int(x) for x in input().split()]
nc=dd(int)
for i in AS:
    nc[i]+=1
nckeys=len(nc)
sa=nckeys-K
if sa>0:
    ndch=[]
    for i in range(sa):
        ndch.append(int(min(nc[x] for x in nc)))
    hw=sum(ndch)
else:
    hw=0
print(hw)

Submission status: Wrong Answer

Solution code:

n, k = map(int, input().split())
a_s = input().split()

kind = []
for i in range(n):
    a_s[i] = int(a_s[i])
    if a_s[i] in kind:
        pass
    else:
        kind.append(a_s[i])

kind_suuzi = len(kind)
a_s_suuzi = len(a_s)
now_shurui = len(kind)
if k>=kind_suuzi:
    print(0)
else:
    kind_nums = [0 for x in range(kind_suuzi)]
    for i in range(kind_suuzi):
        for ii in range(a_s_suuzi):
            if a_s[ii] == kind[i]:
                kind_nums[i] += 1
    cnt = 0
    kind_nums_sorted = sorted(range(len(kind_nums)), key=kind_nums.__getitem__)
    for i in range(1000000):
        cnt += kind_nums[i]
        now_shurui -= 1
        if k == now_shurui:
            print(cnt)
            break

Submission status: Wrong Answer

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

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

li  = [0] * len(dic)
i   = 0
for d in dic:
    li[i] = dic[d]
    i    += 1

total = 0
li.sort()
if len(li) > int(K):
    for l in li:
        total += l
        li.pop(0)
        if len(li) <= int(K):
            break

print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input())
del listA[" "]
# print(listA)
listA = list(listA.values())
listA.sort()
# print(listA)

num = 0
# print(len(listA),K)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        for _ in range(tmp):
            listA[0] += 1
            listA.sort()

print(num)

Submission status: Wrong Answer

Solution code:
import collections

N,K=input().split(" ")
N = int(N)
K = int(K)
A = input().split(" ")
#temp_list = list(set(A))

test = collections.Counter(A)
test_key = list(test.keys())
#print(type(test_key))
temp = []
for i in test_key:
    temp.append(int(i))
tyouka = K - len(temp)
temp = sorted(temp)
ans = 0 
if tyouka >=0:
    print(ans)
else:
    tyouka = -tyouka 
    for i in range(tyouka):
        ans += int(temp[i])
    print(ans)

Submission status: Wrong Answer

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

m_l = [0] * (n+1)

for a in a_l:
    m_l[a] += 1

r = 0
for m in m_l:
    if m != 0: r+= 1

import sys
if r <= k:
    print(0)
    sys.exit(0)

mn = 0
while True:
    mm = n
    for i in range(n):
        if a_l[i] != 0 and mm >= a_l[i]:
           mm = a_l[i]
           a_l[i] = 0

    mn += mm
    r -= 1
    if r <= k: break

print(mn)

Submission status: Wrong Answer

Solution code:
import collections

N,K=input().split(" ")
N = int(N)
K = int(K)
A = input().split(" ")
#temp_list = list(set(A))

test = collections.Counter(A)
test_key = list(test.keys())
#print(type(test_key))
temp = []
for i in test_key:
    temp.append(int(i))
tyouka = K - len(temp)
temp = sorted(temp)
ans = 0 
if tyouka >0:
    print(ans)
else:
    tyouka = -tyouka 
    for i in range(tyouka):
        ans += int(temp[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
li=sorted(list(map(int,input().split())))
keys=set(li)
knum=len(keys)
if knum <= k:
    print(0)
    quit()
li=[]
for key in keys:
    li.append(li.count(key))
print(sum(sorted(li,reverse=True)[k:]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input())
del listA[" "]
# print(listA)
listA = list(listA.values())
listA.sort()
# print(listA)

num = 0
# print(len(listA),K)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        # print(listA[len(listA)-1])
        listA[0] += tmp
        listA.sort()
        #  print(listA)


print(num)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
counter = [] #要素の種類別にいくつあるかを並べたもの
x = 0
count = 1
while x < n-1:
	for i in range(n-x-1):
		if a[x] == a[x+1+i]:
			count += 1
		else:
			break
	counter.append(count)
	x = x+1+i
	count = 1
if a[n-2] != a[n-1]:
	counter.append(1)
counter.sort()
print(counter)

y = len(counter)
l = y
answer = 0
for i in range(y): #同じ種類の要素が少ないものから順に書き換える
	if l > k:
		answer += counter[i]
		l = l - 1
	else:
		break
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input())
del listA[" "]
# print(listA)
listA = list(listA.values())
listA.sort()

num = 0
# print(len(listA),K)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        # print(listA[len(listA)-1])
        listA[len(listA)-1] += tmp
        # print(listA[len(listA)-1])
        # print(listA)


print(num)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, K = list(map(int,input().split()))
listA = Counter(input())
del listA[" "]
# print(listA)
listA = list(listA.values())
listA.sort()

num = 0
# print(len(listA),K)
if len(listA) <= K:
    num = 0
else:
    while len(listA) > K:
        tmp = listA.pop(0)
        num += tmp
        listA[len(listA)-1] += 1

print(num)

Submission status: Wrong Answer

Solution code:
N , K = list(map(int,input().split()))
li = list(map(int,input().split()))
typ = []
li.sort()
count = 0 
for i in range(N - 1): 
    count += 1
    if li[i] != li[i + 1]: 
        typ.append(count)
if li[N -1] != li[N - 2]: 
    typ.append(1)
else:
    typ.append(count)
typ.sort()
count = 0 
if len(typ) > K:
    for i in range(len(typ) - K): 
        count += typ[i]
print(count)

Submission status: Wrong Answer

Solution code:
import collections

N,K=input().split(" ")
N = int(N)
K = int(K)
A = input().split(" ")
temp_list = list(set(A))

judge = K - len(temp_list)
test = collections.Counter(A)
test_key = list(test.keys())
#print(type(test_key))
temp = []
for i in test_key:
    temp.append(int(i))
temp = sorted(temp)
judge = True
ans = 0
while judge:
    if K - len(temp)>=0:
        judge = False
        print(ans)
    else:
        ans+=temp[0]
        del temp[0]