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())
taste = [L+k for k in range(N)]
min_t = abs(taste[0])
ind = 0
for i in range(N):
    x = abs(taste[i])
    if min_t > x:
        min_t = x
        ind = i
taste[ind] = 0
print(sum(taste))

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

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

print(int(res))

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

Solution (Python):
import numpy as np

def LI():
  return [int(s) for s in input().split()]

N,L = LI()
ringo = np.array(list(range(1,N+1))) + L - 1

taste_all = sum(ringo)

min_index = 0
min_abs = abs(ringo[0])

for i in range(1,N):
  if min_abs > abs(ringo[i]):
    min_index = i
    min_abs = abs(ringo[i])

print(taste_all - ringo[min_index])

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

res = 10 ** 9
res_abs = 10 ** 9
for i in range(n):
  part_v = all_v - v[i]
  if abs(all_v - part_v) < res_abs:
    res = part_v
    res_abs = abs(all_v - part_v)
print(res)

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

Solution (Python):
N, L = input().split(" ")
N = int(N)
L = int(L)
trimRingoIndex = 0
trimRingoAji = 0
for value in range(N):
    aji = abs(L + value)
    if value == 0:
        trimRingoAji = aji
    else:
        if trimRingoAji > aji:
            trimRingoIndex = value
            trimRingoAji = aji

totalAji = 0
for value in range(N):
    if value != trimRingoIndex:
        totalAji += L + value

print(totalAji)

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

Solution (Python):
N,L=map(int,input().split())
lis=list(range(L,N+L,1))

min=1000
index=0
sum=0
for i in range(len(lis)):
    if abs(lis[i])<min:
        min=abs(lis[i])
        index=i
    sum=sum+lis[i]

print(sum-lis[index])

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

l = list(map(lambda x:x+m, range(n)))

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

Solution (Python):
n, l = map(int, input().split())
a = 0
ap = []
abp = []
while a <= n-1:
    a += 1
    ap.append(l + a - 1)
    abp.append(abs(l + a - 1))
x = abp.index(min(abp))
ap.remove(ap[x])
print(sum(ap))

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

    aji_list = [0]*n

    count = 0

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

    if aji_list[0] >= 0:
        for i in range(1,n):
            count += aji_list[i]
    else:
        if aji_list[n-1] >= 0:
            for i in range(n):
                count += aji_list[i]
        else:
            for i in range(n-1):
                count += aji_list[i]

    print(count)

if __name__ == '__main__':
    main()

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

t = float("inf")
s = 0
for i in range(n):
    s += i + l
    if abs(t) > abs(i + l):
        t = i+l

print(s - t)

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

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

lst = list()
for i in range(0, N):
    lst.append(L + i)

base = sum(lst)
div = abs(lst[0])
res = base - lst[0]
for i in range(1, len(lst)):
    if abs(lst[i]) < div:
        div = abs(lst[i])
        res = base - lst[i]

print(res)

Solution (Python):
N,L = map(int,input().split())
mm = 300
for i in range(1, N+1):
    if abs(i+L-1) < abs(mm): mm = i+L-1
print(int(N*(N+1)/2)+N*(L-1)-mm)

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

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

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

if l < 0 and l+n-1 > 0:
  print(result)
elif result >0 :
  print(result-l)
else:
  print(result-(l+(n-1)))

Solution (Python):

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

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

total = sum(aji)

if aji[0] <= 0 and 0 <= aji[-1]:
    ans = total
elif aji[-1] < 0:
    ans = total - aji[-1]
else:
    ans = total - aji[0]

print(ans)

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

taste=[]
buf=[]

for i in range(n):
    tmp=l-1+(i+1)
    taste.append(tmp)
    buf.append(abs(tmp))

s=sum(taste)

minindex=buf.index(min(buf))

print(s-taste[minindex])

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

A.remove(min(max(A), *[abs(a) for a in A]))

print(sum(A))

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, l = na()

m = 1 << 60
res = 0
for i in range(n):
    q = l + i
    m = min(m, abs(q))
    res += q

if res < 0:
    res += m
else:
    res -= m

