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 = input().split(' ')
N = int(N)
L = int(L)

if L >= 0:
    remove = 0
elif abs(L) < N:
    remove = abs(L)
else:
    remove = N-1

print((N-1)*L+sum(range(N))-remove)

Solution (Python):
a = list(map(int,input().split()))
N = a[0]
L = a[1]
  

 
def if_test(N,L):
  taste = 0
  if L > 0:
     for i in range(N):
      taste += (L + i)

       
     taste = taste - L
     print(taste)
      
  elif (L+N-1) < 0:
     for i in range(N):
      taste = taste + L + i 

          
     taste = taste - (L + N - 1)   
     print(taste)
        
  else:
     for i in range(N):
      taste = taste + L + i

     print(taste)
    
if_test(N,L)

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

abs_l = {}
taste = []
for i in range(n):
    taste.append(l+i)
taste_s = sum(taste)
for i in range(n):
    abs_l[i] = abs(taste[i])

abs_min = min(abs_l, key=abs_l.get)
print(sum(taste)-taste[abs_min])

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

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

abs_list = [abs(l+i) for i in range(n)]
abs_min_taste_index = abs_list.index(min(abs_list))

ans = sum - list[abs_min_taste_index]
print(ans)

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

list1 = []
for i in range(1, n+1):
    list1.append(l + i - 1)
if min(list1) > 0:
    print(sum(list1) - list1[0]) 
elif max(list1) < 0:
    print(sum(list1) - list1[n-1])
else:
    print(sum(list1) - list1[list1.index(0)])

Solution (Python):


import math
x =  [int(s) for s in input().split()]
aji = [x[1]+i-1 for i in range(1,x[0]+1)]

sum = 0
for i in range(0,len(aji)):
        sum += aji[i]

sum2 = 0
if(0 in aji):
    for i in range(0,len(aji)):
        sum2 += aji[i]
else:
    if(sum < 0):
        for i in range(0,len(aji)-1):
            sum2 += aji[i]
    else:
        for i in range(1,len(aji)):
            sum2 += aji[i]
print(sum2)

Solution (Python):
n,l=map(int,input().split())
total=0
a=[]
for i in range(n):
    a.append(i+l)
total=sum(a)
ans=1e9
for i in range(n):
    t=total-a[i]
    if abs(total-t)<abs(total-ans):
        ans=t
print(ans)

Solution (Python):
n,l=map(int,input().split())
total=0
for i in range(n):
    total+=i+l
if 0<=l:
    print(total-l)
else:
    if abs(l)<n:
        print(total)
    else:
        diff=abs(l)-(n-1)
        print(total+diff)

Solution (Python):
N, L = map(int, input().split())
R = L + N - 1
x = L + R
m = R
if abs(L) < abs(R):
    m = L 
if L <= 0 and L + N - 1 >= 0:
    m = 0
print(int(x * N / 2 )-m)

Solution (Python):
data = input().split()
N = int(data[0])
L = int(data[1])
taste = []
for i in range(N):
    taste.append(L + (i+1) - 1)
absTaste = []
for i in range(N):
    absTaste.append(abs(taste[i]))
index = 0
minimum = 0
for i in range(1,N):
    if absTaste[i-1] > absTaste[i]:
        index = i
        minimum = taste[i]
ans = sum(taste) - taste[index]
print(ans)

Solution (Python):
N,L = map(int,input().split())
l1 = [L+i for i in range(N)]
allsum = sum(l1)
l2 = list(map(abs,l1))
minimum = l2.index(min(l2))
print(allsum-l1[minimum])

Solution (Python):
n, l = map(int, input().split())
taste = [l + i for i in range(n)]
min_abs = None
for i in taste:
    
    if min_abs == None or abs(min_abs) > abs(i):
        min_abs = i

print(sum(taste)-min_abs)

Solution (Python):
n,l=map(int,input().split())
apples=[l+i for i in range(n)]
a=[abs(l+i) for i in range(n)]
apple=a.index(min(a))
print(sum(apples)-apples[apple])

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

Solution (Python):
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

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

for i in range(1,N+1):
    apple.append(L + i - 1)
del apple[getNearestValue(apple, 0)]
print(sum(apple))

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

if l+n-1<=-1:
  print(int((n-1)*l + (n-2)*(n-1)/2))
  
elif l>=1:
  print(int((n-1)*l + n*(n-1)/2))
  
