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())
apples = [L + i for i in range(N)]
abs_sort = [(abs(x), i) for i, x in enumerate(apples)]
abs_sort.sort()
eat = apples[abs_sort[0][1]]
print(sum(apples) - eat)

Solution (Python):
N,L=map(int,input().split())
A=list()
sa1=1000
ans=1000
for i in range(N):
    A.append(L+i)
for i in range(N):
    azi=sum(A)-A[i]
    sa2=sum(A)-azi
    if sa1>sa2:
        if sa2<0:
            sa2*=-1
        sa1=sa2
        ans=azi
print(ans)

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

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

temp = 500
ans = 0

for i in range(N):
    if temp >= abs(app[i]):
        temp = abs(app[i])
        ans = app[i]
print(sum(app) - ans)

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

Solution (Python):
a,c=map(int,input().split())
d=0
m=5000
for i in range(1,a+1):
    d=d+c+i-1
    if abs(m)>abs(c+i-1):
        m=c+i-1
print(d-m)

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

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

Min = 100000000
for j in apple:
    a = abs(j)
    if Min >= a:
        Min = a
        eat = j

print(sum(apple)-eat)

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

Min = l + 1 - 1
Max = l + n - 1

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

if (Max < 0) :
    ans -= Max

if (Min > 0):
    ans -= Min

print(ans)

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

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

Solution (Python):
n,l=map(int,input().split())
ringo=[0]*n
ringoz=[0]*n
min=1000000000000000
mini=0
for i in range(n):
    ringo[i]+=i+l
    if ringo[i]<0:
        ringoz[i]=-ringo[i]
    else:
        ringoz[i]=ringo[i]
    if ringoz[i]<min:
        min=ringoz[i]
        mini=i
ringo.pop(mini)

print(sum(ringo))

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

Solution (Python):

N, L = map(int, input().split())
full_apple = 0
for i in range(N):
    full_apple += (L + i)
notfull_apple = 10 ** 9

for i in range(N):
    test_apple = full_apple - (L + i)
    if abs(full_apple - notfull_apple) > abs(full_apple - test_apple):
        notfull_apple = test_apple

print(notfull_apple)

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

if l*(l+n-1) <0:
    print(ans)

elif l >=0:
    print(ans-l)

else:
    print(ans-(l+n-1))

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

Solution (Python):


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

apple = [L + i - 1 for i in range(1, N + 1)]
diff = abs(apple[0])
for i in range(1, N):
    diff = min(diff, abs(apple[i]))

print(sum(apple) - diff if sum(apple) > 0 else sum(apple) + diff)

Solution (Python):
n,l = map(int,input().split())
a = 0
for i in range(n):
    a += l + i
t = 0
u = 0
z = 999
ans = 0
for i in range(n):
    t = a - (l+i)
    u = abs(a - t)
    if z > u:
        z = u
        ans = t
print(ans)

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

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

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

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

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

X = [L + i - 1 for i in range(1, N+1)]
if 0 in X:
    s = 0
elif abs(X[0]) < abs(X[-1]):
    s = X[0]
else:
    s = X[-1]

print(sum(X) - s)

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

stack=65535
sum=0

for x in range(1, N+1):
    sum+=x+L-1
    if(abs(stack)>abs(x+L-1)>=0):
        stack=x+L-1

print(sum-stack)

Solution (Python):
import bisect

n, l = map(int, input().split())
Ts = [l+i for i in range(n)]
Ts.sort()

zero = bisect.bisect_left(Ts, 0)

if n-1 >= zero:
    if abs(Ts[zero-1]) > abs(Ts[zero]):
        ans = sum(Ts) - Ts[zero]
else:
    ans = sum(Ts) - Ts[zero-1]
print(ans)

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

a = [0]*n

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

min = 10000
check = 0

for i in range(n):
	
	if min > abs(a[i]):
		
		min = abs(a[i])
		check = a[i]

print( sum(a)-check )

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

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

Solution (Python):
import numpy as np

N, L = list(map(int, input().split()))
taste = np.array([L + i for i in range(N)])
total = sum(taste)
abs_ta = abs(taste)
smallest = abs_ta[0]
smallest_i = 0
for i in range(1, N):
    if abs_ta[i] < smallest:
        smallest = abs_ta[i]
        smallest_i = i
print(total - taste[smallest_i])

