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())
 
min_abs=99999999999
min_abs_i=-1
n_aji=0
for i in range(1,n+1):
  aji=l+i-1
  aji_abs=abs(aji)
  if aji_abs < min_abs:
    min_abs = aji_abs
    aji_abs_i = i
  n_aji+=aji
 
print(n_aji-(l+aji_abs_i-1))

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

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

def main():
    n, l = map(int, input().split())
    apple = [l+i-1 for i in range(1, n+1)]
    if apple[-1] < 0:
        print(sum(apple[:-1]))
    elif apple[0] > 0:
        print(sum(apple[1:]))
    else:
        print(sum(apple[:]))
    
if __name__ == '__main__':
    main()

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


a = []
res = 300
for i in range(n):
  a.append(l+i)
  res = min(res, abs(l+i))
s = sum(a)
if res in a:
  print(s-res)
else:
  print(s+res)

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

m = 10 ** 9
pre = 0
for i in range(N):
  t = L + i
  pre += t
  
  if abs(t) < abs(m):
    m = t

print(pre - m)

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

all=0
now=0
for i in range(N):
    all =all +L+(i+1)-1
 
dif=all
for i in range(N):
    if abs(dif) >= abs(L+i):
        dif =L+i
 
print(all-dif)

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

if (l >= 0):
    ans.pop(0)
    print(sum(ans))
elif(n > abs(l)):
    ans.pop(ans.index(0))
    print(sum(ans))
else:
    ans.pop(ans.index(max(ans)))
    print(sum(ans))

Solution (Python):
import numpy as np
n,l = list(map(int, input().split())) 
t_list = np.array([l+(x+1)-1 for x in range(n)])
flags = [True]*n
idx = np.argmin(np.abs(t_list))
flags[idx] = False
print(np.sum(t_list[flags]))

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

if 0 in a_l:
    print(sum(a_l))
elif a_l[0] < 0 :
    print(sum(sorted(a_l, reverse=True)[1:]))
else:
    print(sum(sorted(a_l)[1:]))

Solution (Python):
n,l=map(int,input().split())
a=list(range(l,l+n,1))
x=sum(a)
if(0 in a):
  a.remove(0)
  print(sum(a))
elif(x<0):
  a.remove(max(a))
  print(sum(a))
elif(x>0):
  a.remove(min(a))
  print(sum(a))

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

Solution (Python):
import math
n, l = map(int, input().split())
a_l = [l + i for i in range(n)]
 
min1 = 100
min2 = 10000
 
for j in a_l:
    if j ** 2 <= min2:
        min2 = j **2
        min1 = j
print(sum(a_l) - min1)

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

print(t)

Solution (Python):
N,L = map(int,input().split())
T = range(L,L+N)
print(sum(T)-min(T,key=abs))

Solution (Python):
n,l = map(int,input().split())
aji = [l+i for i in range(n)]
mn= 100
for i in range(n):
    mn= min(mn,abs(aji[i]))
if mn in aji:del aji[aji.index(mn)]
else:del aji[aji.index(-mn)]
print(sum(aji))

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

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

Solution (Python):
N,L=map(int,input().split())
taste = [0]*N
taste_minus = [0]*N
for i in range(N):
    taste[i]=L+i
for j in range(N):
    taste_minus[j]=abs(taste[j])
    minus = min(taste_minus)
    if taste[j]<0:
        minus = -1*minus
    

print(sum(taste)-minus)

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

apple = [L+i for i in range(N)]
min = 500
for k in range(len(apple)):
    if abs(apple[k])<abs(min):
        min = apple[k]

apple.remove(min)
print(sum(apple))

Solution (Python):
n, l = map(int, input().split())
m = 300
ls = []
for i in range(l, l+n):
    m = i if abs(i) < abs(m) else m
    ls.append(i)
print(sum(ls) - m)

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

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

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

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

s1 = 0
m1 = 10**8

for i in range(n):
    if abs(m1) > abs(l):
        m1 = l
    s1 += l
    l += 1

print(s1 - m1)

Solution (Python):
n, l = list(map(int, input().split()))
total = 0
for i in range(1, n+1):
    total += l+i-1

m = 1000000000
ans = 0
for i in range(1, n+1):
    a = total-(l+i-1)
    
    if abs(total-a) < m:
        m = abs(total-a)
        ans = a

print(ans)

