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):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



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


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

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

    total = sum(a)
    mini = INF
    ans = INF
    for i in range(N):
        x = total - a[i]
        if abs(total - x) < mini:
            mini = abs(total - x)
            ans = x
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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


for i in range(len(flavour)):
    sum2.append(abs(sum1 - sum(flavour[:i] + flavour[i+1:])))


print(sum1 - flavour[sum2.index(min(sum2))])

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

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

pai = 0

for n in range(N):
    if L < 0:
        if L+n == 0:
            next

    pai = pai + L + n

if L+N <= 0:
    pai = pai - (L + N - 1)

if L > 0:
    pai = pai - L

print(pai)

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

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

Solution (Python):
n,l=map(int,input().split())
least = 1000000
res = 0
for i in range(1,n+1):
    f = l + i - 1
    if least > abs(f):
        least = abs(f)
        least_f = f
    res += f
print(res - least_f)

Solution (Python):
import numpy as np

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

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

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

Solution (Python):
N, L = map(int, input().split())
name = [i for i in range(1, N+1)]
all_taste = [j + L -1 for j in name]
all_sum = sum(all_taste)
if 0 in all_taste:
  print(all_sum)
else:
  abs_li = [abs(k) for k in all_taste]
  mi = min(abs_li)
  if not mi in all_taste:
    mi = -1 * mi
  print(all_sum - mi)

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

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

Solution (Python):
lst = []
n, l = map(int, input().split())
lst = list(range(l, l+n))
if lst.count(0) == 1:
	ans = sum(lst)
elif max(lst) > 0:
	del lst[0]
	ans = sum(lst)
else:
	del lst[-1]
	ans = sum(lst)
print(ans)

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

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

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

m = res[0]
for r in res:
    if abs(r) < abs(m):
        m = r
res.remove(m)

print(sum(res))

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

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

diff = 99999999
ans_taste = 0
ans_i = 9999
for i in range(1,N+1) :
    taste = taste_all - (L+i-1)
    d = abs(taste_all - taste)
    if (d < diff ) :
        diff = d
        ans_taste = taste
        ans_i = i

print(ans_taste)

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

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

Solution (Python):
n, l = list(map(int, input().split()))
arr = [_ for _ in range(l, l + n)]
_sum = sum(arr)
tmp = 1000
for i in range(1, n + 1):
    n_sum = sum(arr[:i - 1] + arr[i:])
    if abs(_sum - n_sum) < tmp:
        tmp = abs(_sum - n_sum)
        ans = n_sum
print(ans)

Solution (Python):
def solve(l:list)->int:
    ab_l = list(map(abs, l))
    del l[ab_l.index(min(ab_l))]
    return sum(l)


def main():
    n, k = map(int, input().split())
    l = [i + k for i in range(n)]
    print(solve(l))

if __name__ == "__main__":
    main()

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

for i in range(1, n+1):
    apples.append(l+i-1)
    if abs(l+i-1) < check:
        eat = l+i-1
        check = abs(l+i-1)

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

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

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

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


apples_taste = []
abs_apples_taste = []

for i in range(int(N)):
  apples_taste.append(i+int(L))
  abs_apples_taste.append(abs(i+int(L)))

abs_apples_taste.sort()
if abs_apples_taste[0] in apples_taste:
  print(sum(apples_taste) - abs_apples_taste[0])
else:
  print(sum(apples_taste) + abs_apples_taste[0])

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

Solution (Python):

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


all_taste = 0

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


act_taste = 0


eat_apple = l + 1 - 1
for i in range(1, n+1):
    cmp_apple = l + i - 1
    
    if abs(cmp_apple) <= abs(eat_apple):
        eat_apple = cmp_apple
        act_taste = all_taste - eat_apple


print(act_taste)

Solution (Python):
def main():
    N, L = map(int, input().split())
    tot = 0
    remove = float('inf')
    for i in range(1, N+1):
        tot += L+i-1
        if abs(remove) > abs(L+i-1):
            remove = L+i-1
    return tot - remove

