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())
m = []
for i in range(1, n+1):
    m.append(l+i-1)
ab = 10**10
apple = 0
for i in range(n):
    if ab > abs(m[i]):
        apple = i
        ab = abs(m[i])
ans = 0
for i in range(n):
    if i == apple: continue
    ans += m[i]
print(ans)

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

total = L*N
for i in range(N):
    total += i
    
if L > 0:
    ans = total-L
elif L+N-1 < 0:
    ans = total-(L+N-1)
else:
    ans = total
    
print(ans)

Solution (Python):
N, L = (int(x) for x in input().split())
A = []
for i in range(N):
  A.append(L+i)
s = sum(A)
m = 1000
ans = 0
for i in range(N):
  t = A.pop(i)
  if abs(sum(A)-s) <= m:
    m = abs(sum(A)-s)
    ans = sum(A)
  A.insert(i,t)
print(ans)

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

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

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

Solution (Python):
n,l=map(int,input().split())
lst=[]
for i in range(l, n+l):
  lst.append(i)
total = sum(lst)
gap = 10000000
digit=0
for j in range(len(lst)):
  if abs(lst[j])<gap:
    gap=abs(lst[j])
    digit = j
del lst[digit]
print(sum(lst))

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

Solution (Python):
def main():
    N, L = (int(x) for x in input().split())
    azi = [L + i for i in range(N)]
    ans = sum(azi)
    if 0 not in azi:
        if azi[0] > 0:
            ans -= azi[0]
        else:
            ans -= azi[N-1]
    print(ans)


if __name__ == "__main__":
    main()

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

import numpy as np

apple = np.array([l+(i+1)-1 for i in range(n)])

ringo = np.argmin(np.array(list(map(abs,apple))))

apple=np.delete(apple,ringo)

print(sum(apple))

Solution (Python):
import functools
N, L = list(map(int,input().split()))
NL = [L+i-1 for i in range(1,N+1)]
MINABS = functools.reduce(lambda x,y: x if abs(x) < abs(y) else y, NL )
print(sum(NL)-MINABS)

Solution (Python):
def solve():
    N, L = map(int, input().split())
    m = abs(L)
    for i in range(N):
        if abs(m) > abs(L+i):
            m = L+i
    print(int(N*(L+0.5*N-0.5)-m))


solve()

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

if apple.max() <= 0:
    print(apple.sum()-apple.max())
elif apple.min() > 0:
    print(apple.sum()-apple.min())
else:
    print(apple.sum())

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

Solution (Python):
n,l=map(int, input().split())
t=0
c=0
for i in range(n):
  if i==0:
    t=abs(l+(i+1)-1)
    c=i+1
  else:
    t=min(t, abs(l+(i+1)-1))
    if t==abs(l+(i+1)-1):
      c=i+1

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

print(g-l-c+1)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, l = Is()
A = [l+i-1 for i in range(1, n+1)]
index = bisect_left(A, 0)
if index == n:
    m = A[-1]
else:
    m = A[index]
print(sum(A)-m)

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

for i in range(N):
    APsum += i+L
    AJIList.append(i+L)
    AbsList.append(abs(i+L))
    



del AJIList[AbsList.index(min(AbsList))]

print(sum(AJIList))

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

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

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

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

ans=0
min_apple = 10**10
for i in range(1,n+1):
    taste = l+i-1
    if abs(min_apple)>abs(taste):
        min_apple=taste
    ans+=taste
print(ans-min_apple)

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

for i in range(n):
  li1[i] = l+i
  li2[i] = abs(l+i)

li1.pop(li2.index(min(li2)))

print(sum(li1))

Solution (Python):


import numpy as np
n, l = map(int, input().split())
x = l+np.arange(n)
print(sum(x) - x[np.argmin(abs(x))])

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

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

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

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

if taste[0] > 0:
    ans = sum(taste) - taste[0]
elif taste[-1] < 0:
    ans = sum(taste) - taste[-1]
else:
    ans = sum(taste)

print(ans)

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

aji_abs = [0]*n
for i in range(1,n+1,1):
    aji_abs[i-1]  = abs(aji[i-1])
