Problem:
 Score : 200 points    Problem Statement You have N apples, called Apple 1 , Apple 2 , Apple 3 , ..., Apple N . The flavor of Apple i is L+i-1 , which can be negative.  You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.  You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.  You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.  Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.  We can prove that this value is uniquely determined.      Constraints  2 \leq N \leq 200  -100 \leq L \leq 100  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  L       Output Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.        Sample Input 1 5 2      Sample Output 1 18  The flavors of Apple 1 , 2 , 3 , 4 , and 5 are 2 , 3 , 4 , 5 , and 6 , respectively. The optimal choice is to eat Apple 1 , so the answer is 3+4+5+6=18 .       Sample Input 2 3 -1      Sample Output 2 0  The flavors of Apple 1 , 2 , and 3 are -1 , 0 , and 1 , respectively. The optimal choice is to eat Apple 2 , so the answer is (-1)+1=0 .       Sample Input 3 30 -50      Sample Output 3 -1044

Solution (Python):
N, L = map(int, input().split())

total_taste = 0
min_taste = float('inf')
for i in range(1, N + 1):
    taste = L + i - 1
    total_taste += taste
    if abs(taste) < abs(min_taste):
        min_taste = taste

print(total_taste - min_taste)

Solution (Python):
n, l = map(int, input().split())
apples = [l+i-1 for i in range(1, n+1)]
apples.sort(key=lambda x: abs(x))

del apples[0]
print(sum(apples))

Solution (Python):
N, L = map(int, input().split())

if L + N - 1 < 0:
    eaten = N + L - 1
elif L <= 0 <= L + N - 1:
    eaten = 0
else:
    eaten = L

ans = (L + (L + N - 1)) * N // 2 - eaten
print(ans)

Solution (Python):
n, l = map(int, input().split())
apples = list()
apple_total = 0
for i in range(1, n+1):
    apples.append(l+i-1)
    apple_total += l+i-1
if 0 in apples:
    print(apple_total)
else:
    if apple_total > 0:
        apple_total -= apples[0]
        print(apple_total)
    else:
        apple_total -= apples[-1]
        print(apple_total)

Solution (Python):
N, L = map(int, input().split())
apple = [L + i for i in range(N)]

if apple[0] >= 0:
   apple.pop(0)
elif apple[N-1] < 0:
    apple.pop(N-1)
else:
    apple.pop(-apple[0])
    
print(sum(apple))

Solution (Python):
import numpy as np
i = list(map(int, input().split()))
arr = np.linspace(i[1],i[0]+i[1]-1,i[0])
abs_arr = np.abs(arr)
min_index = np.argmin(abs_arr)
print(int(arr.sum() - arr[min_index]))

Solution (Python):
N, L = map(int, input().split())
apple = []
for i in range(1, N+1):
    apple.append(L + i - 1)
    
apple_eating = []
sum_apple = sum(apple)
for j in apple:
    apple_eating.append(sum_apple - j)
    
temp = 100
ans = 0
for k in apple_eating:
    if abs(sum_apple - k) <= temp:
        temp = abs(sum_apple - k)
        ans = k
        
print(ans)

Solution (Python):
N, L = map(int, input().split())

apples = [i for i in range(L, L+N)]
abs_apples = [abs(i) for i in apples]
eaten_apple_taste = apples[abs_apples.index(min(abs_apples))]

taste_N = sum(apples)
ans = taste_N - eaten_apple_taste
print(ans)

Solution (Python):
n,l=map(int,input().split())
taste=[l+i-1 for i in range(1,n+1)]
ttastee=[]
for i in taste:
	if i<0:
		ttastee.append(i*(-1))
	else:
		ttastee.append(i)

taste.pop(ttastee.index(min(ttastee)))
print(sum(taste))

Solution (Python):
N, L = map(int, input().split())
lin = []
a = []
for i in range(N):
    lin.append(L)
    L += 1
for i in range(len(lin)):
    b = abs(lin[i])
    a.append(b)
if sum(lin) < 0:
    print(sum(lin) + min(a))
else:
    print(sum(lin) - min(a))

Solution (Python):
N,L = map(int,input().split())

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

for i in range(N):
    flag = True
    for j in range(N-1):
        if abs(apple[j]) > abs(apple[j+1]):
            apple[j],apple[j+1] = apple[j+1],apple[j]
            flag = False
    if flag == True :
        break

del(apple[0])
print(sum(apple))

Solution (Python):
N, L = map(int, input().split())

lst_A = []

for i in range(N):
    lst_A.append(L)
    L += 1

eat = 999

