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

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
ans = 100000000000
for i in range(0, n-k):
  ans = min(ans, trees[i] - trees[i+k-1])
print(ans)

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

trees = []
for _ in range(0, n):
  trees.append(int(input()))
trees.sort()
trees.reverse()
ans = 100000000000
for i in range(0, n-k+1):
  ans = min(ans, trees[i] - trees[i+k-1])
print(ans)
Buggy code:
N,K=map(int, raw_input().split())

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

H.sort()

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

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

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

Fixed code:
n,k=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
h_sort=sorted(h)
print(min(h_sort[j+k-1]-h_sort[j] for j in range(n-k+1)))
Buggy code:
n,k=map(int,input().split())
L=sorted([int(input()) for _ in range(n)])
ans=10**10
for i in range(n-k):
    ans=min(L[i+k-1]-L[i],ans)
print(ans)

Fixed code:
n,k=map(int,input().split())
L=sorted([int(input()) for _ in range(n)])
ans=10**10
for i in range(n-k+1):
    ans=min(L[i+k-1]-L[i],ans)
print(ans)
Buggy code:
n,k = map(int,input().split())
h_list = [int(input()) for _ in range(n)]
h_list.sort(reverse=True)
i = 0
j = k-1
ans = 10**9

while j < n:
    diff = h_list[j]-h_list[i]
    ans = min(ans,diff)
    i  = j
    j += k-1
print(ans)

Fixed code:
n,k = map(int,input().split())
h_list = [int(input()) for _ in range(n)]
h_list.sort(reverse=True)
i = 0
j = k-1
ans = 10**9

while j < n:
    diff = h_list[i]-h_list[j]
    ans = min(ans,diff)
    i += 1
    j += 1
print(ans)
Buggy code:
N, K = map(int,input().split())
li = []

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

li.sort()

co = K - 1
hmin = 1000000
for i in range(N):
        if hmin > li[i+co] - li[i]:
                hmin = li[i+co] - li[i]
                if hmin == 0:
                        break
print(hmin)

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

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

li.sort()

co = K - 1
hmin = li[co] - li[0]
for i in range(N-K+1):
        if hmin > li[i+co] - li[i]:
                hmin = li[i+co] - li[i]
                if hmin == 0:
                        break
print(hmin)
Buggy code:

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(ans)

Fixed code:

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

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

h = np.zeros(N)

for n in range(N):
    h[n] = int(input())

h = np.sort(h)

m = h[N-1] - h[0]

for n in range(0,N-K+1):
    d = h[n+K-1] - h[n]
    if d < m:
        m = d

print(int(d))


Fixed code:
import sys 
import numpy as np

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

h = np.zeros(N)

for n in range(N):
    h[n] = int(input())

h = np.sort(h)

m = h[N-1] - h[0]

for n in range(0,N-K+1):
    d = h[n+K-1] - h[n]
    if d < m:
        m = d

print(int(m))
Buggy code:
N, K = map(int, input().split(" "))
treehight = []
difference = []
for i in range(N):
    treehight.append(int(input()))
treehight.sort()
for j in range(N - 1):
    difference.append(treehight[j+1]-treehight[j])

print(min(difference))


Fixed code:
N, K = map(int, input().split(" "))
treehight = []
difference = []
for i in range(N):
    treehight.append(int(input()))
treehight.sort()
for j in range(N - K + 1):
    difference.append(treehight[j+K-1]-treehight[j])

print(min(difference))
Buggy code:
n, k = map(int,input().split())
h = []
for i in range(n):
	h.append(int(input()))
h.sort()

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

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

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


print(min(h))


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


print(min(l))
Buggy code:
N,K=map(int,input().split())
h=[int(input()) for i in range(N)]
h.sort()
mindif=h[K-1]-h[0]
for i in range(N-K):
    tmp=h[i:i+K]
    dif=tmp[-1]-tmp[0]
    if mindif>dif:
        mindif=dif
print(mindif)

