ZhenlongDai/ACPR huggingface dataset:
Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
result = max(h)-min(h)
for i in range(N-K+1):
  tmp = h[i+K-1]-h[i]
  min(result, tmp)

print(result)

Failing test case input:
5 3
14
15
17
14
12

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
result = max(h) - min(h)
for i in range(N-K+1):
  tmp = h[i+K-1]-h[i]
  result = min(result, tmp)

print(result)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=(int(x) for x in input().split())
i=1
p=[]
while i<=N:
    p.append(int(input()))
    i=i+1

p.sort()
high=[]
i=0
while i+K<=N:
        L=int(K+i)
        a = p[int(L-1)]
        b = p[i]
        deff = int(a - b)
        high.append(int(deff))
        i = i + 1

print(p)
print(high)
print(int(min(high)))

Failing test case input:
3 3
10
15
33
14
12

Expected output:
23


Actual output:
[10, 15, 33]
[23]
23


Fixed submission (verdict: Accepted):
N,K=(int(x) for x in input().split())
i=1
p=[]
while i<=N:
    p.append(int(input()))
    i=i+1

p.sort()
high=[]
i=0
while i+K<=N:
        L=int(K+i)
        a = p[int(L-1)]
        b = p[i]
        deff = int(a - b)
        high.append(int(deff))
        i = i + 1

print(int(min(high)))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n_k=list(map(int,input().split()))
n,k=n_k[0],n_k[1]
h_list=[]
for i in range(n):
    h_list.append(int(input()))
h_list.sort()
max = 99999999
for i in range(n-k+1):
    if max>h_list[n-1]-h_list[n-k]:
        max=h_list[n-1]-h_list[n-k]
print(max)

Failing test case input:
5 3
5
7
10
0
6

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n_k = list(map(int, input().split()))
n, k = n_k[0], n_k[1]
tree_list = []
for i in range(n):
    tree_list.append(int(input()))
tree_list.sort()
min = 999999999
for i in range(n-k+1):
    if tree_list[i+k-1]-tree_list[i] <= min:

        min = tree_list[i+k-1]-tree_list[i]
print(int(min))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i-k])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)

Failing test case input:
3 3
5
7
10
0
13

Expected output:
5


Actual output:
0


Fixed submission (verdict: Accepted):
m = input()
n = int(m.split()[0])
k = int(m.split()[1])
t = []
for i in range(n):
    t.append(int(input()))
t.sort()
a = None
for i in range(len(t)-k+1):
    w = abs(-1*t[i] + t[i+k-1])
    if i == 0:
        a = w
    elif a > w:
        a = w
print(a)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
h=[i for i in range(n)]
h.sort()
l=[]
for i in range(len(h)-k+1):
  l.append(abs(h[i]-h[i+k-1]))
print(min(l))

Failing test case input:
5 4
10
21
39
0
8

Expected output:
21


Actual output:
3


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
l=[]
for i in range(len(h)-k+1):
  l.append(abs(h[i]-h[i+k-1]))
print(min(l))

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = h[-1] - h[0]

for i in range(K - 1, N):
    ans = min(ans, h[i] - h[i - 2])

print(ans)

Failing test case input:
5 2
6
7
10
0
7

Expected output:
0


Actual output:
-4


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = h[-1] - h[0]

for i in range(K - 1, N):
    ans = min(ans, h[i] - h[i - K + 1])

print(ans)

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
h.sort()
res = 10**9
for i in range(N-K):
    if res > h[i+K-1]-h[i]:
        res = h[i+K-1]-h[i]
print(res)

Failing test case input:
3 3
5
7
0
1
7

Expected output:
7


Actual output:
1000000000


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
h.sort()
res = 10**9
for i in range(N-K+1):
    if res > h[i+K-1]-h[i]:
        res = h[i+K-1]-h[i]
print(res)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()


answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    x = heights[i:i + k]
    print(x)
    candidate = max(x) - min(x)
    if candidate < answer:
        answer = candidate

print(answer)

Failing test case input:
5 3
5
21
4
0
6

Expected output:
2


Actual output:
[0, 4, 5]
[4, 5, 6]
[5, 6, 21]
2


Fixed submission (verdict: Accepted):
n, k = [int(i) for i in input().split()]
heights = [int(input()) for i in range(n)]

heights.sort()


answer = max(heights) - min(heights)

for i in range(0, n-k+1):
    candidate = heights[i+k-1] - heights[i]
    if candidate < answer:
        answer = candidate

print(answer)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N ,K = map(int, input().split())
a = [int(input()) for i in range(N)]
a = sorted(a)
res = float('inf')

for i in range(N - K):
  if res > a[i+K-1] - a[i]:
    res = a[i+K-1] - a[i]

print(res)




Failing test case input:
4 3
10
21
21
0
10

Expected output:
11


Actual output:
21


Fixed submission (verdict: Accepted):
N ,K = map(int, input().split())
a = [int(input()) for i in range(N)]
a = sorted(a)
res = float('inf')

for i in range(N - K + 1):
  if res > a[i+K-1] - a[i]:
    res = a[i+K-1] - a[i]

