qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N, k = [int(s) for s in input().split(' ')]
 
h = []
while len(h) != N:
    heapq.heappush(h, int(input()))
  
min_height = 1000000000
h.sort()
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)

Fixed code:
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)
Buggy code:
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])

Fixed code:
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])
Buggy code:
import math

n, k = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
ans = math.inf
for i in range(n - k):
    ans = min(ans, max(h[i : i + k]) - min(h[i : i + k]))

print(ans)


Fixed code:
import math

n, k = list(map(int, input().split()))
h = [int(input()) for _ in range(n)]
h.sort()
ans = math.inf
for i in range(n - k + 1):
    ans = min(ans, h[i + k - 1] - h[i])

print(ans)
Buggy code:
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(min([h[i+K] - h[i] for i in range(N-K+1)]))

Fixed code:
N, K = map(int, input().split())
h = sorted([int(input()) for i in range(N)])
print(min([h[i+K-1] - h[i] for i in range(N-K+1)]))
Buggy code:
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)))


Fixed code:
n, k = map(int, input().split())
hl = [int(input()) for _ in range(n)]
hl.sort()
print(min([hl[k - 1 + i] - hl[i] for i in range(0, n - k + 1)]))
Buggy code:
n,k = map(int,input().split())
h = []
for i in range(n):
  hi = int(input())
  h.append(hi)
h.sort()
l = []
for i in range(n-k+1):
  l.append(h[i+k-1] - h[i])
print(max(l))

Fixed code:
n,k = map(int,input().split())
h = []
for i in range(n):
  hi = int(input())
  h.append(hi)
h.sort()
l = []
for i in range(n-k+1):
  l.append(h[i+k-1] - h[i])
print(min(l))
Buggy code:
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
mn=999999999999999
for i in range(n-k):
    mn=min(mn,h[i+k-1]-h[i])
print(mn)


Fixed code:
# coding: utf-8
# Your code here!
n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
mn=999999999999999
for i in range(n-k+1):
    mn=min(mn,h[i+k-1]-h[i])
print(mn)
Buggy code:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]

h.sort()
inf = float('inf')
min_ = inf

for i in range(n - k):
    if h[i+k-1] - h[i] < min_:
        min_ = h[i+k-1] - h[i]
print(min_)

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

h.sort()
inf = float('inf')
min_ = inf

for i in range(n - k + 1):
    min_ = min(min_, h[i+k-1] - h[i])
print(min_)
Buggy code:
N,K = map(int,input().split())
h = list(map(int,input().split()))
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)

Fixed code:
N,K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort(reverse = True)
l = [0]*(N-(K-1))
for i in range(N-(K-1)):
  l[i] = h[i]-h[i+K-1]
ans = min(l)
print(ans)
Buggy code:
n.k = map(int,input().split())
L = []
for val in rnage(n):
    L.append(val)

L = sorted(L)
ans_L = []
for i in range(n-k+1):
    ans = L[i+k-1] - L[i]
    ans_L.append(ans)
print(min(ans_L))

Fixed code:
n,k = map(int,input().split())
L = []
for val in range(n):
    val = int(input())
    L.append(val)

L = sorted(L)
ans_L = []
for i in range(n-k+1):
    ans = L[i+k-1] - L[i]
    ans_L.append(ans)
print(min(ans_L))
Buggy code:
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort()

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

print(ans)


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

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

print(ans)
Buggy code:
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 0
        break
if cnt != 0:
    print('0')
else:
    print(H[K-1] - H[0])


Fixed code:
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 1
        break
ans = 999999999999999
for i in range(N-K+1):
    ans = min(ans,H[K-1+i] - H[i]) 

if cnt != 0:
    print('0')
else:
    print(ans)
Buggy code:
n,k=map(int, input().split())
h=[]
for i in range(n):
  h.append(int(input()))
h.sort()
ans=h[k-1]-h[0]
for i in range(1,n-k):
  ans=min(ans,h[i+k-1]-h[k])
print(ans)

Fixed code:
n, k = map(int, input().split())
h = list()
ans = list()

for i in range(n):
    h.append(int(input()))
h.sort()