print(res)

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

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

    for i in range(N):
        taste.append(L+i)
    
    pie = sum(taste)
    ans = 1e10
    ans = [0]*N

    for i in range(N):
        tmp = taste[i]
        taste[i] = 0
        ans[i] = abs(pie-sum(taste))
        taste[i] = tmp
    
    print(pie-taste[ans.index(min(ans))])




if __name__=="__main__":
    main()

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

t = [l+i-1 for i in range(1,n+1)]
tt = [abs(i) for i in t]
t.pop(tt.index(min(tt)))
print(sum(t))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

R = L + N - 1
eat = 0
if R <= 0:
    eat = R
elif L >= 0:
    eat = L

ans = (R + L) * (R - L + 1) // 2 - eat

print(ans)

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

apple = []
flav = []

for i in range(1, N+1):
    apple.append(i)
    flav.append(L+i-1)

abs_flav = list(map(abs, flav))
num = abs_flav.index(min(abs_flav))

print(sum(flav) - flav[num])

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

ai=0
if 1 <= 1-l <= n:
  ai=1-l
elif n<1-l:
  ai=n
else:
  ai=1

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

print(ans)

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

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

Solution (Python):

n,l=map(int, input().split())
print(sum(sorted([l+i for i in range(n)], key=abs)[1:]))

Solution (Python):

n,l=map(int, input().split())
a=[l+i for i in range(n)]
s=sum(a)
index=0
ab=10**9
for i in range(n):
  if ab > abs(a[i]):
    ab=abs(a[i])
    index=i

print(s-a[index])

Solution (Python):

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

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

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys


import itertools

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

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

print(sum(F[1:]))

Solution (Python):
def main():
    n, l = map(int, input().split())
    m = [ i + l - 1 for i in range(1,n+1)]
    mabs = [abs(i) for i in m]

    eat = min(mabs)
    if eat in m:
        idx = m.index(eat)
    else:
        idx = m.index(-eat)
    print(sum(m)-m[idx])
    return

if __name__ == '__main__':
    main()

Solution (Python):
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys


import itertools

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

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


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

print(ans)

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

elif L + N - 1 >= 0:
    for i in range(L, L+N):
        ans += i

else:
    for i in range(L, L+N-1):
        ans += i

print(ans)

Solution (Python):
import numpy as np

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

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

ss = np.zeros(N, dtype=int)
for k in range(1, N+1):
    ss[k-1] = s-(L+k-1)

dif = abs(ss - s)
print(*ss[np.where(dif==min(dif))])

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

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

ss = []
for k in range(1, N+1):
    ss.append(s - (L+k-1))

dif = []
for kk in range(0, N):
    dif.append(abs(s-ss[kk]))

print(ss[dif.index(min(dif))])

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

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

Solution (Python):
N,L=map(int,input().split())
ans=(L-1)*N+(N+1)*N//2

if (L<0 and L+N-1<0):
    ans-=L+N-1
elif L>0:
    ans-=L
print(ans)

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

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

Solution (Python):
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, L = map(int, input().split())

        pie = [L + i - 1 for i in range(1, N + 1)]
        print(sum(pie) - min(pie, key=abs))


if __name__ == '__main__':
    AtCoder().main()

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

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

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

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

tmp = taste[:]
for i in range(N):
    tmp[i] = abs(tmp[i])

ind = tmp.index(min(tmp))
print(sum(taste)-taste[ind])

Solution (Python):
def binary_search(x,li):
    low = 0
    high = len(li)-1
    mid = (low + high)//2
    while low <= high:
        if li[mid] == x:
            return True
        elif x < li[mid]:
            low = mid + 1
        else:
            high = mid - 1
        mid = (low + high)//2
    return False

n,l = map(int,input().split())
taste = [0 for i in range(n)]
check = len(taste)
for i in range(n):
    taste[i] = l + i
taste = sorted(taste)
state = 0
for i in range(n):
    if taste[i] == 0:
        state = 1
        break
    else:
        state = 0
if state == 1:
    ans = 0
    for i in range(n):
        ans+=taste[i]
    print(ans)