print(res)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i]) for i in range(N-K+1))

Failing test case input:
4 3
10
21
11
0
6

Expected output:
11


Actual output:
<generator object <genexpr> at 0x7fad1f5acc70>


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))

H.sort()

print(H)

ans=H[n-1]-H[0]

for i in range(n-k+1):
    
    ans=min(ans,H[i+k-1]-H[i])

print(ans)


Failing test case input:
5 1
5
1
10
0
11

Expected output:
0


Actual output:
[0, 1, 5, 10, 11]
0


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
H=[]
for i in range(n):
    H.append(int(input()))

H.sort()



ans=H[n-1]-H[0]

for i in range(n-k+1):
    
    ans=min(ans,H[i+k-1]-H[i])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h_list = []
for i in range(N):
    h_list.append(int(input()))
h_list.sort()
ans = 10**10
for i in range(N-K):
    ans = min(ans,h_list[i+K-1]-h_list[i])
print(ans)

Failing test case input:
5 4
10
21
28
0
8

Expected output:
20


Actual output:
21


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h_list = []
for i in range(N):
    h_list.append(int(input()))
h_list.sort()
ans = 10**10
for i in range(N-K+1):
    ans = min(ans,h_list[i+K-1]-h_list[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

n,k = input().split()
n = int(n)
k = int(k)
h =[]
for i in range(n):
    h.append(int(input()))

h.sort(reverse=True)
c = collections.Counter(h)
flg = False
for i in c:
    if c[i] >= k:
        print(0)
        flg = True
        break

diff=[]
for i in range(0,n-k+1):
    diff.append(abs(h[i] - h[i+k-1]))
print(min(diff))

Failing test case input:
5 2
8
8
10
0
11

Expected output:
0


Actual output:
0
0


Fixed submission (verdict: Accepted):
import collections

n,k = input().split()
n = int(n)
k = int(k)
h =[]
for i in range(n):
    h.append(int(input()))

h.sort(reverse=True)








diff=[]
for i in range(0,n-k+1):
    diff.append(abs(h[i] - h[i+k-1]))
print(min(diff))
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
tree_list,new_tree_list = [],[]
for i in range(N):
    tree_list.append(int(input()))

tree_list.sort(reverse=True)

for i in range(len(tree_list)-K+1):
    print(tree_list[0+i],tree_list[K+i-1])
    new_tree_list.append(tree_list[0+i]-tree_list[K+i-1])
new_tree_list.sort()
print(new_tree_list[0])


Failing test case input:
5 2
10
6
2
0
11

Expected output:
1


Actual output:
11 10
10 6
6 2
2 0
1


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
tree_list,new_tree_list = [],[]
for i in range(N):
    tree_list.append(int(input()))

tree_list.sort(reverse=True)

for i in range(len(tree_list)-K+1):
    new_tree_list.append(tree_list[0+i]-tree_list[K+i-1])
new_tree_list.sort()
print(new_tree_list[0])

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = list(int(input()) for _ in range(N))
fin = h[K-1] - h[0]
for i in range(1, N-K+1):
  t = h[i+K-1] - h[i]
  if fin > t :
    fin = t
print(fin)


Failing test case input:
5 3
10
21
10
0
8

Expected output:
2


Actual output:
-21


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = sorted(list(int(input()) for _ in range(N)))
fin = h[K-1] - h[0]
for i in range(1, N-K+1):
  t = h[i+K-1] - h[i]
  if fin > t :
    fin = t
print(fin)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = list(map(int, input().split()))

h = []
for i in range(N):
    h.append(int(input()))

h.sort()

minDistance = 10 ** 9
for i in range(0, N - K):
    if h[i + K] - h[i] < minDistance:
        minDistance = h[i + K] - h[i]

print(minDistance)

Failing test case input:
5 2
8
8
10
0
11

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = list(map(int, input().split()))

h = []
for i in range(N):
    h.append(int(input()))

h.sort()

minDistance = 10 ** 9
for i in range(0, N - K + 1):
    if h[i + K - 1] - h[i] < minDistance:
        minDistance = h[i + K - 1] - h[i]

print(minDistance)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min_number = 10**9
for i,j in zip(h[0:k],h[k-1:]):
    min_number = min(min_number,j-i)
print(min_number)


Failing test case input:
5 2
10
6
10
0
11

Expected output:
0


Actual output:
4


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
min_number = 10**9+1
for i,j in zip(h[0:n-k+1],h[k-1:]):
    min_number = min(min_number,j-i)
    
print(min_number)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
lst = []
for i in range(N):
    x = int(input())
    lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
    L.append(lst[i + K -1] - lst[i])
L.sort()
print(L)
print(L[0])

Failing test case input:
5 3
10
15
11
16
12

Expected output:
2


Actual output:
[2, 4, 4]
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
lst = []
for i in range(N):
    x = int(input())
    lst.append(x)
lst.sort()
L = []
for i in range(N - K + 1):
    L.append(lst[i + K -1] - lst[i])
L.sort()
print(L[0])

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

h = [int(input()) for i in range(N)]
ans = float('INF')
for i in range(N - K +1):
    ans = min(ans, h[i + K -1] - h[i])
    
print(int(ans))

Failing test case input:
5 3
10
21
10
0
8

Expected output:
2


Actual output:
-21


Fixed submission (verdict: Accepted):

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

h = [int(input()) for i in range(N)]
h.sort()
ans = float('INF')
for i in range(N - K +1):
    ans = min(ans, h[i + K -1] - h[i])
    
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



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

trees = []

for i in range(N):
   trees.append(int(input()))


trees.sort(reverse=True)

diff_list =[]

for i in range(N-1):
   diff_list.append(trees[i]-trees[i+1])

diff_list.sort()


print(min(diff_list[:K]))


Failing test case input:
3 3
10
15
33
14
12

Expected output:
23


Actual output:
5


Fixed submission (verdict: Accepted):

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

trees = []

for i in range(N):
    trees.append(int(input()))


trees.sort()

ans = 1000000000
for i in range(N-K+1):
    aa = trees[i+K-1]-trees[i]
    if aa < ans:
        ans = aa

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import heapq
 
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
for start in range(0, N - k):
    end = start + k
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)

Failing test case input:
5 3
5
11
10
0
6

Expected output:
5


Actual output:
1


Fixed submission (verdict: Accepted):
import heapq
 
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
h = heapq.nsmallest(N, h)
for start in range(0, N - k + 1):
    end = start + k - 1
    diff = h[end] - h[start]
    if diff < min_height:
        min_height = diff
print(min_height)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])

