CodeEff/ECCO huggingface dataset:
# Original solution
N, L = list(map(int, input().split()))
APsum=0
AJIList=[]
AbsList=[]

for i in range(N):
    APsum += i+L
    AJIList.append(i+L)
    AbsList.append(abs(i+L))
    
#print(AJIList)
#print(AbsList)

del AJIList[AbsList.index(min(AbsList))]

print((sum(AJIList)))


# Optimized solution
N,L=list(map(int, input().split()))
List=[]
i=1
while i<=N:
    List.append(L+i-1)
    i+=1
MIN=abs(List[0])
HIKU=List[0]
j=1
while j<N:
    if abs(List[j])<MIN:
        HIKU=List[j]
        MIN=abs(List[j])
    j+=1
del List[List.index(HIKU)]
print((sum(List)))
# Original solution
n,l=list(map(int,input().split()))
import copy
apple_l=[]

pie=0
deli=[]
for i in range(1,n+1):
  pie+=l+i-1
  deli.append(l+i-1)
ans={}
ans2=[]
for j in range(1,n+1):
  deli2=copy.copy(deli)
  deli2.remove(l+j-1)
  ans[abs(sum(deli2)-pie)]=sum(deli2)
  ans2.append(abs(sum(deli2)-pie))
print((ans[min(ans2)]))



# Optimized solution
n,l=list(map(int,input().split()))

mngap=[1,abs(l+1-1)]
for i in range(2,n+1):
  if mngap[1]>abs(l+i-1):
    mngap=[i,abs(l+i-1)]

total=0
for i in range(1,n+1):
  total+=l+i-1
print((total-(l+mngap[0]-1)))
# Original solution
N, L = list(map(int, input().split()))
l = [L + i for i in range(N)]
l.sort(key=lambda x: abs(x))
ans = sum(l[1:])
print(ans)

# Optimized solution
N, L = list(map(int, input().split()))
n = []
for i in range(1, N+1):
  n.append(L+i-1)

a = 200
I = ""
for i in range(N):
  if abs(n[i]) < a:
    a = abs(n[i])
    I = i
print((sum(n) - n[I]))
# Original solution
n,l = list(map(int,input().split()))
p1 = [(l+i-1) for i in range(1,n+1)]
p2 = [i**2 for i in p1]
num = p2.index(min(p2))
sums = sum(p1)-p1[num]
print(sums)


# Optimized solution
n,l = list(map(int,input().split()))
mn = 1000
for i in range(1,n+1):
    ans = l+i-1
    if abs(ans)<abs(mn):
        ans1 = ans
        mn = min(abs(mn),abs(ans))
ans2 = 0      
for j in range(1,n+1):
    ans2 += (l+j-1)
print((ans2-ans1))
# Original solution
n,l = list(map(int,input().split()))
mn = 1000
for i in range(1,n+1):
    ans = l+i-1
    if abs(ans)<abs(mn):
        ans1 = ans
        mn = min(abs(mn),abs(ans))
ans2 = 0      
for j in range(1,n+1):
    ans2 += (l+j-1)
print((ans2-ans1))

# Optimized solution
n,l = list(map(int,input().split()))
mn = 1000
sums = 0
for i in range(n):
    taste = l+i
    sums += taste
    
for i in range(n):
    taste = l+i
    if mn > abs(taste):
        ans = taste
        mn = abs(taste)
print((sums-ans))
# Original solution
N, L = list(map(int, input().split()))
 
s = N*(2*L+N-1) // 2
l = [abs(L+i) for i in range(N)]

print((s - (L+l.index(min(l)))))

# Optimized solution
N, L = list(map(int, input().split()))

# 元々の味（等差数列の和の公式より）
s = N*(2*L+N-1) // 2
# 味の差の絶対値=リンゴiの味の絶対値
l = [abs(L+i) for i in range(N)]
 
# 味の絶対値が最小になるリンゴのindexを求め、sからその味を引けばよい
print((s - (L+l.index(min(l)))))
# Original solution
N, L = list(map(int, input().split()))