Solution (Python):
n, l = map(int,input().split())
sum1 = 0
num = 1000
for i in range(n):
  a = l+(i+1)-1
  sum1 += a
  if abs(a) < num:
    num1 = a
    num = abs(a)
if num1 == num:
  print(sum1-num)
else:
  print(sum1+num)

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

Solution (Python):


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

tastes = []
for n in range(N):
    tastes.append(L + n)

minimum = tastes[0]
for t in tastes:
    if abs(t) < abs(minimum):
        minimum = t

tastes.remove(minimum)
pie_taste = sum(tastes)

print(pie_taste)

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

t = [L+i-1 for i in range(1, N+1)]
idx = np.abs(np.asarray(t)).argmin()

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

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

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

Solution (Python):
nums=list(map(int,input().split()))
N=nums[0]
L=nums[1]
taste=[L+i for i in range(N)]
abs_taste=[abs(x) for x in taste]
tabel=min(abs_taste)
if(tabel in taste):
  taste.remove(tabel)
  print(sum(taste))
else:
  taste.remove(-tabel)
  print(sum(taste))

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

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

if min(abs_out) == 0:
    out = out
elif min(all_out) > 0:
    out = out - min(all_out)
elif max(all_out) < 0:
    out = out - max(all_out)

print(out)

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

print(ret-A[0][1])

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

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

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

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

print(sum(apple_taste) - apple_taste[apple_taste_abs.index(min(apple_taste_abs))])

Solution (Python):
n, l = map(int,input().split())
count = 10000
for i in range(n):
    if abs(count) > abs(l+i):
        count = l+i 

ans = (l-1) * n + n * (n+1) // 2 - count

print(ans)

Solution (Python):

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


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


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)



show_flg = True


def main():
    N, L = MI()
    apples = [L + i - 1 for i in range(1, N+1)]
    apple_pie = sum(apples)
    apple_pie_n = []

    for i in range(N):
        tmp = 0
        for j in range(N):
            if j != i:
                tmp += apples[j]
        apple_pie_n.append((abs(apple_pie - tmp), i))

    apple_pie_n.sort()
    print(apple_pie - apples[apple_pie_n[0][1]])


if __name__ == '__main__':
    main()

Solution (Python):
N,L=map(int,input().split())
A=[0]*201
m=100000
point=0
for i in range(1,N+1):
  A[i]=L+i-1
  if abs(L+i-1)<m:
    m=abs(L+i-1)
    p=i
print(sum(A)-A[p])

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

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

aaa_list = []

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

print(sum(aaa_list)-min(aaa_list,key=lambda x: abs(x)))

Solution (Python):
n,l = map(int,input().split())
 
ll = []
p = []
for i in range(n):
    ll.append(l + i)
    p.append(abs(l + i))
sm = 0
ind = 0
a_min = 0
a_min = min(p)
ind = p.index(a_min)
ll.pop(ind)
sm = sum(ll)

print(sm)

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

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

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

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

ans = 0

for i in range(l, l+n):
  ans += i

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


print(ans)

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

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

if all([i > 0 for i in orig_pie]):
  print(sum(orig_pie[1:]))
elif 0 in orig_pie:
  print(sum(orig_pie))
else:
  print(sum(orig_pie[:-1]))

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

Solution (Python):
import numpy as np

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

NL = list(map(int,input().split()))
N = NL[0]
L = NL[1]

taste=[]

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

print(sum(taste)-getNearestValue(taste, 0))

Solution (Python):
N,L = map(int,input().split(' '))
lst = [i+L-1 for i in range(1,N+1)]
normal_ans = sum(lst)
count = 10000000
result = 0
for i in range(len(lst)):
    ans_lst =  lst.copy()
    del ans_lst[i]
    special_ans = sum(ans_lst)
    
    if count >= abs(normal_ans-special_ans):
        count = abs(normal_ans-special_ans)
        result = special_ans
print(result)

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

sum_apple_pie = 0
min_abs_apple = float('inf')
min_num = float('inf')
for i in range(N):
    sum_apple_pie += i + L
    if abs(i + L) < min_abs_apple:
        min_abs_apple = abs(i + L)
        min_num = i + L
print(sum_apple_pie - min_num)

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())
minabs = 10000
midx = -1
for i in range(1, n + 1):
    if abs(l + i - 1) < minabs:
        midx = i
        minabs = abs(l + i - 1)
ans = 0
for i in range(1, n + 1):
    if i != midx:
        ans += l + i - 1
