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())

num=1+l-1
number=[]
for _ in range(n):
  number.append(num)
  num+=1

if 0 in number:
  print(sum(number))
    
else:
  if all(i<0 for i in number):
    print(sum(number)-max(number))
    
  else:
    print(sum(number)-min(number))

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

for i in range(1 ,n+1):
    apple.append(l+i-1)
apple_pai = sum(apple)

if l >0:
    eat =l
elif l+n-1 <0:
    eat =l+n-1
ans =apple_pai - eat
print(ans)

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

delicious = (lambda L: lambda i: L + i - 1)(L)
delicious_N = sum([delicious(i) for i in range(1, N + 1)])


i = -L + 1
i = max(1, i)
i = min(i, N)
delicious2 = delicious(i)

answer = delicious_N - delicious2

print(answer)

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

apple = []
for i in range(1,n+1):
    apple.append(i+l-1)
pai = sum(apple)
ans = 10**9
for i in range(n):
    if ans > abs(apple[i]):
        ans = abs(apple[i])
        eat = apple[i]
print(pai-eat)

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

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

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def PL(L) : print(*L, sep="\n")

N, L = LI()

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

print(sum(A[1:]))

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

def taste(i):
  return L + i
m = 1e+10
t = 0
appleN = [taste(i) for i in range(N)]
for n in range(N):
  appleN_1 = [taste(i) for i in range(N) if i != n]
  m = min(m, abs(sum(appleN) - sum(appleN_1)))
  if m == abs(sum(appleN) - sum(appleN_1)):
    t = sum(appleN_1)
print(t)

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

x = []
y = []
for i in range(N):
  a = L + (i + 1) - 1
  x.append(a)
  y.append(abs(a))
z = min(y)
if z in x:
  x.remove(z)
else:
  j = -z
  x.remove(j)
print(sum(x))

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

Solution (Python):
n,l = map(int,input().split())
s = n*(l-1) + n*(n+1)//2

d = float('inf')
for i in range(1,n+1):
  if abs(d) > abs(l+i-1):
    d = l+i-1
print(s-d)

Solution (Python):
import bisect

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

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

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

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

if l >= 0:
    print(sum(p)-l)
else:
    if max(p) >= 0:
        print(sum(p))
    else:
        print(sum(p)-max(p))

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

Solution (Python):
p,q= input().split()
a,b =(int(p), int(q))
key_num = 0
azi_list = []
for i in range(a):
    azi_list.append(b + i)
if key_num in azi_list:
    print(sum(azi_list))
elif key_num not in azi_list and azi_list[0] > 0:
    print(sum(azi_list[1:]))
else:
    print(sum(azi_list[:-1]))

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

Solution (Python):
def q2():
    N, L = (int(i) for i in input().split())
    aji = [L+i for i in range(N)]
    aji_min_i = 999
    aji_min = 999
    for i, a in enumerate(aji):
        if abs(a) < aji_min:
            aji_min = abs(a)
            aji_min_i = i
    aji.pop(aji_min_i)
    print(sum(aji))

if __name__ == '__main__':
    q2()

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

total_taste = 0
temp = 1000000007
ans = 0
for i in range(n):
    total_taste += l + i
    if abs(l + i) < temp:
        temp = abs(l + i)
        ans = l + i

print(total_taste - ans)

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

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,l = map(int,input().split())
  APPLE = []
  for i in range(n):
    APPLE.append(l+(i+1)-1)
  if 0 in APPLE:
    print(sum(APPLE))
    exit()
  if sum(APPLE) > 0:
    print(sum(APPLE[1:]))
  elif sum(APPLE) < 0:
    APPLE = APPLE[::-1]
    print(sum(APPLE[1:]))
if __name__ == '__main__':
  main()

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

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


assumed_apple_pie = ( L - 1 ) * N + sum( range( 1, N + 1 ) )



edible_apple = 0
if L > 0:
  edible_apple = L
elif ( L + N - 1 ) < 0:
  edible_apple = L + N - 1

real_apple_pie = assumed_apple_pie - edible_apple

print( real_apple_pie )

Solution (Python):
n, l = map(int, input().split())
apple = [l+i for i in range(n)]
absmin = float('inf')
idx = 0
for i in range(n):
    if absmin >= abs(apple[i]):
        absmin = abs(apple[i])
        idx = i

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,l = iim()
aji = 0
flag = False

for i in range(1,n+1):
    if l+i-1 == 0:
        flag = True
    aji += l+i-1