# 元々の味（等差数列の和の公式より）
s = N*(2*L+N-1) // 2
# 味の差の絶対値=リンゴiの味の絶対値
l = [abs(L+i) for i in range(N)]
 
# 味の絶対値が最小になるリンゴのindexを求め、sからその味を引けばよい
print((s - (L+l.index(min(l)))))

# Optimized solution
N, L = list(map(int, input().split()))
 
# 元々の味（等差数列の和の公式より）
s = N*(2*L+N-1) // 2
# 味の絶対値が最小になるリンゴの味を求める
if L+N-1 < 0: eat = L+N-1
elif L > 0: eat = L
else: eat = 0

# 食べる（最適なリンゴ）以外の味の和
print((s - eat))
# Original solution
n, l = list(map(int,input().split()))

pies = [l+i-1 for i in range(1,n+1)]
pie_plan = sum(pies)
pie_real = 0
diff_plan_real = float("inf")
for i in range(1,n+1):
    pie_provisonal = sum([l+j-1 for j in range(1,n+1) if j != i])
    if abs(pie_plan - pie_provisonal) < diff_plan_real:
        diff_plan_real = abs(pie_plan - pie_provisonal)
        pie_real = pie_provisonal
    
print(pie_real)

# Optimized solution
def main():
    N, L = (int(i) for i in input().split())
    s = 0
    li = []
    for i in range(1, N+1):
        s += L + i - 1
        li.append((abs(L + i - 1), i))
    li.sort()

    print((s - (L + li[0][1] - 1)))


if __name__ == '__main__':
    main()
# Original solution
n, l = list(map(int, input().split()))
taste = [l+i for i in range(n)]
ans = [abs(i) for i in taste]

del taste[ans.index(min(ans))]
print((sum(taste)))


# Optimized solution
n, l = list(map(int, input().split()))
taste = [l+i for i in range(n)]
taste.sort(key=lambda x: abs(x))

print((sum(taste[1:])))
# Original solution
N, L = list(map(int,input().split()))
a = L - 1
b = [a + i for i in range(1, N+1)]
s = sum(b)

if 0 in b:
    print(s)
elif s > 0:
    print((s - min(b)))
else:
    print((s - max(b)))

# Optimized solution
N, L = list(map(int,input().split()))
b = [L -1 + i for i in range(1, N+1)]
s = sum(b)

if 0 in b:
    print(s)
elif s > 0:
    print((s - min(b)))
else:
    print((s - max(b)))
# Original solution
n, l = list(map(int, input().split()))
apples = list(range(l, l + n))
if 0 in apples:
    print((sum(apples)))
elif l < 0:
    print((sum(apples) - max(apples)))
else:
    print((sum(apples) - min(apples)))


# Optimized solution
n, l = list(map(int, input().split()))
apples = list(range(l, l + n))
print((sum(apples) - min(apples, key=abs)))
# Original solution
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, L = list(map(int, readline().split()))
F = [L + i for i in range(N)]


tmp = 1000
ans=0
for i in itertools.combinations(F, N - 1):
    if abs(sum(F)-sum(i)) < tmp:
        tmp = abs(sum(F)-sum(i))
        ans=sum(i)

print(ans)


# Optimized solution
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, L = list(map(int, readline().split()))
F = [L + i for i in range(N)]
F.sort(key=lambda x: abs(x))

print((sum(F[1:])))
# Original solution
n,l=list(map(int,input().split()))
ll=[]
lll=[]
mi=False
for i in range(1,n+1):
    ll.append(l+i-1)
    lll.append(abs(l+i-1))
    if (l+i-1)<0:
        mi=True
if 0 in ll:
    print((sum(ll)))
elif mi:
    print((sum(ll)+min(lll)))
else:
    print((sum(ll)-min(ll)))


# Optimized solution
n,l=list(map(int,input().split()))
a=[l+i for i in range(n)]
l=[abs(l+i) for i in range(n)]
l.sort()
x=l[0]
s=sum(a)
if x in a:
    print((s-x))
else:
    print((s+x))
# Original solution
N , L = list(map(int,input().split()))

taste = [0] * N

for i in range(1,N+1) :
    taste[i-1] = L + i - 1