else:
    if taste[0]>0:
        ans = 0
        for i in range(1,len(taste)):
            ans+=taste[i]
        print(ans)
    elif taste[0]<0:
        ans = 0
        for i in range(n):
            if taste[i] > 0:
                check = i
                break
        for i in range(n):
            if i != check-1:
                ans+=taste[i]
        print(ans)

Solution (Python):
import sys
import math
import numpy as np
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

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

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

apple = min(range(l,l+n),key=abs)
print(sum(range(l,l+n))-apple)

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

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

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

    if abs(sum - temp) < abs(sum - ans):
        ans = temp

print(ans)

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

Solution (Python):
from bisect import bisect_left


def main():
    N, L = map(int, input().split(" "))
    taste = []
    for i in range(N):
        taste.append(L + i)
    taste.sort()
    zero = bisect_left(taste, 0)
    if zero == 0:
        eat = taste[0]
    elif zero == N:
        eat = taste[-1]
    elif abs(taste[zero]) >= abs(taste[zero - 1]):
        eat = taste[zero - 1]
    else:
        eat = taste[zero]
    print(sum(taste) - eat)


if __name__ == '__main__':
    main()

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

if l>=0:
    aji -= l
else:
    if abs(l)<n:
        pass
    else:
        aji-= l-1+n

print(int(aji))

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

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

s=sum(l)

p=10**10

ans=0
for x in l:
  if p>abs(s-(s-x)):
    p=abs(s-(s-x))
    ans=s-x

print(ans)

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

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

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

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














hoge = sorted([abs(t) for t in tastes])[0]
if hoge in tastes:
    tastes.remove(hoge)
else:
    tastes.remove(-hoge)
print(sum(tastes))

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

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

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

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

prev_taste_diff = 10 ** 10

ans = 0
for i in range(N):
    s = sum(tastes[:i] + tastes[i+1:])
    curr_taste_diff = abs(s - sum_taste)
    if curr_taste_diff < prev_taste_diff:
        ans = s
    prev_taste_diff = curr_taste_diff
print(ans)

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

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

if 0 in apple:
    print(aji)
elif apple[0] > 0:
    print(aji - min(apple))
else:
    print(aji - max(apple))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n, l = map(int, input().split())

    ls = [i + l for i in range(n)]
    if l >= 0:
        ls = ls[1:]
    elif n + l - 1 < 0:
        ls = ls[:-1]

    print(sum(ls))

if __name__ == '__main__':
    main()

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

Solution (Python):
import numpy as np

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

if l < 0:
    if l + n <= 0:
        
        taste = sum(range(l, l+n-1))
    else:
        
        taste = sum(range(l, l+n))
else:
        
        taste = sum(range(l+1, l+n))

print(taste)

Solution (Python):
N, L = map(int, input().split())
min_s = 100000000000
s = 0
for i in range(1,N+1):
    t = L+i-1
    s += t

    if abs(t) <= abs(min_s):
        min_s = t

print(s-min_s)

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

taste = [l+i for i in range(n)]
taste_abs = [abs(i) for i in taste]
print(sum(taste) - taste[taste_abs.index(min(taste_abs))])

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

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

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

aji = [L+i for i in range(N)]
s = sum(aji)
m = aji[0]
for i in range(N):
    if abs(m) > abs(aji[i]):
        m = aji[i]
print(s-m)

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

apple = []
for i in range(n):
    apple.append(l+i)

p = []
for j in range(len(apple)):
    p.append(abs(apple[j]))

m = p.index(min(p))
apple.pop(m)
print(sum(apple))

Solution (Python):
N, D = map(int, open(0).read().split())
L = D
R = D + N - 1
S = (L+R)*(R-L+1)//2

if L >= 0:
    E = L
elif R <= 0:
    E = R
else:
    E = 0

print(S - E)

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

ind=aji_abs.index(min(aji_abs))

print(sum(aji)-aji[ind])

Solution (Python):

import numpy as np


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

def taste(i, L=L):
    return L + i -1

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


diff_value = np.inf
diff_total = np.inf

for i in range(N):
    if diff_value > abs(T[i]) and diff_total > abs(sum(T) - (sum(T) - T[i])):
        diff_value = abs(T[i])
        diff_total = abs(sum(T) - (sum(T) - T[i]))
        res = sum(T) - T[i]