m = float('inf')

print(h)
for i in range(N-K+1):
    m = min(m, h[i+K-1] - h[i])
    print(h[i+K-1], h[i])

print(m)

Failing test case input:
3 3
10
15
33
14
12

Expected output:
23


Actual output:
[10, 15, 33]
33 10
23


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])

m = float('inf')

for i in range(N-K+1):
    m = min(m, h[i+K-1] - h[i])

print(m)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))

h.sort()

ans = 10 ** 9
for i in range(N-2):
    tmp = h[i+2] - h[i]
    if tmp < ans:
        ans = tmp

print(ans)


Failing test case input:
5 2
10
8
10
0
7

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))

h.sort()

ans = 10 ** 9
for i in range(N-(K-1)):
    tmp = h[i+(K-1)] - h[i]
    if tmp < ans:
        ans = tmp

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def cChristmas(n, k, hl):


    hl.sort()
    ans = 10**10

    for i in range(n-k+1):
        print(hl[i+k-1],hl[i])
        ans = min(ans, hl[i+k-1]-hl[i])

    return ans

def main():
    n, k = map(int, input().split())
    hl = [int(input()) for i in range(n)]
    print(cChristmas(n, k, hl))

if __name__ == '__main__':
    main()


Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
28 0
30 8
22


Fixed submission (verdict: Accepted):
def cChristmas(n, k, hl):


    hl.sort()
    ans = 10**10

    for i in range(n-k+1):
        ans = min(ans, hl[i+k-1]-hl[i])

    return ans

def main():
    n, k = map(int, input().split())
    hl = [int(input()) for i in range(n)]
    print(cChristmas(n, k, hl))

if __name__ == '__main__':
    main()

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int, input().split())
h = [0 for i in  range(N)]
for i in range(N):
    h[i] = int(input())
h.sort()
ans = h[K-1] - h[0]
for i in range(1,N-K):
    ans = min(ans,(h[K-1+i] - h[i]))
print(ans)

Failing test case input:
5 3
5
7
5
7
7

Expected output:
0

Actual output:
2


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
h = [0 for i in  range(N)]
for i in range(N):
    h[i] = int(input())
h.sort()
ans = h[K-1] - h[0]
for i in range(1,N-K+1):
    ans = min(ans,(h[K-1+i] - h[i]))
print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):



N, K = map(int, input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())


h = sorted(h)
min_ans = float('INF')
for i in range(N-K):
    tmp_max = h[i+K-1]
    tmp_min = h[i]
    min_ans = min(min_ans, tmp_max - tmp_min)


print(min_ans)


Failing test case input:
3 3
5
7
10
7
7

Expected output:
5


Actual output:
inf


Fixed submission (verdict: Accepted):



N, K = map(int, input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())


h = sorted(h)
min_ans = float('INF')
for i in range(N-K+1):
    tmp_max = h[i+K-1]
    tmp_min = h[i]
    min_ans = min(min_ans, tmp_max - tmp_min)


print(min_ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
p=[int(input()) for i in range(n)]
p.sort()
q=9999999999999
for i in range (n-k+1):
    print(p[k+i-1])
    print(p[i])
    if p[k+i-1]-p[i]<q:
        q=p[k+i-1]-p[i]
print(q)

Failing test case input:
5 3
5
7
5
9
7

Expected output:
2


Actual output:
7
5
7
5
9
7
2


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
p=[int(input()) for i in range(n)]
p.sort()
q=9999999999999
for i in range (n-k+1):
    if p[k+i-1]-p[i]<q:
        q=p[k+i-1]-p[i]
print(q)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = h[0]

for i in range(0, n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])