else:
  print(int(l*n + (n-1)*n/2))

Solution (Python):
N,L = map(int,input().split())
eat = N - 1
for m in range(N):
    if abs(L + m) < abs(L + eat):
        eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)

Solution (Python):
N,L = map(int,input().split())
if L >=0:
    eat = 0
else:
    eat = N - 1
    for m in range(N):
        if abs(L + m) < abs(L + eat):
            eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)

Solution (Python):
import numpy as np

N, L = map(int, input().split())
Nstr = []
Lstr = []
ans = 0

for i in range(N):
  Nstr.append(i)

for i in range(N):
  Lstr.append(i + L)

Lstr.remove(Lstr[np.abs(np.asarray(Lstr) - 0).argmin()])

for i in range(len(Lstr)):
  ans += Lstr[i]

print(ans)

Solution (Python):
def main():
    n,l = map(int,input().split())
    tot = int(l*n + (n+1)*n/2 - n)
    res = tot - l
    for i in range(2,n+1):
        if abs(l+i-1) < abs(tot - res):
            res = tot - (l+i-1)
    print(res)

if __name__ == "__main__":
    main()

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

a=[l+i for i in range(n)]
if a[0]>0:
    eat=a[0]
elif a[n-1]<0:
    eat=a[n-1]
else:
    eat=0
print(sum(a)-eat)

Solution (Python):
N,L=map(int,input().split())
m=L
M=L+N-1
s=0
for i in range(1,N+1):
    s += L+i-1
if m > 0:
    s -= m
elif M < 0:
    s -= M
print(s)

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

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

Solution (Python):
import numpy as np
n,l=map(int,input().split())
li=[]
for i in range(n):
  li.append(l+i)
li2=sorted(li, key=abs)
print(sum(li2[1:]))

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

print(sum((x + L for x in range(N))) - min((x + L for x in range(N)), key = abs))

Solution (Python):
if __name__ == "__main__":
    N,L = input().split()
    tastesum = 0
    tastemin = 1000000000
    N = int(N)
    L = int(L)
    for i in range(N):
        tmptaste = i + L
        if abs(tastemin) > abs(tmptaste):
            tastemin = tmptaste
        tastesum = tastesum + tmptaste
    tastesum = tastesum - tastemin
    print(tastesum)

Solution (Python):
a, b = map(int, input().split())
c = []
for i in range(a):
    c.append([b + i, abs(b + i)])
c = sorted(c, key=lambda x: x[1])
d = 0
for i in range(1, a):
    d += c[i][0]
print(d)

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

array = []

for i in range(1, N+1):
    azi = L+i-1
    array.append(azi)

if array[0]>0:
    print(sum(array[1:]))
elif array[-1]<0:
    print(sum(array[:-1]))
else:
    print(sum(array))

Solution (Python):


def main():
  n,l = map(int,input().split())
  ans = (2*l+n-1)*n//2
  if l > 0:
    ans -= l
  elif l+n-1 <0:
    ans -= (l+n-1)
  print(ans)
main()

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

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

total = 0
min_a = 200
min_v = 0
for i in range(N):
    a = L+i
    total += a
    if abs(a) <= min_a:
        min_a = abs(a)
        min_v = a
print(total-min_v)

Solution (Python):
import numpy as np


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

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

RINGO.pop(AJI.index(min(AJI)))
print(sum(RINGO))

Solution (Python):
N, L = map(int, input().split())
tmp = 100000
proper_i = 0
for i in range(N):
    i = i+1
    m = abs(L + i - 1)
    if m == 0:
        proper_i = i
        break
    elif m < tmp:
        tmp = m
        proper_i = i
apple = []
for i in range(N):
    i = i + 1
    apple.append(L + i - 1)
taste = sum(apple) - apple[proper_i - 1]
print(taste)

Solution (Python):
N, L = map(int, input().split())
tmp = 100000
proper_i = 0
for i in range(N):
    i = i+1
    m = abs(L + i - 1)
    if m == 0:
        proper_i = i
        break
    elif m < tmp:
        tmp = m
        proper_i = i
apple = []
for i in range(N):
    i = i + 1
    apple.append(L + i - 1)
taste = sum(apple) - apple[proper_i - 1]
print(taste)