if __name__ == '__main__':
    print(main())

Solution (Python):
N,L=map(int,input().split())
ringo=[L+i for i in range(N)]
idealy = sum(ringo)
min_ringo = min(list(map(abs, ringo)))

if min_ringo in ringo:
    ringo.append(-min_ringo)
else:
    ringo.append(min_ringo)

print(sum(ringo))

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

Solution (Python):
import sys
N, L = map(int, sys.stdin.readline().split())
tastes= [L+i-1 for i in range(1, N+1)]

if 0 <= L:
  tastes.pop(0)

elif L+N <= 0:
  tastes.pop(-1)

print(sum(tastes))
exit()

Solution (Python):
N,L = list(map(int, input().split()))
s = []
min = 1000
for i in range(N):
    s.append(i+L)
    if abs(s[i]) < min:
        min = abs(s[i])
        i_min = i
print(sum(s)-s[i_min])

Solution (Python):

A=list(map(int, input().split()))
aji1=0
B=[]
C=[]
for i in range(1,A[0]+1):
    aji1+=A[1]+i-1
    B.append(abs(A[1]+i-1))
    C.append(A[1]+i-1)
print(aji1-C[B.index(min(B))])

Solution (Python):

A=list(map(int, input().split()))
aji1=0
B=[]
C=[]
for i in range(1,A[0]+1):
    aji1+=A[1]+i-1
    B.append(abs(A[1]+i-1))
    C.append(A[1]+i-1)
print(aji1-C[B.index(min(B))])

Solution (Python):
n, l = map(int, input().split())
val = [l + i for i in range(n)]
min_v = 100
min_i = 0

for i in range(n):
    abs_v = abs(val[i])
    if abs_v < min_v:
        min_v = abs_v
        min_i = i

print(sum(val) - val[min_i])

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



list_aji = []
abs_aji_min = 100000
index_abs_aji_min = 0
for n in range(1,N+1):
  aji = n + L - 1
  if abs(aji) < abs_aji_min:
    abs_aji_min = abs(aji)
    index_abs_aji_min = n-1
  
  list_aji.append(aji)
  
ans = sum(list_aji) - list_aji[index_abs_aji_min]
print(ans)

Solution (Python):
import numpy as np

N, L = map(int, input().split())
v = np.arange(N) + L

if v[0] >= 0:
    s = v[1:].sum()
else:
    d  = v[np.argmin(abs(v))]
    s = v.sum() - d

print (s)

Solution (Python):
I=input()
N=int(I.split()[0])
L=int(I.split()[1])
x=1
A=[]
R=0

for i in range(N):
    A.append(x+L-1)
    R+=x+L-1
    x+=1
    
B=[]
for w in A:
    B.append(abs(w))

print(R-A[B.index(min(B))])

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

eat_taste = 99999
sum_taste = 0
for i in range(n):
  taste = l + i
  sum_taste += taste
  if abs(taste) < abs(eat_taste):
    eat_taste = taste
print(sum_taste - eat_taste)

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

full = int(N*L + N*(N+1)/2 - N)
absdiff = []
diff = []
for i in range(1,N+1):
    absdiff.append(abs(L+i-1))
    diff.append(full-(L+i-1))

print(diff[absdiff.index(min(absdiff))])

Solution (Python):

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

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

if (l-1) < 0:
  if (l+n-1) < 0:
    ret = sum(apples[:-1])
  else: 
    ret = sum(apples)
else: 
  ret = sum(apples[1:])

print(ret)

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

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

total = sum(score)


ans = 9999999999
for i in range(n):
  temp = score[i]
  score[i] = 0
  culTotal = sum(score)  
  score[i] = temp
  diff = abs(total-culTotal)
  if ans > diff:
    ans = diff
    result = culTotal
  
print(result)

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

t_all = 0
t_bite = 0

for i in range(N):
    t_all += (L+i)