taste.sort(key=lambda i : abs(i))

ans = sum(taste[1:N])

print(ans)

# Optimized solution
N, L = list(map(int, input().split()))

A = [L + i for i in range(N)]
A.sort(key=lambda a: abs(a))

print((sum(A) - A[0]))
# Original solution
n,l=list(map(int,input().split()))
pi=0
a=[]
abs_a=[]
for i in range(1,n+1):
    pi+=l+i-1

for i in range(1,n+1):
    a.append(l+i-1)

for i in range(n):
    abs_a.append(abs(a[i]))    

if max(a)<0:
    p=pi+min(abs_a)
else:
    p=pi-min(abs_a)
    
print(p)

# Optimized solution
n,l=list(map(int,input().split()))
pi=0
a=[]
abs_a=[]
for i in range(1,n+1):
    pi+=l+i-1
    a.append(l+i-1)

for i in range(n):
    abs_a.append(abs(a[i]))    

if max(a)<0:
    p=pi+min(abs_a)
else:
    p=pi-min(abs_a)
    
print(p)
# Original solution
N,L = list(map(int,input().split()))

lis_taste = [L + (i + 1) - 1 for i in range(N)]
lis_abs = [abs(i) for i in lis_taste]
lis_taste.pop(lis_abs.index(min(lis_abs)))
print((sum(lis_taste)))


# Optimized solution
n,l=list(map(int,input().split()))
a=list([l+x-1 for x in list(range(1,n+1))])
a_abs=list([abs(x) for x in a])
print((sum(a)-a[a_abs.index(min(list([abs(x) for x in a])))]))
# Original solution
N,L=list(map(int,input().split()))
taste=[L+i for i in range(N)]
print((sum(taste)-min(taste,key=abs)))

# Optimized solution
N,L=list(map(int,input().split()))
taste=list(range(L,L+N))
print((sum(taste)-min(taste,key=abs)))
# Original solution
n, l = list(map(int, input().split()))
nt = 0
nt1 = 0
for i in range(n):
    nt += l + i
if l >= 0:
    nt1 = nt - l
elif l + n -1 <=0:
    nt1 = nt -(l + n -1)
else:
    nt1 = nt
print(nt1)

# Optimized solution
n, l = list(map(int, input().split()))
eat = 0
nt = 0
if l >= 0:
    eat = l
elif l + n-1 <= 0:
    eat = l + n -1
else:
    eat = 0
for i in range(n):
    nt += l + i
print((nt- eat))
# Original solution
N, L = list(map(int, input().split()))
total = 0
for i in range(N):
    total += (L + i)

if L > 0: print((total - L))
elif L + N - 1 < 0: print((total - (L + N - 1)))
else: print(total)


# Optimized solution
import sys

def solve():
    input = sys.stdin.readline
    N, L = list(map(int, input().split()))
    sumT, minT = 0, 100000000000
    pm = 0
    for i in range(N):
        sumT += L + i
        if abs(L + i) < minT:
            minT = abs(L + i)
            if L + i < 0: pm = 1
    print((sumT - minT * (-1) ** pm))
        

    return 0

if __name__ == "__main__":
    solve()
# Original solution
import copy

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

apple_taste = [L+i for i in range(N)]

pie_taste = sum(apple_taste)

min_diff = 100000
for i in range(N):
    ap = copy.deepcopy(apple_taste)
    ap[i] = 0

    pie_taste2 = sum(ap)
    diff = abs(pie_taste - pie_taste2)

    if diff < min_diff:
        min_diff = diff
        min_index = i


apple_taste[min_index] = 0

print((sum(apple_taste)))

# Optimized solution
N, L = list(map(int, input().split()))

pie = 0
min_abs = 10000
min_abs_apple = None
for i in range(N):
    if min_abs > abs(i + L):
        min_abs = abs(i + L)
        min_abs_apple = i + L
    pie += i + L

print((pie - min_abs_apple))
# Original solution
n,l = list(map(int,input().split()))

all_eat = 0
abs_min = float("inf")
for i in range(n):
    all_eat += l + i
    if abs(l + i) < abs(abs_min):
        abs_min = l + i
        
    
    
