qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N,n = map(int,input().split())


N = [int(input()) for i in range(N)]
N = sorted(N)
Q = []
for i in range(len(N)-n+1):
	max1 = int(*N[i+n-1:i+n])
	min1 = int(*N[i:i+1])
	Q.append(max1 - min1)
print(max(Q))

Fixed code:
N,n = map(int,input().split())
 
 
N = [int(input()) for i in range(N)]
N = sorted(N)
Q = []
for i in range(len(N)-n+1):
	max1 = int(*N[i+n-1:i+n])
	min1 = int(*N[i:i+1])
	Q.append(max1 - min1)
print(min(Q))
Buggy code:
n_k = input()
n_k_list =n_k.split(' ')

N = int(n_k_list[0])
K = int(n_k_list[1])

h_list = [0] * N
for i in range(N):
    h_list[i] = int(input())

sorted_h_list = sorted(h_list)
print(sorted_h_list)

# print(h_list)
min_dif = 1000000000
for i in range(N-K+1):
    start = i
    end = K - 1 + i
    # print('start,end', start, end)
    end_v = sorted_h_list[end]
    start_v = sorted_h_list[start]
    dif = end_v - start_v
    # print('dif', dif)
    # print('min_dif', min_dif)
    if min_dif > dif:
        min_dif = dif

print(int(min_dif))

Fixed code:
n_k = input()
n_k_list =n_k.split(' ')

N = int(n_k_list[0])
K = int(n_k_list[1])

h_list = [0] * N
for i in range(N):
    h_list[i] = int(input())

sorted_h_list = sorted(h_list)

min_dif = 1000000000
for i in range(N-K+1):
    start = i
    end = K - 1 + i

    end_v = sorted_h_list[end]
    start_v = sorted_h_list[start]
    dif = end_v - start_v

    if min_dif > dif:
        min_dif = dif

print(int(min_dif))
Buggy code:
n, k = map(int, input().split())
trees = [int(input()) for _ in range(n)]
trees.sort()
diff_trees_height = []
print(trees)
for i in range(n - (k - 1)):
    diff = abs(trees[i] - trees[i + k - 1])
    diff_trees_height.append(diff)
print(diff_trees_height)
print(min(diff_trees_height))


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

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

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

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

h.sort()
l = []
for i in range(N-K+1):
    l.append(h[i+K-1] - h[i])
print(min(l))
Buggy code:
from operator import sub

n, k = map(int, input().split())
hhh = sorted(int(input()) for _ in range(n))
print(min(map(sub, zip(hhh[k - 1:], hhh))))


Fixed code:
from itertools import starmap
from operator import sub

n, k = map(int, input().split())
hhh = sorted(int(input()) for _ in range(n))
print(min(starmap(sub, zip(hhh[k - 1:], hhh))))
Buggy code:
import numpy as np
N,K = map(int,input().split())
list = []
for i in range(N):
 list.append(int(input()))
list = sorted(list);
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))

Fixed code:
import numpy as np
N,K = map(int,input().split())
list = []
for i in range(N):
 list.append(int(input()))
list = sorted(list);
print(min(list[i+K-1] - list[i] for i in range(N-K+1)))
Buggy code:
N,K = input().split()
N = int(N)
K = int(K)

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

trees.sort()
min_diff = 99999999999
a,b,c = trees[0:K]
for i in range(N-K+1) :
	max_v = c
	min_v = a
	diff = max_v - min_v
	if (min_diff > diff) :
		min_diff = diff
	if (min_diff == 0) :
		break

	a,b,c = b,c,trees[i+K]


print(min_diff)

Fixed code:
N,K = input().split()
N = int(N)
K = int(K)

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

trees.sort()
min_diff = 99999999999
for i in range(N-K+1) :
	max_v = trees[i+K-1]
	min_v = trees[i]
	diff = max_v - min_v
	if (min_diff > diff) :
		min_diff = diff
	if (min_diff == 0) :
		break



print(min_diff)
Buggy code:
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
a=10**9
for i in range(n-3):
    a1=max(h[i:i+3])-min(h[i:i+3])
    a=min(a,a1)