for i in range(N):
    t_tmp = 0
    for j in range(N):
        if i == j:
            continue
        else:
            t_tmp += (L+j)

    if abs(t_all - t_bite) > abs(t_all - t_tmp):
        t_bite = t_tmp

print t_bite

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

ans=0
for i in apple[1:]:
    ans+=i[1]

print(ans)

Solution (Python):
n, l = map(int, input().split())
L = l
R = n+l-1
eat = 0

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

sum = (R+L)*(R-L+1)/2 -eat
print(int(sum))

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

Solution (Python):
n, l = map(int, input().split())
r = 10 ** 9
v = 0
ans= 0

for i in range(l, n + l):
    ans += i
    if abs(i) < r:
        v = i
        r = abs(i)

ans -= v
print(ans)

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


for i in range(N):
    p = abs(sum(taste) - sum(taste[:i] + taste[i+1:]))
    if i == 0:
        minnum = p
        min_i = 0
    elif p < minnum:
        minnum = p
        min_i = i


print(sum(taste[:min_i] + taste[min_i + 1:]))

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

m = 300
cnt = 0
for i in range(n):
    if abs(l+i) < m:
        m = abs(l+i)
        cnt = i
ans = int(l*n + (1/2)*(n-1)*n - (l+cnt))
print(ans)

Solution (Python):

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

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

for i in range(n):
    lis.append(l+i)
som=0
for i in range(n):
    som+=lis[i]
a=abs(lis[0])
for i in range(n-1):
    if abs(lis[i+1])<abs(a):
        a=lis[i+1]

print(int(som-a))

Solution (Python):

import sys


def solve(N: int, L: int):
    
    taste_perfect_pi = 0
    firstTaste = L
    lastTast = L + N - 1

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

    if L >= 0:
        print(taste_perfect_pi - firstTaste)
    elif L + N -1 >= 0:
        print(taste_perfect_pi)
    else:
        print(taste_perfect_pi - lastTast)
    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)=input().split(' ')
N = int ( N )
L = int ( L )
A =[]
B =[]
for i in range ( N ) :
   A.append ( abs ( L + i ) )
   B.append ( L + i )

A.sort()   

if  ( L < 0 ) :
    print ( sum ( B ) + A[0] )

else :
    print ( sum ( B ) - A[0] )

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

Solution (Python):
N, L = map(int, input().split())
flavors = [x + L - 1 for x in range(1, N + 1)]
flavors.remove(min(flavors, key=abs))

print(sum(flavors))

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

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

state = [0 for _ in range(N)]

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

tmp = 10 ** 9

for i in range(N):
    if tmp > abs(sum(state) - sum(state)-state[i]):
        tmp = abs(sum(state) - sum(state)-state[i])
        res = sum(state) - state[i]

print(res)

Solution (Python):
n,l = map(int,input().split())
min_abs = 10**9
tmp = 10**9
for i in range(n):
    if abs(l + i) < min_abs:
        min_abs = abs(l+i)
        tmp = i
ans = 0
for i in range(n):
    if i == tmp:
        continue
    else:
        ans += l + i

print(ans)

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

Solution (Python):
import copy
import numpy as np
N, L = map(int, input().split())
taste = []
for i in range(N):
  taste.append(L + i)

pie = []
for i in range(N):
  temp = copy.deepcopy(taste)
  del temp[i]
  pie.append(abs(sum(taste) - sum(temp)))
del taste[np.argmin(pie)]
print(sum(taste))

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

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

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

Solution (Python):
def main():
    n, l = map(int, input().split(' '))
    a = 199
    for i in range(1, n+1):
        if abs(taste(i, l)) < abs(a):
            a = taste(i, l)
    print(sum([taste(j, l) for j in range(1, n+1)]) - a)


def taste(i, l):
    return l + i - 1


if __name__ == '__main__':
    main()