print(ans)

Solution (Python):
n,l = [int(i) for i in input().split(" ")]
L = [i for i in range(l,l+n)]
max = sum(L)
wei = 10000000000000
ans = 0
for i in range(n):
    tmp = 0
    for j in range(n):
        if i !=j:
            tmp+=L[j]
    if wei > abs(max - tmp):
        wei = abs(max - tmp)
        ans = tmp
print(ans)

Solution (Python):

n, l = [int(s) for s in input().split()]

flavor_apples = [l + i - 1 for i in range(1, n + 1)]
abs_flavor_apples = [abs(i) for i in flavor_apples]
flavor_apple_pie = sum(flavor_apples)

print(flavor_apple_pie - flavor_apples[abs_flavor_apples.index(min(abs_flavor_apples))])

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

ans = abs(max(L+N-1, L))

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

for i in lst:
    if abs(ans) > abs(i):ans=-i

ans += sum(lst)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, L):
    """Test Case
    >>> print_ans(5, 2)
    18
    >>> print_ans(3, -1)
    0
    >>> print_ans(30, -50)
    -1044
    """
    ar = np.arange(N)
    ar = ar + L
    minimum = np.argmin(np.abs(ar))
    print(np.sum(ar) - ar[minimum])



if __name__ == '__main__':
    N, L = map(int, input().rstrip().split())
    print_ans(N, L)

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

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

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

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

Solution (Python):
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0

[n,l]=inpl()
applist = np.arange(1,n+1) + l - 1
applist.sort()

if 0 in applist:
    ans = applist.sum()
elif applist[0] > 0:
    ans = applist[1:].sum()
elif applist[-1] < 0:
    ans = applist[:-1].sum()
print(ans)

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

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

a_abs = list(map(abs, a))
min_index = a_abs.index(min(a_abs))

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

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

Solution (Python):
def inpl():
    return list(map(int, input().split()))


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

tmp = 10**9
for a in A:
    if tmp > abs(a):
        tmp = abs(a)
        ans = sumA - a


print(ans)

Solution (Python):

import sys






import operator as op



def main():
    n, l = [int(x) for x in sys.stdin.readline().split()]
    flavors = []
    for i in range(1, n+1):
        flavors.append(l + i - 1)
    
    flavors.sort(key=abs)
    print(sum(flavors[1:]))
    
if __name__ == "__main__":
    main()

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

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

apple_taste = []

for i in range(N):
    taste = L + i + 1 - 1
    apple_taste.append(taste)
    
import numpy as np

abs_apple_taste = np.abs(apple_taste)
m = min(abs_apple_taste)

for j in range(N):
    if m == abs_apple_taste[j]:
        apple_taste.remove(apple_taste[j])

pie_taste = 0       

for k in range(N-1):
    pie_taste += apple_taste[k]
    
print(pie_taste)

Solution (Python):
n, l = map(int, input().split())
e = l+n-1

if (l * e) < 0:
    print(int(n/2*(l+e)))
else:
    if min(abs(l), abs(e)) == abs(l):
        print(int(n/2*(l+e)) - l)
    else:
        print(int(n/2*(l+e)) - e)

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

for i in range(n):
    sum2 = (sum1 - (l+i))
    li.append(sum2)

li2 = []
for i in range(n):
    li2.append(abs(sum1-li[i]))

a = li2.index(min(li2))
print(li[a])

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

apl = [ l+i for i in range(n) ]
tst = 100
for a in apl:
    if abs(a) < abs(tst):
        tst = a
print( sum(apl)-tst )

Solution (Python):

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

def main():
    N, L = map(int, input().split())
    
    s = (N-1)*N//2 + L * N
    if L > 0:
        s = s - L
    else:
        s = s - min(L+N-1, 0)
    print(s)



if __name__ == '__main__':
    main()

Solution (Python):
n,l=map(int,input().split())
nl=[l+i-1 for i in range(1,n+1)]
mini=10**5
for i in nl:
    mini=min(mini,abs(i))
if mini in nl:
    nl.remove(mini)
if len(nl)==n:
    nl.remove(-mini)
print(sum(nl))

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

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

diff = 10000000000
ans = 0
for i in range(1,n+1):
    ansSum = (l-1) * (n-1) + sum([j for j in range(1,n+1) if j != i])
    if abs(sumN - ansSum) < diff:
        ans = ansSum
        diff = abs(sumN - ansSum)