for i in range(n-k+1):
    ans.append(h[i+k-1] - h[i])

print(min(ans))
Buggy code:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i] - h[i+k-1])
print(g)

Fixed code:
n,k = map(int,input().split())
h = []
for i in range(n):
  h.append(int(input()))
h.sort()
g = float('inf')
for i in range(n-k+1):
  g = min(g, h[i+k-1] - h[i])
print(g)
Buggy code:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
res = [h[i+k-1]-h[i] for i in range(n-k+1) ]
print(res)


Fixed code:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
res = [h[i+k-1]-h[i] for i in range(n-k+1) ]
print(min(res))
Buggy code:
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


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

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


Fixed code:
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


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

H.sort()
ans = 10**10
for i in range(N-(K-1)):
    ans = min(ans, H[i+(K-1)]-H[i])
print(ans)
Buggy code:
N,K = map(int,input().split(" "))
H = sorted([int(input()) for _ in range(N)])
Min = 10**10
print(H)
for i in range(K-1,len(H))[::-1]:
    Abs = H[i]-H[i-(K-1)]
    if Abs<Min:
        Min = Abs
print(Min)

Fixed code:
N,K = map(int,input().split(" "))
H = sorted([int(input()) for _ in range(N)])
Min = 10**10
for i in range(K-1,len(H))[::-1]:
    Abs = H[i]-H[i-(K-1)]
    if Abs<Min:
        Min = Abs
print(Min)
Buggy code:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

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

print(ans)

Fixed code:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

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

print(ans)
Buggy code:
N,K=(int(i) for i in input().split())
hlist=[int(input()) for i in range(N)]
hlist.sort()
print(hlist)
dif=[]
for j in range(N-K):
    dif.append(hlist[j+K-1]-hlist[j])
print(min(dif))

Fixed code:
N,K=(int(i) for i in input().split())
hlist=[int(input()) for i in range(N)]
hlist.sort()
dif=[]
for j in range(N-K+1):
    dif.append(hlist[j+K-1]-hlist[j])
print(min(dif))
Buggy code:
N, K = input().split()
N = int(N)
K = int(K)
a = [int(input()) for i in range(N)]

a.sort()
print(a)

print(min([a[i+K-1]-a[i] for i in range(N-K+1)]))

Fixed code:
N, K = input().split()
N = int(N)
K = int(K)
a = [int(input()) for i in range(N)]

a.sort()


print(min([a[i+K-1]-a[i] for i in range(N-K+1)]))
Buggy code:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h = sorted(h)

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

print(ans)

Fixed code:
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)
Buggy code:
n,k=map(int,input().split())
H=sorted([int(input()) for i in range(n)])
print(min(h[i+k-1]-h[i] for i in range(n-k+1)))


Fixed code:
n,k=map(int,input().split())
h=sorted([int(input()) for i in range(n)])
print(min([h[i+k-1]-h[i] for i in range(n-k+1)]))
Buggy code:
N,K = map(int,input().split())
arr = []

for i in range(N):
  a = int(input())
  arr.append(a)
  
arr.sort()
ans = 10**10

for i in range(N-K):
  a = arr[i]
  b = arr[i+K]
  c = b-a
  ans = min(ans,c)
  
print(ans)

Fixed code:
N,K = map(int,input().split())
arr = []

for i in range(N):
  a = int(input())
  arr.append(a)
  
arr.sort()
ans = 10**10

for i in range(N-K+1):
  a = arr[i]
  b = arr[i+K-1]
  c = b-a
  ans = min(ans,c)
  
print(ans)
Buggy code:
N,K = map(int, input().split())
A = [0]*N

for i in range(N):
    A[i] = int(input())
    
A.sort()
print(A)

ans = A[K-1]-A[0]
for i in range(N-K):
    if A[K+i]-A[i+1] < ans:
        ans = A[K+i]-A[i+1]
        
print(ans)

Fixed code:
N,K = map(int, input().split())
A = [0]*N
DP=[0]*N

for i in range(N):
    A[i] = int(input())
    
A.sort()

ans = A[K-1]-A[0]
for i in range(N-K):
    if A[K+i]-A[i+1] < ans:
        ans = A[K+i]-A[i+1]
        
