Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

1 \leq K \leq N \leq 200000

1 \leq A_i \leq N

All input values are integers.

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 ... A_N

Output

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

Sample Input 1

5 2
1 1 2 2 5

Sample Output 1

1

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

Sample Input 2

4 4
1 1 2 2

Sample Output 2

0

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

Sample Input 3

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

Sample Output 3

3



Sample input:
5 2
1 1 2 2 5


Sample output:
1

Submission status: Accepted

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

num.sort(reverse=True)
ans = 0

for c in num[k:] :
    if c == 0 :
        break
    ans += c

print(ans)

Submission status: Accepted

Solution code:
n, k = map(int, raw_input().split())
a = map(int, raw_input().split())
s = set(a)
if len(s) < k:
    print 0
    exit()
d = dict()
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
cnt = 0
for i in sorted(d.values())[:len(s) - k]:
    cnt += i
print cnt

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys,collections
from collections import deque
from operator import itemgetter
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n,k = Is()
a = Is()
d = collections.defaultdict(int)
for i in range(len(a)):
    d[a[i]] += 1 
dl = sorted(list(d.items()),key=itemgetter(1))
ans = 0
for i in range(len(dl)):
    if len(d) <= k:
        break
    ans += dl[i][1]
    del d[dl[i][0]]
print(ans)

Submission status: Accepted

Solution code:
N, K= map(int, input().split())
A = map(int, input().split())
d = {}
for a in A:
    if a in d:
        d[a] = d[a] + 1
    else:
        d[a] = 1
o = []
for k, v in d.items():
    o.append(v)
o = sorted(o, reverse=True)

if K >= len(o):
    print(0)
else:
    print(sum(o[K:]))

Submission status: Accepted

Solution code:
from collections import Counter

n,k = map(int, input().split())
a = input().split()
c = Counter(a)
t = len(c) - k
r = 0

if t > 0:
    serial = c.most_common()[-t:]
    for s in serial:
        r += s[1]

print(r)

Submission status: Accepted

Solution code:
def solve():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    num_dict = {}
    for i, num in enumerate(A):
        if not num in num_dict:
            num_dict[num] = 1
        else:
            num_dict[num] = num_dict[num] + 1
    cnt, ans = 0, 0
    num_dict_size = len(num_dict)
    for k, v in sorted(num_dict.items(), key =lambda x: x[1]):
        if cnt >= num_dict_size - K:
            print(ans)
            return
        else:
            ans += v
            cnt += 1
        
solve()

Submission status: Accepted

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

nk = raw_input()
nk = nk.split()
n,k = map(int,nk)

a = raw_input()
a = a.split()
a = map(int,a)

d = {}

for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1

l = d.values()

ans = 0

if len(l) <= k:
    pass
else:
    l.sort()
    for i in range(len(l)-k):
        ans += l[i]

print ans

Submission status: Accepted

Solution code:
n, k = map(int, input().split())
dic = {}
a = map(int, input().split())
for i in a:
    if int(i) in dic:
        dic[int(i)] += 1
    else:
        dic[int(i)] = 1
len_all = len(dic.keys())
a = [[i, dic[i]] for i in dic.keys()]
a = sorted(a, key=lambda x: x[1])

ans = 0
if k == len_all:
    print(0)
else:
    for i in range(len_all - k):
        ans += a[i][1]
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

cnt = list(Counter(As).values())
cnt.sort(reverse=True)

print(sum(cnt[K:]))

Submission status: Accepted

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

data={}

for num in A:
        if num in data:
                data[num]+=1
        else:
                data[num]=1
num=[int(i) for i in data.values()]
#type(num)
num.sort()

num.reverse()

ans=sum(num)

if len(num)<=K:
        print(0)
else:
        for i in range(K):
                ans-=num[i]
        print(ans)

Submission status: Accepted

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

cnt = {}

for a in A:
    if a not in cnt:
        cnt[a] = 0
    cnt[a] += 1

cnt = sorted(cnt.items(), key=lambda x: x[1])
ans = 0

for i in range(len(cnt)):
    if len(cnt) - i <= K:
        break
    ans += cnt[i][1]

print(ans)

Submission status: Accepted

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

cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
ls = []
for ai, c in cnt.items():
    ls.append((c, ai))
ls.sort()
ans = 0
for i in range(len(ls) - k):
    ans += ls[i][0]
print(ans)

Submission status: Accepted