Solution (Python):
n, l = map(int, input().split())
s = sum(range(l, n+l))
ans = -1
ans_dif = 10**9
for i in range(l, n+l):
    if ans_dif > abs(s - (s - i)) :
        ans_dif = abs(s - (s - i))
        ans = s - i
print(ans)

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

Solution (Python):
def main():
    N, L = map(int, input().split())
    P = 0
    for i in range(1, N+1):
        P += L + i - 1
    ans = float("inf")
    for i in range(1, N+1):
        tmp = L + i - 1
        x = P - tmp
        if abs(P - x) < abs(P - ans):
            ans = x
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N,L = map(int,input().split())
A = list()
for i in range(N):
  A.append(L+i)
A.sort()
S = sum(A)
if min(A)*max(A)<=0:
  print(S)
else:
  if L>=0:
    print(S-min(A))
  else:
    print(S-max(A))

Solution (Python):
N,L = (int(x) for x in input().split())
Apple = list(L-1+x for x in range(1,N+1))
Abs = list(abs(x) for x in Apple)
Remove = Abs.index(min(Abs))
del Apple[Remove]
print(sum(Apple))

Solution (Python):
n, l = map(int, input().split())
apple = []
for i in range(1, n + 1):
    apple.append(i+l-1)
for i in range(400):
    if i in apple:
        apple.remove(i)
        print(sum(apple))
        break
    elif -i in apple:
        apple.remove(-i)
        print(sum(apple))
        break
    else:
        pass

Solution (Python):
def main():
    N,L = map(int, input().split())
    eat = 10**6
    apples = 0
    for i in range(N):
        apples += i+L
        eat = min(eat,abs(i+L))
    if apples < 0:
        eat *= -1

    print(apples-eat)


if __name__ == '__main__':
    main()

Solution (Python):

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

Solution (Python):
N, L = map(int, input().split())
l = [x+L-1 for x in range(1, N+1)]
l_2 = list(map(abs, l))
min_index = l_2.index(min(l_2))

l[min_index] = 0
print(sum(l))

Solution (Python):
n,l=map(int,input().split())
t=[]
tmp=0
for i in range(n):
    k=i+l
    t.append(k)
    tmp+=k
if min(t)>0:
    tmp-=min(t)
if max(t)<0:
    tmp-=max(t)
print(tmp)

Solution (Python):
n,l=map(int,input().split())
a=10*10
b=int(n*(n+2*l-1)/2)
for i in range(1,n+1):
    if abs(b-a)>abs(l+i-1):
        a=(b-l-i+1)
print(a)

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

if L-1 >= 0:
  i = 1
elif L-1 >= -N:
  i = -(L-1)
else:
  i = N

A = (N-1)*(L-1) + sum([n for n in range(1, N+1)]) - i
print(A)

Solution (Python):
n, l = map(int, input().split())
li = [l+i for i in range(n)]
INF = 1001001001
mn = INF
sum = 0
for i in li:
    sum += i
    if abs(mn) > abs(i):
        mn = i
print(sum - mn)

Solution (Python):
import sys

def S(): return sys.stdin.readline().rstrip()

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

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

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

Solution (Python):
import numpy as np
N,L  = map(int,input().split())
L_list=np.array(range(1,N+1))+L-1
if (0 in L_list):
    print(sum(L_list))
    exit()
if(N<=abs(L) and L<0):
    print(sum(L_list)-L_list[N-1])
    
    exit()
else:
    print(sum(L_list)-L_list[0])
    exit()

Solution (Python):
N,L=map(int,input().split())
li=[]
for i in range(N):
    li.append(L+i+1-1)
A=True
li.sort()
S=sum(li)
for j in range(N-1):
    if abs(li[j])<=abs(li[j+1]):
        S-=li[j]
        A=False
        break

if A==True:
    S-=li[N-1]

print(S)

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

tot=N*L+(N-1)*N/2
ans=[]


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

a=ans.index(min(ans))

print(int(tot-(a+L)))

Solution (Python):
N,L = list(map(int,input().split()))
app_taste = list(range(L,L+N))
bite_apple=L
for i in app_taste:
    if abs(bite_apple) > abs(i):
        bite_apple = i
print(sum(app_taste) - bite_apple)