aji.remove(aji[aji_abs.index(min(aji_abs))])
print(sum(aji))

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

apple = []
for i in range( N):
    apple.append(L + i)
    
min_l = apple[0]
for j in apple:
    if abs(j) < abs(min_l):
        min_l = j
print(sum(apple)-min_l)

Solution (Python):


N, L = map(int, input().split())
ans = 0
mn = float('inf')
for i in range(1, N + 1):
    ans += L + i - 1
    if abs(L + i - 1) < abs(mn):
        mn = L + i - 1

print(ans - mn)

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

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    N, L = map(int, input().split())
    AJI = 0
    INF = float('inf')
    SA = INF
    I = 0

    for i in range(1,N+1):
        if abs(L+i-1)<SA:
            SA = abs(L+i-1)
            I = i
        AJI += L + i - 1
    print(AJI-(L+I-1))

if __name__ == '__main__':
    main()

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi

N, L = ri_()
if L >= 0:
    eaten = 0
elif L <= -N:
    eaten = N - 1
else:
    eaten = -L
ans = N * L + N * (N - 1) // 2 - (L + eaten)
print(ans)

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

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


p=1000
for i in range(n):
    if abs(aji[i])<=abs(aji[i-1]):
        p=aji[i]
        
print(sum-p)

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

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

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

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

Apple_List1=[]
Apple_List2=[]
for i in range(N):
    Apple_List1.append(L+i)
    Apple_List2.append(abs(L+i))


Apple_List2.sort()

flag=0
if Apple_List2[0] in Apple_List1:
    flag=1
elif -Apple_List2[0] in Apple_List1:
    flag=-1
    
print(sum(Apple_List1)-flag*Apple_List2[0])

Solution (Python):
n,l = map(int, input().split())
m = float('inf')
ans = 0
for i in range(l,l+n):
  ans += i
  if abs(m) > abs(i):
    m = i
print(ans-m)

Solution (Python):
N,L = map(int, input().split())
def func_abs(n):
    return abs(n)
An = [0]*N
for i in range(N):
  An[i] = L + i
print(sum(An)-min(An, key=func_abs))

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

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

Solution (Python):
n, l = map(int, input().split())
d = []
for i in range(1, n + 1):
    d.append(l + i - 1)
wa = sum(d)
k = []
for i in range(1, n + 1):
    t = n * l + n * (n - 1) // 2 - (l + i - 1)
    k.append(t)
for i in range(n):
    k[i] = abs(k[i] - wa)