print(ans)


Failing test case input:
5 4
10
21
28
0
8

Expected output:
20


Actual output:
0


Fixed submission (verdict: Accepted):

n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
ans = h[0]

print(min(h[i + k - 1] - h[i] for i in range(n - k + 1)))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()

h_min = h[0]
h_max = h[k-1]
for i in range(1, n-k+1):
    if h[k-1 + i] - h[i] < h_max - h_min:
        h_max = h[k-1 + 1]
        h_min =h[i]
        
print(h_max - h_min)

Failing test case input:
5 3
14
15
11
14
12

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()

h_min = h[0]
h_max = h[k-1]
for i in range(1, n-k+1):
    if h[k-1 + i] - h[i] < h_max - h_min:
        h_max = h[k-1 + i]
        h_min = h[i]
        
print(h_max - h_min)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
def c():
    n, k = map(int, input().split())
    h = []
    for i in range(n):
        h.append(int(input()))
    h.sort()
    d = collections.deque(maxlen = k)
    mins = []
    while len(d) < k:
        d.append(h.pop())
    while h:
        mins.append(d[k-1] - d[0])
        d.append(h.pop())
    mins.append(d[k-1] - d[0])
    print(min(mins))
c()



Failing test case input:
5 2
8
8
17
0
11

Expected output:
0


Actual output:
-8


Fixed submission (verdict: Accepted):
import collections
def c():
    n, k = map(int, input().split())
    h = []
    for i in range(n):
        h.append(int(input()))
    h.sort()
    d = collections.deque(maxlen = k)
    mins = []
    while len(d) < k:
        d.append(h.pop())
    while h:
        mins.append(d[0] - d[k-1])
        d.append(h.pop())
    mins.append(d[0] - d[k-1])
    print(min(mins))
c()

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()

ans = max(h) - min(h)
for i in range(n-k+1):
    ans = min(ans, h[i+k-1] - h[i])


Failing test case input:
5 1
3
1
16
0
11

Expected output:
0


Actual output:

Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()

ans = max(h) - min(h)
for i in range(n-k+1):
    ans = min(ans, h[i+k-1] - h[i])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]

h = sorted(h)

ans = max(h[0:3]) - min(h[0:3])
for i in range(1, n-2):
    ans = min(ans, max(h[i:i+3]) - min(h[i:i+3]))
print(ans)


Failing test case input:
3 1
5
7
10
7
0

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
 
h = sorted(h)
 
ans = h[k-1] - h[0]
for i in range(1, n-k+1):
    ans = min(ans, h[i+k-1] - h[i])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())

h = [input() for i in range(N)]
H = [int(s) for s in h]
H.sort()
d = 10000000000
for i in range(N-K):
    if d > (H[i+K-1] - H[i]):
        d = H[i+K-1] - H[i]

print(d)
    


Failing test case input:
5 4
10
30
28
0
8

Expected output:
22


Actual output:
28


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())

h = [input() for i in range(N)]
H = [int(s) for s in h]
H.sort()
d = 10000000000
for i in range(N-K+1):
    if d > (H[i+K-1] - H[i]):
        d = H[i+K-1] - H[i]

print(d)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
minh = h[0]
for i in range(n-k+1):
    minh = min(minh,h[i+k-1]-h[i])
print(minh)

Failing test case input:
5 5
14
15
11
6
12

Expected output:
9


Actual output:
6


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = [int(input()) for i in range(n)]
h.sort()
minh = min(h[i+k-1]-h[i] for i in range(n-k+1))
print(minh)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(h)

inf = 10**9
min_height = inf
for i in range(N-K+1):
    print(i+(K-1), h[i+(K-1)], i, h[i])
    min_height = min(min_height, h[i+(K-1)] - h[i])

print(min_height)


Failing test case input:
4 3
10
21
21
0
10

Expected output:
11


Actual output:
[0, 10, 21, 21]
2 21 0 0
3 21 1 10
11


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])


inf = 10**9
min_height = inf
for i in range(N-K+1):
    
    min_height = min(min_height, h[i+(K-1)] - h[i])

print(min_height)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
arr=[int(input()) for _ in range(n)]
arr=sorted(arr)
ans=10**10
for i in range(n-k):
  ans=min(ans,arr[i+k]-arr[i])
print(ans)

Failing test case input:
5 3
5
2
2
0
6

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
arr=[int(input()) for _ in range(n)]
arr=sorted(arr)
ans=10**10
for i in range(n-k+1):
  ans=min(ans,arr[i+k-1]-arr[i])
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = sorted(H)
mi = 10**9
for i in range(N-K):
    _ = H[i+K] - H[i]
    if mi > _:
        mi = _
print(mi)

Failing test case input:
5 2
3
6
10
0
11

Expected output:
1


Actual output:
5


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
H = []
for i in range(N):
    h = int(input())
    H.append(h)
H = sorted(H)
mi = 10**9
for i in range(N-K+1):
    _ = H[i+(K-1)] - H[i]
    if mi > _:
        mi = _