Solution (Python):
n,l = map(int,input().split())
arr = [l+i for i in range(n)]
arr2 = [abs(i) for i in arr]
if arr.count(min(arr2))>=1:
  print(sum(arr)-min(arr2))
else:
  print(sum(arr)+min(arr2))

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

Solution (Python):

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

print(aji)

Solution (Python):
import math





inputa = input().split()


a = int(inputa[0])
b = int(inputa[1])








sum = 0

smallest = -1
idx = 0

for i in range(a):
    sum += b + i

    if smallest == -1:
        smallest = abs(b + i)
    elif smallest > abs(b + i):
        smallest = abs(b + i)
        idx = i

ans = sum - (b + idx)
print(int(ans))

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

x=[l+i-1 for i in range(1,n+1)]
x.remove(min(x, key=abs))
print(sum(x))

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

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

x=[l+i-1 for i in range(1,n+1)]
min_val=None
idx=0
for i in range(1,n+1):
  tmp=abs(l+i-1)
  if min_val is None or tmp < min_val:
    min_val=tmp
    idx=i-1

x.pop(idx)
print(sum(x))

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

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

apple=np.array(list(range(1,n+1,1))) 
taste = np.array(list(range(1,n+1,1))) + l -1

if n+l > 0:
    ans=np.sum(taste)-min(np.abs(taste))
else:
    ans=np.sum(taste)+min(np.abs(taste))

print(ans)

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

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


sumtaste=0
if taste[0]*taste[-1]<0:
    for i in taste:
        sumtaste+=i
elif taste[0]>=0:
    del taste[0]
    for i in taste:
        sumtaste+=i
else:
    taste.pop()
    for i in taste:
        sumtaste+=i
print(sumtaste)

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

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

apples=[a+i for i in range(n)]
eat=min(apples,key=lambda x:abs(x))
res=sum(apples)-eat

print(res)

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

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

import numpy as np
b=min(np.abs(l))

if b==0:
  l.remove(0)
elif b in l:
  l.remove(b)
elif -b in l:
  l.remove(-b)
  
print(sum(l))

Solution (Python):
n, l = map(int,input().split())
s = []
cnt = 0
min_apple = 9999
sub_apple = 0
for i in range(n):
    s.append(l + i)
    if min_apple > abs(l + i):
        min_apple = abs(l + i)
        sub_apple = s[i]
print(sum(s) - sub_apple)

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

apples = [L + i for i in range(N)]
eat = min(apples, key=lambda x: abs(x))
res = sum(apples) - eat
print(res)

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

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

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

print(ans)

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

apples = [l+i-1 for i in range(1, n+1)]
del apples[list(map(abs, apples)).index(min(list(map(abs, apples))))]
print(sum(apples))

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

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

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

absmin = -1
absi   = -1
for i in range(N):
    absval = abs( L + i )
    if absmin == -1 or absmin > absval:
        absmin = absval
        absi = i

print( allpi - (L+absi))

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

for i in range(1,n+1):
    aji = l + i -1
    ans.append(aji)

if 0 in ans:
    print(sum(ans))
else:
    mn = min(ans)
    mx = max(ans)
    if abs(mn) <= abs(mx):
        ans.remove(mn)
        print(sum(ans))
    else:
        ans.remove(mx)
        print(sum(ans))

Solution (Python):
n, l = map(int, input().split())
lst = []
for i in range(n):
    lst.append([i + l, abs(i + l)])
lst = sorted(lst, key=lambda x: x[1])
total = 0
for i in range(1, len(lst)):
    total += lst[i][0]
print(total)

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

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

k = [abs(i) for i in _list].index(min([abs(i) for i in _list]))

_list.pop(k)
ans = sum(_list)

print(ans)

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

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

apples = [0] * (N + 1)
applepie = 0
eaten = 100 + 200

for i in range(1, N + 1):
    apples[i] = L + i - 1
    applepie += apples[i]

    if eaten**2 > apples[i]**2:
        eaten = apples[i]

print(applepie - eaten)