for i in range(N):
    if abs(lst_A[i]) < abs(eat):
        eat = lst_A[i]

i = 0
while 1:
    if lst_A[i] == eat:
        del lst_A[i]
        break
    i += 1

print(sum(lst_A))

Solution (Python):
N, L = map(int, input().split())
sum_py = 0
apple_list = []
eat_num = 0
eat_i = 0

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

for i in range(1, N + 1):
    if abs(L + i - 1) < eat_num:
        eat_num = abs(L + i - 1)
        eat_i = i
    apple_list.append(L + i - 1)

del apple_list[eat_i - 1]
sum_py = sum(apple_list)

print(sum_py)

Solution (Python):
import sys
n,l=map(int,input().split())
ls=[]
for i in range(n):
    ls.append(l+i)  

ls.sort()
st=0
hoge=0
sum_ls=sum(ls)

def i_hantei(k):
    if k!=0:
        return True
    return False


if ls[-1]<0:
    print(sum_ls-ls[-1])
    sys.exit()
if ls[0]>0:
    print(sum_ls-ls[0])
    sys.exit()

for i in range(n):
    if ls[i]<0:
        continue
    else:
        if i_hantei(i)==False:
            hoge=ls[i]
            break
        if abs(ls[i-1])<=abs(ls[i]):
            hoge=ls[i-1]
        else:
            hoge=ls[i]
        break
    
print(sum_ls-hoge)

Solution (Python):
N, L = input().split()
apples = [x + int(L) for x in list(range(int(N)))]
abs_apples = [abs(x) for x in apples]
abs_min_index = abs_apples.index(min(abs_apples))
print(sum(apples) - apples[abs_min_index])

Solution (Python):
N, L = input().split()
N = int(N)
L = int(L)

apples = list(range(N)) 
apples = [x + L for x in apples]
abs_apples = [abs(x) for x in apples]
abs_min_index = abs_apples.index(min(abs_apples))

print(sum(apples) - apples[abs_min_index])

Solution (Python):
import numpy as np
def getNearestValue(list, num):

    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

n,l=map(int,input().split())
ap=[i+l-1 for i in range(1,n+1)]
aps=sum(ap)
apsav=[aps-ap[i] for i in range(n)]
print(getNearestValue(apsav,aps))

Solution (Python):
import numpy as np
n, l = map(int,input().split())
q = np.array([l+i for i in range(n)])
s = np.argmin(np.abs(q))
print(np.sum(q)-q[s])

Solution (Python):
N,L = map(int,input().split())
sumL = 0
mainasu = 0
plus = 0
aji = []
count = 0
for i in range(N):
  aji.append(L + i)
  sumL += L + i
  if L + i == 0:
    count = 1
  elif L + i  < 0:
    mainasu += 1
  elif L + i > 0:
    plus += 1
if count == 1:
  print(sumL)
elif mainasu > plus :
  print(sumL-max((aji)))
else:
  print(sumL-min((aji)))

Solution (Python):
N, L = map(int, input().split())

addList = []
total = 0
for n in range(1, N+1):
    addList.append(L + n-1)
    total = total + L + n-1

exceptNum = 0
if addList[-1] <= 0:
    exceptNum = addList[-1]
elif addList[0] >= 0:
    exceptNum = addList[0]

print(total - exceptNum)

Solution (Python):
n,l = map(int,input().split())
mn=10**5
taste = [l+i for i in range(n)]
sm=sum(taste)
for i in range(n):
    if abs(taste[i])<mn:
        mn = abs(taste[i])
        ans = sm - taste[i]

print(ans)

Solution (Python):
N, L = map(int, input().split())
T = [L+i for i in range(N)]
T_abs = [abs(x) for x in T]
min_T_abs_idx = T_abs.index(min(T_abs))
print(sum(T) - T[min_T_abs_idx])

Solution (Python):
N, L = map(int, input().split())
n = []
m = []
for i in range(N):
    n.append(L + (i + 1) - 1)
for j in range(N):
    m.append(abs(n[j]))
a = m.index(min(m))
print(sum(n) - n[a])

Solution (Python):
n, L = map(int, input().split())

d = 10 ** 9
ans = 0

s = 0
for i in range(n):
    s += L + i

for i in range(n):
    if d > abs(L + i):
        d = abs(L + i)
        ans = s - (L + i)

print(ans)

Solution (Python):
n,l = map(int,input().split())
a = [i+l for i in range(n)]
if 0 in a:
  pass
else:
  if abs(a[0]) > abs(a[-1]):
    a.pop()
  else:
    a = a[1:]
print(sum(a))