if flag:
    print(aji)
elif l > 0:
    print(aji - l)
else:
    print(aji - (l+n-1))

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

Solution (Python):

import sys


def solve(N: int, L: int):
    a = tuple(range(L, L+N))
    return sum(a) - min(a, key=abs)



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    print(solve(N, L))

if __name__ == '__main__':
    main()

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

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

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

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

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

print(ans-m)

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

if 0 in m:
  print(sum(m))
  
else:
  if m[0] < 0:
    print(sum(m)-max(m))
  else:
    print(sum(m)-min(m))

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,l=INTM()
    ls=[]
    ct=9999999
    for i in range(n):
        ls.append(l+i)
    ls=sorted(ls,key=lambda x:abs(x))
    print(sum(ls)-ls[0])
if __name__ == '__main__':
    do()

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

Solution (Python):
n, l = map(int, input().split())
applepi = sum([l + i - 1 for i in range(1,n+1)])
minas = 100000000000
for j in range(1, n+1):
  a = l + j - 1
  if abs(a) <= abs(minas):
    minas = a
print(applepi - minas)

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

taste = []
mini = 10**9
suf = 0
for i in range(1,n+1):
    if abs(l+i-1) < mini:
        mini = abs(l+i-1)
        suf = i
    taste.append(l+i-1)

taste.pop(suf-1)
print(sum(taste))

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

if taste.count(0) == 1:
  ans = sum(taste)
elif max(taste) < 0:
  taste.remove(max(taste))
  ans = sum(taste)
else:
  taste.remove(min(taste))
  ans = sum(taste)
print(ans)

Solution (Python):
import heapq

n, l = map(int, input().split())
taste = list(range(l, n + l))
ans = 0

if taste.count(0) == 1:
  ans = sum(taste)
elif max(taste) < 0:
  taste = list(map(lambda x: x * (-1), taste))
  heapq.heapify(taste)
  heapq.heappop(taste)
  ans = sum(taste) * (-1)
else:
  heapq.heapify(taste)
  heapq.heappop(taste)
  ans = sum(taste)
print(ans)

Solution (Python):
n, l = map(int, input().split())
scores = [ i+l for i in range(n) ]
min_abs = float("inf")

for s in scores:
    if abs(s) < abs(min_abs):
        min_abs = s

print(sum(scores)-min_abs)

Solution (Python):
import numpy as np
N, L = map(int, input().split())

aji = np.array([L + i for i in range(N)])

min_diff = 10e20
for i in range(N):
    diff = abs(aji[i])
    if diff < min_diff:
        min_diff = diff
        true_aji = sum(aji) - aji[i]

print(true_aji)

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

App=[L+j for j in range(N)]
abs_App=[abs(L+j) for j in range(N)]
print(sum(App)-App[abs_App.index(min(abs_App))])

Solution (Python):
N, L = map(int, input().split())
aji = [(L + i) for i in range(N)]
Naji = [abs(j) for j in aji]
del aji[Naji.index(min(Naji))]
print(sum(aji))

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

total = (l - 1) * n + n * (n + 1) // 2
min_diff = 1e20
for i in range(n):
  apple = l + i
  apple_pie = total - apple
  diff = abs(apple)
  if diff < min_diff:
    min_diff = diff
    min_apple_pie = apple_pie
print(min_apple_pie)

Solution (Python):
n, l = map(int, input().split())
ref = []
ans = n*l + n*(n - 1)/2

if l >= 0:
    ans = ans - l
else:
    for i in range(n):
        ref.append(-l - i)
    ref = map(abs, ref)
    ref = min(ref)
    ans = ans + ref

print(int(ans))

Solution (Python):
n, l = map(int, input().split())
total = 0
total = n*l + n*(n - 1)/2
ref0 = (n - 1)*l + n*(n - 1)/2

for i in range(n):
    ref1 = 0
    ref1 = (n - 1)*l + n*(n - 1)/2 - i
    if abs(total - ref0) > abs(total - ref1):
        ref0 = ref1

print(int(ref0))

Solution (Python):
n , l = map ( int , input ( ).split ( ) ) 
lst = [i + l - 1 for i in range ( 1 , n + 1 )]
ans=1000000 
sum1=sum(lst) 
for i in lst: 
	if abs(i)<abs(ans): 
		ans=i
print(sum1-ans)

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

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

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

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

print(sum(taste[1:]))

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

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

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

print(sum(taste[1:]))

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

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