Solution code:
eN, K = map(int, input().split())
d = {}
for a in input().split():
    a = int(a)
    d[a] = d.get(a, 0) + 1
if len(d) <= K:
    print(0)
else:
    aa = list(sorted(d, key=lambda a: d[a]))
    print(sum(d[a] for a in aa[:len(aa)-K]))

Submission status: Accepted

Solution code:
from collections import Counter
N,K = map(int,input().split())
src = list(map(int,input().split()))
ctr = Counter(src)

if len(ctr) <= K:
    print(0)
else:
    print(sum(sorted(ctr.values())[:len(ctr) - K]))

Submission status: Accepted

Solution code:
from collections import Counter
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
C = Counter(A)
V = [C[k] for k in C]
V.sort()
if(len(V) <= K):
    print(0)
else:
    print(sum(V[:len(V)-K]))

Submission status: Accepted

Solution code:
from collections import Counter

def solve():
  N,K = map(int,input().split())

  counter = Counter(map(int,input().split()))

  k = len(counter)

  if k <= K:
    return 0

  n = k-K
  return sum(sorted(counter.values())[:n])

print(solve())

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, K = list(map(int, sys.stdin.readline().rstrip().split()))
As = list(map(int, sys.stdin.readline().rstrip().split()))

count = collections.defaultdict(int)

for A in As:
    count[A] += 1

values = list(sorted(count.values()))

print(sum(values[:len(values)-K]))
exit(0)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    c = Counter(A)
    v = list(sorted(c.values()))
    if len(v) <= K:
        print(0)
        return
    print(sum(v[:-K]))






if __name__ == '__main__':
    main()

Submission status: Accepted

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

B.sort()
B.reverse()

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

Submission status: Accepted

Solution code:
from collections import Counter
N, K = map(int, input().split())
counter = Counter(input().split())
arr = counter.most_common()
print(sum(map(lambda x:x[1], arr[K:])))

Submission status: Accepted

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*200000
for i in a:
    l[i-1] += 1
l = sorted(l)
s = len(list(set(a)))
ret = 0
for i in range(s-k):
    ret += l[-s+i]
print(ret)

Submission status: Accepted

Solution code:
from collections import Counter

N, K = map(int, raw_input().split())
A = map(int, raw_input().split())
C = Counter(A)
D = C.items()[:]
D.sort(key=lambda x: x[1])

ans = 0
X = len(D)
for e, v in D:
    if X > K:
        ans += v
    X -= 1
print ans

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
def inpl(): return tuple(map(int, input().split()))

N, K = inpl()
A = inpl()
C = Counter(A)

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

Submission status: Accepted

Solution code:
from collections import Counter
from operator import itemgetter

n, k = map(int, input().split())
a = Counter(map(int, input().split()))
sa = sorted(a.items(), key=itemgetter(1), reverse=True)

if len(sa) <= k:
    print(0)
else:
    print(sum(c for m, c in sa[k:]))

Submission status: Accepted

Solution code:
from collections import defaultdict

n, k = map(int, raw_input().split())
a = map(int, raw_input().split())


d = defaultdict(int)

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


s = d.values()

s = sorted(s)[::-1]
print sum(s[k:])

Submission status: Accepted

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**15
mod = 10**9+7

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 S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    a = LI()
    d = collections.defaultdict(int)
    for c in a:
        d[c] += 1
    s = sum(sorted(d.values(), reverse=True)[:k])

    return n - s



print(main())

Submission status: Runtime Error

Solution code:
import collections as c
N,K,*A= map(int,open(0).read().split())
ans=0
C=c.Counter(A)
C=sorted(C.values())

for i in range(N):
  if len(C)<=K:
    break
  ans+=C[i]
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
tab=[0 for i in range(n+1)]
for num in A:
    tab[num]+=1
tab.sort(reverse=True)
print(n-10 sum(tab[:k]))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(set(a))
if(len(b)<=k):
  print(0)
else:
  s = []
  for i in range(len(b)):
    s.append(a.count(b[i]))
  s.sort()
  ans = sum(s[:len(b-k)])
  print(ans)

Submission status: Runtime Error

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

for i in range(n):
    if not a[i] in kaburi:
        kaburi.append(a[i])

kaisu = 0

while True:
    p = n
    q = 0
    if k >= len(kaburi):
        print(kaisu)
        break
    else:
        for j in range(len(kaburi)):
            p = min(p,a.count(kaburi[j]))
            if p > a.count(kaburi[j]):
                q = kaburi[j]
        kaisu += p
        print(p,q,kaisu,len(kaburi))
        kaburi.remove(q)