print(ans)

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

sum = 0
rep = 0

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

    if (0 <= abs(tmp) <= abs(rep)) or (i == 0):
        rep = tmp

print(sum - rep)

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

print(apple_sum-apple[List.index(min(List))])

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

aji_souwa = n*(n + 2*l - 1)/2

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

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

tastes = [L+i for i in range(N)]
original_sum = np.sum(tastes)
diff = float('inf')
for n in range(N):
    tmp = abs(tastes[n])
    if tmp < diff:
        diff = tmp
if original_sum < 0:
    print(original_sum+diff)
else:
    print(original_sum-diff)

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

tmp = 101
for i in p:
    if abs(i) < abs(tmp):
        tmp = i

print(sum(p)-tmp)

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

all_eat = 0
abs_min = float("inf")
for i in range(n):
    all_eat += l + i
    if abs(l + i) < abs(abs_min):
        abs_min = l + i
        
    
    
print(all_eat - abs_min)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,l=map(int,input().split())
    A=[l+i for i in range(n)]
    S=sum(A)
    a=INF
    for i in range(n):
        if(abs(a)>abs(A[i])):
            a=A[i]
    print(S-a)
resolve()

Solution (Python):
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(5, 2), 18)

    def test_2(self):
        self.assertEqual(think(3, -1), 0)

    def test_3(self):
        self.assertEqual(think(30, -50), -1044)


def solve():
    n, l = read()
    result = think(n, l)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, l):
    a = [l + i - 1 for i in range(1, n + 1)]
    original_sum = sum(a)
    buf = []
    for i, e in enumerate(a):
        buf.append((abs(e), i))
    buf.sort(key=lambda x: x[0])
    return original_sum - a[buf[0][1]]


def write(result):
    print(result)


if __name__ == '__main__':
    
    solve()

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

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

apple = [l+i for i in range(n)]
ans = -1
vol = apple[n-1]
for i in range(n):
  tmp = sum(apple)
  if abs(vol) > abs(apple[i]):
    vol = apple[i]
    ans = i
print(tmp - apple[ans])

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


if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

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


if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

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


if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

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

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

li = list()
tmp = 999
for i in range(1, n+1):
    li.append(l+i-1)
    if(abs(tmp) > abs(l+i-1)):
        tmp = l+i-1
print(sum(li)-tmp)

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

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

t.sort(key=lambda x:abs(x))
print(sum(t[1:]))

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

li = [x for x in range(l, l+n)]
t_i = 0
mi = 301
for i in range(len(li)):
  if mi >= abs(li[i]):
    mi = abs(li[i])
    t_i = i
n_sum = sum(li)
print(n_sum-li[t_i])

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

Solution (Python):
N, L = map(int, input().split())
import copy
j_sum = 0
absum = 0
j_sum_max = 0
ab = 0
for i in range(1, N+1):
    ab += L+i-1
for i in range(1, N+1):
    for j in range(1, N+1):
        if j != i:
            j_sum += L+j-1
    if i == 1:
        absum = abs(ab-j_sum)
        j_sum_max = copy.copy(j_sum)
        j_sum = 0
    else:
        if absum > abs(ab-j_sum):
            absum = abs(ab-j_sum)
            j_sum_max = copy.copy(j_sum)
            j_sum = 0
print(j_sum_max)

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

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

ls.remove(min(ls, key=abs))
print(sum(ls))

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

if l*(n+l) < 0:
  print(sum(range(l, n+l)))
elif l >= 0:
  print(sum(range(l, n+l))-l)
else:
  print(sum(range(l, n+l))-(n+l-1))

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


a = l
if l >= 0:
    total = 1/2 * n * (2 * a + (n - 1) * 1) - l
elif l < 0 and abs(n) > abs(l):
    total = 1/2 * n * (2 * a + (n - 1) * 1)
elif l < 0:
    total = 1/2 * n * (2 * a + (n - 1) * 1) - (l + n - 1)
print(int(total))

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

eaten = 'None'
if l >= 0:
  eaten = 0
elif (l+n-1) < 0:
  eaten = n-1

total = 0
for i in range(n):
  if i != eaten:
    total += l + i

print(total)

Solution (Python):
n,l =map(int, input().strip().split())
a=-1000000009
b=1000000009
ans=0
for i in range(0,n):
  ans+=l+i
  if(l+i<0):
    a=max(a,l+i)
  elif l+i>=0:
    b=min(b,l+i)
  

