Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
binary = [0 for _ in range(n)]
ls = list(map(int, input().split()))
for i in ls:
    binary[i-1] += 1
binary = sorted(binary)
binary.pop(binary.index(0))

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

Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

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

Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
binary = [0 for _ in range(n)]
ls = list(map(int, input().split()))
for i in ls:
    binary[i-1] += 1
binary = sorted(binary)

ans = 0
while k < len(binary):
    ans += binary[0]
    binary.pop(0)
print(ans)

Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
c = Counter(A)
ans = 0

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

Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
c = Counter(A)
ans = 0


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


Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
a = list(map(int, input().split()))
setA = set(a)
countNum = {}
ans = 0
for i in setA:
    countNum[i] = a.count(i)
max_v = max(countNum.values())

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


Fixed submission:
from collections import Counter

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

c = Counter(A)
d = sorted(c.values())
l = len(d)
print(sum(d[0:l-K]))