Fixed code:
N,K=map(int,input().split())
h=[int(input()) for i in range(N)]
h.sort()
mindif=h[K-1]-h[0]
for i in range(N-K+1):
    dif=h[i+K-1]-h[i]
    if mindif>dif:
        mindif=dif
print(mindif)
Buggy code:
N, K = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = 1<<31
for i in range(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.sort()
ans = 1<<31
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())
h = []
for i in range(N):
  h.append(int(input()))
h.sort()
mini = 1e9
for i in range(N-K+1):
  sub = h[i+K-1] - h[i]
  if(sub < mini){
    mini = sub
print(mini)

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

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

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

Fixed code:
n, k = map(int,input().split())
h = [int(input()) for _ in range(n)]
h.sort()
between = [h[i+1]-h[i] for i in range(n-1)]
answer = 10**9
for i in range(1,n-1):
  between[i] += between[i-1]
between.insert(0,0)

for i in range(n-k+1):
  answer = min(answer, between[i+k-1]-between[i])
  
print(answer)
Buggy code:
import itertools

def q49(n, k, h):
    h.sort()
    a = [h[i+k-1]-h[i] for i in range(n-1)]
    return min(a)
            
N, K = [int(i) for i in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
print(q49(N, K, h))

Fixed code:
import itertools

def q49(n, k, h):
    h.sort()
    a = [h[i+k-1]-h[i] for i in range(n-k+1)]
    return min(a)
            
N, K = [int(i) for i in input().split()]
h = []
for _ in range(N):
    h.append(int(input()))
print(q49(N, K, h))
Buggy code:
N, K = (int(i) for i in input().split())
H = []
for index in range(0, N):
    H.append(int(input()))
H.sort()
print(H[K-1] - H[0])

Fixed code:
N, K = (int(i) for i in input().split())
H = []
for index in range(0, N):
    H.append(int(input()))
H.sort()
print(min(H[i + K-1] - H[i] for i in range(0, N-K+1)))
Buggy code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = [ii() for _ in range(N)]
    H = sorted(H, reverse=True)
    print(max(H[:K]) - min(H[:K]))


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    H = [ii() for _ in range(N)]
    H = sorted(H, reverse=True)
    cnt = len(H)-K+1
    ret = [0]*cnt
    for i in range(cnt):
        ret[i] = H[i] - H[i+K-1]
    print(min(ret))


if __name__ == '__main__':
    main()
Buggy code:
n,k = map(int,input().split())
h = sorted(list(map(int, [input() for i in range(n)])))
ans = h[n-1]
for j in range(n-k+1):
    ans = min(ans, (h[j+k]-h[j]))
print(ans)

Fixed code:
n,k = map(int,input().split())
h = sorted(list(map(int, [input() for i in range(n)])))
print(min(h[j+k-1]-h[j] for j in range(n-k+1)))
#for j in range(n-k):
    #ans = min(ans, (h[j+k-1]-h[j]))
#print(ans)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jan  2 09:59:01 2019

@author: Yamazaki Kenichi
"""

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

h.sort()

ans = h[K-1] - h[0]

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

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jan  2 09:59:01 2019

@author: Yamazaki Kenichi
"""

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

h.sort()

ans = h[K-1] - h[0]

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

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


Fixed code:
n,k = map(int,input().split())
a = [int(input()) for i in range(n)]
a.sort()
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())
H = [int(input()) for _ in range(n)]
H.sort()
ans = float('inf')

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

Fixed code:
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(H[i+k-1]-H[i], ans)
print(ans)
Buggy code:
if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list()
    for i in range(N):
        h.append(int(input()))

    h = sorted(h)

    res = 10 ** 9 + 1
    for i in range(N-K):
        if res > max(h[i:i+K]) - min(h[i:i+K]):
            res = max(h[i:i+K]) - min(h[i:i+K])
    
    print(res)


Fixed code:
if __name__ == "__main__":
    N, K = map(int, input().split())
    h = list()
    for i in range(N):
        h.append(int(input()))

    h = sorted(h)

    res = 10 ** 9 + 1
    for i in range(N-K+1):
        if res > h[i+K-1] - h[i]:
            res = h[i+K-1] - h[i]
    
    print(res)
Buggy code:
start = list(map(int, input().split()))
n,k = start[0], start[1]

lst = [int(input()) for i in range(n)]

lst.sort()
lst.reverse()

diff_lst = list()
for i in range(n-k+1):
    diff_lst.append(lst[i] - lst[i+k-1])
min(diff_lst)

Fixed code:
start = list(map(int, input().split()))
n,k = start[0], start[1]

lst = [int(input()) for i in range(n)]

lst.sort()
lst.reverse()

diff_lst = list()
for i in range(n-k+1):
    diff_lst.append(lst[i] - lst[i+k-1])
print(min(diff_lst))
Buggy code:
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])


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