print(mi)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort
print(min(h[i+K-1]-h[i] for i in range(N-K+1)))

Failing test case input:
5 2
6
7
10
0
7

Expected output:
0


Actual output:
-10


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1]-h[i] for i in range(N-K+1)))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
h = []
for i in range(N):
    h.append(int(input()))

h.sort()
ans = 1e9

print(h)
for i in range(0,N-K+1):
    ans = min(ans,h[i+K-1]-h[i])
    print(i,ans)
print(ans)

Failing test case input:
5 1
3
1
10
0
11

Expected output:
0


Actual output:
[0, 1, 3, 10, 11]
0 0
1 0
2 0
3 0
4 0
0


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
h = []
for i in range(N):
    h.append(int(input()))

h.sort()
ans = 1e9


for i in range(0,N-K+1):
    ans = min(ans,h[i+K-1]-h[i])

print(ans)
Problem: p03208
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
N, K = map(int, input().split())
A=[0]*N
for i in range(N):
    a=int(input())
    A[i]=a
A=sorted(A)

ans=[]
for i in range(N-2):
    ans.append(A[i+2]-A[i])

print(min(ans))

Failing test case input:
5 5
14
25
15
0
12

Expected output:
25


Actual output:
3


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
A=[0]*N
for i in range(N):
    a=int(input())
    A[i]=a
A=sorted(A)

ans=[]
for i in range(N-K+1):
    ans.append(A[i+K-1]-A[i])

print(min(ans))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
l=list()
for i in range(N):
  l.append(input())
l.sort()
ans=int(l[K-1])-int(l[0])
for i in range(1,N-K+1):
  key=int(l[i+K-1])-int(l[i])
  if ans>key:
    ans=key
print(ans)

Failing test case input:
5 3
5
11
10
0
6

Expected output:
5


Actual output:
-5


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
l=list()
for i in range(N):
  l.append(int(input()))
l.sort()
ans=int(l[K-1])-int(l[0])
for i in range(1,N-K+1):
  key=int(l[i+K-1])-int(l[i])
  if ans>key:
    ans=key
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int,input().split())
h = []
for i in range(n):
    hi = int(input())
    h.append(hi)
h.sort()

min = 10**100
for i in range(n-k):
    if min > h[k+i-1]-h[i]:
        min = h[k+i-1]-h[i]

print(min)


Failing test case input:
3 3
10
7
1
1
10

Expected output:
9


Actual output:
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


Fixed submission (verdict: Accepted):
n,k = map(int,input().split())
h = []
for i in range(n):
    hi = int(input())
    h.append(hi)
h.sort()

min = 10**100
for i in range(n-k+1):
    if min > h[k+i-1]-h[i]:
        min = h[k+i-1]-h[i]

print(min)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K = list(map(int,input().split()))
H=[]

for n in range(N):
    H.append(int(input()))
    
h_max=max(H[:K])
h_min=min(H[:K])

for h in H[K:]:
    if h < h_max:
        h_max = h
    elif h > h_min:
        h_min = h
    
print(h_max-h_min)

Failing test case input:
4 3
18
21
21
0
10

Expected output:
3


Actual output:
-18


Fixed submission (verdict: Accepted):
N,K = list(map(int,input().split()))
H=[]

for n in range(N):
    H.append(int(input()))
    
H.sort()

ans=10**10
for h in range(K-1,N):
    h_min=H[h-K+1]
    h_max=H[h]
    if ans > h_max-h_min:
        ans=h_max-h_min
print(ans)

Problem: p03208
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
ans=10**9
for i in range(n-k):
    ans=min(h[k+i-1]-h[i],ans)
print(ans)

Failing test case input:
3 3
5
7
5
7
6

Expected output:
2


Actual output:
1000000000


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
ans=10**9
for i in range(n-k+1):
    ans=min(h[k+i-1]-h[i],ans)
print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int, input().split())
h=sorted([int(input()) for _ in range(n)])
d=n-k

ans = 10**10
for i in range(d, n):
	ans = min(ans, h[i] - h[i-d])

print(ans)


Failing test case input:
5 1
3
1
16
0
11

Expected output:
0


Actual output:
16


Fixed submission (verdict: Accepted):
n,k=map(int, input().split())
h=sorted([int(input()) for _ in range(n)])
print(min(h[i] - h[i-k+1] for i in range(k-1, n)))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(input()))

m = 10e9
h.sort()
for i in range(len(h)-k):
    if h[i+k-1]-h[i] <= m:
        print(h[i+k-1],h[i])
        m = h[i+k-1] - h[i]
print(m)


Failing test case input:
4 3
10
21
21
-1
7

Expected output:
11


Actual output:
21 -1
22


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(input()))

m = []
h.sort()
for i in range(len(h)-k+1):
    m.append(h[i+k-1] - h[i])
print(sorted(m)[0])

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = list(map(int, input().split()))

a = [int(input()) for _ in range(n)]
a.sort()
b = 0
ans = []
print(a)
for i in range(n - k + 1):
    b = a[i + k - 1] - a[i]
    ans.append(b)
ans.sort()
print(ans[0])

Failing test case input:
5 5
14
15
11
9
12