print((all_eat - abs_min))


# Optimized solution
n,l = list(map(int,input().split()))

k = (l + (l + n - 1)) * n // 2

a = float("inf")
v = 0
for i in range(l, l+n):
    if a > abs(i):
        v = i
        a = abs(i)

print((k - v))
# Original solution
n,l = list(map(int,input().split()))
id = 0
ans = 0
for i in range(n):
    ans+=l+i
    if abs(l+id)>abs(l+i):
        id = i
print((ans-l-id))

# Optimized solution
def solve():
    n,l = list(map(int,input().split()))
    mn = 10**10
    s = 0
    for i in range(n):
        s+=l+i
        if abs(mn)>abs(l+i):
            mn = l+i
    print((s-mn))
if __name__=='__main__':
    solve()
# Original solution
n, l = list(map(int, input().split()))

a = [0]*n
b = [0]*n

for i in range(n):
  a[i] = l+i

for i in range(n):
  b[i] = abs(sum(a) - (sum(a) - a[i]))

remove = a[b.index(min(b))]

print((int(sum(a)-remove)))



# Optimized solution
n, l = list(map(int, input().split()))

a = [0]*n
b = [0]*n

for i in range(n):
  a[i] = l+i

for i in range(n):
  b[i] = abs(a[i])

remove = a[b.index(min(b))]

print((int(sum(a)-remove)))
# Original solution
import sys
# input = sys.stdin.readline

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

Lsum = sum([L + i for i in range(N)])

for i in range(N):
    if L + i == 0:
        ans = i
        break
else:
    if L + N - 2 < 0: ans = N - 1
    else: ans = 0

print((Lsum - (L + ans)))

# Optimized solution
N, L = list(map(int, input().split()))

apples = [L + i - 1 for i in range(1, N + 1)]

apples.sort(key=lambda x: abs(x))

print((sum(apples) - apples[0]))
# Original solution
n,l=list(map(int,input().split()))
t=a=0
m=1e9
for i in range(n):
    if abs(l+i)<m:
        m=abs(l+i)
        t=l+i
    a+=l+i
print((a-t))

# Optimized solution
n,l=list(map(int,input().split()));print((sum(sorted(list(range(l,l+n)),key=abs)[1:])))
# Original solution
N, L = [int(i) for i in input().split(' ')]

min_ = L
max_ = L + N -1

def eat_apple(N, L):
    if L < 0:
        if max_<0:
            return max_ 
        return 0
    return L

print((int((min_+max_)*(max_-min_+1)/2 - eat_apple(N, L))))

# Optimized solution
N, L = [int(i) for i in input().split()]

min_ = L
max_ = L + N -1

def eat_apple(N, L):
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L)))
# Original solution
N, L = [int(i) for i in input().split()]

min_ = L
max_ = L + N -1

def eat_apple():
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple()))

# Optimized solution
N, L = [int(i) for i in input().split()]

min_ = L
max_ = L + N -1

def eat_apple(N, L, max_):
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print(((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_)))
# Original solution
N,L = list(map(int,input().split()))
A = [L+i for i in range(N)]
x = 10**9
y = -1
for a in A:
    if abs(a) < x:
        x = abs(a)
        y = a
print((sum(A) - y))

# Optimized solution
N,L = list(map(int,input().split()))
R = L+N-1
if L <= 0 <= R:
    print((sum(range(L,R+1))))
elif L > 0:
    print((sum(range(L+1,R+1))))
else:
    print((sum(range(L,R))))
# Original solution
import bisect

n,l = list(map(int,input().split()))

aji = [l+i for i in range(n)]

index = bisect.bisect_left(aji,0)
if index == n:
	index -= 1
print((sum(aji) - aji[index]))


# Optimized solution
n,l = list(map(int,input().split()))

ans = (l-1) * n + n * (n+1) // 2
if l + n - 1 < 0:
	print((ans - (l+n-1)))
elif l > 0:
	print((ans - l))
else:
	print(ans)
# Original solution
N, L = list(map(int, input().split()))
diff_min = 100 + 200 - 1
apples = list()
remove_apple = 0