print(ans)
Buggy code:
n, k =map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
ans = 10000000000000000
print(h)
for i in range(n-k+1):
    if h[i+(k-1)] - h[i] <= ans:
        ans = h[i+(k-1)] - h[i]
print(ans)

Fixed code:
n, k = map(int, input().split())
h =[]
for i in range(n):
    h.append(int(input()))
h.sort()
ans = int(1e10)
for i in range(n-(k-1)):
    if h[i+(k-1)] - h[i] < ans:
        ans = h[i+(k-1)] - h[i]
#print(h)
print(ans)
Buggy code:
n, k = map(int,input().split())
h = []

for i in range(n):
    h.append(int(input()))
h = sorted(h)

minval = int(1e10)

#print(h)
for i in range(len(h)-k):
    if minval >= h[i+(k-1)] - h[i]:
        minval = h[i+(k-1)] - h[i]
print(minval)


Fixed code:
n, k = map(int,input().split())
h = []

for i in range(n):
    h.append(int(input()))
h = sorted(h)

minval = int(1e10)

#print(h)
for i in range(n-k+1):
    if minval >= h[i+(k-1)] - h[i]:
        minval = h[i+(k-1)] - h[i]
print(minval)
Buggy code:
n, k = map(int, input().split())
h = []
for i in range(n):
  h.append(int(input()))

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





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

h.sort()
  
ans = []
for i in range(n-k+1):
  ans.append(h[i+k-1]-h[i])
  
print(min(ans))
Buggy code:
N, K = map(int,input().split())
h = []
for i in range(N):
    x = int(input())
    h.append(x)

h.sort()
m = []
for i in range(N):
    m.append(h[i+K-1] - h[i])

print(min(m))

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

h.sort()
m = []
for i in range(N-K+1):
    m.append(h[i+K-1] - h[i])

print(min(m))
Buggy code:
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)

Fixed code:
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)
Buggy code:
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)

Fixed code:
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)
Buggy code:
n,k = map(int,input().split())
hn = [int(input()) for i in range(n)]

hn.sort()

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

Fixed code:
n,k = map(int,input().split())
hn = [int(input()) for i in range(n)]

hn.sort()

print(min(hn[i+k-1] - hn[i] for i in range(n-k+1)))
Buggy code:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
min = 1024
for i in range(len(h)-k-1):
    if h[i+k-1] - h[i] < min:
        min = h[i+k-1] - h[i]
print(min)


Fixed code:
n, k = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
min = h[k-1] - h[0]
for i in range(len(h)-k+1):
    dif = h[i+k-1] - h[i]
    if dif < min:
        min = dif
print(min)
Buggy code:
N, K = map(int, input().split())
ps = []
for i in range(N):
	ps.append(int(input()))
ps = sorted(ps)
ans = ps[K-1]-ps[0]
for i in range(N - K):
	ans = min(ans, ps[i+K-1], ps[i])
print(ans)


Fixed code:
N, K = map(int, input().split())
ps = []
for i in range(N):
	ps.append(int(input()))
ps = sorted(ps)
ans = ps[K-1]-ps[0]
for i in range(N-K+1):
	ans = min(ans, ps[i+K-1]-ps[i])
print(ans)
Buggy code:
n, k = map(int, input().split())
h = [int(input()) for i in range(n)]
h.sort()

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


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

ans = 100000000000000000000000000000000000000
for i in range(n-k+1):
    ans = min(ans, h[i+k-1] - h[i])
print(ans)
Buggy code:
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)

Fixed code:
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)
Buggy code:
import numpy as np

N,K = list(map(int, input().split(",")))
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
res = h[N-1] - h[0]
for i in np.arange(0,N-K+1,1):
    tmp = h[i+K-1] - h[i]
    if res > tmp:
        res = tmp
    
print(res)
    


Fixed code:
import numpy as np

N,K = list(map(int, input().split()))
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
res = h[N-1] - h[0]
for i in np.arange(0,N-K+1,1):
    tmp = h[i+K-1] - h[i]
    if res > tmp:
        res = tmp
    