Solution (Python):
N,L=map(int,input().split())
taste=0
if L>=0:
    for i in range(2,N+1):
        taste=taste+L+i-1
elif L+N-1>=0:
    for i in range(1,N+1):
        taste=taste+L+i-1
else:
    for i in range(1,N):
        taste=taste+L+i-1

print(taste)

Solution (Python):
n, l = map(int, input().split())
ans = sum([l + i - 1 for i in range(1, n+1)])

prev_abs_min = 1000
abs_min = 0
for i in range(1, n+1):
    if prev_abs_min > abs(l + i - 1):
        prev_abs_min = abs(l + i - 1)
        abs_min = l + i - 1
ans -= abs_min
print(ans)

Solution (Python):
N,L=map(int,input().split())
Max=L+N-1
a=int((L+Max)*N/2)
if Max<0:
    a=a-Max
if Max>0:
    if L>0:
        a=a-L
print(a)

Solution (Python):
N,L=input().split()


ApplesTaste=[]
for i in range(int(N)):
    taste=int(L)+i
    ApplesTaste.append(taste)


hu=0
zero=0
for i in ApplesTaste:
    
    if i is 0:
        zero+=1
    if i < 0:
        hu+=1


if zero is 1:
    point=ApplesTaste.index(0)
    del ApplesTaste[point]
    print(sum(ApplesTaste))


elif hu > 0 and zero is 0:
    point=len(ApplesTaste)-1
    
    del ApplesTaste[point]
    print (sum(ApplesTaste))

else:
    del ApplesTaste[0]
    print(sum(ApplesTaste))

Solution (Python):
N,L=map(int,input().split())
ls1=[]
for i in range(N):
    aj=L+i
    ls1.append(aj)
ls2=sorted(ls1,key=lambda x:abs(x))
del ls2[0]
print(sum(ls2))

Solution (Python):
N,L=map(int,input().split())
ls1=[]
for i in range(N):
    aj=L+i
    ls1.append(aj)
ls2=sorted(ls1,key=lambda x:abs(x))
del ls2[0]
print(sum(ls2))

Solution (Python):
N, L = list(map(int, input().split()))
dict_N = {}
min_zero = 100 + 200 - 1
min_id = 0
for i in range(1, N + 1):
    dict_N[i] = L + i - 1
    if min_zero > abs(dict_N[i]):
        min_zero = abs(dict_N[i])
        min_id = i

del dict_N[min_id]
print(sum(dict_N.values()))

Solution (Python):
N,L = map(int,input().split())
a = []
minabs = 1000
tmp = -1

for i in range(N):
    p = L + i
    a.append(L + i)
    if abs(p) < minabs:
        minabs = abs(p)
        tmp = i

print(sum(a) - a[tmp])

Solution (Python):

import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    n, l = map(int, input().split())
    MIN = l
    MAX = l + n - 1
    ans = l * n + n * (n - 1) / 2
    if MIN >= 0:
        print(int(ans - l))
    elif MIN < 0 and 0 < MAX:
        print(int(ans))
    else:
        print(int(ans - MAX))

Solution (Python):
N,L=map(int,input().split())
if L*(L+N-1)<=0:
  print(int((L-1)*N+N*(N+1)/2))
  
elif L<0:
  print(int((L-1)*N+N*(N+1)/2-(L+N-1)))

else:
  print(int((L-1)*N+N*(N+1)/2-L))

Solution (Python):
input = input().split(' ')
N = int(input[0])
L = int(input[1])

tasts = [L + i -1 for i in range(1, N+1)]
abs_tasts = [abs(t) for t in tasts]
print(sum(tasts) - tasts[abs_tasts.index(min(abs_tasts))])

Solution (Python):
n,l=map(int,input().split())
ans=0;count=100
for i in range(n):
    ans+=i+l
    if abs(i+l)<=abs(count):
        count=i+l
print(ans-count)

Solution (Python):
n, l = map(int, input().split())
a = [0] * n
i = 0
s = 0
while i < n:
    a[i] = l + i  
    s += a[i]  
    i += 1
f = 1e9
ans = 0
i = 0
while i < n:
    if f > abs(a[i]):
        f = abs(a[i])
        ans = s - a[i]
    i += 1
print(ans)

Solution (Python):


if __name__ == '__main__':
    n, l = list(map(int, input().split()))
    a = []
    for i in range(1, n+1):
        a.append(l + i - 1)

    ab = abs(sum(a))
    for i in a:
        if abs(ab) > abs(i):
            ab = i
    print(sum(a) - ab)