Solution (Python):
def resolve():
    n,l = map(int,input().split())
    min1,sum1 = 10*10,0
    for i in range(n):
        if abs(min1)>abs(i+l):
            min1 = i+l
        sum1 += i+l
    print(sum1-min1)
resolve()

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

min = 10000
min_raw = 100000
ans = 0

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

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

print(ans-min_raw)

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

Solution (Python):
n,l = list(map(int,input().split()))
ans = int((2*l-1+n)*(n/2))
if l <= 0 and 0 <= 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())
sum=0
A=[]
ans=-1
for x in range(0,N):
    A.append(-L-x)
for i in range(0,N):
    sum=sum+L+i
for i in range(0,N):
    for j in range(0,N):
        A[i]=A[i]+L+j
    if sum==A[i]:
        ans=i
        break
if ans>-1:
    print(A[ans])
elif A[0]<sum:
    print(A[0])
else:
    print(A[N-1])

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

m = abs(L)+abs(N)
j = 0
for i in range(N):
    if abs(L+i) < m:
        m = min(abs(L+i), m)
        j = i

t = 0
for i in range(N):
    if i != j:
        t += L+i

print(t)

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

Solution (Python):
n, a = map(int,input().split())
l = a
r = a+n-1
if r<=0: e = r
elif l>=0: e = l
else: e = 0

print(int((r+l)*(r-l+1)/2-e))

Solution (Python):

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

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

all_tas = sum(tastes)

ptn = [all_tas - x for x in tastes]

di  = [abs(all_tas - x) for x in ptn]

val = min(di)

print (ptn[di.index(val)])

Solution (Python):
def main():
    n, l = list(map(int, input().split()))
    a = [l + i for i in range(n)]
    if l < 0 and abs(l) >= n:
        score = sum(a[:n - 1])
    if l < 0 and abs(l) < n:
        score = sum(a)
    if l >= 0:
        score = sum(a[1:])
    print(score)


main()

Solution (Python):
import numpy as np
N,L=map(int,input().split())
a=[]
for i in range(1,N+1):
  b=L+i-1
  a.append(b)
c=sum(a)
if L>0:
  d=min(a)
  print(c-d)
elif L<=0 and L>-N:
  print(c)
elif L<=-N:
  d=max(a)
  print(c-d)

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

import numpy as np

a=[]
m=1e1000
for i in range(N):
    tmp=L+i+1-1
    a.append(tmp)
    if np.abs(m)>np.abs(tmp):
        m=tmp
a.remove(m)
print(sum(a))

Solution (Python):
def solve():
    n, l = map(int, input().split())
    tastes = [l + i for i in range(n)]
    if 0 in tastes:
        return sum(tastes)
    elif all([t > 0 for t in tastes]):
        return sum(tastes) - min(tastes)
    elif all([t < 0 for t in tastes]):
        return sum(tastes) - max(tastes)


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

Solution (Python):

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

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

if A[0] > 0:
	for j in range(1, N):
		ans += A[j]

elif A[N - 1] < 0:
	for j in range(0, N - 1):
		ans += A[j]

else:
	for j in range(N):
		ans += A[j]
print(ans)

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

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

B = list(map(lambda x: abs(x), A))
print (sum(A) - A[B.index(min(B))])

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

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

for i in range(n):
    tot+=l+i

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

Solution (Python):


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

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

A_abs = [abs(x) for x in A]
abs_min = min(A_abs)
index = A_abs.index(abs_min)
eat = A[index]
ans = sum(A) - eat
print(ans)

Solution (Python):
"""
- https://atcoder.jp/contests/abc131/tasks/abc131_b
- 最もおいしさの絶対値の小さいりんごを食べるのが、最適
"""
base = 0
n, l = map(int, input().split())
eat = min([abs(i+l-1) for i in range(1, n+1)])
for i in range(1, n+1):
    base+=(i+l-1)
    pie = base-eat if l>=0 else base+eat
print(pie)