Solution (Python):
N, L = map(int, input().split())
min = 1000
min_ans = 1000
abs_a = 0
answer = 0
for i in range(1,N+1):
    a = i + L - 1
    answer += a
    abs_a = abs(a)
    if(min > abs_a):
        min = abs_a
        min_ans = a
print(answer - min_ans)

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

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

mi=l
ma=l+n-1

if mi <= 0 and 0 <= ma:
    print(int((mi+ma)*n/2))
elif abs(mi) < abs(ma):
    print(int((mi+ma)*n/2-mi))
else:
    print(int((mi+ma)*n/2-ma))

Solution (Python):
n, L = map(int, input().split())
N = 0
G = 999
for i in range(1, n+1):
    N += (i + L - 1)
NN = N
for i in range(1, n+1):
    DD = NN - (L + i - 1)
    if abs(NN-DD)< G :
        G = abs(NN-DD)
        ZZ = DD
print(ZZ)

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

Solution (Python):

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

diff = 0
if l+1-1 < 0 and l+n-1 > 0:
    diff = 0
elif l+1-1 < 0:
    diff = l+n-1
else:
    diff = l+1-1

ans = 0
for i in range(1,n+1):
    ans += l+i-1

print(ans-diff)

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

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

if L > 0:
    ans -= L
if L < 0:
    if L+N-1 < 0:
        ans -= L+N-1

print(ans)

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

eat_apple = 0

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

total = 0
for i in range(1,N+1):
    total += L  + i  - 1

print(total - (L + eat_apple - 1))

Solution (Python):
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, L] = string_to_int(inputs[0])
    apples = [x + L for x in range(0, N)]
    min_i = 0
    for i in range(1, len(apples)):
        if abs(apples[min_i]) > abs(apples[i]):
            min_i = i
    apples.pop(min_i)

    return sum(apples)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

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

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


if 0 <= L:
    eat = 0
elif -(N-1) <= L:
     eat = -L
else:
    eat = N-1


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

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

if L > 0: print(sum([i for i in range(L+1, L+N)]))
elif L+N-1 < 0: print(sum([i for i in range(L, L+N-1)]))
else: print(sum([i for i in range(L, L+N)]))

Solution (Python):
N, L = list(map(int, input().split()))
D = 99999999
I = 0
for i in range(1, N + 1):
    d = abs(L - 1 + i)
    if d < D:
        D = d
        I = i
print((N - 1) * L + (1 + N) * N // 2 - I - (N - 1))

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

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

Solution (Python):
import numpy as np

n, l = map(int, input().split())
apples = np.array([l + i for i in range(n)])
m = np.argmin(np.abs(apples))
print(np.sum(apples) - apples[m])

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

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

Solution (Python):
import sys


if __name__ == '__main__':
    N, L = map(int, input().split())

    eat_apple = 0
    min_abs_apple_taste = sys.maxsize
    apples = []
    for i in range(N):
        taste = L+(i+1)-1
        apples.append(taste)
        if min_abs_apple_taste > abs(taste):
            min_abs_apple_taste = abs(taste)
            eat_apple = taste

    answer = 0
    for apple in apples:
        if apple != eat_apple:
            answer += apple
    print(answer)

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

apples = [L + i for i in range(N)]
if min(apples) > 0:
    diff = min(apples)
elif max(apples) < 0:
    diff = max(apples)
else:
    diff = 0
print(sum(apples) - diff)

Solution (Python):
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(N-1):
  lst.append(lst[-1]+1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))

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



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


first, last = l, l + n - 1

if first >= 0:
  taste = total - first

elif first < 0 and last >= 0: 
  taste = total - 0

else:
  taste = total - last  

print(taste)

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


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


first, last = l, l + n - 1

if first >= 0:
  taste = total - first

elif first < 0 and last >= 0: 
  taste = total - 0







else:
  taste = total - last  

print(taste)

Solution (Python):
nl = list(map(int, input().split()))
n = nl[0]
l = nl[1]

aji = []
aji_abs = []
for i in range(n):
    aji.append(l + i)
    aji_abs.append(abs(l + i))

if min(aji_abs) == 0:
    print(sum(aji))
elif max(aji) < 0:
    print(sum(aji) - max(aji))
else:
    print(sum(aji) - min(aji))

Solution (Python):
N,L = map(int, input().split())
ringo = []
for i in range(1,N+1):
    ringo.append(L+i-1)