Solution (Python):
N,L = map(int,input().split())
A = [L+i-1 for i in range(1,N+1)]
a = min(map(abs,A))
S = sum(A)
if a in A:print(S-a)
else:print(S+a)

Solution (Python):
n, l = list(map(int, input().split()))
a = [0 for i in range(n)]
for i in range(n):
  a[i] = l+i
a.sort(key=lambda x:abs(x))
print(sum(a[1:]))

Solution (Python):
N, L = map(int, input().split(" "))

a = list(range(L, L+N))
a.sort(key=abs)

print(sum(a[1:]))

Solution (Python):
n,l = map(int,input().split())
apple = [i + l for i in range(n)]
eat = 10 ** 10
num = 10 ** 10
for i in range(n):
  if eat >= abs(apple[i]):
    num = i
    eat = abs(apple[i])
print(sum(apple)-apple[num])

Solution (Python):
N, L = map(int, input().split())
 
if L > -1:
  N_eat = 1
elif N+L-1 < 1:
  N_eat = N
else:
  N_eat = 1-L
 
pie = N*(N+1)/2 +N*(L-1) - (L + N_eat-1) 
print(int(pie) )

Solution (Python):
import numpy as np

n,l=list(map(int, input().split()))
tastes=list(range(l,n+l))
abs_tastes=np.abs(tastes)
tastes.pop(np.argmin(abs_tastes))
print(sum(tastes))

Solution (Python):
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_))

Solution (Python):
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_))

Solution (Python):
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())

Solution (Python):
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))

Solution (Python):
n,k=map(int,input().split())
ju=False
for i in range(n):
  if k+i==0:
    ju=True
    break
ans=0
if not ju:
  if k<0:
    for i in range(n-1):
      ans+=k+i
  else:
    for i in range(1,n):
      ans+=k+i
else:
  for i in range(n):
    ans+=k+i
print(ans)

Solution (Python):
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)))

Solution (Python):
n,l = map(int,input().split(" "))
ll = []
total=0;
for i in range(0,n):
	s = l+i
	total = total+s
	ll.append(s)
kam = 1000000
for i in range(0,n):
	if(abs(ll[i])<abs(kam)):
		kam=ll[i]
print(total-kam)

Solution (Python):
N, L = map(int, input().split())

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

print(sum(val_of_apples[1::]))

Solution (Python):
a, b = [int(i) for i in input().split()]

c = 0
d = 999999

for i in range(b, a + b):
    c += i
    if abs(i) < d:
        d = abs(i)

if c > 0:
    print(c - d)
else:
    print(c + d)

Solution (Python):

import math
inp = input().split()

n = int(inp[0])
l = int(inp[1])

min_abs = abs(l)
min_num = 0
for i in range(n):
    if abs(l+i) < min_abs:
        min_abs = abs(l+i)
        min_num = i


print(math.ceil(0.5*n*n + n*l - 0.5*n - l - min_num ))

Solution (Python):
N, L = [int(n) for n in input().split()]
ans = [L+i-1 for i in range(1,N+1)]
if 0 in ans:
    print(sum(ans))
elif L < 0 and N <= abs(L):
    print(sum(ans)-max(ans))
else:
    print(sum(ans)-min([abs(n) for n in ans]))

Solution (Python):
n, l = map(int, input().split())

a = [i for i in range(l,n+l)]
s = sum(a)
ans = 1e9
for i in range(n):
    t = s-a[i]
    if abs(t-s) < abs(ans-s):
        ans = t 
print(ans)

Solution (Python):
n,l = map(int,input().split())
if l >= 0:
  print(int((n-1)*(2*l+n)/2))
elif n > abs(l):
  print(int(n*(2*l+n-1)/2))
else:
  print(int((n-1)*(2*l+n-2)/2))

Solution (Python):
def main():
    N, L = map(int, input().split())
    lst = []
    for i in range(N):
        lst.append(L+i+1-1)
    convertLst = list(map(abs, lst))
    minElement = min(convertLst)
    lst.pop(convertLst.index(minElement))
    print(sum(lst))
main()

Solution (Python):
n, l = map(int, input().split())

apple_tastes = [(l+i-1) for i in range(1, n+1)]

n_diff_abs = []
for a in apple_tastes:
    
    n_diff_abs.append(abs(sum(apple_tastes) - (sum(apple_tastes)-a)))


diff_abs_min_index = n_diff_abs.index(min(n_diff_abs))
print(sum(apple_tastes) - apple_tastes[diff_abs_min_index])

Solution (Python):
N,L = (int(x) for x in input().split())
if L<=0 and L+N-1>=0:
        sum = N*(2*L+N-1)//2