if(a==-1000000009):
  print(ans-b)
elif(b==1000000009):
  print(ans-a)
else:
  if(min(a*-1 , b))*-1 ==a:
  	print(ans-a)
  else:
  	print(ans-b)

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

answer = sum(list[1:])
print(answer)

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

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

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())
ans=(((2*l)+n-1)*n)/2

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

Solution (Python):
N, L = map(int, input().split())
a = sum(L + i for i in range(N))
min_ = None
for i in range(N):
    b = sum(L + j for j in range(N) if i != j)
    if min_ is None or abs(a - b) < abs(a - min_):
        min_ = b
print(min_)

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

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

    bbb = [abs(j) for j in aaa]

    print(sum(aaa)-aaa[bbb.index(min(bbb))])
    
resolve()

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

oishisa = [0] * n
min = l

for i in range(0, n):
    oishisa[i] = l + i
    if abs(oishisa[i]) < abs(min):
        min = oishisa[i]

sum = sum(oishisa) - min
print(sum)

Solution (Python):
N, L = map(int, input().split())
A = [L + i for i in range(N)]
d = 10000
min_i = -1
for i in range(N):
    if abs(A[i]) < d:
        min_i = i
        d = abs(A[i])

del A[min_i]

print(sum(A))

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

mngap=[1,abs(l+1-1)]
for i in range(2,n+1):
  if mngap[1]>abs(l+i-1):
    mngap=[i,abs(l+i-1)]

total=0
for i in range(1,n+1):
  total+=l+i-1
print(total-(l+mngap[0]-1))

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

pie=0
deli=[]
for i in range(1,n+1):
  pie+=l+i-1
  deli.append(l+i-1)
ans={}
ans2=[]
for j in range(1,n+1):
  deli2=copy.copy(deli)
  deli2.remove(l+j-1)
  ans[abs(sum(deli2)-pie)]=sum(deli2)
  ans2.append(abs(sum(deli2)-pie))
print(ans[min(ans2)])

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

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

print(sum(apple) - apple[ab.index(min(ab))])

Solution (Python):
n,l=map(int,input().split())
t=[l+i for i in range(n)]
t1=[abs(item) for item in t]
eat=min(t1)

def check_eat(L,X):
  for i in range(n):
    if abs(L[i])==X:
      break
  return i

print(sum(t)-t[check_eat(t,eat)])

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

mn = [float('inf'), -1]
for i in range(N):
	cur = L + i
	mn = min(mn, [abs(cur), cur])
print(azi - mn[1])

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

mn = float('inf')
for i in range(N):
	cur = L + i
	if mn > abs(cur):
		mn = abs(cur)
		ans = azi - cur

print(ans)

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

Solution (Python):


def main():
    N,L= map(int, input().split())
    ringos = []
    for i in range(N):
        ringos.append(L + i)
    
    full_ringo_pie = sum(ringos)
    min_taste_ringo = 101
    for ringo in ringos:
        if abs(min_taste_ringo) > abs(ringo):
            min_taste_ringo = ringo
    
    print(full_ringo_pie - min_taste_ringo)
        



if __name__ == "__main__":
    main()

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

ans=0
if L<1-N:
    ans=(N-1)*(L-1)+(N-1)*N//2
elif 0<=L:
    ans=(N-1)*(L-1)+N*(N+1)//2-1
else:
    ans=N*(L-1)+N*(N+1)//2

print(ans)

Solution (Python):

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

tast = [L+i for i in range(N)]
tast_abs = [t if t>0 else -t for t in tast]
tast_min_idx = sorted(range(len(tast_abs)), key = lambda x : tast_abs[x])
tast_min = tast[tast_min_idx[0]]

tast_sum = sum(tast) - tast_min

print(tast_sum)

Solution (Python):
n, l = map(int, input().split())
la = [l+i for i in range(n)]
ans = sum(la)
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()))

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

a = sum(aji)

ans = 0
diff = 10**9
for i in range(N):
    s = sum(aji) - aji[i]
    t = abs(a - s)
    if t < diff:
      diff = t
      ans = s

print(ans)

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

List = [0]*N
c = 10**6
for i in range(N):
    List[i] = L+i
    c = min(c, abs(L+i))
    
for i in range(N):
    if List[i] == c or List[i] == -c:
        List[i] = 0
        break
        
print(sum(List))