m = k.index(min(k))
print(n * l + n * (n - 1) // 2 - (l + m))

Solution (Python):
N,L=map(int, raw_input().split())
A=[]
for i in range(1,N+1):
    A.append((abs(L+i-1),L+i-1))
A.sort()
ans=0
for i,t in enumerate(A):
    if i==0: continue
    ans+=t[1]
print ans

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

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

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

Solution (Python):
n,l = map(int,input().split())
n_l = [0]*n
flag = "ng"
for i in range(n):
    n_l[i] = l + (i+1) - 1
    if n_l[i] == 0:
        flag = "ok"
if flag == "ok":
    print(sum(n_l))
    exit()
n_l_min = min(n_l)
if n_l_min < 0 :
    print(sum(n_l)-max(n_l))
    exit()
print(sum(n_l)-n_l_min)

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

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

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

def resolve():
    n,l=map(int, input().split())
    ll=list(range(l,l+n))
    moto=sum(ll)
    if ll[0]>0:
        print(moto-ll[0])
    elif ll[-1]<0:
        print(moto-ll[-1])
    else:
        print(moto)
resolve()

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

count -= aji[0][1]
print(count)

Solution (Python):
import itertools

import math
n, l = map(int, input().split())
l_list = []
abs_list = [0]*n

for i in range(0, n):
    l_list.append(l + i)

min_tmp = 10**9
mini = 0
for i in range(0, n):
    if(abs(l_list[i]) <= min_tmp):
        min_tmp = abs(l_list[i])
        mini = l_list[i]
print(sum(l_list) - mini)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, L = map(int, readline().split())
a = []
tmp = 0
min_tmp = 100000

for i in range(n):
    a.append(i+L)

for i in range(n):
    tmp = abs(a[i])
    if tmp < min_tmp:
        min_tmp = tmp
        min_i = i

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

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

if 0 in t:
	print(sum(t))
else:
	if t[0] <0:
		t.pop()
		print(sum(t))

	else:
		t.pop(0)
		
		print(sum(t))

Solution (Python):
N, L = map(int, input().split())
list = [L+i for i in range(N)]
a = float("inf")
for i in range(N):
  if abs(a) > abs(list[i]):
    a = list[i]
print(sum(list) - a)

Solution (Python):
N,L=map(int,input().split())
r=[]
i=0
s=10000
for i in range(N):
  r.append(L+i)
  a=abs(L+i)
  if s>a:
    s=a
    l=i
del r[l]
print(sum(r))

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

print(sum(tas) - tas[ab_tas.index(min(ab_tas))])

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

Solution (Python):
import numpy as np

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

a = np.array(range(0,n)) + l
b = np.abs(a)
i = np.argmin(b)

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

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

Solution (Python):

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

ans = sum(apple) 
rem = sorted([abs(i) for i in (apple)])[0]
if rem in apple:
    ans -= rem
else:
    ans+=rem
print(ans)

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

def main():
    N, L = map(int, readline().rstrip().split())
    A = [L+i-1 for i in range(1, N+1)]
    A_abs = [abs(a) for a in A]
    mi_idx = A_abs.index(min(A_abs))
    print(sum(A) - A[mi_idx])

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from collections import Counter
import itertools



def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())

def LI(): return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'


p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")



n,L=MI()
l=[0]*n
for i in range(1,n+1):
    l[i-1] = L+i-1
s=sum(l)

mini=999
target=0
for i in range(n):
    if mini > abs(s-(s-l[i])):
        mini =abs(s-(s-l[i]))
        target=l[i]

print(s-target)

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

Solution (Python):
n, l = map(int, input().split())
pie = 0
comp = 300

for i in range(1, n+1):
    pie = pie + l + i - 1
    if abs(l + i -1) < abs(comp):
        comp = l + i -1

print(pie - comp)

Solution (Python):


def main():
    N, L = map(int, open(0).read().split())

    T = []
    T_abs = []
    for i in range(1, N + 1):
        T.append(L + i - 1)
        T_abs.append(abs(L + i - 1))
    
    Remv = T[T_abs.index(min(T_abs))]
    print(sum(T) - Remv)


main()

Solution (Python):
n,l=map(int,input().split())
motomoto=n*l-n+n*(n+1)//2
zettaisa=10**100
keep=0
for i in range(1,n+1):
  aji=motomoto-(l+i-1)
  sa=abs(motomoto-aji)
  if sa<=zettaisa:
    zettaisa=sa
    keep=aji
print(keep)

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

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

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

Solution (Python):
import numpy as np
n,l=map(int,input().split())
a = np.arange(l,l+n)
d = abs(a).argmin() 
print(a.sum() - a[d])

Solution (Python):

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

N_sum=sum(aji_lis)
ap=min([abs(i) for i in aji_lis])

if N_sum >=0:
    print(N_sum-ap)
else:
    print(N_sum+ap)

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

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

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

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

sumA = 0
for i in range(N):
    sumA += (L + i)
    