Submission status: Runtime Error

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

dic = {}

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

li = [0] * N

for a in dic:
    li[dic[a]] += 1

ans = 0
k = len(dic)

for i in range(N):
    if li[i] > 0:
        if k - li[i] >= K:
            ans += i * li[i]
            k -= li[i]
        else:
            ans += i * (k - li[i])
            k -= li[i]

    if k <= K:
        break

print(ans)

Submission status: Runtime Error

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

a1 = sorted(a)
a2 = []
count = 0
for i in range(n - 1):
    if a1[i] == a1[i + 1]:
        count += 1
    else:
        a2.append(count)
        break
a2.append(count)
l = sorted(a2)
print(sun(l[:len(l) - k - 1]))

Submission status: Runtime Error

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

cnt_l = [0]*10**5
num = []
ans = 0

for i in A:
    cnt_l[i] += 1
    if i not in num:
        num.append(i)

cnt_l.sort()

cnt_l = cnt_l[10**5-len(num):]

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

cnt_l = cnt_l[:k-1]

print(sum(cnt_l))

Submission status: Runtime Error

Solution code:
import math
import sys
import collections
n,k = map(int, input().split())
A = list(map(int, input().split()))
count=len(A)
Adel=list(set(A))
ans=len(Adel)-k
#print(Adel)
if ans<0:
    ans=0
    print(ans)
    sys.exit()
newA=collections.Counter(A)
ans=len(Adel)
Aans=n
for i in range(k+1):
    count=newA.most_common()[i][i]
    #print(count)
    ans=ans-1
    Aans=Aans-count
    if ans==k:
        print(n-Aans)
        sys.exit()
    #print(count)
#print(newA)
#print(A)

Submission status: Runtime Error

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

d = Counter(A)
d.most_common()
n =len(d)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)

Submission status: Runtime Error

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

d = Counter(A)
d.most_common()
n =len(d_)
ans = 0
if n <= K:
    print(0)
    exit()