Solution (Python):
def main():
    import numpy as np
    n, l = map(int,input().split())
    inlis = []
    taishou = 10 *10000
    flag = 0

    for i in range(l, l+n):
        if taishou > np.abs(i):
            taishou = np.abs(i)
            if i < 0:
                flag = 1
        inlis.append(i)
    if flag == 0:
        print(sum(inlis) - taishou)
    else:
        print(sum(inlis) + taishou)

    
        

    
if __name__ == "__main__":
    main()

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

expect = sum(A)
minimum = float('inf')
for a in A:
    tmp = expect
    minimum = min(minimum,abs(sum(A)-(tmp-a)))
    if minimum == abs(sum(A)-(tmp-a)):
        ans = tmp-a
print(ans)

Solution (Python):
import numpy as np

n, l = map(int, input().split())
a = np.arange(1, n+1) + l - 1
print(np.sum(a) - a[np.argmin(np.abs(a))])

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

print(sum(taste[1:]))

Solution (Python):
n, l = 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))

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

tmp = float('inf')
sum = sum(taste)
for i in range(n):
    if abs(taste[i]) < tmp:
        tmp = abs(taste[i])
        ans = sum - taste[i]

print(ans)

Solution (Python):
N, L = map(int, input().split())
v = [L+i for i in range(N)]
ans = sum(v) - min(v, key=abs)
print(ans)

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

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

ans = 0
min_abs = max(b)
min_i = 0

for i in range(N):
    ans += a[i]
    if min_abs > b[i]:
        min_abs = b[i]
        min_i = i

ans -= a[min_i]
print(ans)

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

Solution (Python):
N,L=map(int,input().split())
v=[L+i for i in range(N)]
ans=sum(v)-min(v,key=abs)
print(ans)

Solution (Python):
N,L=map(int,input().split())
v=[L+i for i in range(N)]
s=sum(v)
ans=10**9
for i in range(N):
    if abs(s-(s-v[i]))<abs(s-ans):
        ans=s-v[i]
print(ans)

Solution (Python):
import heapq
n,l = map(int,input().split())
a = [l+i for i in range(n)]
print(sum(a) - min(a,key = lambda x:abs(x)))

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

Solution (Python):
n, l = map(int, input().split())
lst = [l + i for i in range(n)]
m = min(lst, key=lambda x: abs(x))
print(sum(lst) - m)

Solution (Python):
N, L = map(int, input().split())
s = []
for i in range(N):
  s.append(i+L)
t = list(map(abs, s))
del s[t.index(min(t))]
print(sum(s))

Solution (Python):


n, l = map(int, input().split())
cmin = float('inf')
sum = 0

for i in range(1, n+1):
    f = l + i - 1
    sum += f
    if cmin >= 0:
        cmin = min(cmin, f)
    else:
        cmin = max(cmin, f)

print(sum - cmin)

Solution (Python):
A,B=map(int,input().split())
tot=A*(A+2*B-1)//2
X=B
Y=A+B-1
if abs(X)<abs(Y):
  Z=X
else:
  Z=Y
if X<=0 and Y>=0:
  print(tot)
else:
  print(tot-Z)

Solution (Python):
import numpy as np
N, L = map(int,input().split())
AL = []
ans = 0

for i in range(1, N+1):
    Ap = L + i - 1
    AL.append(Ap)
tmp = sorted(np.abs(AL))[0] 

for i in range(1, N+1):
    App = L + i - 1
    if abs(App) != tmp:
        ans += App

print(ans)

Solution (Python):
n,l = map(int,input().split())
liste =[int(x+l) for x in range(n)]
liste2 = [abs(x) for x in liste]
roger = liste2.index(min(liste2))
liste.pop(roger)
print(sum(liste))

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

curr_min = float('inf')
curr_sum = 0
for i in range(1, N + 1):
    curr_flavour = L + i - 1
    curr_sum += curr_flavour
    if curr_min >= 0:
        curr_min = min(curr_min, curr_flavour)
    else:
        curr_min = max(curr_min, curr_flavour)
print(curr_sum - curr_min)

Solution (Python):
N, L = map(int, input().split())
a = [L + i for i in range(N)]
ans = 1000
index = 0
for i in range(N):
    if ans > abs(a[i]):
        ans = abs(a[i])
        index = i

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

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

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

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

Solution (Python):
arr = input().split()

n = int(arr[0])
l = int(arr[1])
s = 0
arr2 = []
for i in range(0,n):
  s += l + i
  arr2.append(l + i)
  
minimum = l + n - 1

for i in range(0, n):
  minimum = min(minimum, abs(arr2[i]))
  