Expected output:
6


Actual output:
[9, 11, 12, 14, 15]
6


Fixed submission (verdict: Accepted):
n, k = list(map(int, input().split()))

a = [int(input()) for _ in range(n)]
a.sort()
b = 0
ans = []

for i in range(n - k + 1):
    b = a[i + k - 1] - a[i]
    ans.append(b)
ans.sort()
print(ans[0])

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
H=[int(input()) for _ in range(N)]
H=sorted(H)
Diff=[]
for i in range(1,N):
  Diff +=[H[i]-H[i-1]]

Diff=sorted(Diff)

print(sum(Diff[:K-1]))

Failing test case input:
5 3
14
0
10
0
7

Expected output:
7


Actual output:
3


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H=[int(input()) for _ in range(N)]
H=sorted(H)
answer=float('inf')
for i in range(N-K+1):
  answer=min(answer,H[K+i-1]-H[i])
print(answer)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
H = [int(input()) for _ in range(N)]

H.sort()
ans = 10**10
for i in range(N-K+1):
    ans = min(ans, H[i-1+K]-H[i])
    print(i,ans)

print(ans)

Failing test case input:
5 3
5
11
4
0
6

Expected output:
2


Actual output:
0 5
1 2
2 2
2


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
H = [int(input()) for _ in range(N)]

H.sort()
ans = 10**10
for i in range(N-K+1):
    ans = min(ans, H[i-1+K]-H[i])

print(ans)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k=map(int,input().split())
x=list(int(input()) for _ in range(n))
y=sorted(x)

df=[]

for i in range(n-2):
	df.append(y[i+2]-y[i])
    
print(min(df))

Failing test case input:
5 5
14
15
11
15
12

Expected output:
4


Actual output:
1


Fixed submission (verdict: Accepted):
n, k=map(int,input().split())
x=list(int(input()) for _ in range(n))
y=sorted(x)

df=[]

for i in range(n-k+1):
	df.append(y[i+k-1]-y[i])
    
print(min(df))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K=map(int,input().split())
H=[int(input()) for _ in range(N)]
H.sort(reverse=True)
ans=10**6

for i in range(N-K):
    ans=min(ans,H[i]-H[i+K-1])

print(ans)    

Failing test case input:
5 5
14
15
11
9
12

Expected output:
6


Actual output:
1000000


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
H=[int(input()) for _ in range(N)]
H.sort(reverse=True)
ans=10**9

for i in range(N-K+1):
    ans=min(ans,H[i]-H[i+K-1])

print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,A= [int(i) for i in input().split()]
n=[]
m=[]
for i in range(N):
	n.append(int(input()))
n.sort()
for i in range(N-1):
	m.append(n[i+1] - n[i])
m.sort() 
print(sum(m[0:(A-1)]))

Failing test case input:
4 3
18
21
2
0
10

Expected output:
18


Actual output:
5


Fixed submission (verdict: Accepted):
N,A= [int(i) for i in input().split()]
n = [int(input()) for i in range(N)]
n.sort()
mn = 10**9
for i in range(N-A+1):
	m = n[i+A-1] - n[i]	
	if m == 0:
		print(0)
		exit()
	elif mn > m: mn=m 
print(mn)

Problem: p03208
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
h.sort()
dif = []
for i in range(N-1):
    dif.append(h[i+1]-h[i])
print(min(dif))

Failing test case input:
4 3
10
21
11
0
6

Expected output:
11


Actual output:
1


Fixed submission (verdict: Accepted):
N,K = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
h.sort()
res = 10**9
for i in range(N-K+1):
    if res > h[i+K-1]-h[i]:
        res = h[i+K-1]-h[i]
print(res)

Problem: p03208
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)], reverse=True)

m = 10**10
for i in range(n-k+1):
  m = min(m, h[i]-h[i-k])

print(m)

Failing test case input:
5 1
10
8
10
0
7

Expected output:
0


Actual output:
-7


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = sorted([int(input()) for _ in range(n)], reverse=True)

m = float('inf')
for i in range(n-k+1):
  m = min(m, h[i]-h[i+k-1])

print(m)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = h[1] - h[0]
for j in range(0,k-n):
  if ans < h[j+k-1] - h[0]:
    ans = h[j+k-1] - h[0]
print(ans)

Failing test case input:
5 3
10
21
10
0
6

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
n,k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()
ans = h[k-1] - h[0]
for j in range(0,n-k+1):
  if  h[j+k-1] - h[j] < ans:
    ans = h[j+k-1] - h[j]
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=float("inf")
for i in range(n-2):
    ans=min(ans,h[i+2]-h[i])
print(ans)

Failing test case input:
5 1
5
1
10
0
11

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
ans=float("inf")
for i in range(n-k+1):
    ans=min(ans,h[i+k-1]-h[i])
    if ans==0:
        print(ans)
        exit()
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,K = map(int,input().split())
Hs = sorted([int(input()) for i in range(N)])
nums = []
for h in range(2,len(Hs)):
    nums.append(Hs[h]-Hs[h-2])
print(min(nums))