print(a)

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

min_h = 1e15
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
    if tmp < min_h:
        min_h = tmp


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

min_h = 1e15
for i in range(N-K+1):
    tmp = H[i+K-1] - H[i]
    if tmp < min_h:
        min_h = tmp
print(min_h)
Buggy code:
n, k = map(int, input().split())
h = list(map(int, [input() for i in range(n)]))
h.sort()
res = 10**10
for i in range(k-1, n):
    res = min(res, h[i]-[i-k+1])
print(res)

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

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

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

ans=1000000000
h.sort()
for i in range(n-k+1):
    tmp=h[i+k-1]-h[i]
    ans=min(ans,tmp)
print(ans)
Buggy code:
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengthes)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)

Fixed code:
N, K = map(int, input().split())
lengths = list(int(input()) for i in range(N))
sorted_lengths = sorted(lengths)
min_score = 2**100

for i in range(N-K+1):
  score = sorted_lengths[i+K-1] - sorted_lengths[i]
  min_score = min(min_score, score)

print(min_score)
Buggy code:
n,k=map(int,input().split())
h=[i for i in range(n)]
h.sort()
l=[]
for i in range(k-2):
  l.append(abs(h[i]-h[i+k-1]))
print(min(l))

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


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

Fixed code:
n,k = map(int,input().split())
a = [int(input()) for i in range(n)]
a.sort()
ans = 1000000000000000
for i in range(n-k+1):
  ans = min(ans,a[i+k-1]-a[i])
    
print(ans)
Buggy code:
n, k = [int(i) for i in input().split()]
hs = []
for i in range(n):
    hs.append(int(input()))

hs.sort()
print(hs)

min_diff = hs[k - 1] - hs[0]
for i in range(n - k + 1):
    diff = hs[i + k - 1] - hs[i]
    if diff == 0:
        min_diff = 0
        break

    if diff < min_diff:
        min_diff = diff

print(min_diff)


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

hs.sort()
# print(hs)

min_diff = hs[k - 1] - hs[0]
for i in range(n - k + 1):
    diff = hs[i + k - 1] - hs[i]
    if diff == 0:
        min_diff = 0
        break

    if diff < min_diff:
        min_diff = diff

print(min_diff)
Buggy code:
x,y=list(map(int, input().split()))
list=[]
for i in range(x):
	list.append(int(input()))
list.sort()
print(list)
ans=10**10

for j in range(x-y+1):
	if list[j+y-1]-list[j]<ans:
		ans=list[j+y-1]-list[j]
print(ans)

Fixed code:
x,y=list(map(int, input().split()))
list=[]
for i in range(x):
	list.append(int(input()))
list.sort()
ans=10**10

for j in range(x-y+1):
	if list[j+y-1]-list[j]<ans:
		ans=list[j+y-1]-list[j]
print(ans)
Buggy code:
N,K = map(int,input().split())
H = sorted(int(input()) for _ in range(N))
ans = float("INF")
print(H)
for i in range(N-K):
    ans = min(H[i+K-1]-H[i],ans)
print(ans)

Fixed code:
N,K = map(int,input().split())
H = sorted(int(input()) for _ in range(N))
ans = float("INF")
for i in range(N-K+1):
    ans = min(H[i+K-1]-H[i],ans)
print(ans)
Buggy code:
n,k=map(int,input().split())
hList=[]
for i in range(n):
  hList.append(int(input()))
hList.sort()
//print(hList)
ans=100000000000000
for i in range(n-k+1):
  tmp=hList[i+k-1]-hList[i]
  if(ans>tmp):
    ans=tmp
print(ans)

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

lis = []

for _ in range(n):
    lis.append(int(input())

lis.sort()

min = 10**10
for i in range(len(lis)-k+1):
    dist = lis[i+k-1] - lis[i]
    if min > dist: min = dist
print(min)


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

lis = []

for _ in range(n):
    lis.append(int(input()))

lis.sort()

min = 10**10
for i in range(len(lis)-k+1):
    dist = lis[i+k-1] - lis[i]
    if min > dist: min = dist
print(min)
Buggy code:
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))