p = 200
p1 = 200
for i in ringo:
    p = abs(i)
    if p1 > p:
        p1 = p 
        ans = i
ringo.remove(ans)
print(sum(ringo))

Solution (Python):
n,l=map(int,input().split())
su,mi=0,9999
for i in range(1,n+1):
    su+=(l+i-1)
    if abs(l+i-1)<abs(mi):mi=l+i-1
print(su-mi)

Solution (Python):
import math
n,l=map(int,input().split())
list0=[]
su,mi=0,9999
for i in range(1,n+1):
    list0=list0+[l+i-1]
    su+=(l+i-1)
    if abs(l+i-1)<abs(mi):mi=l+i-1
print(su-mi)

Solution (Python):
import numpy as np
x = input().split()
n = int(x[0])
l = int(x[1])

ap = np.array(range(1,n+1))
ap = ap + (l-1)
ap = np.delete(ap,abs(ap).argmin())
print(ap.sum())

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

work = 1e9
ans = -1
for i in range(1,N+1):
  al = N*L + N * (N-1) // 2 
  a = L + i - 1
  b = al - a
  
  if abs(al - b) < work:
    work = abs(al - b)
    ans = b
    
print(ans)

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

list =[]
abs_list = []

for i in range(n):
  list.append(l+i)
  abs_list.append(abs(l+i))

x = min(abs_list)

for i in range(len(abs_list)):
  if abs_list[i] == x:
    x = i
    break

list.pop(x)

print(sum(list))

Solution (Python):
N, L=map(int, input().split())
s=0
S=[L+i-1 for i in range(1, N+1)]
T = [abs(S[i]) for i in range(N)]

for i in range(N-1):
    if T[i] < T[i+1]:
        del S[i]
        break
    elif i == N-2:
        del S[N-1]

for i in range(0,N-1):
    s+=S[i]
print(s)

Solution (Python):
import numpy as np

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

t = np.zeros(2)
t[0] = L
t[1] = L+N-1
sum_all = (2*L+N-1)*N/2


if t[0]*t[1] <= 0:
	print(int(sum_all))
else:
	print(int(sum_all-t[np.argmin(np.abs(t))]))

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

tastes = [l+x for x in range(n)]

taste_abs_min = 300

for i in range(n):
    if abs(tastes[i]) < abs(taste_abs_min):
        taste_abs_min = tastes[i]

print(sum(tastes) - taste_abs_min)

Solution (Python):
N,L =map(int,input().split())
total = 0
for i in range(N):
  total = total +(i +L)
if ((L<0) and (N + L>0))or (L == 0):
  print(total)
elif L>0 and N+L>0:
   print(total -L)
else:
   print(total-(N+L-1))

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

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

aji = list(map(lambda x: L + x - 1, range(1, N + 1)))

if (aji[0] <= 0 and aji[N - 1] >= 0) :
    print(sum(aji))
elif (aji[0] < 0 and aji[N - 1] < 0):
    print(sum(aji) - aji[N -1])
else:
    print(sum(aji) - aji[0])

Solution (Python):
N,L =map(int,input().split())
inoazi=0
azi=0
min=100000
bag=[]
for i in range(1,N+1):
    azi+=L+i-1

for j in range(1,N+1):
    tab=azi-(L+j-1)
    if (min>abs(azi-tab)):
        min=abs(azi-tab)
        bag.append(j)
        
m=max(bag)
kotae=azi-(L+m-1)
print(kotae)

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




ans = 0
ls = []
for i in range(1,n+1):
  ls.append(l + i - 1)
ls.sort()
if ls.count(0) == 1:
  print(sum(ls))
else:
  try:
    ls.remove(min(map(abs,ls)))
  except:
  	ls.remove(-min(map(abs,ls)))
  print(sum(ls))

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


lis = []
for n in range(1, N+1):
    azi = L + n - 1
    lis.append(azi)

lis2 = [abs(l) for l in lis]

min = lis2.index(min(lis2))
del lis[min]

print(sum(lis))

Solution (Python):
N, L = map(int, input().split())
min_n = 300
sum_n = 0
for i in range(1, N + 1):
  sum_n += (L + i - 1)
  if min_n > abs(L + i - 1):
    min_n = abs(L + i - 1)
    eat_apple_taste = L + i - 1
print(sum_n - eat_apple_taste)

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