cur_diff = float('inf')
ans = 0
for i in range(N):
    tmp = sumA - (L + i)
    diff = abs(sumA - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp
        
print(ans)

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 






n, l = map(int, input().split())
minv = 300
sumv = 0
it = 0
for i in range(n):
    sumv += (l + i)
    if abs(l + i) < minv:
        it = i
        minv = abs(l + i)
print(sumv - (l + it))

Solution (Python):
n, l = map(int, input().split())
taste = [0]*n
taste2 = [0]*n
for i in range(n):
    taste[i] = l + i
    taste2[i] = abs(l + i)
ate_idx = taste2.index(min(taste2))
taste[ate_idx] = 0
print(sum(taste))

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

s=0
for i in range(n):
  s+=l+i
cnt=0  
m=100000000
for i in range(n):
  u=m
  m=min(abs(l+i),m)
 
  if u!=m:
    cnt=i
    
    
print(s-(l+cnt))

Solution (Python):
n, l = map(int, input().split())
t = [l+i for i in range(n)]
s = sum(t)
df = float('inf')
ans = 0
for i in range(n):
  pie = s - t[i]
  if abs(s - pie) < df:
    df = abs(s - pie)
    ans = pie
print(ans)

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


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

if max(a) < 0:
  print(sum(a)-max(a))
elif max(a) >= 0 and min(a) <= 0:
  print(sum(a))
else:
  print(sum(a)-min(a))

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

nums = []
total = 0
for i in range(L, L + N):
  nums.append(i)
  total += i

if max(nums) < 0:
  total -= max(nums)
elif min(nums) > 0:
  total -= min(nums)

print(total)

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

list=[]
for i in range(1,N+1):
  s=i+L-1
  list.append(s)
if 0 in list:
  print(sum(list))
else:
  list=sorted(list)
  if list[0]>0:
    del list[0]
    print(sum(list))
  elif list[0]<0:
    list=sorted(list,reverse=True)
    del list[0]
    print(sum(list))

Solution (Python):

N, L = map(int,input().split())
apple = []
for i in range(N):
    apple.append(L+i)
taste = sum(apple)
diff = 10**9
ans = 0
for i,v in enumerate(apple):
    if diff > abs(taste-(taste-v)):
        diff = abs(taste-(taste-v))
        ans = taste-v
print(ans)

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

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

Solution (Python):


import sys



















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, l = mi()
    summation = (2 * l + n - 1) * n // 2
    left = l
    right = l + n - 1
    if left <= 0 <= right:
        print(summation)
    elif 0 < left:
        print(summation - left)
    else:
        print(summation - right)

if __name__ == "__main__":
    main()

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

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

print(sum(taste)-t)

Solution (Python):
def main():
	n , l = map(int,input().split())
	arr= []
	for i in range(n):
		arr.append(l+i)
	arr.sort()
	add = sum(arr)
	mn = 10000000000000
	
	
	for i in range(len(arr)):
		if abs(arr[i])<abs(mn):
			mn = arr[i]
	print(add-mn)
main()

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

Solution (Python):

n,l = map(int,input().split())
apple = [0]*n

for i in range(n):
  apple[i] = l+i
eat = apple[i]
for i in range(n):
  eat = min(abs(apple[i]),abs(eat))

if eat in apple:
  apple.remove(eat)
else:
  apple.remove(-1*eat)

print(sum(apple))

Solution (Python):

def inputlist(): return [int(k) for k in input().split()]

N,L = inputlist()
li = [0]*N
for i in range(N):
    li[i] = L+i
ans = -1
d = 10**18
s = sum(li)
for i in range(N):
    sa = s
    sa -=li[i]
    da = abs(s-sa)
    if da < d:
        ans = sa
        d = da
print(ans)

Solution (Python):
N,L = map(int,input().split())
Apple = []
compare = []
for i in range(N):
  Apple.append(L + i)
tot = sum(Apple)
for i in range(N):
  a = Apple[i]  
  Apple.remove(a)
  compare.append(abs(tot - sum(Apple)))
  Apple.insert(i,a)
Apple.remove(Apple[compare.index(min(compare))])
print(sum(Apple))

Solution (Python):

import sys
input = sys.stdin.readline









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

total = L*N
for i in range(N):
    total += i

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

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

d_list = [l + i - 1 for i in range(1, n + 1)]
d_sum = sum(d_list)

ans = 0
temp = abs(d_sum)
for d in d_list:
    if abs(d) < temp:
        ans = d_sum - d
        temp = abs(d)
print(ans)

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

d_list = [l + i - 1 for i in range(1, n + 1)]
d_sum = sum(d_list)

temp_list = sorted([(abs(d), d) for d in d_list])

ans = d_sum - temp_list[0][1]
print(ans)

Solution (Python):

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

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

Solution (Python):
import math
n, l = map(int, input().split())
t = []
for i in range(1, n+1):
    t.append(l+i-1)
fab = []
sum_t = sum(t)
tmp = 0
if n+l > 0:
    for i in range(n):
        fab.append(sum_t-t[i])
    ans = []
    for i in range(n):
        ans.append(math.fabs(sum_t-fab[i]))
    print(int(sum_t-min(ans)))

else:
    for i in range(n-1):
        tmp += t[i]
    print(tmp)

Solution (Python):
n,l = list(map(int,input().split()))
n_l = []
for i in range(n):
    n_l.append(i+l)
    
min_i = n_l[0]
for i in n_l:
    if abs(i) < abs(min_i):
        min_i = i

print(sum(n_l) - min_i)

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

taste_list = [L + i for i in range(N)]
taste_abs_list = [abs(n) for n in taste_list]
abs_min = min(taste_abs_list)
min_idx = taste_abs_list.index(abs_min)
total_sum = sum(taste_list)

ans = total_sum - taste_list[min_idx]
print(ans)

Solution (Python):

N, L = list(map(int,input().split()))
A = [None for _ in range(N)]

m = float('inf')
M = 0
for i in range(N):
  A[i] = L + i
  if m > abs(A[i]):
    m = abs(A[i])
    M = A[i] 

print(sum(A) - M)

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

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

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

sm = sum(range(L, L+N))

if L <= 0 <= L+N-1:
    ans = sm
else:
    if 0 < L:
        ans = sm-L
    else:
        ans = sm-(L+N-1)

print(ans)

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

Solution (Python):
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())