sh = sorted(h)

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

print(min_)

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


sh = sorted(h)

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

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

diff = heights[K-1] - heights[0]
ans = diff

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

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

diff = heights[K-1] - heights[0]
ans = diff

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

trees = list()

for i in range(N):
  trees.append(int(input()))
  
trees = sorted(trees)
print(trees)
diff_list = []

for i in range(N - K + 1):
  diff = trees[i + K - 1] - trees[i]
  diff_list.append(diff)
  
print(diff_list)
print(min(diff_list))

Fixed code:
N, K = (int(x) for x in input().split())

trees = list()

for i in range(N):
  trees.append(int(input()))
  
trees = sorted(trees)
diff_list = []

for i in range(N - K + 1):
  diff = trees[i + K - 1] - trees[i]
  diff_list.append(diff)
  
print(min(diff_list))
Buggy code:
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):
    ans.append(A[i+K-1]-A[i])

print(min(ans))

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

ans_list = []
for index, tree in enumerate(trees):
    if  k-1 <= index:
        print(tree)
        ans_list.append(tree-trees[index-(k-1)])
print(min(ans_list))


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

ans_list = []
for index, tree in enumerate(trees):
    if  k-1 <= index:
        ans_list.append(tree-trees[index-(k-1)])
print(min(ans_list))
Buggy code:
n, k = [int(c) for c in input().split()]
h = [int(input()) for _ in range(n)]

h.sort()

min_d = 100000
for i in range(n-k):
    d = h[i+k-1] - h[i]
    if d < min_d:
        min_d = d

print(min_d)


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

h.sort()

min_d = 1000000000
for i in range(n-k+1):
    d = h[i+k-1] - h[i]
    if d < min_d:
        min_d = d

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


Fixed code:
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)
Buggy code:
N,K=(int(i) for i in input().split())
h=[]
for i in range(N):
    h.append(int(input()))

h.sort()
m=abs(h[0]-h[K-1])
for i in range(1,N-K):
    if m>abs(h[i]-h[K-1]):
        m=abs(h[i]-h[K-1])
print(m)

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

h.sort()
m=abs(h[0]-h[K-1])
for i in range(1,N-K+1):
    if m>abs(h[i]-h[i+K-1]):
        m=abs(h[i]-h[i+K-1])
print(m)
Buggy code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,k = map(int, input().split())
h = np.zeros(n, dtype = int)
for i in range(n):
    h[i] = int(input())

h.sort()
# eprint(h)
ll = np.zeros(n-k+1,dtype=int)
for i in range(n-(k-1)):
    ll[i] = abs(h[i] - h[i+(k-1)])
    
print(ll)
print(ll.min())
    
    
# sorted(h)
# np.sort(h)
# h.sort()
# print(h)




Fixed code:
from __future__ import print_function
import numpy as np
import sys
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy,functools
# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)

n,k = map(int, input().split())
h = np.zeros(n, dtype = int)
for i in range(n):
    h[i] = int(input())

h.sort()
# eprint(h)
ll = np.zeros(n-k+1,dtype=int)
for i in range(n-(k-1)):
    ll[i] = abs(h[i] - h[i+(k-1)])
    
# eprint(ll)
print(ll.min())
    
    
# sorted(h)
# np.sort(h)
# h.sort()
# print(h)
Buggy code:
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,sum(arr[i:i+k]))
print(ans)

Fixed code:
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)
Buggy code:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]

h = sorted(h)

ans = 10000000000
for i in range(N - K - 1):
    if ans > h[i + K - 1] - h[i]:
        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 = 10000000000
for i in range(N - K + 1):
    if ans > h[i + K - 1] - h[i]:
        ans = h[i + K - 1] - h[i]

print(ans)
Buggy code:
import itertools
min_all = 1000000
    
N,K = [int(i) for i in input().split(" ")]
H = [int(input()) for _ in range(N)]
H.sort()
print(H)
    
for i in range(N+1-K):
  min_now = H[K-1+i] - H[i]
  if min_all > min_now:
    min_all = min_now
print(min_all)
        

Fixed code:
import itertools
min_all = 1000000000000000000000000
    