before = sum(taste)

ans = 999999999999
for t in taste:
  if abs(t) < abs(before - ans):
    ans = before - t

print(ans)

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

if N > abs(L) and L < 0:
    print(sum(A))
elif max(B) < 0:
    print(min(B))
else:
    print(max(B))

Solution (Python):
n, l = [int(x) for x in input().split()]
res = 0
if l > 0:
  res = (n - 1) * (2 * l + n) // 2
elif l + n - 1 < 0:
  res = (n - 1) * (l + l + n - 2) // 2
else:
  res = n * (l + l + n - 1) // 2
print(res)

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

Solution (Python):
n,l = map(int,input().split())
azi = (l-1)*n + (n*(n+1))//2
x = []
y = []
for i in range(1,n+1):
    x.append(l+i-1)
    y.append(abs(l+i-1))
print (azi-x[y.index(min(y))])

Solution (Python):

n, l = map(int, input().split())
min = abs(l)
s = 0
for i in range(n):
    s += l + i
    if abs(l + i) < abs(min):
        min = l + i
print(s-min)

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

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

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

Solution (Python):
import sys
n,l=input().split()

n=int(n)
l=int(l)
v=[]
vv=[]
for i in range(1,n+1):
    v.append(abs(l+i-1))
    vv.append(l+i-1)
v.sort()


ss=sum(vv)
for i in range(1,n+1):
    if abs(l+i-1)==v[0]:
        print(ss-(l+i-1))
        sys.exit()

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):

import sys


def solve(N: int, L: int):
    sum = 0
    minAbs = 10**16
    minVal = 10**16
    for i in range(N):
        c = L + i
        sum += c
        if abs(c) < minAbs:
            minAbs = abs(c)
            minVal = c
    print(sum - minVal)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)

if __name__ == '__main__':
    main()

Solution (Python):
n,l=map(int,input().split())
m=[l+i for i in range(n)]
s=sum(m)
t=101
d=0
for i in range(n):
  if t>abs(m[i]):
    t=abs(m[i])
    d=m[i]
print(s-d)

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

l = [0] * N
for i in range(N):
    l[i] = L + i

ans = sum(l)
res = 10 ** 9
d = 0
for i in range(N):
    tmp = l[:i] + l[i+1:]
    solve = sum(tmp)
    c = abs(ans - solve)

    if(res > c):
        res = c
        d = solve

print(d)

Solution (Python):
n, l = [int(x) for x in input().split()]

taste = 0
for i in range(n):
    taste = taste + l + i

diff_min = abs(taste)
result = 0
for i in range(n):
    taste2 = 0
    for j in range(n):
        if j == i:
            pass
        else:
            taste2 = taste2 + l + j

    diff = abs(taste - taste2)
    if diff < diff_min:
        diff_min = diff
        result = taste2


print(result)

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

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

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

taste = 0
for k in range(1, N + 1):
    if k != ind:
        taste += L + k - 1
print(taste)

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

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

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

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

ans = sorted(tmp, key=abs)
print(sum(ans)-ans[0])

Solution (Python):
N,L=map(int,input().split())
taste=[L+i for i in range(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))
ans = sum(L + i - 1 for i in range(2, N + 1))
for i in range(1, N + 1):
    s1 = s - (L + i - 1)
    if abs(s - ans) > abs(s - s1):
        ans = s1
print(ans)

Solution (Python):








import numpy as np



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

apple = [l+i-1 for i in range(1,n+1)]
apple = np.array(apple)
abs_apple = abs(apple)
min_idx = np.argmin(abs_apple)

ans = sum(apple) - apple[min_idx]

print(ans)

Solution (Python):
n, l = map(int, input().split())
x = 100
y = 100
for i in range(n):
    if abs(l+i) < x:
        x = abs(l+i)
        y = l+i
print(l*n+sum(range(1, n+1))-n-y)

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

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

Solution (Python):

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

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

apples = []
for i in range(n):
    apples.append(l+(i+1)-1)

total = sum(apples)

pies = []
for j in range(n):
    pies.append(total-apples[j])

tmp = 1000000000
for k in range(n):
    if abs(total-pies[k]) < tmp:
        aji = pies[k]
        tmp = abs(total-pies[k])

print(aji)

Solution (Python):
N,L=map(int,input().split())
n=[]
for i in range(N):
    n.append(L+i)
b=[]
for j in range(len(n)):
    b.append(abs(n[j]))
min_abs=b.index(min(b))
n.pop(min_abs)
print(sum(n))