print(res)

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

r = l+n-1
eat = 0
if l >= 0:
    eat = l
elif r <= 0:
    eat = r

ans = int((r + l) * n / 2 - eat)
print(ans)

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

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

Solution (Python):
def main():
    N, L = map(int, input().split())
    apples = [i+L-1 for i in range(1, N+1)]
    app_abs = list(map(abs, apples))
    ix_min = app_abs.index(min(app_abs))

    apples.pop(ix_min)
    return sum(apples)
    
if __name__ == '__main__':
    print(main())

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

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

if L > 0:
  j = 1
else:
  if L >= 1 - N:
    j = 1 - L
  else:
    j = N

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

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

F = [i + l for i in range(n)]
if 0 in F:
    print(sum(F))
elif min(F) > 0:
    F.pop(0)
    print(sum(F))
else:
    F.pop(-1)
    print(sum(F))

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

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

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

lst = []
tmp=1000000

for i in range(n):
	lst.append(i+l)
	
for i in lst:
	if abs(i) < abs(tmp):
		tmp = i
		
print(sum(lst)-tmp)

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

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

for i in range(n-1):
    lst1.append(sum(x[:i])+sum(x[i+1:]))

lst1.append(sum(x[:n-1]))

for i in range(n):
    lst2.append(abs(sum(x)-lst1[i]))

for i in range(n):
    if lst2[i] == min(lst2):
        print(lst1[i])

Solution (Python):
a, b = map(int,input().split())
B = []
A = []
for i in range(1, a+1):
    B.append(b+i-1)
    A.append(abs(b+i-1))

if min(A) in B:
    print(sum(B) - min(A))
else:
    print(sum(B) + min(A))

Solution (Python):
N,L=map(int, input().split())
def umasa(i):
    return L+i
box = []
for i in range(N):
    box.append(umasa(i))
new = sorted(box,key=abs)
print(sum(box)-new[0])

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

tastes = [L + i for i in range(N)]
tastes.sort(key=abs)
ans = sum(tastes[1:])
print(ans)

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

all = 0
tmp = 0
for x in range(N):
	all += (x+L)

for i in range (1,N+1):
	tmp = all-(i+L-1)
	tmp_2 = tmp*tmp
	if i == 1:
		ans = tmp
	elif tmp == all:
		ans = tmp
		break
	else:
		if ans*ans < tmp_2:
			ans = tmp
print(ans)

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


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

Solution (Python):
(A, B), = [list(map(int, s.split())) for s in open(0)]
apples = [B + i for i in range(A)]
apples_abs = [abs(a) for a in apples]
apple_idx = apples_abs.index(min(apples_abs))
apples.pop(apple_idx)
print(sum(apples))

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

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

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

abs_taste = list(map(abs, tastes))

del tastes[abs_taste.index(min(abs_taste))]

print(sum(tastes))

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

ans = 0
jogai = 500
fugo = 0
for i in range(1, N+1):
    aji = L+i-1
    ans += aji
    if aji < 0:
        if -aji < jogai:
            jogai = -aji
            fugo = -1
    else:
        if aji < jogai:
            jogai = aji
            fugo = 1

print(ans-fugo*jogai)

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

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

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

Solution (Python):
import numpy as np

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

apple = np.array([L + i - 1 for i in range(1, N + 1)])
abs_apple = np.abs(apple)
idx = abs_apple.argmin()
print(apple.sum() - apple[idx])

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

taste = [L+i-1 for i in range(1, N+1)]
taste_abs = [abs(L+i-1) for i in range(1, N+1)]
i = taste_abs.index(min(taste_abs))

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

Solution (Python):
a,b=map(int,input().split())
sum1=0
min1=1000

for i in range(a):
    if abs(min1)>abs(b):
        min1=b
    sum1+=b
    b+=1

print(sum1-min1)

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

if a+b-1<0:
  print(sum(apple)-a-b+1)
  
elif b>0:
  print(sum(apple)-b)
else:
  print(sum(apple))

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

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

Solution (Python):
n, l = map(int, input().split())
sum = 0
for i in range(l, l + n):
    sum += i