N,K = [int(i) for i in input().split(" ")]
H = [int(input()) for _ in range(N)]
H.sort()
    
for i in range(N+1-K):
  min_now = H[K-1+i] - H[i]
  if min_all > min_now:
    min_all = min_now
print(min_all)
Buggy code:
n,k = map(int,input().split())
c = [int(input()) for _ in range(n)]

c.sort()

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

print(ans)

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

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

print(ans)


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

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())
l=sorted([int(input()) for i in range(n)])
print(min([abs(l[i]-l[i+k]) for i in range(n-k)]))

Fixed code:
n,k=map(int,input().split())
l=sorted([int(input()) for i in range(n)])
print(min([abs(l[i]-l[i+k-1]) for i in range(n-k+1)]))
Buggy code:
n, k = map(int, input().split())
ls = sorted([int(input()) for _ in range(n)])
ans = float('inf')

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

Fixed code:
n, k = map(int, input().split())
ls = sorted([int(input()) for _ in range(n)])
ans = float('inf')

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

def h_find(list,n):
    k=list[n-1]-list[0]
    for i in range(1,len(list)-n+1):
        k2=list[i+n-1]-list[i]
        if k2<k:
            k=k2
        if k==0:
            break
    return k

print(h_find(h,K))

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

def h_find(list,n):
    k=list[n-1]-list[0]
    for i in range(1,len(list)-n+1):
        k2=list[i+n-1]-list[i]
        if k2<k:
            k=k2
        if k==0:
            break
    return k

print(h_find(h,K))
Buggy code:
n,k = map(int, input().split())
ls = k[int(input()) for _ in range(n)]
ls.sort()
tmp = 10 ** 9
for i in range(n-k+1):
    diff = ls[i+k-1] - ls[i]
    if diff < tmp:
        tmp = diff
print(diff)

Fixed code:
n,k = map(int, input().split())
ls = [int(input()) for _ in range(n)]
ls.sort()
tmp = 10 ** 9
for i in range(n-k+1):
    diff = ls[i+k-1] - ls[i]
    if diff < tmp:
        tmp = diff
print(tmp)
Buggy code:
N,K = list(map(int, input().split()))
h = [int(input()) for i in range(N)]
candidate = None
candidate = 1000000000
h.sort()
for i in range(N-K-1):
    tmp = h[i+K-1] - h[i]
    if candidate == None or tmp < candidate:
        first_flg = False
        candidate = tmp
print(candidate)

Fixed code:
N,K = list(map(int, input().split()))
h = [int(input()) for i in range(N)]
candidate = None
h.sort()
for i in range(N-K+1):
    tmp = h[i+K-1] - h[i]
    if candidate == None or tmp < candidate:
        candidate = tmp
print(candidate)
Buggy code:
N,K = map(int,input().split())
lis = [int(input()) for x in range(N)]
lis.sort()
print(min(lis[i+K-1] - lis[i] for x in range(N-K+1)))

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

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

h.sort()

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


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

ans = 1e+12
for i in range(k-1, n):
  ans = min(ans, h[i] - h[i-k+1])
  
print(ans)
Buggy code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, K =mi()
A = [ii() for _ in range(N)]

tmp = float('inf')
for i in range(N-K+1):
    if A[i+K-1] - A[i] < tmp:
        tmp = A[i+K-1] - A[i]
print(tmp)


Fixed code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, K =mi()
A = sorted([ii() for _ in range(N)])

tmp = float('inf')
for i in range(N-K+1):
    if A[i+K-1] - A[i] < tmp:
        tmp = A[i+K-1] - A[i]
print(tmp)
Buggy code:
n,k = map(int,input().split())
ab = []
for _ in range(n):
    a=int(input())
    ab.append(a)
ab.sort()
print(ab)
ans = 1000000000000000000000

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

Fixed code:
n,k = map(int,input().split())
ab = []
for _ in range(n):
    a=int(input())
    ab.append(a)
ab.sort()
#print(ab)
ans = 1000000000000000000000

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

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

Fixed code:
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)
Buggy code:
n, k = map(int, input())

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i range(n-k+11)
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

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

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