total = sum([L+i for i in range(N)])
diff = float('inf')
for i in range(N):
    a = total - (L+i)
    diff = min(abs(total - a), diff)
if total > 0:
    print(total-diff)
else:
    print(diff+total)

Solution (Python):
N,L=map(int,input().split())
list_=list(range(L,L+N))
a = 1 if max(list_) > 0 else -1
ans = min(map(abs,list_))*a
print(sum(list_)-ans)

Solution (Python):
import math

n, l = map(int, input().split())
sum = 0
small_sum = 0
small_sums = []
diffs = []

for i in range(1,n+1):
    sum += (l + i -1)


for i in range(1, n+1):
    small_sum = 0
    for j in range(1,n+1):
        if j==i:
            continue
        else:
            small_sum += (l+j-1)
    diffs.append(math.fabs(sum-small_sum))
    small_sums.append(small_sum)

print(small_sums[diffs.index(min(diffs))])

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

for i in range(1, N+1):
    taste = L + i - 1
    taste_list.append((taste, abs(taste)))
    
sorted_taste_list = sorted(taste_list, key=lambda x: x[1])
del sorted_taste_list[0]
sum = 0
while sorted_taste_list:
    sum += sorted_taste_list.pop()[0]
print(sum)

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

taste =[]

for i in range(n):
    taste.append(l + i)

sum = 0

for i in range(n):
    sum += taste[i]

sa = 1000
ans = 0
for i in range(n):
    if sa > abs(sum - (sum - taste[i])):
        sa = abs(sum - (sum - taste[i]))
        ans = i

print(sum - taste[ans])

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

Solution (Python):
def main():

    n,l = map(int,raw_input().split())
    taste = []
    flag = True
    sum_taste = 0
    for i in range(n):
        sum_taste = sum_taste + i + l
        if (i + l) < 0:
            taste.append((abs(i + l),"nag"))
        else:
            taste.append((abs(i + l),"pog"))
    sorted_taste = sorted(taste,key = lambda x:x[0])
    if sorted_taste[0][1] == "nag":
        print(sum_taste + sorted_taste[0][0])
    else:
        print(sum_taste - sorted_taste[0][0])



if __name__ == "__main__":
    main()

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

azi=[]
for i in range(N):
  azi.append(L+i)
  
if azi[0]*azi[N-1]<=0:
  eat = 0
elif abs(azi[0])<=abs(azi[N-1]):
  eat = azi[0]
else:
  eat = azi[N-1]

total=sum(azi)-eat

print(total)

Solution (Python):
N, L = map(int, input().split())
num_min = L + 1 - 1
num_max = L + N - 1
if 0 < num_min:
    s = sum([L + i - 1 for i in range(1, N+1)] ) - num_min
elif num_max < 0:
    s = sum([L + i - 1 for i in range(1, N+1)] ) - num_max
else:
    s = sum([L + i - 1 for i in range(1, N+1)] )
print(s)

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

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

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

t1 = 100
s1 = 0
t4 = 0
for i1 in range(n1):

    t4 = n2 + i1
    
    s1 += t4
    if abs(t1) >= abs(t4):
        t1 = t4
print(s1 - t1)

Solution (Python):











N, L = map(int, input().split())
A = [L+x for x in range(N)]

min_abs = abs(A[0])
ate = A[0]

for i in range(len(A)):
    if min_abs > abs(A[i]):
        min_abs = abs(A[i])
        ate = A[i]
        
print(sum(A)-ate)

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

total = sum(list(range(l, n+l)))
pie = []
min_abs = 9999999
for i in range(n):
    a = list(range(l, n+l))
    a.pop(i)
    if abs(total-sum(a)) < min_abs:
        min_abs = abs(total-sum(a))
        ans = sum(a)
print(ans)

Solution (Python):
def resolve():
	n,l=map(int,input().split())
	a=[i+l for i in range(n)]
	p=[i for i in a if i>0]
	m=[i for i in a if i<0]
	if 0 in a:
		print(sum(a))
	elif len(p)<len(m):
		print(sum(a)-max(m))
	else:
		print(sum(a)-min(p))
		
resolve()

Solution (Python):
import numpy as np
N, L = map(int, input().split())
a = [L + i - 1 for i in range(1, N+1)]
a.pop([i for i, j in enumerate(a) if min(np.abs(a)) == abs(j)][0])
print(sum(a))