Solution (Python):
N,L=list(map(int, list(input().split())))
N=[i+1 for i in range(N)]
F=[i+L-1 for i in N]
Fmin=min(map(abs, F))
f=[i for i in F if abs(i) != Fmin]
print(sum(f))

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

Solution (Python):

n,l=map(int,input().split())
x=[l+i for i in range(n)]
y=[abs(x[i]) for i in range(n)]
a,b=sum(x)-min(y), sum(x)+min(y)
if abs(a)<abs(b):
    print(a)
else:
    print(b)

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

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

aji.sort(key=abs)
print(sum(aji[1:]))

Solution (Python):

import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)

def main(N, L):
    min_val = 1000
    apples = list(range(L, L+N))
    for apple in apples:
        if abs(apple) < abs(min_val):
            min_val = apple
    ans = (apples[0] + apples[N-1]) * N / 2 - min_val
    return ans

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

Solution (Python):
import numpy as np

N, L = map(int, input().split())
print(int(N*L+N**2/2-N/2-L+1-np.clip(-L+1, 1, N)))

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

plus = []
minus = []
for i in range(N):
    taste = L + i
    if taste >= 0:
        plus.append(taste)
    else:
        minus.append(taste)

if plus and minus:
    ans = sum(plus) + sum(minus)  
elif plus:
    ans = sum(plus) - plus[0]
else:
    ans = sum(minus) - minus[-1]

print(ans)

Solution (Python):

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


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


if 0 in tastes:
    print(sum(tastes))
else:
    
    tastes.sort(key=abs)
    print(sum(tastes[1:]))

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


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


all_tastes = sum(tastes)


ptn = []
for x in tastes:
    ptn += [all_tastes - x]


di = []
for i in range(n):
    di += [abs(all_tastes - ptn[i])]

min_value = min(di)
print(ptn[di.index(min_value)])

Solution (Python):
import numpy as np

def main():
    N, L = map(int, input().split())
    apple = np.zeros(N)
    R = L + N - 1
    eat = 0
    if R <= 0:
        eat = R
    elif L >= 0:
        eat = L
    print(int((R + L) * (R - L + 1)/2 - eat))



       

if __name__ == '__main__':
    main()

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

tmp = float("inf")

for i in range(N):
    if abs(tmp) > abs(L+i):
        tmp = L+i
answer = 0
for i in range(N):
    answer += L+i
answer -= tmp
print(answer)

Solution (Python):


import os
import sys

N, L = map(lambda x: int(x), input().split(" "))

t = [0 for i in range(N)]

for i in range(N):
	t[i] = L + i + 1 - 1

t0 = sum(t)

min_diff = 10**9
min_idx = -1
min_t = 10**9

for i in range(N):
	tmp = t[i]
	t[i] = 0
	tt = sum(t)
	diff = abs(tt - t0)
	if diff < min_diff:
		min_diff = diff
		min_idx = i
		min_t = tt
	t[i] = tmp

print(min_t)

Solution (Python):
import numpy as np


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


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

num = list(range(1, n+1))
aji = list(range(d, d+n))

aji.pop(aji.index(getNearestValue(aji, 0)))

print(sum(aji))

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

Solution (Python):
import numpy as np
N, L = map(int, input().split())
A = [L + i for i in range(N)]
v = min(np.abs(A))
b = 0
for j in range(N):
    b += A[j]
if A.count(v) >= 1:
    print(b-v)
else:
    print(b+v)

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

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

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

arr = []
e = l
for i in range(1, n+1):
    tmp = l+i-1
    if abs(e) > abs(tmp):
        e = tmp
    arr.append(tmp)

print(sum(arr)-e)

Solution (Python):
n, l = map(int, input().split())
sa = 1000
sum = 0
for i in range(1,n+1):
    if sa != min(abs(l+i-1), sa):
        sa = min(abs(l+i-1), sa)
        app = l+i-1
    sum += l+i-1

print(sum-app)