Solution (Python):
n,l=map(int,input().split())
r=l+n-1;s=(l+r)*n//2
print([s-r,s,s-l][(l>0)+(r>0)])

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

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

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

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

print(ans)

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

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

ans = float('inf')
ans2 = 0
for i in range(n):
    tmp = total - apple[i]
    if ans > abs(total - tmp):
        ans = abs(total - tmp)
        ans2 = tmp

print(ans2)

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

total = sum(aji)


eat = 1000
j=0
for i in range(N):
  if eat > abs(aji[i]):
    eat = abs(aji[i])
    

if min(aji) >0:
  print(total-eat)
else:
  print(total+eat)

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

Solution (Python):
from itertools import accumulate

def solve():
    N, M = map(int, input().split())
    l = []
    for i in range(N):
        l.append(M + i)
    
    s = list(accumulate(l))
    
    if 0 in l:
        return s[-1]

    if M >= 0:
        return s[-1] - s[0]
    else:
        return s[-1] - l[-1]
    
print(solve())

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

x = list(range(1, n+1))
y = []
for i in x:
    y.append(l + i - 1)

z = [abs(i) for i in y]
zi = z.index(min(z))

ans = 0
for i,name in enumerate(y):
    if i == zi: continue
    ans += name

print(ans)

Solution (Python):
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, L = lr()
total = sum(range(L, L+N))
sub = min(range(L, L+N), key=abs)
print(total-sub)

Solution (Python):
N , L = (map(int , input().split()))
aji = [i+L for i in range(N)]
ajisum = sum(aji)
mi = []
for i in aji:
    mi.append(abs(i))
if ajisum > 0:
    print(ajisum - min(mi))
else:
    print(ajisum + min(mi))

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

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

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

Solution (Python):
n, l = map(int, input().split())
t = list(range(l, l + n))
s = [abs(_) for _ in t]
print(sum(t) - t[s.index(min(s))])

Solution (Python):
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, L = lr()
A = np.arange(1, N+1)
A += (L - 1)
answer = A.sum() - A[np.argmin(np.abs(A))]
print(answer)

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

Solution (Python):
N, L = map(int, input().split())
apple = [0]*N
for i in range(N):
  apple[i] = L+i
sum = sum(apple)  
ans = float("INF")
k = -1
for j in range(N):
  sub = abs(sum - (sum - apple[j]))
  if ans > sub:
    ans = sub
    k = j
print(sum - apple[k])

Solution (Python):







import math

import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, l = list(map(int,ipti().split()))
    a = [i+l for i in range(n)]

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



if __name__ == '__main__':
    main()

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


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

abs_min = float('Inf')
for i in apple:
    if abs(i) < abs(abs_min):
        abs_min = i

apple.remove(abs_min)
print(sum(apple))

Solution (Python):
N, L = map(int, input().split())
A = list(range(1, N+1))
ans = 0
saisyo = float("inf")
saidai = -float("inf")
for i in range(N):
    x = A[i] + L-1 
    saisyo = min(x, saisyo)
    saidai  = max(x, saisyo)
    ans += x
if saidai < 0:
    print(ans-saidai)
elif saidai >= 0 and saisyo <= 0 :
    print(ans)
else:
    print(ans-saisyo)

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

ans=0
t=[]

for i in range(n):
  ans+=l+i
  t.append(l+i)

t.sort(key=lambda x:abs(x))
print(ans-t[0])

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

ans=0
min_a=10**9
for i in range(n):
  ans+=l+i
  if abs(min_a)>abs(l+i):
    min_a=l+i
print(ans-min_a)

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

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

Solution (Python):
n,l = map(int,input().split())
s = 0
m = 10**3
for i in range(n):
  s += l+i
  if abs(m) > abs(l+i):
    m = l+i
print(s-m)

Solution (Python):
N, L = map(int, input().split())
diff_min = 100 + 200 - 1
apples = list()
remove_apple = 0

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

print(sum(apples) - remove_apple)

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

Solution (Python):
n,L=list(map(int,input().split()))
l=[]
for i in range(1,n+1):
    l.append(L+i-1)
m=abs(l[0])
t=l[0]
for i in range(1,len(l)):
    if abs(l[i])<m:
        m=abs(l[i])
        t=l[i]

print(sum(l)-t)

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

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

a = [l+int(x)-1 for x in range(1, n+1)]
b = [abs(a[i]) for i in range(n)]

