qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n=int(input())
a=[]
for i in range(n):
  p=int(input())
  a.append(p)

a.sort()
s=p[n-1]//2
print(sum(a)-s)

Fixed code:
n=int(input())
a=[]
for i in range(n):
  p=int(input())
  a.append(p)

a.sort()
s=a[n-1]//2
print(sum(a)-s)
Buggy code:
N = int(input())
price = []
p = 0
for i in range(N):
  price.append(int(input())
m = price.index(max(price))
for j in range(len(price)):
  if j != m:
     p += price[j]
  else:
     p += price[j]//2
print(p)

Fixed code:
N = int(input())
price = []
p = 0
for i in range(N):
  price.append(int(input()))
m = price.index(max(price))
for j in range(len(price)):
  if j != m:
     p += price[j]
  else:
     p += price[j]//2
print(p)
Buggy code:
N = int(input())
p = [int(input()) for i in N]
print(sorted(p)[-1]//2 + sum(sorted(p)[:N-1]))

Fixed code:
N = int(input())
p = [int(input()) for i in range(N)]
print(sorted(p)[-1]//2 + sum(sorted(p)[:N-1]))
Buggy code:
N = int(input())
P = [int(input()) for _ in range(N) ]
total = 0
for p in P:
    print(p)
    total += p
print(total - max(P)//2 )

Fixed code:
N = int(input())
P = [int(input()) for _ in range(N) ]
total = 0
for p in P:
    total += p
print(total - max(P)//2 )
Buggy code:
n=int(input())
p=[int(input()) for i in range(n)]
print(int(sum(p)-(max(p)/2))


Fixed code:
p = [int(input()) for i in range(int(input()))]
print(int(sum(p) - max(p)/2))
Buggy code:
N = int(input())
sum = 0
max = -1
for i in range(N):
    price = int(input())
    sum += price
    if price > max:
        max = price
print(sum-max/2)


Fixed code:
N = int(input())
sum = 0
max = -1
for i in range(N):
    price = int(input())
    sum += price
    if price > max:
        max = price
print(int(sum-max/2))
Buggy code:
n = int(input())
a = list(map(int, [input() for i in range(n)]))
a.sort()
print(a[:-1]+a[-1]//2)

Fixed code:
n = int(input())
a = list(map(int, [input() for i in range(n)]))
a.sort()
print(sum(a[:-1])+a[-1]//2)
Buggy code:
N = int(input())
p = [int(input()) for _ in range(N)]
print(sum(p) - max(p)/2)


Fixed code:
N = int(input())
p = [int(input()) for _ in range(N)]
print(int(sum(p) - max(p)/2))
Buggy code:
l=int(input())
b=[int(i) for i in range(l)]
print(sum(b)-max(b)/2)

Fixed code:
l=int(input())
b=[int(input()) for i in range(l)]
print(sum(b)-max(b)//2)
Buggy code:
n = int(input)
present_list = [0]*n
for i in range(n):
	present_list[i] = int(input())

print(sum(present_list)-present_list[-1]//2)


Fixed code:
n = int(input())
present_list = [0]*n
for i in range(n):
	present_list[i] = int(input())
present_list = sorted(present_list)
print(sum(present_list)-present_list[-1]//2)
Buggy code:
N = int(input())
p = []
for i in range(N):
    _p = int(input())
    p.append(_p)
biggest = 0
j = 0
for i in range(N):
    if(p[i]>biggest):
        j = i
        biggest=p[i]
p[j] = p[j] / 2
print(sum(p))

Fixed code:
N = int(input())
p = []
for i in range(N):
    _p = int(input())
    p.append(_p)
biggest = 0
j = 0
for i in range(N):
    if(p[i]>=biggest):
        j = i
        biggest=p[i]
p[j] = p[j] / 2
print(int(sum(p)))
Buggy code:
n=int(input())
p=[input() for i in range(n)]
print(sum(p)-int(max(p)/2))

Fixed code:
n=int(input())
p=[int(input()) for i in range(n)]
print(sum(p)-int(max(p)/2))
Buggy code:
n = int(input())
p = []
for i in range(n):
    p.append(int(input()))
p.reverse()
ans = 0
for i in range(n):
    if i == 0:
        ans += p[i]/2
    else:
        ans += p[i]
if ans - int(ans) != 0:
    print(ans)
else :
    print(int(ans))

Fixed code:
n = int(input())
p = []
for i in range(n):
    p.append(int(input()))
p.sort()
p.reverse()
ans = 0
for i in range(n):
    if i == 0:
        ans = p[i]/2
    else:
        ans += p[i]
if ans - int(ans) != 0:
    print(ans)
else :
    print(int(ans))
Buggy code:
N=int(input())
List = [int(input()) for i in range(N)]
print(sum(List)-(max(List)/2))

Fixed code:
N=int(input())
List = [int(input()) for i in range(N)]
print(int(sum(List)-(max(List)/2)))
Buggy code:
N = int(input())
p = [0] * N
for i in range(N):
  p[i]=int(input())
  
p = sorted(p,reverse=True)
ans += p.pop(0) / 2 +sum(p)
print(ans)

Fixed code:
N = int(input())
p = [0] * N
for i in range(N):
  p[i]=int(input())
  
p = sorted(p,reverse=True)
ans = p.pop(0) / 2 +sum(p)
print(int(ans))
Buggy code:
m = int(input())
ls = []
for i in range(m):
    ls.append(int(input()))
ls = sorted(ls,reverse=True)
ls[0] = ls[0]/2
n=0
for i in range(m):
    n=n+ls[i]
print(n)

Fixed code:
m = int(input())
ls = []
for i in range(m):
    ls.append(int(input()))
ls = sorted(ls,reverse=True)
ls[0] = ls[0]/2
n=0
for i in range(m):
    n = n + ls[i]
print(int(n))
Buggy code:
a,*n=map(int,open(0));print(sum(n)-max(n)/2)

Fixed code:
a,*n=map(int,open(0));print(int(sum(n)-max(n)/2))
Buggy code:
N = int(input())
p = [int(input()) for i in range(N)]
print(sum(p) - max(p)/2)


Fixed code:
N = int(input())
p = [int(input()) for i in range(N)]
print(sum(p) - max(p) // 2)
Buggy code:
N = int(input())
list = [int(input()) for i in range(N)]
print(sum(list)-(max(N)/2))

Fixed code:
N = int(input())
list = [int(input()) for i in range(N)]
print(sum(list)-(max(list)//2))
Buggy code:
N=int(input())
S=0 
A=0
for i in range(N) :
  B=int(input())
  S = S + B
  if A<B :
    A=B
print(int(S-B/2))

Fixed code:
N=int(input())
S=0 
A=0
for i in range(N) :
  B=int(input())
  S = S + B
  if A<B :
    A=B
print(int(S-A/2))
Buggy code:
N = int(input())
List = [int(input()) for _ in range(N)]
last = sorted(List)[-1] * 0.1
print(sum(List) - last)

Fixed code:
N = int(input())
List = [int(input()) for _ in range(N)]
last = sorted(List)[-1] * 0.5
print(int(sum(List) - last))
Buggy code:
n=int(input())
p=[]
for i in range(n):
    p.append(int(input()))

m=max(p)
for i in range(n):
    if p[i]==m:
        p[i]=int(m)/2

print(sum(p))


Fixed code:
n=int(input())
p=[]
for i in range(n):
    p.append(int(input()))

m=max(p)
for i in range(n):
    if p[i]==m:
        p[i]=int(m)/2
        break

print(int(sum(p)))
Buggy code:
N = int(input())
P = []
for i in range(N):
    P.append(int(input))
print(sum(P)-max(P)//2)

Fixed code:
N = int(input())
P = []
for i in range(N):
    P.append(int(input()))
print(sum(P)-max(P)//2)
Buggy code:
print(sum(p)-max([int(input()) for i in range(int(input()))])//2)

Fixed code:
p = [int(input()) for i in range(int(input()))]
print(sum(p)-max(p)//2)
Buggy code:
N = int(input())
P = []
for n in range(N):
    P.append(int(input()))
print(P)
total = 0
for p in P:
    total +=p
total -= max(P)/2
print(int(total))

Fixed code:
N = int(input())
P = []
for n in range(N):
    P.append(int(input()))
total = 0
for p in P:
    total +=p
total -= max(P)/2
print(int(total))
Buggy code:
N = int(input())
a = [int(input()) for i in range(N)]
MAX_PRICE = max(a)

SUM = sum(a) - MAX_PRICE/2

print(SUM)

Fixed code:
N = int(input())
a = [int(input()) for i in range(N)]
MAX_PRICE = max(a)

SUM = sum(a) - MAX_PRICE/2

print(int(SUM))
Buggy code:
n=int(input())
m=0
s=0
for i in range(n):
    p=int(input())
    s+=p
    m=max(m,p)
print(s-(m/2))

Fixed code:
n=int(input())
m=0
s=0
for i in range(n):
    p=int(input())
    s+=p
    m=max(m,p)
print(int(s-(m/2)))
Buggy code:
N = int(input())
arr = [int(input() for i in range(N))]
print(sum(arr) - max(arr)//2)

Fixed code:
N = int(input())
arr = [int(input()) for i in range(N)]
print(sum(arr) - max(arr)//2)
Buggy code:
N = int(input())
p_list = [int(input()) for i in range(N)] 
sum = 0
for i in range(N):
  if p_list[i] == max(p_list):
    sum += int(p_list[i]/2)
  else:
    sum += p_list[i]
print(sum)

Fixed code:
N = int(input())
p_list = [int(input()) for i in range(N)] 
sum = 0
for i in range(N):
  if i == p_list.index(max(p_list)):
   sum += int(p_list[i]/2)
  else:
    sum += p_list[i]
print(sum)
Buggy code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 20:13:03 2019

@author: avina
"""

n,k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
l.sort(reverse=True)
i = 0
mins = 1e6
while i < n - k +1:
  mins = min(mins, l[i+k-1] - l[i])
  i+=1
print(mins)

Fixed code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 20:13:03 2019

@author: avina
"""

n,k = map(int, input().split())
l = []
for i in range(n):
    l.append(int(input()))
l.sort()
i = 0
mins = 1e10
while i < n - k +1:
  mins = min(mins, l[i+k-1] - l[i])
  i+=1
print(mins)
Buggy code:

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

a.sort()
min_high=1000000000000

for i in range(n-k):
    high=-a[i]+a[i+k-1]
    if high<min_high:
        min_high=high

print(min_high)

Fixed code:

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

a.sort()
min_high=1000000000000

for i in range(n-k+1):
    high=-a[i]+a[i+k-1]
#    print(high,a[i],i)
    if high<min_high:
        min_high=high

print(min_high)
Buggy code:
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):
        m.append(h[i+k-1] - h[i])
print(sorted(m)[0])


Fixed code:
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])
Buggy code:
#ABC115C-ChristmasEve.py

from sys import stdin

input = stdin.readline

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

h = [int(input()) for _ in range(N)]
h.sort()

hdiff = [None]*(N-K+1)

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

print(h)
print(hdiff)
print(min(hdiff))


Fixed code:
#ABC115C-ChristmasEve.py

from sys import stdin

input = stdin.readline

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

h = [int(input()) for _ in range(N)]
h.sort()

hdiff = [None]*(N-K+1)

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

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

ans = 1000000000

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

print(ans)


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

ans = 1000000000

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

print(ans)
Buggy code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,K = cin.mapInt()
    H = cin.intColsList(N)
    print(H)
    H.sort()
    ans = int(1e09)
    for i in range(N - K + 1):
        ans = min(ans,H[i + K - 1] - H[i])
    print(ans)
    return

if __name__ == "__main__":
    main()


Fixed code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N,K = cin.mapInt()
    H = cin.intColsList(N)
    H.sort()
    ans = int(1e09)
    for i in range(N - K + 1):
        ans = min(ans,H[i + K - 1] - H[i])
    print(ans)
    return

if __name__ == "__main__":
    main()
Buggy code:
Cn,k = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
h.sort()
h_max = 0
h_min = 0
r = 0
ans = []
#print(h)
for i in range(r,n):
    h_max = max(h[r:k+r])
    #print(h[r:k])
    h_min = min(h[r:k+r])
    if n -r < k: 
        break
    ans.append(h_max - h_min)
    r += 1
print(min(ans))


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

item=[]
for i in range(n):
    b=int(input())
    item.append(b)
    
item.sort()
temp=[]

for i in range(n-p):
    a=item[i+p-1]-item[i]
    temp.append(a)
    
temp.sort()
print(temp[0])

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

item=[]
for i in range(n):
    b=int(input())
    item.append(b)
    
item.sort()
temp=[]

for i in range(n-p+1):
    a=item[i+p-1]-item[i]
    temp.append(a)
    
temp.sort()
print(min(temp))
Buggy code:
N, K = map(int, input().split())
h = [0] * N
for i in range(N):
    h[i] = int(input())
h.sort()
print(min(h[i+K-1]-h[i] for i in range(N)))


Fixed code:
N, K = map(int, input().split())
h = [0] * N
for i in range(N):
    h[i] = int(input())
h.sort()
print(min(h[i+K-1]-h[i] for i in range(N-K+1)))
Buggy code:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 1000000000
loop = min(K,N-K)
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

Fixed code:
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)
Buggy code:
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))


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

Fixed code:
n,k = map(int,input().split())
li=list(range(n))
for i in range(n):
    li[i]=int(input())
li.sort()
ans=100000000000
for i in range(n-k+1):
    if ans>(li[i+k-1]-li[i]):
        ans=li[i+k-1]-li[i]
print(ans)
Buggy code:
n,k = map(int,input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
c = 10**9
h.sort()
for j in range(n-k):
    c =  min(c,h[j+k-1]-h[j])
print(c)

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

Fixed code:
N,K=map(int,input().split())
List = []
for i in range (N):
  List.append(int(input()))
List.sort()
res = 10000000000000
for i in range(N-K+1):
  res = min(res, List[i+K-1]-List[i])
print(res)
Buggy code:
N, K = map(int,input().split())
h_list = [int(input()) for _ in range(N)]

h_list.sort(reverse = True)
diff = [h_list[i] - h_list[i+K-1] for i in range(N-K+1)]
min(diff)

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

h_list.sort(reverse = True)
diff = [h_list[i] - h_list[i+K-1] for i in range(N-K+1)]
print(min(diff))
Buggy code:
N,K = map(int, input().split())
trees = [int(input()) for _ in range(N)]

def solve(N,K,trees):
    trees.sort()

    diffs = []
    for i,h in enumerate(trees[:N-K+1]):
        min_h = h
        max_h = trees[i+K-1]
        print(min_h,max_h)
        diffs.append(max_h-min_h)

    print(min(diffs))
return

solve(N,K,trees)

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

def solve(N,K,trees):
    trees.sort()

    diffs = []
    for i,h in enumerate(trees[:N-K+1]):
        min_h = h
        max_h = trees[i+K-1]
        #print(min_h,max_h)
        diffs.append(max_h-min_h)

    print(min(diffs))
    return

solve(N,K,trees)
Buggy code:
n, k = (list)(map(int, input().split()))
h = [(int)(input()) for _ in range(n)]

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


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

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


print(ans)

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

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

ans = 10**9
for i,j in zip(h,h[k-1:]):
  ans = min(ans,j-i)
print(ans)

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

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

Fixed code:
N,K = map(int,input().split())
H = sorted([int(input()) for _ in range(N)])
print(min([H[i+K-1]-H[i] for i in range(N-K+1)]))
Buggy code:
# ABC 115 C

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

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

h.sort()

ans = 1.0e+9

print(h)

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

print(ans)


Fixed code:
# ABC 115 C

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

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

h.sort()

ans = 1.0e+9

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

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

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

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


list2=list()

h.sort()

for i in range(N-K):
    list2.append(h[i+K]-h[i+1])
    continue
print(min(list2))

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

list2=list()
h.sort()

for i in range(N-K+1):
    list2.append(h[i+K-1]-h[i])
    continue
print(min(list2))
Buggy code:
n, k = map(int, input().split())
l = [0]*n
for _ in range(n):
  l[_] = int(input())
l.sort()
print(l)

ans = 10**9+1
for i in range(n-k+1):
  d = l[i+k-1]-l[i]
  ans = min(ans, d)
print(ans)
  

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

ans = 10**9+1
for i in range(n-k+1):
  d = l[i+k-1]-l[i]
  ans = min(ans, d)
print(ans)
Buggy code:
N,K=map(int,input().split(" "))
H=[int(input()) for _ in range(N)]
H.sort()
tmax=10**9
for a in range(N-K+1):
    h1,h2=H[a],H[a+K]
    tmax=min(tmax,abs(h1-h2))
    if(tmax==0):
        break
print(tmax)

Fixed code:
N,K=map(int,input().split(" "))
H=[int(input()) for _ in range(N)]
H.sort()
tmax=10**9
for a in range(N-K+1):
    h1,h2=H[a],H[a+K-1]
    tmax=min(tmax,abs(h1-h2))
    if(tmax==0):
        break
print(tmax)
Buggy code:
def main():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])

    print(ans)


if __name__ == '__main__':
    main()


Fixed code:
def main():
    N, K = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]
    ans = 10**12
    H.sort()
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])
    print(ans)


if __name__ == '__main__':
    main()
Buggy code:
N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i] - h[i+K-1])
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))

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

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i+K-1]-h[i])
  if ans[-1] == 0:
    print(0)
    exit()

print(min(ans))
Buggy code:
n, k = map(int, input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
print(h)
ans = 10**10
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 = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
ans = 10**10
for i in range(n-k+1):
  if ans >= h[i+k-1] - h[i]:
    ans = h[i+k-1] - h[i]
    if ans == 0:
      break
print(ans)
Buggy code:
import sys
import numpy as np

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

input = sys.stdin.readline
N,K = map(int,input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = float("inf")
for i in range(N-K):
    ans = min(ans,h[i+K-1]-h[i])
print(ans)

Fixed code:
import sys
import numpy as np

# import os
# path = os.getcwd()
# path = os.path.join(path,"input.txt")
# sys.stdin = open(path)

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

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

Fixed code:
N,K=map(int,input().split())
H=[int(input()) for i in range(N)]
A=sorted(H)[::-1]
ans=10**9
for i in range(N-K+1):
  a=A[i]-A[i+K-1]
  ans=min(ans,a)
print(ans)