Fixed code:
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)
Buggy code:
n,k = map(int, input().split())
h = sorted(list(map(int, [input() for _ in range(n)])))
print(h)
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(list(map(int, [input() for _ in range(n)])))
print(min([h[i+k-1]-h[i] for i in range(n-k+1)]))
Buggy code:
from sys import stdin
N, K = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(stdin.readline().rstrip()) for _ in range(N)]
h.sort()
diff = [h[k + K] - h[k] for k in range(N - K)]
diff.sort()
print(diff[0])


Fixed code:
from sys import stdin
N, K = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(stdin.readline().rstrip()) for _ in range(N)]
h.sort()
diff = [h[k + K - 1] - h[k] for k in range(N - K + 1)]
diff.sort()
print(diff[0])
Buggy code:
N,K = (int(i) for i in input().split())

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


h.sort()
print(h)
smallest = 10**9

for i in range(N-K+1):
    print(h[i+K-1],h[i])
    diff = h[i+K-1] - h[i]
    if diff < smallest:
        smallest = diff

print(smallest)

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

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


h.sort()
#print(h)
smallest = 10**9

for i in range(N-K+1):
    #print(h[i+K-1],h[i])
    diff = h[i+K-1] - h[i]
    if diff < smallest:
        smallest = diff

print(smallest)
Buggy code:
N,K=list(map(int,input().split()))
a=[]
for i in range(N):
  a.append(int(input()))
a.sort(reverse=True)
print(a[0]-a[K-1])

Fixed code:
N,K=list(map(int,input().split()))
a=[]
for i in range(N):
  a.append(int(input()))
a.sort(reverse=True)
ans=a[0]-a[K-1]
for i in range(N-K+1):
  ans = min(ans, a[i]-a[i+K-1])
print(ans)
Buggy code:
import numpy as np
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
data.sort()
data.reverse()
ans=float("inf")
for i in range(N-K+1):
    tmp=data[i]-data[i+K-1]
    if ans > tmp:

Fixed code:
import numpy as np
from sys import stdin
N,K=[int(x) for x in stdin.readline().rstrip().split()]
data=[]
for i in range(N):
    data.append(int(input()))
data.sort()
data.reverse()
ans=float("inf")
for i in range(N-K+1):
    tmp=data[i]-data[i+K-1]
    if ans > tmp:
        ans=tmp
print(ans)
Buggy code:
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
print(h)
ans = []
for i in range(n-k+1):
  ans.append(h[i+k-1]-h[i])
print(min(ans))

Fixed code:
n,k = map(int,input().split())
h = sorted([int(input()) for _ in range(n)])
ans = []
for i in range(n-k+1):
  ans.append(h[i+k-1]-h[i])
print(min(ans))
Buggy code:
n,s=map(int, input().split())
N=[]
for _ in range(n):
    N.append(int(input()))
N=sorted(N)
for i in range(s-1,len(N)):
    diff_list.append(N[i]-N[i-s+1])
print(min(diff_list))

Fixed code:
n,s=map(int, input().split())
N=[]
for _ in range(n):
    N.append(int(input()))
N=sorted(N)
diff_list=[]
for i in range(s-1,len(N)):
    diff_list.append(N[i]-N[i-s+1])