print(s-minimum)

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

Solution (Python):
import math
import datetime
from math import fabs
def main():
    inp,var = map(int, input().split())
    var3 = [var+i-1 for i in range(1,inp+1)]
    var2 = min(var3, key=abs)
    x=sum(var3)-var2
    return x
print(main())

Solution (Python):
a,b=map(int,input().split())
n=list(range(b,b+a))
o=[]
for i in n:
    o.append(abs(i))

del n[o.index(min(o))]

print(sum(n))

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, L = map(int, readline().split())
    
    full = N * L + N * (N-1) // 2
    min_error = INF
    for i in range(N):
        tmp = (N-1) * L + sum(j for j in range(N) if j != i)
        if min_error > abs(full-tmp):
            min_error = abs(full-tmp)
            ans = tmp
            
    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
a,b=map(int,input().split())
total=a*(a+2*b-1)//2
x=b
y=a+b-1
if abs(x)<abs(y):
  z=x
else:
  z=y
if x<=0 and y>=0:
  print(total)
else:
  print(total-z)

Solution (Python):
N,L=map(int,input().split())
taste=range(L,L+N)
print(sum(taste)-min(taste,key=abs))

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

Solution (Python):
n,l = [int(z) for z in input().split()]
a = [0]*n
m = 10000000000
index = 0
for i in range(n):
      a[i] = l+i
      if (abs(a[i])<m):
            index = i
            m = abs(a[i])
print(sum(a)-a[index])

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

Solution (Python):
N,L = map(int,input().split())
taste = []
tmp = []
for i in range(1,N+1):
	tmp.append(abs(L + i -1))
	taste.append((L + i -1))
num = tmp.index(min(tmp)) 
taste[num] = 0
print(sum(taste))

Solution (Python):
import numpy as np

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

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

taste = np.array(taste)

if 0 in taste:
  print(taste.sum())
else:
  if sum(taste) >= 0:
    print(sum(taste) - np.abs(taste).min())
  else:
    print(sum(taste) + np.abs(taste).min())

Solution (Python):
import sys
a=sys.stdin.readline()
res = [int(i) for i in a.split(" ")] 
N,L = [res[i] for i in (0,1)]
flavour1=0
if (N>=2 and N<=200) and (L>=-100 and L<=100) and type(N)==int and type(L)==int:
    a1=[x for x in range(1,N+1)]
    b=[(L+i-1) for i in a1]
    for i in a1:
        flavour1+=b[i-1]
    c=[abs(x) for x in b]
    d=min(c)
    e=c.index(d)
    print((flavour1)-(b[e]))
else:
    print("Error")

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

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

if 0 in li:
    ans = sum([i for i in range(l,l+n)])
elif li[0] > 0:
    ans = sum([i for i in range(l+1,l+n)])
else:
    ans = sum([i for i in range(l,l+n-1)])
print(ans)

Solution (Python):
def solve():
    n, l = map(int, input().split())
    t = [l+i for i in range(n)]
    mint = 100
    index = 0
    for i, v in enumerate(t):
        if mint > abs(v):
            mint = min(mint, abs(v))
            index = i
    t.pop(index)
    print(sum(t))




if __name__ == '__main__':
    solve()

Solution (Python):
N,L=map(int,input().split())
Aji=[0]*N
Sum=0
AjiMin=10**9
EatApple=0
for i in range(N):
  if i==0:
    Aji[i]=L
  else:
    Aji[i]=Aji[i-1]+1
  Sum+=Aji[i]
  AbsVal=abs(Aji[i])
  if AbsVal<AjiMin:
    AjiMin=AbsVal
    EatApple=Aji[i]
print(Sum-EatApple)

Solution (Python):
N,L=map(int,input().split())
Aji=[0]*N
Sum=0
AjiMin=10**9
EatApple=0
for i in range(N):
  if i==0:
    Aji[i]=L
  else:
    Aji[i]=Aji[i-1]+1
  Sum+=Aji[i]
  AbsVal=abs(Aji[i])
  if AbsVal<AjiMin:
    AjiMin=AbsVal
    EatApple=Aji[i]
print(Sum-EatApple)

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

n = [i for i in range(1,N+1)]

l = [abs(i) for i in range(L,N+L)]

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

l2.pop(l2.index(l2[l.index(min(l))]))
ans = sum(l2)    

print(ans)

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

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

min1 = 100
min2 = 10000

