Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
input = sys.stdin.readline

N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1

List_sorted = sorted(List.items(), key=lambda x:x[1])
tmp=0
Num=len(List_sorted)-K

for i in range(Num):
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


Fixed submission:
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys
input = sys.stdin.readline

N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1

List_sorted = sorted(List.items(), key=lambda x:x[1])
tmp=0
Num=len(List_sorted)-K

for i in range(Num):
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


Fixed submission:
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1

List_sorted = sorted(List.items(), key=lambda x:x[1])
tmp=0
Num=len(List_sorted)-K

for i in range(Num):
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


Fixed submission:
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1
#c = collections.Counter(List)
#print(min((v, k) for k, v in List.items()))
List_sorted = sorted(List.items(), key=lambda x:x[1])
tmp=0
while(True):
    if(len(List_sorted)<=K):break
    tmp+=list(List_sorted[0])[1]
    del List_sorted[0]

print(tmp)


Fixed submission:
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N,K = map(int, input().split())
A = list(map(int, input().split()))
List = {}
for i in A:
    if List.get(i,None)==None:
        List[i]=1
    else:
        List[i]+=1
#c = collections.Counter(List)
#print(min((v, k) for k, v in List.items()))
tmp=0
while(True):
    c = collections.Counter(List)
    if(len(c)<=K):break
    Str=min((v, k) for k, v in List.items())
    tmp+=int(Str[0])
    del List[int(Str[1])]

print(tmp)


Fixed submission:
import heapq

N,K=map(int,input().split())
A=list(map(int,input().split()))
l=[0]*max(A)
ans=0
for item in A:
    l[item-1]+=1
    
heapq.heapify(l)

while len(l)>K:
    ans+=heapq.heappop(l)
    
print(ans)