print(min(diff_list))
Buggy code:
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):
    #print(H[i+k-1]-H[i])
    ans=min(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()

#print(H)

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

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

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



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


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


if __name__ == '__main__':
    main()


Fixed code:
def main():
    N, K = map(int, input().split())
    h = [int(input()) for count in range(N)]
    h.sort()
    min_value = min(h[i + K - 1] - h[i] for i in range(N - K + 1))
    print(min_value)


if __name__ == '__main__':
    main()
Buggy code:
""" Atcoder """

import sys
input = sys.stdin.readline

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

H.sort()

min_h = 1000000000

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


Fixed code:
""" Atcoder """

import sys
input = sys.stdin.readline

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

H.sort()

min_h = 1000000000

for i in range(N - K + 1):
    if H[i+K-1] - H[i] < min_h:
        min_h = H[i+K-1] - H[i]
print(min_h)
Buggy code:
N, K = data = list(map(int, input().split()))
h_list = list()

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

h_list.sort()

min_diff = 9999999999
for i in range(N - K):
    diff = abs(h_list[i] - h_list[i + K - 1])
    min_diff = diff if diff < min_diff else min_diff

print(min_diff)


Fixed code:
N, K = data = list(map(int, input().split()))
h_list = list()

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

h_list.sort()

min_diff = 9999999999
for i in range(N - K + 1):
    diff = abs(h_list[i] - h_list[i + K - 1])
    min_diff = diff if diff < min_diff else min_diff

print(min_diff)
Buggy code:
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
    
h.sort()
ans = h[-1] - h[0]

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

Fixed code:
NK = input()
NK = NK.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

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 = [0]*n
for i in range(n):
  a[i] = int(input())

a.sort()

ans = a[-1]-a[0]
for i in range(n-k+1):
  if ans > a[i+k-1]-a[i]:
    ans = a[i+k]-a[i]

print(ans)

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

a.sort()

ans = a[-1]-a[0]
for i in range(n-k+1):
  if ans > a[i+k-1]-a[i]:
    ans = a[i+k-1]-a[i]

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

Fixed code:
N,K=map(int,input().split())
h=list(int(input()) for i in range(N))
h=sorted(h)
t=[]
for i in range(N-K+1):
  s=h[i+K-1]-h[i]
  t.append(s)
print(min(t))
Buggy code:
n, k = map(int, input().split())
h = []
for _ 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(max(ans))

Fixed code:
n, k = map(int, input().split())
h = []
for _ 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:
tree_num,choice_num = map(int,input().split())
tree_list = sorted([int(input()) for _ in range(tree_num)])
mi = 99999
for idx in range(tree_num-choice_num):
    cand = tree_list[idx+choice_num-1] - tree_list[idx]
    if cand < mi:
        mi = cand
print(cand)

Fixed code:
tree_num,choice_num = map(int,input().split())
tree_list = sorted([int(input()) for _ in range(tree_num)])
mi = 999999999999999999999999
for idx in range(tree_num-choice_num+1):
    cand = tree_list[idx+choice_num-1] - tree_list[idx]
    if cand < mi:
        mi = cand
print(mi)
Buggy code:
N, K = map(int, input(). split())
h = [int(input()) for i in range (N)]
h = sorted(h)

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

print(m)

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

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

print(m)
Buggy code:
n, k = map(int,input().split())
lis = []
for _ in range(n):
  lis.append(int(input()))
ans = 100000000000000
for i in range(n-k+1):
  s = lis[i+k-1]-lis[i]
  if s < ans:
    ans = s
print(ans)

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

trees = []
for _i in range(n):
  trees.append(int(input())

trees.sort()
ans = float('inf')

for i in range(n - k + 1):
  diff = trees[i + k - 1] - trees[i]
  if ans > diff:
    ans = diff

print(ans)

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

trees = []
for _i in range(n):
  tree = int(input())
  trees.append(tree)

trees.sort()
ans = float('inf')

for i in range(n - k + 1):
  diff = trees[i + k - 1] - trees[i]
  if ans > diff:
    ans = diff

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

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