for j in a_l:
    if j ** 2 <= min2:
        min2 = j **2
        min1 = j
print(sum(a_l) - min1)

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

min1 = 100
min2 = 10000

for j in a_l:
    if j ** 2 <= min2:
        min2 = j **2
        min1 = j
print(sum(a_l) - min1)

Solution (Python):
def main():
	N, L = map(int, input().split())
	apple = [L+i-1 for i in range(1, N+1)]
	original = sum(apple)

	mindiff = float('inf')
	for j in range(N):
		applepai = sum(apple[:j] + apple[j+1:])
		diff = abs(original - applepai)

		if diff < mindiff:
			mindiff = diff
			ans = applepai
	print(ans)

if __name__ == '__main__':
	main()

Solution (Python):
n,l=map(int,input().split())
ans=float('inf')
for i in range(1,n+1):
  ans=min(ans,abs(l+i-1))
  


s=(l*n+n*(n-1)//2)
if s<=0:
  print(s+ans)
  
else:
  print(s-ans)

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

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

Solution (Python):
n,l=map(int,input().split())
s=[]
t=[]

for i in range(n):
    s.append(l+i)
for i in range(n):
    t.append(abs(s[i]))
    
x=t.index(min(t))

print(sum(s)-s[x])

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

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

for i in range(1, N + 1):
    if apple_min > abs(L + i - 1):
        apple_min = abs(L + i - 1)
        ans = L + i - 1 
    apple_sum += L + i - 1
    
print(apple_sum - ans)

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

ans = 0

if l<=0<=l+n-1:
    for i in range(n):
        ans += l+i
    print(ans)

elif l<0:
    for i in range(n-1):
        ans += l+i
    print(ans)

else:
    for i in range(n-1):
        ans += l+i+1
    print(ans)

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

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

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

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

minn = float('INF')
savei = None
for i in range(n):
    num = abs(apple[i])
    if(minn > num):
        minn = num
        savei = i

print(sum(apple) - apple[savei])

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(list(range(L,L+N-1))))
else:
    print(sum(list(range(L,L+N))))

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

l = 0
m = 10000
for i in range(1,N+1):
  l += L+i-1
  m = min(m,abs(L+i-1))
if L+N-1 >= 0:
  l -= m
else:
  l += m
print(l)

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

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

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

for i in range(N):
    if abs(A[i]) == min(P):
        print(sum(A) - A[i])
        break

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

a = []
min_aji = float("inf")

for i in range(n):
    a.append(l + i)
    if abs(min_aji) > abs(l + i):
        min_aji = l + i

a.remove(min_aji)
print(sum(a))

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

a = []
min_aji = l

for i in range(n):
    a.append(l + i)
    if abs(min_aji) > abs(l + i):
        min_aji = l + i

a.remove(min_aji)
print(sum(a))

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

Solution (Python):
def main():
    n,l = map(int,input().split())
    a = [l+i-1 for i in range(1, n+1)]
    b = [abs(i) for i in a]
    m = min(b)
    i = b.index(m)
    del a[i]
    print(sum(a))
    
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, l = map(int, input().split())
    a_score = list()
    
    for i in range(n):
        
        a_score.append(l+i)
    a_sum = sum(a_score)
    if 0 in a_score:
        print(a_sum - 0)
    elif min(a_score) < 0:
        print(a_sum - max(a_score))
    else:
        print(a_sum - min(a_score))
        
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, L = map(int, input().split())
    min_abs = 1e10
    s = 0
    for i in range(N):
        if abs(L + i) < min_abs:
            min_abs = abs(L+i)

    for i in range(N):
        if abs(L+i) != min_abs:
            s += L+i
    print(s)


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N,L=map(int,input().split())
taste=np.zeros(N)
for i in range(N):
  taste[i]=L+i
tot=sum(taste)
min_taste=abs(taste[0])
min_i=0
for i in range(N):
  if min_taste>abs(taste[i]):
    min_taste=abs(taste[i])
    min_i=i
print(int(tot-taste[min_i]))

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7


def solve():

    N, L = map(int, input().split())
    flaver = [0 for _ in range(N)]

    m = INF
    pm = True
    for i in range(1, N + 1):
        n = i + L - 1
        flaver[i - 1] = n
        if abs(n) < m:
            m = abs(n)
            pm = True if n >= 0 else False

    ans = sum(flaver)
    if pm:
        ans -= m
    else:
        ans += m
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
n,l=map(int,input().split())
taste=range(l,l+n)
print(sum(taste)-min(taste,key=abs))

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

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