elif L<0 and L+N-1<0:
        sum = (N-1)*(2*L+N-2)//2
else:
        sum = (N-1)*(2*L+N)//2
print(sum)

Solution (Python):
n, l = map(int, input().split())
sum_ = int(n * (2 * l + (n - 1)) / 2)
min_ = l
max_ = l + n - 1
if min_ * max_ < 0:
  eaten = 0
else:
  eaten = min_ if abs(min_) < abs(max_) else max_
print(sum_ - eaten)

Solution (Python):
N,L = map(int, input().split())

if L>0:
    print(L*N + N*(N+1)//2 - N - (L + 1 -1))
elif L < 1-N:
    print(L*N + N*(N+1)//2 - N - (L + N -1))
else:
    print(L*N + N*(N+1)//2 - N)

Solution (Python):
i = list(map(int,input().split()))
n = i[0]
l = i[1]
 
alist = []
j = 0
 
for j in range(n):
  x = l + j
  alist.append(x)
  
   
k = 0
m = 0
for k in range(n-1):
  if abs(alist[k]) >= abs(alist[k+1]):
    m = k+1
  
  
print(sum(alist) - alist[m])

Solution (Python):
N,L=map(int,input().split())
Full=int((N**2)/2+N*(L-0.5))
ans=-101
for i in range(L,L+N):
    if abs(ans)>=abs(i):ans=i
    else:pass
print(Full-ans)

Solution (Python):
N, L = input().split()
N,L = int(N),int(L)
apples = []
for i in range(N):
    apples.append(L+i)

error = abs(L)
num = 0

for i in range(N):
    if abs(apples[i]) < error:
        error = abs(apples[i])
        num = i
apples.pop(num)

print(sum(apples))

Solution (Python):
def output(in_):
    import numpy as np
    N, L = [int(el) for el in in_.split(' ')]
    tastes = np.arange(L,N+L)
    return sum(tastes) - tastes[np.argmin(abs(tastes))]

  
in_ = input()
print(output(in_))

Solution (Python):
n,l = map(int,input().split())

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

sum1 = sum(li)
ans = 0
abs1 = 10 ** 10

for i in li:
    sum2 = sum1 - i
    if abs(sum2-sum1) < abs1:
        abs1 = abs(sum2-sum1)
        ans = sum2

print(ans)

Solution (Python):
N,L=map(int,input().split())
taste=[0] 
sum1=0
for i in range(1,N+1): 
    a=L+i-1
    sum1+=a
    taste.append(a)




ans=0
best=100000
for i in range(1,N+1): 
    sum2=sum1-taste[i]
    dif=abs(sum1-sum2)
    
    if dif<best:
        best=dif
        ans=sum2
print(ans)

Solution (Python):
N,L=map(int,input().split())
Ans=[0]*N
for i in range(N):
    Ans[i]=L+i
remove=1000000000
for i in range(N):
    if remove>=abs(Ans[i]):
        remove=abs(Ans[i])
        re=i
print(sum(Ans)-Ans[re])

Solution (Python):
N, L = map(int, input().split())

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

if 0 <= taste[0]:
    print(sum(taste) - taste[0])
else:
    if 0 <= taste[-1]:
        print(sum(taste))
    else:
        print(sum(taste) - taste[-1])

Solution (Python):
N,L=map(int, raw_input().split())

AJI=[ L+i-1 for i in range(1,N+1) ]
total=sum(AJI)

sa_min=float("inf")
for x in AJI:
	sa_min=min(sa_min, abs(x))

if sa_min in AJI:
	print total-sa_min
else:
	print total-(-1*sa_min)

Solution (Python):
N,L=map(int, raw_input().split())

AJI=[ L+i-1 for i in range(1,N+1) ]
total=sum(AJI)

sa_min=float("inf")
for x in AJI:
	sa_min=min(sa_min, abs(x))

if sa_min in AJI:
	print total-sa_min
else:
	print total+sa_min

Solution (Python):
n,l=[int(x) for x in input().split(' ')]
arr=sorted([x+l-1 for x in range(1,n+1)])
arr2=[abs(x) for x in arr]
print(sum(arr)-arr[arr2.index(min(arr2))])

Solution (Python):


"""
1~Nの数字がある
数列iの対応する値はL+i-1である

N = [1,2,3,4,5]
l = 1
対応する値=[2,3,4,5,6]

a = 対応する値の総和の絶対値を取得する
b = 1つだけ除外し、残った対応する値の総和の絶対値を取得する
aとbの差をなるべく小さくするには？
対応する値は負になることもある
"""

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

"""
L + i - 1の対応する値の配列を作成する 
"""
apple_taste = []
taste_total = 0
for i in range(1, n + 1):
    apple_taste.append(L + i - 1)
    taste_total += L + i - 1


"""
要素数が少ないので愚直に一つずつ除外していって差がより小さい箇所を探す
"""

abs_taste_total = abs(sum(apple_taste))
ans = 10 ** 9 
diff = 10 ** 9 

for i in apple_taste:
    current_total = taste_total - i 
    abs_current_total = abs(abs(taste_total) - abs(i)) 

    current_abs = abs(abs(abs_taste_total) - abs(current_total))
    if current_abs < diff:
        diff = current_abs
        ans = current_total

print(ans)

Solution (Python):
n, l = map(int, raw_input().split())
arr = [(abs(l + i - 1), (l + i - 1)) for i in range(1, n + 1)]
arr.sort()
ans = 0
for i in range(1, n):
	ans += arr[i][1]
print ans

Solution (Python):
N, L = map(int, input().split())

taste = []
taste_abs = []
for i in range(N):
    taste.append(L+i)
    taste_abs.append(abs(L+i))
    
minidx = taste_abs.index(min(taste_abs))

print(sum(taste) - taste[minidx])

Solution (Python):
n,l=map(int,input().split())
if l >= 0:
  print((l+1+l+n-1)*(n-1)//2)
elif n-1+l>=0:
  print((l+l+n-1)*n//2)
else:
  print((l+l+n-2)*(n-1)//2)

Solution (Python):
import numpy as np
N,L=map(int,input().split())
mylist =[]
for i in range(1,N+1):
  mylist.append(L+i-1)
minimum = min(map(abs,mylist))
if L<0:
  print(sum(mylist)+minimum)
else:
  print(sum(mylist)-minimum)

Solution (Python):
N,L=map(int,input().split())
n_tot=N*(L-1)+(1/2)*N*(N+1)
l=[]
if L<=0<=L+N-1:
  select=0
elif L>0:
  select=L
else: 
  select=L+N-1
print(int(n_tot-select))

Solution (Python):
N, L = map(int, input().split())

val = range(L, L+N, 1)
total = sum(val)
top = float("inf")

for i in range(len(val)):
    if top > abs(total-(total-val[i])):
        top = abs(total-(total-val[i]))
if total<0:
    print(int(abs(total)-top)*-1)
else:
    print(int(total-top))

Solution (Python):
n, l = map(int, input().split())

zero_include = False

ans = 0
current = l - 1

for i in range(n):
    current += 1
    ans += current

    if current == 0:
        zero_include = True
    
if zero_include == False:
    if current < 0:
        ans -= current
    else:
        ans -= l

print(ans)

Solution (Python):
import numpy as np
N, L = map(int, input().split(' '))
azi = np.array([L+(i+1)-1 for i in range(N)])
azi_abs = abs(azi).tolist()
print(sum(azi)-azi[azi_abs.index(min(azi_abs))])

Solution (Python):
N,L = map(int,input().split())

apple=[]
eat=[]
minim=100000000
for i in range(1,N+1):
    tmp=L+i-1
    apple.append(tmp)
    eat.append([abs(tmp), i])

eat.sort()
print(sum(apple)-apple[eat[0][1]-1])

Solution (Python):
N,L = map(int,input().split())
ls = []
for i in range(L,L+N):
    ls.append(i)
    
if ls[0] > 0:
    del ls[0]
    print(sum(ls))
elif ls[0] < 0 and ls[-1] < 0:
    del ls[-1]
    print(sum(ls))
else:
    print(sum(ls))

Solution (Python):
N, L = 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)

Solution (Python):
N, L = [int(i) for i in input().split()]
print(sum(sorted([L + i for i in range(N)], key=abs)[1:]))

Solution (Python):
N, L = map(int, input().split())

S = (1/2)*N*(N-1) + N*L
x = -(L-1)

if x < 1:
    i = 1
elif x < N:
    i = x
else:
    i = N

print(int(S- (L+i-1)))

Solution (Python):
n,l = map(int,input().split())

sum = int(n * (2 * l + n - 1) / 2)

if l > 0:
    print(sum - l)
elif n + l <= 0:
    print(sum - l - n + 1)
else:
    print(sum)

Solution (Python):
inf = input().split()
N = int(inf[0])
L = int(inf[1])
ans = L*N+N*(N-1)//2
m = L*N
for i in range(N):
  if abs(L+i)<abs(m):
    m = L+i

print(ans-m)

Solution (Python):
[n,l] = [int(i) for i in input().split()]
taste = []
for i in range(n):
  taste.append(l + i)
a = 100000000
for i in range(n):
  if abs(taste[i]) < abs(a):
    a = taste[i]
print(sum(taste) - a)

Solution (Python):
import sys
import math

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

all = []
for i in range(n):
    all.append(l+i)
all_sum = sum(all)

minus = 10000
ans = 0
for i in range(len(all)):
    if math.fabs(all_sum - (all_sum - all[i])) < math.fabs(minus):
        minus = math.fabs(all_sum - (all_sum -all[i]))
        ans = all_sum -all[i]
print(ans)

Solution (Python):
N,L = list(input().split())
N = int(N)
L = int(L)
m = []
for i in range(1,N+1):
  m.append(i+L-1)



z = (list(map(abs,m)))
inn = z.index(min(z))
     

del m[inn]
print(sum(m))

Solution (Python):
a,b = map(int,input().split(" "))
ar = []
mn = 10000
for i in range(a):
  ar.append(i+b)
mx = sum(ar)
ans = 0
for r in ar:
    if mn > abs(mx - (mx - r)):
        mn = abs(mx - (mx - r))
        ans = mx - r
print(ans)

Solution (Python):
N, L = (int(x) for x in input().split())
taste = [0] * N
FLAG = False

for i in range(N):
    taste[i] = L + i
    if taste[i]==0:
        FLAG = True

if FLAG==True:
    print(sum(taste))
if FLAG==False:
    if sum(taste)>0:
        print(sum(taste)-min(taste))
    if sum(taste)<0:
        print(sum(taste)-max(taste))

Solution (Python):

"""
Created on Sun Jun 23 14:10:18 2019

@author: Enya
"""

X = input()
N = int(X.split()[0])
L = int(X.split()[1])

A = 0
B = N*(L - 1)

for i in range(N):
    A += i + 1

if B >= 0:
    print(A + B - L)

elif B == -1:
    print(A + B)

else:
    if abs(B) > abs(A):
        print(A + B - L - N + 1)
    
    else:
        print(A + B)

Solution (Python):
import sys
N,L = map(int,input().split())
apples = [L+i for i in range(N)]
best = sum(apples)
if 0 in apples:
    print(sum(apples))
elif L>=0 :
    print(sum(apples)-apples[0])
else :
    print(sum(apples)-apples[len(apples)-1])

Solution (Python):
n,l = (int(i) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)

Solution (Python):
N, L = map(int, input().split())
a = [L+i for i in range(N)]
s = sum(a)
d = float('inf')
ans = 0
for i in a:
    k = s - i
    l = abs(s - k)
    if l < d:
        ans = k
        d = l

print(ans)

Solution (Python):

import sys
input = sys.stdin.readline


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

ans = 0
minimum = 999
minimum_v = 0
for i in range(n):
        ans += i+l
        if abs(i+l) < minimum:
                minimum = abs(i+l)
                minimum_v = i+l

ans -= minimum_v
print(ans)

Solution (Python):
n,l = map(int,input().split())
x = []
for i in range(n):
    x.append(l+i)
if 0 in x:
    print(sum(x))
elif max(x) < 0:
    print(sum(x)-max(x))
else:
    print(sum(x)-min(x))

Solution (Python):
N, L = map(int, input().split())
arr = [(L+i-1) for i in range(1,N+1)]
arr.sort(key=lambda x:abs(x))
print(sum(arr[1:]))

Solution (Python):
N,L = map(int,input().split())
li = [L+i-1 for i in range(1,N+1)]
li2 = []
for i in range(N):
    li2.append([abs(sum(li)-(sum(li)-li[i])),(sum(li)-li[i])])
li2.sort()
print(li2[0][1])

Solution (Python):
n, like = map(int, input().split())
arr = [like + i for i in range(n)]
arr.sort(key=abs)
print(sum(arr[1:]))

Solution (Python):

"""
B - Bite Eating
https://atcoder.jp/contests/abc131/tasks/abc131_b

"""
import sys


def solve(N, L):
    apples = sorted([a  for a in range(L, L+N)], key=lambda x: abs(x))
    return sum(apples[1:])


def main(args):
    N, L = map(int, input().split())
    ans = solve(N, L)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
def main():
	N, L = map(int, input().split())
	min_a = 0
	if L > 0:
		min_a = L
	elif L+N-1 < 0:
		min_a = L+N-1
	print((N*(2*L+N-1))//2 - min_a)

if __name__ == '__main__':
	main()

Solution (Python):





N,L = map(int, input().split())
An = [L+i-1 for i in range(1,N+1)]

eat = 0
for i,a in enumerate(An):
  if abs(An[eat]) > abs(a):
    eat = i

print(sum(An)-An[eat])

Solution (Python):
n, l = (int(i) for i in input().split())
ap=[]
 
for i in range(n):
	ap.append(l+i)
 
mn=min(map(abs,ap))
 
if mn not in ap:
	mn=-mn
 
res=int((l-1)*n+(1+n)*n/2-mn)
print(res)

Solution (Python):

from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)

def main():
    num, l = map(int, input().split())
    data = [i + l for i in range(num)]

    ans = data[0]
    for i in range(num):
        if abs(ans) > abs(data[i]):
            ans = data[i]

    print(sum(data) - ans)



if __name__ == '__main__':
    main()

Solution (Python):
N, L = map(int, input().split())
ans = 0

if L >= 0:
	A = range(2,N+1)
elif L <= 0 and N <= abs(L):
	A = range(1,N)
else:
	A = range(1,N+1)

for i in A:
	ans += L + i - 1

print(ans)

Solution (Python):
N, L = map(int, input().split())

r1, rN = L, L + N - 1          
s  = N * L + N * (N - 1) // 2  
if r1 * rN > 0:                
    s -= r1 if r1 > 0 else rN
print(s)

Solution (Python):
N, L = map(int, input().split())

sums = 0
for i in range(N):
  sums += L + i

ans = 10 ** 9
cnt = 10 ** 9
for i in range(N):
  num = L + i
  if cnt >= abs(num):
    cnt = abs(num)
    ans = sums - num

print(ans)

Solution (Python):









input_line = input()
lines = input_line.split()
N = int(lines[0])
L = int(lines[1])
total = 0
for i in range(1,N+1):
  taste = L + i - 1
  total += taste
best_diff = None
best = None
for i in range(1,N+1):
  this_total = 0
  for j in range(1,N+1):
    if i == j:
      continue
    this_total += L + j - 1
  score = abs(total - this_total)
  if None == best_diff:
    best_diff = score
    best = this_total
  else:
    if score < best_diff:
      best_diff = score
      best = this_total
print(best)

Solution (Python):
N, L = map(int, input().split())

r1 = L          
rN = L + N - 1  
s  = sum(range(r1, rN + 1))

if not (r1 <= 0 <= rN):
    s -= r1 if abs(r1) < abs(rN) else rN
print(s)

Solution (Python):

"""
Created on Sun Jun 23 09:58:29 2019

@author: Yamazaki Kenichi
"""

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

Apple = []
for i in range(N):
    Apple.append(L + i)

eat = 999
for a in Apple:
    if abs(a) < abs(eat):
        eat = a

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

Solution (Python):
N,L=map(int,input().split())
ap=[]
for i in range(N):
    ap.append(L+i)

p=999

for i in range(N):
    if abs(ap[i]) < p:
        ans = ap[i]
        p = abs(ap[i])

print(sum(ap)-ans)

Solution (Python):
N,L = map(int,input().split())

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

al = sum(apple)

pies = [al-a for a in apple]

if 0 in apple :
    ans = al
elif abs(al - pies[0]) < abs(al - pies[-1]) :
    ans = pies[0]
else :
    ans = pies[-1]

print(ans)

Solution (Python):
N, L = list(map(int,input().split()))
a = range(L, L+N)
d,b = min([ (abs(x),x) for x in a])
c = sum(a)
print(c-b)

Solution (Python):
def solve(n, l):
    target = sum([l + i for i in range(n)])
    best = 10**10
    ans = 0
    for i in range(n):
        d = abs(l + i)
        if best > d:
            best = d
            ans = target - l - i
    return ans

n, l = map(int, input().split())
print(solve(n, l))

Solution (Python):
n,l = map(int,input().split())

t = [(l + i - 1) for i in range(1,n + 1)]

if t[0] >= 0:
    p = sum(t) - l
elif t[-1] > 0:
    p = sum(t)
else:
    p = sum(t) - t[-1]

print(p)

Solution (Python):
n,l=map(int,input().split())
a=[i+l for i in range(n)]
s=sum(a)
m=10**9
for i in range(n):
    if abs(a[i])<abs(m):
        m=a[i]
print(s-m)

Solution (Python):
N,L=map(int,input().split())
A=[]
B=[]
for i in range(1,N+1):
    A.append(L+i-1)
for j in range(1,N+1):
    B.append(abs(L+j-1))
idx=B.index(min(B))
print(sum(A)-A[idx])