mnabs = 10000000
mn = 10000000
for i in range(l, l + n):
    if mnabs > abs(i):
        mnabs = abs(i)
        mn = i
print(sum - mn)

Solution (Python):
n,l=map(int,input().split())
lst=[l+i for i in range(n)]
lst2=[abs(l+i) for i in range(n)]
m=min(lst2)
ans=0
for i in lst:
    if i!=m and i!=m*-1:
        ans+=i
print(ans)

Solution (Python):
A,B = list(map(int,input().split()))
L = []
ans=0
for i in range(A):
  L.append(i+B)
L1 = sorted(L, key=lambda x: abs(x))
for i in L1[1::]:
  ans += i
print(ans)

Solution (Python):
def examA():
    S = SI()
    ans = "Good"
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            ans = "Bad"
    print(ans)
    return

def examB():
    N, L = LI()
    ans = 0
    if L>=0:
        for i in range(N - 1):
            ans += (L + i + 1)
    else:
        for i in range(N):
            ans += (L+i)
        if L+N-1<0:
            ans -=(L+N-1)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Solution (Python):
a = []
b = []
A,B = map(int,input().split())
for i in range(B,A+B):
  p =abs(i)
  a.append(p)
  b.append(i)
a = sorted(a)
if a[0] in b:
  b.remove(a[0])
else:
  b.remove(-a[0])
print(sum(b))

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

Solution (Python):
n, l = map(int, input().split())
d = list(range(l, n+l))
d_eaten = min(d, key=lambda x:abs(x))
print(sum(d)-d_eaten)

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

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

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

print(ans)

Solution (Python):
n, l = map(int, input().split())
ans = []
min_l = 99999
des = 9999999
for i in range(n):
    ans.append(l + i)
    if min_l > abs(l + i):
        min_l = abs(l + i)
        des = l + i
print(sum(ans) - des)

Solution (Python):

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

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

SUM = sum(taste)

DIF = abs(SUM - (SUM - taste[0]))
ans = SUM - taste[0]
for i in range(1,N):
    x = SUM - taste[i]
    if abs(SUM - x) < DIF:
        DIF = abs(SUM - x)
        ans = x
print(ans)

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


i = 1
taste = []

while i <= N:
        taste.append(L + i - 1)
        i += 1


if L > 0 :
        print(sum(taste[1:N]))
elif L <= 0 and N + L < 0:
        print(sum(taste[0:N-1]))
elif L <= 0 and N + L > 0:
        print(sum(taste[0:N]))
elif L <= 0 and N + L == 0:
        print(sum(taste[0:N-1]))

Solution (Python):
(n, l) = map(int, input().split())
d = [l + i for i in range(n)]
c = [abs(i) for i in d.copy()]
nearest0 = c.index(min(c))
d.remove(d[nearest0])
ans = sum(d)
print(ans)

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

Solution (Python):
N,L = map(int,input().split())
apple_list = list(map(lambda x: L+x-1 , range(1,N+1)))
print(sum(apple_list) - min(apple_list,key=abs))

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

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

Solution (Python):
N,L = map(int,input().split())
l = list(map(lambda x : L+x-1 , range(1,N+1)))
print(sum(l)-min(l,key=abs))

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

Solution (Python):
def main():
	n,l = map(int,input().split())
	apple = list(range(1,n+1))
	taste = []
	for i in range(1,n+1):
		taste.append(l+i-1)
	
	taste_abs = []
	for i in range(len(taste)):
		taste_abs.append(abs(taste[i]))
	
	if min(taste_abs) == 0:
		print(sum(taste))
	else:
		taste.remove(taste[taste_abs.index(min(taste_abs))])
		print(sum(taste))

if __name__ == '__main__':
	main()

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


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

min = 10000
ans = 0
for i in range(n):
    msum = 0
    for j in range(n):
        if (i != j):
            msum += j + l
    if (abs(sum - msum) < min):
        min = abs(sum-msum)
        ans = msum

print(ans)

Solution (Python):


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

ans=0
eat=10**18
for i in range(N):
    ans+=(i+L)
    if abs(i+L)<=abs(eat):
        eat=i+L
print(ans-eat)