Solution (Python):
import math

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

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

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

if apples[-1] < 0:
    apples[-1] = 0
elif l > 0:
    apples[0] = 0
print(sum(apples))

Solution (Python):
n,l = map(int,input().split())
aji = 0
for i in range(1,n+1):
    aji += l+i-1
sa = 1e10
ans = 0
for i in range(1,n+1):
    ajii = 0
    for j in range(1,n+1):
        if i == j:
            continue
        ajii += l+j-1
    
    if abs(ajii-aji) < sa:
        sa = abs(ajii-aji)
        ans = ajii
print(ans)

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

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

minaji = ringo[0]
for aji in ringo:
  if abs(minaji) > abs(aji):
    minaji = aji

print(sum(ringo) - minaji)

Solution (Python):
n,l = map(int,input().split())
left = l
right = n+l-1
eat = 0
aji = 0

if right <=0:
	eat = right
elif left >=0:
	eat = left
else:
	eat = 0

for i in range(left,right+1):
	aji += i

aji -= eat
print(aji)

Solution (Python):
import math

N, L = (int(i) for i in input().split())

apple_tastes = [L + i - 1 for i in range(1, N + 1)]
sum_apple_tastes = sum(apple_tastes)
should_eat_apple_index = 0


def sum_up_apple_tastes_without_index(index):
    """sum up apple tastes without index"""
    copy = apple_tastes.copy()
    del copy[index]
    return sum(copy)


def abs_diff_sum_of_apple_tastes(index):
    """diff between sum of all tastes and sum of target """
    return math.fabs(
        sum_up_apple_tastes_without_index(index) -
        sum_apple_tastes
    )


for i, taste in enumerate(apple_tastes):
    current_diff = abs_diff_sum_of_apple_tastes(i)
    acc_diff = abs_diff_sum_of_apple_tastes(should_eat_apple_index)
    if (current_diff < acc_diff):
        should_eat_apple_index = i


result = int(sum_up_apple_tastes_without_index(should_eat_apple_index))
print(result)

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

Solution (Python):
n, l = map(int, input().split())
ingredients = [l + i for i in range(n)]
bite_eating = min(ingredients, key=abs)
ans = sum(ingredients) - bite_eating
print(ans)

Solution (Python):
num, t = map(int, input().split())
taste = []
findmin = []

sum= 0
for i in range(1,num + 1):
  taste.append(t+i-1)
  sum += t+i-1
for j in range(len(taste)):
  findmin.append(taste[j]*taste[j])
m = findmin.index(min(findmin))
print(sum - taste[m])

Solution (Python):
x,y = map(int,input().split())
table = []
for i in range(y,y+x):
    table.append(i)

if table[-1] <= 0:
    ans = sum(table) - table[-1]
elif table[0] < 0 and 0 <= table[-1]:
    ans = sum(table)
elif 0 <= table[0]:
    ans = sum(table) - table[0]
print(ans)

Solution (Python):
x,y = map(int,input().split())
minimum = 10000000
table = [i for i in range(y,y+x)]

table1 = list(filter(lambda x: x>=0,table)) + [1000000000]
table2 = list(filter(lambda x: x<0,table))[::-1] + [-1000000]

if table1[0] > table2[0] * -1:
    print(sum(table) - table2[0])
else:
    print(sum(table) - table1[0])

Solution (Python):
import sys
input = sys.stdin.readline

n, l = map(int, input().split())
sum = 0
ans = [0]*n
apple = [0]*n
for i in range(n):
    apple[i] = l+i
    sum += apple[i]
    ans[i] = abs(apple[i])
print(sum-apple[ans.index(min(ans))])

Solution (Python):
x,y = map(int,input().split())
minimum = 10000000
table = [i for i in range(y,y+x)]

for x in table:
    if abs(minimum) > abs(x):
        minimum = x
print(sum(table) - minimum)

Solution (Python):
N, L = map(int, input().split())
A = [L+(x+1)-1 for x in range(N)]
min_abs = abs(A[0])
eat = A[0]
for i in range(len(A)):
  if min_abs > abs(A[i]):
    min_abs = abs(A[i])
    eat = A[i]
print(sum(A)-eat)

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

n = list(range(L, L+N))

if min(n) >= 0:
    n.remove(min(n))
elif min(n) < 0 < max(n):
    n.remove(0)