else:
    for i in range(K,n):
        ans += d[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K=map(int,input().split())
N=list(map(int,input().split()))
A=Counter(N)
C=list(A.values())
C=C.sort(reverse=True)
if len(C)<=K:
    print(0)
else:
    ans=sum(C[-(len(C)-K):])
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K=map(int,input().split())
N=list(map(int,input().split()))
A=Counter(N)
C=list(A.values())
C=C.sort(reverse=True)
print(C)
if len(C)<=K:
    print(0)
else:
    ans=sum(C[-(len(C)-K):])
    print(ans)

Submission status: Runtime Error

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

Aset =list(set(A))
B=[0]*len(Aset)
cnt =0

for i in range(len(Aset)):
  for j in range(len(A)):
    if Aset[i] == A[j]:
      cnt += 1
  B[i] = cnt
  cnt =0

B=sorted(B)[::-1]  

ans =0

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
a = list(map(int,input().split()))
ans = []
for num in list(set(a)):
    ans.append(a.count(num))
ans.sort(reverse=True)
for i in range(k):
    ans.pop(0)
print(sum(ans))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
t=list()
ans=0
vari=0
A_set=set(A)
if len(A_set)<=K:
    print(0)
else:
    vari=len(A_set)
    while vari>K:
        ans+=min(A)
        tmp=min(A)
        A[A.index(min(A))]=200001
        vari=len(set(A)-1)
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
print(n * 2 - 1)
ma, mi = max(a), min(a)
ima, imi = a.index(ma), a.index(mi)
if abs(ma) > abs(mi):
    for i in range(1, n + 1):
        print(ima + 1, i)
    for i in range(1, n):
        print(i, i + 1)
else:
    for i in range(1, n + 1):
        print(imi + 1, i)
    for i in range(1, n):
        print(i + 1, i)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

C = Counter(A).most_common()
L = len(C)

if L <= K:
  print(0)
  exit()

ans = 0
cnt = 0
for v in C.values():
  cnt += 1
  if K < cnt:
    ans += v
    
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

n, m = map(int, input().split())
dic = Counter(map(int, input().split()))
lis = sorted(dic.items(), key=lambda x: x[1], reverse=True)

res = 0
for i in range(m):
    res += lis[i][1]
print(n - res)

Submission status: Runtime Error

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

for i in a:
    if i in cnt.keys():
        cnt[i] += 1
    else:
        cnt[i] = 1

ans, k = 0, len(cnt) - k
for i in range(len(cnt) + 1):
    if 0 >= k:
        print(ans)
        break
    ans += cnt[i][1]
    k -= 1

Submission status: Runtime Error

Solution code:
n, k=map(int, input().split())
a=list(map(int, input().split()))
table=[0]*(n+1)

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

table.sort()
now_length=[]
for count in table:
    if count!=0:
        now_length.append(count)

if len(now_length)<=k:
    print(0)
else:
    ans=0
    i=0
    while len(now_length)!=k:
        ans+=now_length[i]
        now_length.remove(now_length[i])
        i+=1

    print(ans)

Submission status: Runtime Error

Solution code:
import collections
a,b = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = set(ar)
cr = collections.Counter(ar)
n = len(br) - b
dr = []
for k in cr.keys():
    cr.append(k)
cr.sort()
count = 0
for i in range(n):
    count += cr[i]

Submission status: Runtime Error

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

# 減らす種類の個数
SS = len(AS) - K

re = []
for ass in AS:
    re.append(ass)

sorted(re)

print(len(re[::SS]))

Submission status: Runtime Error

Solution code:
def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d

n, k = list(map(int, input().rstrip().split()))
print(sum(sorted(mycounter(list(map(int, input().rstrip().split()))).values(), reverse=True)[k:]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ans = n
    for i in range(k):
        ans -= kv[i][1]
    print(ans)

Submission status: Runtime Error

Solution code:
N, = map(int, input().split())
A = map(int, input().split())
from collections import defaultdict
d = defaultdict(int)
for a in A:
    d[a] += 1
r = 0
for a in d:
    if a > d[a]:
        r += d[a]
    else:
        r += d[a]-a
print(r)

Submission status: Runtime Error

Solution code:
import numpy as np
n,k = map(int,input().split())
L = list( map(int,input().split()))
L = np.array(L)
set1,cnt = np.unique(L,return_counts = True)
cnt1 = sorted(cnt)
print(sum(cnt1[:len(cnt1)-k]))

Submission status: Runtime Error

Solution code:
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
t = 0
ans = n

l = collections.Counter(a)
x = l.most_common(k)

for i in range(k):
    t += x[i][1]

ans -= t
if ans < 0:
    ans = 0
print(ans)

Submission status: Runtime Error

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

for i in range (N):
  for j in range (N-1):
    if a[j]>a[j+1]:
      g=a[j]
      a[j]=a[j+1]
      a[j+1]=g
    
count=1
size=0
b=[]
for p in range (N-1):
  if a[p]==a[p+1]:
    count+=1
  else:
    b.append(count)
    count=1
    size+=1

for q in range (size):
  for r in range (size-1):
    if b[r]<b[r+1]:
      g=b[r]
      b[r]=b[r+1]
      b[r+1]=g

s=0
for u in range (K):
  s+=b[u]

print(N-s)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    A = Scanner.map_int()
    M = [[] for i in range(N)]
    for k, v in Counter(A).items():
        M[v].append(k)
    cnt = 0
    for i in M:
        cnt += len(i)
    ans = 0
    for i in range(len(M)):
        if cnt <= K:
            break
        while M[i] != []:
            cnt -= 1
            ans += i
            M[i].pop(0)
            if cnt <= K:
                break
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import collections
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
if len(c)<= K:
    print(0)
    sys.exit()
for i in range(K):
    cnt += c.most_common()[i][1]    
print(N-cnt)

Submission status: Runtime Error

Solution code:
import collections
import sys
N,K = map(int,input().split())
A = list(map(int,input().split()))
c = collections.Counter(A)
if len(c)<= K:
  print(0)
  sys.exit()
for i in range(K):
    cnt += c.most_common()[i][1]
    if cnt >= K:

print(N-cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

cnt=0
bflag=False
sflag=False

for i in range(1,N):
  if A[i]>A[i-1]:
    if sflag==True:
      cnt+=1
      bflag=False
      sflag=False
    else:
      bflag=True
      sflag=False
  elif A[i]<A[i-1]:
    if bflag==True:
      cnt+=1
      bflag=False
      sflag=False
    else:  
      bflag=False
      sflag=True    
  else:
    pass
    
print(cnt+1)

Submission status: Runtime Error

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

import sys
import collections
c = collections.Counter(t)
c=sorted(list(c.values()))
ans=0
delete_count=len(c)-k
if delete_count<=0:
    print(0)
    sys.exit()
else:
    for i in range(delete_count):
        if len(c)>k:
            ans+=c[i]
            
print(ans)
sys.exit()

Submission status: Runtime Error

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

import sys
import collections
c = collections.Counter(t)
c=sorted(list(c.values()))
ans=0
delete_count=len(c)-k
if delete_count<=0:
    print(0)
else:
    for i in range(delete_count):
        if len(c)>k:
            ans+=c[i]
            
print(ans)
sys.exit()

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0 for i in range(n)]
z=set(a)
y=len(z)
for x in a:
    s[x]+=1
b=sorted(s)
f=0
ans=0
for x in b:
    if x!=0:
        f+=1
        ans+=x
    if f>=y-k:
      	break
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for key in a_li:
    d[key] += 1
d = sorted(d.items(), key=lambda x:x[1])

if k >= len(d):
    print(0)
    eixt()
    
s = len(d) - k
ans = 0

for i in range(s):
    ans += d[i][1]
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
import heapq
from collections import Counter

#N,K=map(int, input[].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

S=Counter(A)
s= S.most_common(K)

print(N-[sum(x) for x in zip(*s)][1])

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    REP(i,n) cin>>a[i];

    sort(ALL(a));
    vector<int> cnt;
    int c=1;
    REP(i,n){
        if(i==0) continue;
        if(a[i-1]==a[i]) c++;
        if(a[i-1]!=a[i] || i==n-1){
            cnt.push_back(c);
            c=1;
        }
    }
    sort(ALL(cnt),greater<int>());
    int ans=n;
    REP(i,k) ans-=cnt[i];
    cout<<ans<<endl;

	return 0; 
}

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n,k = map(int,input().split())
nums = input().split()
count_per_num = defaultdict(int)
for n in nums:
  count_per_num[n] += 1
count_per_nums = sorted(count_per_nums, key=lambda x:x[1])
ans = 0
for i in range(len(count_per_nums)-k):
  ans += count_per_nums[i]
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)
d=c.most_common()
ans=0
for i in range(k):
  ans+=d[i][1]
print(n-ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
n,k= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
s = [0 for i in range(200000)]
for i in range(n):
    s[a[i]]+=1
st = [i for i in s if s[i]]
st.sort()
total = 0
while len(st)>k:
    total+=st.pop(0)
print(total)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
d = [a for a in Counter(A).values()]
tmp = 0
for i in range(min(K,len(d)+1)):
    tmp += max(d)
    d.remove(max(d))
print(len(A)-tmp)

Submission status: Runtime Error

Solution code:
from collections import Counter
N,K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
d = [a for a in Counter(A).values()]
tmp = 0
for i in range(min(K,len(set(d))+1)):
    tmp += max(d)
    d.remove(max(d))
print(len(A)-tmp)

Submission status: Runtime Error

Solution code:
from collections import Counter
N, K = map(int, input().split())
A = list(map(int, input().split()))
dA = Counter(A)
if len(dA) - K <= 0:
  print(0)
  exit()
print(sum(sorted(dA.values())[:len(dA)-K])))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
m=list(d.keys())
m.sort()
n-=k
for i in m:
  if n<=0:
    break
  n-=d[i]
  ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
d=dict()
for i in map(int,input().split()):
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
m=d.keys()
m.sort()
n-=k
for i in m:
  if n<=0:
    break
  n-=d[i]
  ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
import collections
data = list(map(int,input().split()))
da = list(map(int,input().split()))
ta = collections.Counter(da)
dt = ta.most_common(data[1])

for i in range(data[1]):
  data[0] -= dt[i][1]
  
print(data[0])

Submission status: Runtime Error

Solution code:
import collections
data = list(map(int,input().split()))
da = list(map(int,input().split()))
ta = collections.Counter(da)
dt = ta.most_common(data[1])
for k, v in dt.items():
  data[0] -= int(v)
  
print(data[0])

Submission status: Runtime Error

Solution code:
lis = list(map(int, input().split()))
lis2 = list(map(int, input().split()))
n = lis[0]
k = lis[1]
d = {}

for i in range(n):
    if lis2[i] not in d.keys():
       d[lis2[i]] = 1
    else:
        d[lis2[i]] += 1 
        
if len(b) <= k:
    print(0)
else:
    a = list(d.values())
    a.sort()
    a.reverse()
    swap = 0
    for i in range(k,len(a)):
        swap += a[i]
    print(swap)