print(res)
Buggy code:
N, K = map(int, input().split())
print(N, K)
t = [int(input()) for i in range(N)]
t.sort(reverse = True)

l = []

for j in range(N-K+1):
    l.append(t[j] - t[j+K-1])
print(min(l))


Fixed code:
N, K = map(int, input().split())
t = [int(input()) for i in range(N)]
t.sort()
l = []

for j in range(N-K+1):
    l.append(t[j+K-1] - t[j])

print(min(l))
Buggy code:
import numpy as np

N,K=list(map(int,input().split()))
h=np.zeros(N)
for i in range(N):
    h[i]=int(input())
    
h=np.sort(h)
h_min=10**9
for i in range(N-K+1):
    dh=h[i+K-1]-h[i]
    if dh<dh_min:
        dh_min=dh
print(dh_min)

Fixed code:
import numpy as np
 
N,K=list(map(int,input().split()))
h=np.zeros(N)
for i in range(N):
    h[i]=int(input())
    
h=np.sort(h)
dh_min=10**9
for i in range(N-K+1):
    dh=h[i+K-1]-h[i]
    if dh<dh_min:
        dh_min=dh
print(int(dh_min))
Buggy code:
n,k=list(map(int,input().split()))
h=[]
for i in range(n):
    h1=int(input())
    h.append(h1)
h=sorted(h)
ans=10000000000
tmp=0
for i in range(n-k):
    tmp=h[i+k-1]-h[i]
    ans=min(ans,tmp)
print(ans)

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

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


N, K = map(int, input().split())
H = [int(input()) for i in range(N)]

H.sort()

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

Fixed code:

N, K = map(int, input().split())
H = [int(input())  for i in range(N)]

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

print(ans)
Buggy code:
N, K = map(int, input().split())
A = [int(input()) for i in range()]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))

Fixed code:
N, K = map(int, input().split())
A = [int(input()) for i in range(N)]
S = []
A.sort()
for i in range(N - K + 1):
  S.append(A[i+K-1] - A[i])
print(min(S))
Buggy code:
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):
  k = h[i+K-1] - h[i]
  if fin > k :
    fin = k
print(fin)

Fixed code:
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)
Buggy code:
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)

Fixed code:
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+k-1]-h[i])
print(ans)
Buggy code:
N, K = map(int, input().split())
hlist = sorted([int(input()) for _ in range(N)])
ans = 10**9 + 7
for i in range(N - K):
    ans = min(ans, hlist[i + K - 1] - hlist[i])
print(ans)


Fixed code:
N, K = map(int, input().split())
hlist = sorted([int(input()) for _ in range(N)])
ans = 10**9 + 7
for i in range(N - K + 1):
    ans = min(ans, hlist[i + K - 1] - hlist[i])
print(ans)
Buggy code:
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]-h[i],ans)
print(ans)

Fixed code:
n,k = map(int,input().split())
h = [int(input()) for i in range(n)]
h = sorted(h)
ans = 10**9
for i in range(n-k+1):
    ans = min(ans,h[i+k-1]-h[i])
print(ans)
Buggy code:
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)




Fixed code:
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)
Buggy code:
N, K = map(int, input().split())
A = sorted([int(input()) for i in range(N)])
B = [A[i]-A[i-K] for i in range(K, N)]
print(min(B))
            


Fixed code:
N, K = map(int, input().split())
A = sorted([int(input()) for i in range(N)])
B = [A[i-1]-A[i-K] for i in range(K, N+1)]
print(min(B))
Buggy code:
import sys
input = sys.stdin.readline

def main():
    N,K = map(int,input().split())
    h = [int(input()) for _ in range(N)]
    h.sort()
    print(h)
    
    ans = 10**10
    for i in range(N-K+1):
        ans = min(ans,h[K+i-1]-h[i])
        
    print(ans)
    
if __name__ == "__main__":
    main()


Fixed code:
import sys
input = sys.stdin.readline

def main():
    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[K+i-1]-h[i])
        
    print(ans)
    
if __name__ == "__main__":
    main()
Buggy code:
N,K = [int(x) for x in input().split()]
H = [0]*N
for i in range(N):
  H[i] = int(input())