def resolve():
    N,k=pin()
    original=(range(k,k+N))
    temp=0
    min=1000000
    for o in original:
        temp=o
        if min**2>temp**2:
            min=temp
    
    print(sum(original)-min)

resolve()

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

Solution (Python):
N, L = map(int,input().split())
A = [L+k for k in range(N)]
t = 10**9
for e in A:
    if abs(e) < abs(t):
        t = e
print(sum(A)-t)

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

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

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

if int(a_list[n-1])<0:
    a_list.remove(a_list[n-1])

if int(a_list[0])>0:
    a_list.remove(a_list[0])

if 0 in a_list:
    a_list.remove(0)
'''
エラーコード    if int(a_list[n])<0:
               IndexError: list index out of range
if int(a_list[n-2])<0:
    a_list.remove(a_list[n-1])
'''
print(sum(a_list))

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

for i in range(1,N+1):
    l.append(i)
for i in range(len(l)):

    (l[i])=L+(i+1)-1

if l[0]>0 and l[len(l)-1]>0:
    l.remove(l[0])
elif l[0]<0 and l[len(l)-1]<0:
    l.remove(l[len(l)-1])
else:
    l.remove(0) 

print(sum(l))

Solution (Python):
N, L = map(int, input().split())
al = sum(L + i for i in range(N))
ans = 0
m = None
for i in range(N):
    x = al - (L + i)
    y = abs(al - x)
    if m is None or y < m:
        m = y
        ans = x
print(ans)

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

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

Solution (Python):

n,l = map(int,input().split())
t = []
ans = []
w = []
diff = []

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

for i in range(n):
    ans = t.copy()
    del ans[i]
    w.append(sum(ans))
    diff.append(abs(sum(t)-sum(ans)))

num = diff.index(min(diff))

print(w[num])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())

A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
import numpy as np

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

arr = np.arange(1, N+1)
taste = arr + L - 1
total = sum(taste)

min_sa = INF
ans = 0
for a in taste:
    ext = total - a
    sa = abs(total - ext)
    if min_sa > sa:
        ans = ext
        min_sa = sa

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

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

print(ma-b)

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

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

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

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

Solution (Python):
import numpy as np

n,l=map(int,input().split())
li=[]
for i in range(n):
  li.append(l+i)
s=sum(li)
p=np.array(li)
a=np.abs(p).tolist()
k=min(a)
b=a.index(k)
print(s-li[b])