Problem p03495 (python)

Fixed submission:
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * (N+1)


for i in A:
    var[i] += 1
    
var = sorted(var,  reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print(0)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * N+1


for i in A:
    var[i] += 1
    
var = sorted(var,  reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * N+1


for i in A:
    var[i] += 1
    
var.sort( reverse = True )


count = 0
for j in range( K, N+1 ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

var = [0] * 21000


for i in range(N):
    var[A[i]] += 1
    
var.sort( reverse = True )


count = 0
for j in range( K, N ):
    if var[j] == 0:
        break
    
    if var[j] != 0:
        count += var[j]
        
print(count)

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

nums=[0] * 21000
var = [0] * 21000

for i in range(N):
    nums[A[i]] += 1
    var[A[i]] = 1
    
VAR = sum(var)
s_nums = sorted(nums, reverse = True)
ans = 0
# flag = 0
# for j in range(N):
if VAR <= K:
    print(0)
        
        
if VAR > K:
    for k in range(K):
        ans += s_nums[k]
    print(N - ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if s_nums[j] != 0 and count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print("0")

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list( map(int, input().split()) ) #ここでN個受け取る

flags = [0] * 21000
nums = [0] * 21000

for i in range(N):
    flags[A[i]] = 1
    nums[A[i]] += 1
    
s_nums = sorted(nums)
count = 0
ans = 0

if sum(flags) - K > 0:
    for j in range(len(s_nums)):
        if s_nums[j] != 0 and count < sum(flags)-K:
            ans += s_nums[j]
            count += 1
            
    print(ans)
    
else :
    print(0)