for i in range(N):
    taste = L + i
    apples.append(taste)
    if abs(taste) < diff_min:
        diff_min = abs(taste)
        remove_apple = taste

print((sum(apples) - remove_apple))


# Optimized solution
n, l = list(map(int, input().split()))
diff = 300
ans = [0] * n
p = 0
for i in range(n):
    taste = l + i
    ans[i] = taste
    if diff > abs(taste):
        diff = abs(taste)
        p = i
print((sum(ans) - ans[p]))
# Original solution
n, l = list(map(int, input().split()))
if l > 0:
    c = l
elif l + n - 1 < 0:
    c = l + n - 1
else:
    c = 0
print((l * n + n * (n - 1) // 2 - c))

# Optimized solution
n, l = list(map(int, input().split()))
a, b = sorted([l, l + n - 1])
print((sum(range((a + 1 if a > 0 else a),
                (b - 1 if b < 0 else b) + 1))))
# Original solution
n,l=list(map(int,input().split()))
li=[i+l for i in range(n)]
l=[abs(i+l) for i in range(n)]

p=l.index(min(l))
li.pop(p)
print((sum(li)))

# Optimized solution
N, L = list(map(int, input().split()))
L = list(range(L, N+L))
L_abs=list([abs(x) for x in L])
L.pop(L_abs.index(min(L_abs)))
print((sum(L)))
# Original solution
N, L = [int(i) for i in input().split()]
taste = [L + i - 1 for i in range(1, N + 1)]
absolute = float('inf')
ans = float('inf')
total = sum(taste)
for i in range(N):
    total_b = sum(taste[:i] + taste[i + 1:])
    if abs(total - total_b) < absolute:
        ans = total_b
        absolute = abs(total - total_b)
print(ans)

# Optimized solution
N, L = [int(i) for i in input().split()]

max_taste = L + N - 1
# おいしさの絶対値が最も小さいりんごを食べ、残りでアップルパイを作る
if max_taste <= 0:
    eat_taste = max_taste
elif L >= 0:
    eat_taste = L
else:
    eat_taste = 0
print(((L + max_taste) * (max_taste - L + 1) // 2 - eat_taste))
# Original solution
N, L = list(map(int, input().split()))

t = [L + _ - 1 for _ in range(1, N+1)] # 絶対値が一番小さい要素を0に変えてsumをとりたい
abseat = 299
eat = 299

for i in range(N):
    abst = abs(t[i])
    if abst < abseat:
        abseat = abs(t[i])
        eat = t[i]

ans = sum(t) - eat
print(ans)

# Optimized solution
N, L = list(map(int, input().split()))

t = [L + _ - 1 for _ in range(1, N+1)] # 絶対値が一番小さい要素を0に変えてsumをとりたい
t = sorted(t, key=lambda x: abs(x))

"""
abseat = 299
eat = 299

for i in range(N):
    abst = abs(t[i])
    if abst < abseat:
        abseat = abs(t[i])
        eat = t[i]

ans = sum(t) - eat
"""
ans = sum(t) - t[0]
print(ans)
# Original solution
N, L = list(map(int, input().split()))
ans = 0
min = L

for i in range(1, N+1):
    a = L+i-1
    ans += a
    if abs(a) < abs(min):
        min = a

ans -= min
print(ans)

# Optimized solution
N, L = list(map(int, input().split()))
v = [L+i for i in range(N)]
ans = sum(v) - min(v, key=abs)
print(ans)
# Original solution
N, L = list(map(int, input().split()))
tastes = [L + i - 1 for i in range(1, N+1)]
apple_eaten = min([abs(t) for t in tastes])
if apple_eaten in tastes:
    print((sum(tastes) - apple_eaten))
else:
    print((sum(tastes) + apple_eaten))

# Optimized solution
import sys
readline = sys.stdin.readline

def main():
    N, L = list(map(int, readline().rstrip().split()))
    A = [L+i-1 for i in range(1, N+1)]
    A_abs = [abs(a) for a in A]
    mi_idx = A_abs.index(min(A_abs))
    print((sum(A) - A[mi_idx]))

if __name__ == '__main__':
    main()
# Original solution
N, L = list(map(int, input().split()))

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

cur_diff = float('inf') 
ans = float('inf')
Sum = sum(A)
for a in A:    
    tmp = Sum - a
    diff = abs(Sum - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp

print(ans)

# Optimized solution
N, L = list(map(int, input().split()))

sumA = 0
for i in range(N):
    sumA += (L + i)
    
cur_diff = float('inf')
ans = 0
for i in range(N):
    tmp = sumA - (L + i)
    diff = abs(sumA - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp
        
print(ans)
# Original solution
import copy
N,L = list(map(int,input().split()))
flaver = []
for i in range(1,N + 1):
    flaver.append(L + i - 1)
flaver_sum = sum(flaver)
for i in range(len(flaver)):
    c_flaver = copy.deepcopy(flaver)
    del c_flaver[i]
    if i == 0:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
    if abs(flaver_sum - sum(c_flaver)) < tmp_min:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
del flaver[index]
print((sum(flaver)))


# Optimized solution
N, L = list(map(int, input().split()))
apples = [i + L for i in range(N)]
apple_pie = sum(apples)
ans = float('inf')
for apple in apples:
    if ans > abs(apple):
        ans = abs(apple)
        val = apple
print((sum(apples) - val))
# Original solution
N, K = list(map(int, input().split()))
h = [int(eval(input())) for _ in range(N)]
h = sorted(h)
dh = []
for i in range(N - K + 1):
    dh = dh + [h[i + K - 1]-h[i]]

print((min(dh)))

# Optimized solution
N, K = list(map(int, input().split()))
h = sorted([int(eval(input())) for _ in range(N)])
print((min([h[i+K-1]-h[i] for i in range(N - K + 1)])))
# Original solution
n,k = list(map(int,input().split()))
h = [int(eval(input())) for _ in range(n)]

h.sort()
hh = [0]*(n-1)
for i in range(n-1):
  hh[i] = h[i+1] - h[i]

ans = 10**10
for i in range(n-k+1):
  ans = min(ans,sum(hh[i:i+k-1]))

print(ans)


# Optimized solution
n,k = list(map(int,input().split()))
h = [int(eval(input())) for _ in range(n)]

#n,k = 7,3
#h = [10,11,12,14,15,20,0]
h.sort()

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

print(ans)
# Original solution
import itertools 
n,k=list(map(int,input().split()))
H=[int(eval(input())) for i in range(n)]
Hn=list(itertools.combinations(H,k))
print((min([max(list(i))-min(list(i)) for i in Hn])))


# Optimized solution
n,k=list(map(int,input().split()))
h=sorted([int(eval(input())) for i in range(n)])
print((min([h[i+k-1]-h[i] for i in range(n-k+1)])))
# Original solution
n,k=list(map(int,input().split()))
A=[]
for i in range(n):
	A.append(int(eval(input())))
C=[]
A.sort()
for i in range(n-k+1):
	B=[]
	for j in range(k):
		B.append(A[i+j])
	C.append(max(B)-min(B))
print((min(C)))

# Optimized solution
n,k=list(map(int,input().split()))
A=[]
for i in range(n):
	A.append(int(eval(input())))
C=[]
A.sort()
for i in range(n-k+1):
  C.append(A[i+k-1]-A[i])
print((min(C)))
# Original solution
import sys
n, k = list(map(int, input().split()))
lines = sys.stdin.readlines()
trees = [None] * n
for i in range(n):
    trees[i] = int(lines[i])



trees.sort()

#print(trees)
min_h = sys.maxsize
k_ = k-1
for i in range(n-k+1):
    tmp = trees[i+k_] - trees[i]
    if tmp < min_h:
        min_h = tmp

print(min_h)

# Optimized solution
import sys
n, k = list(map(int, input().split()))
lines = sys.stdin.readlines()
trees = [None] * n
for i in range(n):
    trees[i] = int(lines[i])

trees.sort()

#print(trees)
min_h = sys.maxsize
k_1 = k - 1
for i in range(n-k+1):
    height_diff = trees[i + k_1] - trees[i]
    if height_diff < min_h:
        min_h = height_diff


print(min_h)
# Original solution
N,K=list(map(int,input().split(" ")))
H=[int(eval(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)

# Optimized solution
N,K=list(map(int,input().split()))
H=[int(eval(input())) for _ in range(N)]
H.sort()
tmp=H[K-1]-H[0]
for i in range(0,N-K+1):
    if tmp>H[K+i-1]-H[i]:
        tmp=H[K+i-1]-H[i]
print(tmp)
# Original solution
from collections import deque
n,k = list(map(int,input().split()))
h = sorted([int(eval(input())) for _ in range(n)])
x = deque(h[:k])
mn = max(x) - min(x)

for i in range(k,n):
    x.append(h[i])
    x.popleft()
    mn = min(mn,max(x) - min(x))
print(mn)

# Optimized solution
from collections import deque
n,k = list(map(int,input().split()))
h = sorted([int(eval(input())) for _ in range(n)])
x = deque([])
mn = 10**9
for i in h:
    x.append(i)
    if len(x) >= k:
        mn = min(mn,x[k-1]-x[0])
        x.popleft()
print(mn)
# Original solution
from collections import deque
n,k = list(map(int,input().split()))
h = sorted([int(eval(input())) for _ in range(n)])
x = deque([])
mn = 10**9
for i in h:
    x.append(i)
    if len(x) >= k:
        mn = min(mn,x[k-1]-x[0])
        x.popleft()
print(mn)

# Optimized solution
n,k = list(map(int,input().split()))
h = sorted([int(eval(input())) for _ in range(n)])
mn = 10**9
for i in range(n-k+1):
    mn = min(mn,h[i+k-1] - h[i])
print(mn)
# Original solution
def resolve():
    n,k=list(map(int, input().split()))
    l=[int(eval(input())) for i in range(n)]
    l.sort()
    a=0
    ans=10**9
    for i in range(n-k+1):
        a=l[i+k-1]-l[i]
        ans=min(a,ans)
    print(ans)
resolve()

# Optimized solution
def resolve():
    n,k=list(map(int, input().split()))
    l=[int(eval(input())) for i in range(n)]
    l.sort()
    print((min(l[i+k-1]-l[i] for i in range(n-k+1))))
resolve()
# Original solution
def resolve():
    n,k=list(map(int, input().split()))
    l=[int(eval(input())) for i in range(n)]
    l.sort()
    print((min(l[i+k-1]-l[i] for i in range(n-k+1))))
resolve()

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=list(map(int, input().split()))
    l=[int(eval(input())) for i in range(n)]
    l.sort()
    ans=10**18
    for i in range(0,n-k+1):
        ans=min(ans,l[i+k-1]-l[i])
    print(ans)
resolve()
# Original solution
# coding: utf-8
import itertools

N, K = list(map(int, input().split()))
lst = [int(eval(input())) for _ in range(N)]
lst2 = list(itertools.combinations(lst, K))

lst3 = []
for l in lst2:
    diff = max(l)-min(l)
    lst3.append(diff)

print((min(lst3)))

# Optimized solution
# coding: utf-8
import itertools

N, K = list(map(int, input().split()))
lst = sorted([int(eval(input())) for _ in range(N)], reverse=True)

ans = 10000000000
for i in range(N-K+1):
    l = lst[i]-lst[i+K-1]
    if l < ans:
        ans = l
print(ans)
# Original solution
# coding: utf-8
import itertools

N, K = list(map(int, input().split()))
lst = sorted([int(eval(input())) for _ in range(N)], reverse=True)

ans = 10000000000
for i in range(N-K+1):
    l = lst[i]-lst[i+K-1]
    if l < ans:
        ans = l
print(ans)

# Optimized solution
# coding: utf-8
N, K = list(map(int, input().split()))
lst = sorted([int(eval(input())) for _ in range(N)], reverse=True)

ans = 10000000000
for i in range(N-K+1):
    l = lst[i]-lst[i+K-1]
    if l < ans:
        ans = l
print(ans)