Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for a in A:
    if a not in num:
        num.append(a)
        cnt.append(1)
    else:
        cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)
  

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
lst = list(map(int,input().split()))

a = [0]*n
for i in range(n):
  a[i]=lst.count(i+1)
a.sort(reverse=True)
ans = 0
for i in range(k):
  if a[i] == 0:
    ans = n
  else:
    ans += a[i]
print(n-ans)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
lst = list(map(int,input().split()))

a = [0]*200000
for i in range(200000):
  a[i]=lst.count(i+1)
a.sort()
ans = 0
for i in range(k):
  if a[-1] == 0:
    ans = n
  else:
    ans += a[-1]
    del a[-1]
print(n-ans)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
lst = list(map(int,input().split()))

a=[]#種類の記憶
for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
c.sort()
ans = 0
if k < len(c):
  for i in range(k):
    ans += c[-1]
    del c[-1]
  print(n-ans)
else:
  print(0)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
lst = list(map(int,input().split()))

a=[]#種類の記憶

for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
ans = 0
while k < len(c):
  i = c.index(min(c)) #最小の個数のインデックス
  ans += min(c)
  del c[i]
print(ans)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
lst = list(map(int,input().split()))

a=[]#種類の記憶
for i in range(n):
  if a.count(lst[i]) == 0:
    a.append(lst[i])
c=[]#カウント用
for j in a:
  c.append(lst.count(j))
ans = 0
while k < len(a):
  i = c.index(min(c)) #最小の個数のインデックス
  ans += min(c)
  del a[i]
  del c[i]
print(ans)

Fixed submission:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

num = []
cnt = []

for i in range(N):
    if i == 0:
        num.append(A[i])
        cnt.append(1)
    else:
        if A[i-1] != A[i]:
            num.append(A[i])
            cnt.append(1)
        else:
            cnt[-1] += 1
cnt.sort()
#print(num,cnt)

res = 0
M = len(cnt)
if M <= K:
    res = 0
else:
    for i in range(M-K):
        res += cnt[i]
print(res)