Failing test case input:
5 1
5
1
10
0
11

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
N,K = map(int,input().split())
Hs = sorted([int(input()) for i in range(N)])
nums = []
for h in range(K-1,len(Hs)):
    nums.append(Hs[h]-Hs[h-(K-1)])
print(min(nums))

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
d = [h[i+1]-h[i] for i in range(0, len(h)-1)]
S = 0
for i in range(k-1):
    S += d[i]
ans = S
for i in range(0, n-k):
    SS = S + d[i+k-1] - d[i]
    if SS <= S:
        ans = SS
print(ans)


Failing test case input:
5 3
4
7
5
9
7

Expected output:
2


Actual output:
3


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
d = [h[i+1]-h[i] for i in range(0, len(h)-1)]
S = 0
for i in range(k-1):
    S += d[i]
ans = S
for i in range(0, n-k):
    SS = S + d[i+k-1] - d[i]
    if SS <= ans:
        ans = SS
    S = SS
print(ans)

Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a, b = map(int, input().split())
c = [int(input()) for _ in range(a)]
c.sort()
d = 0
for i in range(2, a):
    if d == 0:
        d = abs(c[i] - c[i - 2])
    else:
        if abs(c[i] - c[i-2]) < d:
            d = abs(c[i] - c[i-2])
print(d)


Failing test case input:
5 3
5
7
10
7
7

Expected output:
0


Actual output:
3


Fixed submission (verdict: Accepted):
a, b = map(int, input().split())
c = [int(input()) for _ in range(a)]
c.sort()
d = -1
for i in range(b-1, a):
    if d == -1:
        d = abs(c[i] - c[i-b+1])
    else:
        if abs(c[i] - c[i-b+1]) < d:
            d = abs(c[i] - c[i-b+1])
print(d)
Problem: p03208
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N, K = map(int, input().split())
h_list = []
for _ in range(N):
    h_list.append(int(input()))
h_list.sort()

err_list = [h_list[i+K-1] - h_list[i] for i in range(N-K+1)]
print(max(err_list))


Failing test case input:
4 3
10
38
19
0
6

Expected output:
19


Actual output:
28


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())
h_list = []
for _ in range(N):
    h_list.append(int(input()))
h_list.sort()

err_list = [h_list[i+K-1] - h_list[i] for i in range(N-K+1)]
print(min(err_list))
Problem: p03489
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(num-cnt)
    if num>cnt:
        ans+=cnt
print(ans)


Failing test case input:
6
0 2 2 3 3 1

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

n = ni()
A = lma()
co = collections.Counter(A)
ans = 0
for num,cnt in co.items():
    if num<cnt:
        ans+=(cnt-num)
    if num>cnt:
        ans+=cnt
print(ans)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
l.sort()
l.append(0)
ans = 0
j = 0
for i in unique_l:
    cnt = 0
    while l[j] == i and j < N:
        cnt += 1
        j += 1
    if cnt == i:
        pass
    elif cnt > i:
        ans += cnt - i
    elif cnt < i:
        ans += cnt
print(ans)

Failing test case input:
8
2 7 1 8 2 8 1 8

Expected output:
5

Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
l = list(map(int, input().split()))
unique_l = list(set(l))
unique_l.sort()
l.sort()
l.append(0)
ans = 0
j = 0
cnt =[]
for i in unique_l:
    temp = 0
    while l[j] == i and j < N:
        temp += 1
        j += 1
    cnt.append(temp)
for i, j in zip(unique_l, cnt):
    if i == j:
        pass
    elif j > i:
        ans += j - i
    elif j < i:
        ans += j
print(ans)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
length = input()
nums = input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in numdict:
		numdict[str(num)] = 1
	else:
		numdict[str(num)] += 1

ret = 0
for k,v in numdict.items():
	if int(k) > int(v):
		ret += int(k) - int(v) 
	else:
		ret += int(v) - int(k)

print(ret)

Failing test case input:
8
2 13 1 2 4 2 2 0

Expected output:
5


Actual output:
18


Fixed submission (verdict: Accepted):
length = input()
nums = input().split(" ")

numdict = {}
for i, num in enumerate(nums):
	if num not in numdict:
		numdict[str(num)] = 1
	else:
		numdict[str(num)] += 1

ret = 0
for k,v in numdict.items():
	if int(k) > int(v):
		ret += int(v) 
	else:
		ret += int(v) - int(k)

print(ret)
Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
hm={}
n=int(input())
ans=0
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1

for i in hm:
    if hm[i]==i:
        ans+=i
print(n-ans)

Failing test case input:
8
6 13 1 15 2 2 1 12

Expected output:
5


Actual output:
6


Fixed submission (verdict: Accepted):
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a = a.most_common()
ans = 0
for i in range(len(a)):
  if a[i][0] <= a[i][1]:
    ans += a[i][1] - a[i][0]
  else:
    ans += a[i][0]
    
print(ans)

Failing test case input:
8
2 7 1 8 2 8 1 15

Expected output:
5


Actual output:
31