H.sort(reverse=True)
ans= H[0]-H[K-1]
print(ans)

Fixed code:
N,K = [int(x) for x in input().split()]
H = [0]*N
for i in range(N):
  H[i] = int(input())
H.sort(reverse=True)
ans = 100000000000000000
for i in range(N-K+1):
  ans = min(ans,H[i]-H[i+K-1])
print(ans)
Buggy code:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*(n-1)
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(1,n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
  
  
  
  


Fixed code:
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
d=[0]*n
for j in range(n-1):
  d[j+1]=d[j]+h[j+1]-h[j]
m=float('inf')
for l in range(n-k+1):
  m=min(m,d[l+k-1]-d[l])
print(m)
Buggy code:
nk = input()
nk = nk.split()
n = int(n[0])
k = int(n[1])
trees = []
for i in range(n):
  trees.append(int(input()))
trees.sort()
minimum = 1000000000
i = 0
while i<=n-k:
  if trees[i+k-1]-trees[i]<minimum:
    minimum = trees[i+k-1]-trees[i]
  i+=1
print(minimum)

Fixed code:
nk = input()
nk = nk.split()
n = int(nk[0])
k = int(nk[1])
trees = []
for i in range(n):
  trees.append(int(input()))
trees.sort()
minimum = 1000000000
i = 0
while i<=n-k:
  if trees[i+k-1]-trees[i]<minimum:
    minimum = trees[i+k-1]-trees[i]
  i+=1
print(minimum)
Buggy code:
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    result=10**9
    for i in range(len(strees)):
        result = min(result, strees[i+K-1] - strees[i])
    print(result)

if __name__ == "__main__":
    christmasEve()

Fixed code:
def christmasEve():
    N, K = map(int, input().split())
    h = [int(input()) for i in range(N)]
    strees = sorted(h)
    result=10**9
    for i in range(N-K+1):
        result = min(result, strees[i+K-1] - strees[i])
    print(result)

if __name__ == "__main__":
    christmasEve()
Buggy code:
#Coding:Utf-8

N,K=list(map(int, input().split()))
a=[int(input()) for i in range(N)]

a.sort()

min=a[N-1]-a[0]
print(a)
for l in range(N-K+1):
    if min>a[l+K-1]-a[l]:
        min=a[l+K-1]-a[l]

print(min)


Fixed code:
#Coding:Utf-8

N,K=list(map(int, input().split()))
a=[int(input()) for i in range(N)]

a.sort()

min=a[N-1]-a[0]
for l in range(N-K+1):
    if min>a[l+K-1]-a[l]:
        min=a[l+K-1]-a[l]

print(min)
Buggy code:
N, K = map(int, input().split())
h_list = []

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()
answer = h_list[N-1] - h_list[0]

for i in range(N-K+1):
    a = h_list[i+K-2] - h_list[i]
    answer = min(a,answer)

print(answer)

Fixed code:
N, K = map(int, input().split())
h_list = []

for _ in range(N):
    h_list.append(int(input()))

h_list.sort()
answer = h_list[N-1] - h_list[0]

for i in range(N-K+1):
    a = h_list[i+K-1] - h_list[i]
    answer = min(a,answer)

print(answer)
Buggy code:
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]

h.sort()

print(h)

min_h = 1000000000

for i in range(K - 1, N):

    print([h[i], h[i - K + 1], h[i] - h[i - K + 1], min_h])
    min_h = min(min_h, h[i] - h[i - K + 1])

print(min_h)


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

h.sort()

min_h = 1000000000

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

print(min_h)
Buggy code:
# coding:utf-8
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))


Fixed code:
# coding:utf-8
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)))
Buggy code:
n,k=map(int,input().split())
a=[int(input()) for i in range(n)]
a.sort()
x=10**9
for i in range(n-k+1):
  x=min(x,a[i+k-1]-a[k])
print(x)

Fixed code:
n,k=map(int,input().split())
a=[int(input()) for i in range(n)]
a.sort()
x=10**9
for i in range(n-k+1):
  x=min(x,a[i+k-1]-a[i])
print(x)