else:
    n.remove(max(n))

print(sum(n))

Solution (Python):
N, L = map(int, input().split())
n = 101
ret = 0
for x in range(L, L + N):
    ret += x
    if abs(x) < abs(n):
        n = x
print(ret - n)

Solution (Python):
inputs = [int(i) for i in input().split()]

min_abs_value = 1000
result = 0

for i in range(1, inputs[0]+1):
    value = inputs[1] + i - 1
    result += value
    if (abs(value) < abs(min_abs_value)):
        min_abs_value = value

result -= min_abs_value
print(result)

Solution (Python):
N,L=map(int,input().split(" "))
if N<2 or N > 200 or L<-100 or L>100:
	print ('Illegal')
else:
	s=L*N+N*(N+1)/2-N
	e=1-L

	if e<=0:
		e=1
	elif e>N:
		e=N
	s=s-(L+e-1)
	print(int(s))

Solution (Python):
NL = input().split()
N = int(NL[0])
L = int(NL[1])
apple = []
apple_abs = []
sum = 0
for i in range(1,N+1):
  apple.append(L+i-1)
  apple_abs.append(abs(L+i-1))

apple_min = min(apple_abs)

for i in apple:
  if abs(i) == apple_min:
    continue
  sum += i
print(sum)

Solution (Python):
N,L = map(int, input().split())
azi=list(map(lambda x:L+(x+1)-1,range(N)))
sum=sum(azi)
min=float("inf")
for n in azi:
    if min > abs(n):
        min = abs(n)
        ans=sum-n 
print(ans)

Solution (Python):
check = 10000000
taste_all = 0
list1 = []
N, L = map(int, input().split()) 
for i in range(1,N+1):
    taste = L + i -1
    if (check > abs(taste)):
        check = min (check,abs(taste))
        remove_apple = taste
    list1.append(taste)
    taste_all =taste_all + taste
list1.remove(remove_apple)

print(sum(list1))

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

t = list(range(L, L + N))
s = sum(t)

if 0 in t:
    print(s)
else:
    if abs(t[0]) < abs(t[N - 1]):
        print(s - t[0])
    else:
        print(s - t[N - 1])

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

T = [L + i for i in range(N)]
T = sorted(T, key=lambda x: abs(x))

print(sum(T) - T[0])

Solution (Python):
N,L = map(int,input().split())
aji1 = [L+i-1 for i in range(1,N+1)]
aji = [abs(L+i-1) for i in range(1,N+1)]

minaji = max(aji1)
no = 0
for i in range(N):
    if aji[i] < minaji:
        no = i + 1
        minaji = aji[i]
aji1[no-1] = 0
print(sum(aji1))

Solution (Python):
a, b = map(int, input().split())
c = []
for i in range(a):
    c.append([abs(b+i), b+i])
c.sort()
d = 0
for i in range(1, a):
    d += c[i][1]
print(d)

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

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

Solution (Python):
N,L=map(int,input().split())
list_=list(range(L,L+N))
print(sum(list_)-min(list(map(abs,list_)))*(1,-1)[max(list_)<0])

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

for i in range(N):
  lst.append(L + (i+1) - 1)
  
if L >= 0:
  print(sum(lst)-lst[0])
elif L+N-1 >= 0:
  print(sum(lst))
else:
  print(sum(lst) - lst[N-1])

Solution (Python):
n,l = [int(i) for i in input().split()]
taste = [l+i for i in range(n)]

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

Solution (Python):

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


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




if L >= 0:
    Output = sum(Apple_taste) - min(Apple_taste)
elif abs(L) >= N:
    Output = sum(Apple_taste) - max(Apple_taste)
else :
    Output = sum(Apple_taste)

print(Output)

Solution (Python):
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))

N, L = read_int()

apples = [L + i for i in range(N)]
tasteN = sum(apples)
INF = float('INF')
def solve():
    res = INF
    for a in apples:
        res = min(res, abs(a))
    return tasteN - res if res * tasteN > 0 else tasteN + res

if __name__ == "__main__":
    print(solve())

Solution (Python):
n, l = [int(item) for item in input().split()]
apples = [item + l for item in range(n)]
if apples[0] <= 0 and apples[-1] >= 0:
    print(sum(apples))
elif apples[0] > 0:
    print(sum(apples[1:]))
else:
    print(sum(apples[:-1]))