Fixed submission (verdict: Accepted):
import collections
N = int(input())
a = list(map(int, input().split()))
a = collections.Counter(a)
a = a.most_common()
ans = 0
for i in range(len(a)):
  if a[i][0] <= a[i][1]:
    ans += a[i][1] - a[i][0]
  else:
    ans += a[i][1]
    
print(ans)

Problem: p03489
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += x
    else:
        res += occ[x] - x

print(res)

Failing test case input:
5
1 4 2 4 2

Expected output:
2


Actual output:
4


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        res += occ[x] - x

print(res)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
print(hm)
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)

Failing test case input:
8
16 13 1 2 4 2 1 1

Expected output:
5


Actual output:
{16: 1, 13: 1, 1: 3, 2: 2, 4: 1}
5


Fixed submission (verdict: Accepted):
hm={}
n=int(input())
ans=n
arr=[int(i) for i in input().split()]
for i in arr:
    hm[i]=hm.get(i,0)+1
for i in hm:
    if hm[i]!=i:
        if hm[i]>i:
            ans-=hm[i]-i
        else:
            ans-=hm[i]
print(n-ans)
Problem: p03489
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]!=i:
        cnt+=min(abs(dic[i]-i),dic[i])
print(cnt)
    

Failing test case input:
6
0 2 2 3 3 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
arr=list(map(int,input().split()))
dic,cnt={},0
for i in arr:
    dic[i]=dic.get(i,0)+1
for i in dic:
    if dic[i]>i:
        cnt+=dic[i]-i
    elif dic[i]<i:
        cnt+=dic[i]
print(cnt)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input().strip())
a=list(map(int, input().split()))
nlis={}

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    ans+=min(abs(nlis[i]-i),nlis[i])
print(ans)

Failing test case input:
6
0 2 2 3 3 1

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
N=int(input().strip())
a=list(map(int, input().split()))
nlis={}

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    if nlis[i]<i:
        ans+=nlis[i]
    else:
        ans+=abs(nlis[i]-i)
    
print(ans)

Problem: p03489
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        print(x, occ[x] - x)
        res += occ[x] - x

print(res)


Failing test case input:
8
12 13 1 1 2 2 1 12

Expected output:
5


Actual output:
1 2
2 0
5


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

occ = {}
for i in range(n):
    if a[i] not in occ:
        occ[a[i]] = 0
    occ[a[i]] += 1

res = 0
for x in occ:
    if (occ[x] < x):
        res += occ[x]
    else:
        res += occ[x] - x

print(res)

Problem: p03489
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
  if a[i] in dic:
    dic[a[i]] += 1
  else:
    dic[a[i]] = 1
clear = 0
for k, v in dic.items():
  if k >= v:
    clear += v
  else:
    clear += v-k
print(clear)

Failing test case input:
8
2 7 1 8 2 8 1 8

Expected output:
5

Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in range(n):
  if a[i] in dic:
    dic[a[i]] += 1
  else:
    dic[a[i]] = 1
clear = 0
for k, v in dic.items():
  if k > v:
    clear += v
  else:
    clear += v-k
print(clear)
Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
arr=list(map(int,input().split()))
d=dict()
count=0 
for i in arr:
    d[i]=d.get(i,0)+1 
print(d)
for k,v in d.items():
    if not d[k]==k:
        if d[k]<k:
            count+=d[k]
        else:
            count+=d[k]-k 
print(count)

Failing test case input:
1
1100101000

Expected output:
1


Actual output:
{1100101000: 1}
1


Fixed submission (verdict: Accepted):
n=int(input())
arr=list(map(int,input().split()))
d=dict()
count=0 
for i in arr:
    d[i]=d.get(i,0)+1 
for k,v in d.items():
    if not d[k]==k:
        if d[k]<k:
            count+=d[k]
        else:
            count+=d[k]-k 
print(count)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
current=A.pop()
num=1
if len(A)==0:
  if num<current: ans+=num
  else: ans+=num-current
while A:
  if A[-1]==current:
    num+=1
    current=A.pop()
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
  else:
    if num<current: ans+=num
    else: ans+=num-current
    current=A.pop()
    num=1
print(ans)

Failing test case input:
8
2 13 1 2 5 2 2 0

Expected output:
5


Actual output:
4


Fixed submission (verdict: Accepted):
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
current=A.pop()
num=1
if len(A)==0:
  if num<current: ans+=num
  else: ans+=num-current
while A:
  if A[-1]==current:
    num+=1
    current=A.pop()
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
  else:
    if num<current: ans+=num
    else: ans+=num-current
    current=A.pop()
    num=1
    if len(A)==0:
      if num<current: ans+=num
      else: ans+=num-current
print(ans)

Problem: p03489
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]

if(N==1):
    print(0)
else:
    print(cnt)

Failing test case input:
1
1111101101

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import collections

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

c = collections.Counter(A)
cs = sorted(c.items(), key=lambda x:x[0])
cnt = 0
for i in range(len(cs)):
    if(cs[i][0] != cs[i][1]):
        if(cs[i][0] < cs[i][1]):
            cnt += cs[i][1]-cs[i][0]
        else:
            cnt += cs[i][1]
print(cnt)