Solution (Python):
import numpy

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

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


apps_abs = list(numpy.abs(apps))


apps.pop(apps_abs.index(min(apps_abs)))

print(sum(apps))

Solution (Python):

def main():
    n, l = list(map(int, input().split()))
    lis = [i+l for i in range(n)]
    ans = sum(lis)
    if 0 in lis:
        pass
    elif lis[0] < 0:
        ans -= lis[-1]
    else:
        ans -= lis[0]
    print(ans)


if __name__ == '__main__':
    main()

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

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

tmp = 10**12
for taste in tastes:
    s = sum([x for x in tastes if x != taste])
    if abs(sum(tastes)-s) <= tmp:
        tmp = abs(sum(tastes)-s)
        ans = s

print(ans)

Solution (Python):
n, l = map(int, input().split())
a = list(range(l, l + n))
if n + l <= 0:
    print(sum(a) + min(map(abs, a)))
else:
    print(sum(a) - min(map(abs, a)))

Solution (Python):
n,L = map(int,input().split())
a = []
m = float("Inf")
x = 0
for i in range(n):
    a.append(i+L)
    if abs(i+L) < m:
        m = abs(i+L)
        x = i+L
print(sum(a)-x)

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

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

if 0 in taste:
    select = 0
else:
    select_with_ind = min(enumerate(taste), key = lambda x: abs(x[1]))
    select = select_with_ind[1]
    
print(sum(taste) - select)

Solution (Python):
n,l = map(int, raw_input().split(' '))
m = (+float('inf'), -1)
cumul = 0
for a in range(1, n + 1):
  	cumul += l + a -1 
	m = min(m, (abs(l + a - 1), a))
print cumul - (l + m[1] - 1)

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

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

m=[l+i for i in range(n)]
ans=sum(m)-m[mi]

print(ans)

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

Solution (Python):
def actual(n, l):
    apples = [l + i - 1 for i in range(1, n + 1)]
    yotei = sum(apples)

    if 0 in apples:
        return yotei

    if apples[0] >= 0:
        return yotei - apples[0]

    if apples[-1] <= 0:
        return yotei - apples[-1]

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

Solution (Python):
N,X=map(int,input().split())
S=[]
eat=1000000
eatpos=0
for i in range(N):
    S.append(X+i)
    if abs(S[i])<eat:
        eat=abs(S[i])
        eatpos=i

goukei=0
for i in range(N):
    if i!=eatpos:
        goukei+=S[i]
print(goukei)

Solution (Python):
n,l=map(int,input().split())
lis=[l+i-1 for i in range(1,n+1)]
taste=1000
for i in lis:
    
    if abs(taste)>abs(i):
        taste=i
print(sum(lis)-taste)

Solution (Python):
n, l = map(int, input().split())
sum,flag,mini = 0,0,10000
for i in range(1,n+1):
    hoge = l+i-1
    sum += hoge
    if abs(mini) >= abs(hoge):
        mini = hoge
    if (hoge == 0):
        flag = 1
if flag == 1:
    print(sum)
else:
    print(sum-mini)

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

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

r = [l+i for i in range(n)]
min_r = 1000000000
for i in r:
    if min_r > abs(i):
        min_r = abs(i)
        ans = i
print(sum(r)-ans)

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

Solution (Python):
import math
def ip():return int(input())
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

n,l=inp()
ans=l*n+(1+n)*n//2-n
if l>=0:k=1+l-1
elif l<-(n-1):
    k=l+n-1
else:k=0
print(ans-k)

Solution (Python):
from sys import stdin, setrecursionlimit
from bisect import bisect_right


def main():
    input = stdin.buffer.readline
    n, l = map(int, input().split())
    arr = []
    for i in range(n):
        arr.append(l + i)
    arr.sort()
    print(sum(arr) - arr[min(bisect_right(arr, -1), n - 1)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

lis = []

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

lis = sorted(lis)


if 0 in lis:
    lis.remove(0)
elif lis[0] >= 0:
    lis.remove(min(lis))
else:
    lis.remove(max(lis))
    
print(sum(lis))

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

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

if 0 in a :
  print(sum(a))
else :
  if a[0] > 0 :
    print(sum(a[1:]))
  else :
    print(sum(a[:-1]))