if a[-1] >= 0:
  print(sum(a) - min(b))
else:
  print(sum(a) + min(b))

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

Solution (Python):
import numpy as np


def main():
    N, L = map(int, input().split())
    Ns = np.array(range(1, N+1)) + L - 1
    abs_Ns = np.where(Ns < 0, Ns*-1, Ns)
    eat_indx = np.where(abs_Ns == np.min(abs_Ns))[0][0]
    ans = np.sum(np.delete(Ns, eat_indx, 0))
    print(ans)


if __name__ == "__main__":
    main()

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

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

ans = 0
azi = float("inf")
for i in range(N):
    ans += L + i
    if abs(azi) > abs(L + i):
        azi = L + i

ans -= azi

print(ans)

Solution (Python):
n, l = map(int, input().split())
ans = l
sum = l
for i in range(2, n + 1):
    sum += l + i - 1
    if abs(l + i - 1) < abs(ans):
        ans = l + i - 1
print(sum - ans)

Solution (Python):
N, L = map(int, input().split())
taste = []
for i in range(N):
  taste.append(L+i)
if L>=0:
  eat = min(taste)
else:
  eat = (-1)*min(list(map(abs,taste)))

print(sum(taste)-eat)

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

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

eat = float('inf')
for a in apples:
  eat = a if abs(a)< abs(eat) else eat
  

print(sum(apples) - eat)

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

py=0
lostpy=0

for i in range(1,N+1):
  py=py+(L+i-1)
tmp=10000000
ans=0
for i in range(1,N+1):
  lostpy=py-(L+i-1)
  if abs(py-lostpy) < tmp:
    ans=lostpy
    tmp=abs(py-lostpy)
print(ans)

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

yotei = sum(a)

if 0 in a:
    print(yotei)
    exit()

if abs(a[0]) < abs(a[n-1]):
    print(yotei-a[0])
else:
    print(yotei-a[n-1])

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

Solution (Python):
N,L = map(int, input().split())
ans = 0
min = 99999999
for i in range(1, N+1):
  t = L + i - 1
  if abs(t) < abs(min) : min = t
  ans += t
ans -= min
print(ans)

Solution (Python):
N,L = map(int,input().split())
a = list()
ans = 0
wa = 0
for i in range(1,N+1):
    a.append(L+i-1)
    ans += L+i-1
mi = 10**7
for i in range(N):
    if abs(a[i]) < mi:
        mi = abs(a[i])
        wa = a[i]
print(ans-wa)

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

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

if 0 in taste:
    print(sum(taste))
elif L < 0:
    print(sum(taste[:-1]))
else:
    print(sum(taste[1:]))

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

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

Solution (Python):

import sys




def main():
    N,L = [ int(s) for s in input().split() ]
    pie_all = 0
    pie_taste = [0]* N
    for i in range(N):
        pie_taste[i] = L + (i+1) -1
        pie_all += pie_taste[i]

    min_index = 0
    min_value = 100000000000
    pie_mean = pie_all / N
    for i in range(N):
        if min_value > abs(pie_taste[i]):
            min_index = i
            min_value = abs(pie_taste[i])

    print(pie_all - pie_taste[min_index])

if __name__ == '__main__':
    main()

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

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

if 0 in taste:
  print(sum(taste))
elif L < 0:
  print(sum(taste[:-1]))
else:
  print(sum(taste[1:]))

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

n_sum = (l*n)+sum(list(range(1,n+1)))-n
ans = n_sum

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

Solution (Python):


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

w = N*(N+1)//2 + N*L - N

mi = 200+100

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

print(w-mi)

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


x = []
for i in range(1,n+1):
    x.append(l + i - 1)


m = 10 ** 12
k = 10 ** 12
for i in range(n):
    diff = abs(x[i])
    if m >= diff:
        m = diff
        k = x[i]

        
print(sum(x) - k)

Solution (Python):
import math
import itertools
import statistics

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

m = abs(total)
for i in range(1, n+1):
    if abs(total-(total2-(l+i-1))) < m:
        m = abs(total-(total2-(l+i-1)))
        




if total > 0:
    print(total2-m)
else:
    print(total+m)

Solution (Python):
import sys
import math
import numpy as np
'''a,b= map(int,input().split())'''


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

li=[]
ans=0
for i in range(n):
  li.append(i+l)
  ans+=i+l
for i in range(n):
    li[i]=abs(li[i])
if ans<0:
  print(ans+min(li))
else:
  print(ans-min(li))