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())
tar=0
for i in range(N):
    tar += L + i
ANS = []
for i in range(N):
    ANS.append(tar - (L + i))
ans = 1000000
tmp2 = 1000000
for a in ANS:
    tmp = abs(tar - a)
    if tmp < tmp2:
        ans = a
        tmp2 = tmp
print(ans)

Solution (Python):
import numpy as np

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

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

X = np.arange(L, L+N)
X_sum = abs(sum - (sum-X))
print(int(sum - X[X_sum == min(X_sum)]))

Solution (Python):

N, L =map(int,input().split())
apple =  [i+1 for i in range(N)]
apple_taste = [L+i-1 for i in apple]
delete = min(apple_taste)
if delete < 0:
    abs_apple_taste = [abs(L+i-1) for i in apple]
    delete = -min(abs_apple_taste)
apple_taste.remove(delete)
print(sum(apple_taste))

Solution (Python):



def min_abs(ts):
    if ts[0] <= 0 and ts[-1] >= 0:
        return 0
    if ts[-1] <= 0:
        return ts[-1]
    else:
        return ts[0]


def solv(n, l1):
    ts = list(range(l1, l1+n))
    eat = min_abs(ts)
    return sum(ts) - eat


if __name__ == '__main__':

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

    ans = solv(n, l1)

    print(ans)

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

total = ((m)+(m+n-1))*n/2

min_abs = 101
min = 0
for i in range(n):
  now = abs(m + i)
  if now < min_abs:
    min_abs = now
    min = m + i

if total > 0:
    if min > 0:
        min_total = int(total - min)
    else:
        min_total = int(total + min)
else:
    if min > 0:
        min_total = int(total + min)
    else:
        min_total = int(total - min)
    

print(min_total)

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

T = []

for i in range(N):
    T.insert(i, L+i-1+1)

for i in range(101):
    if T.count(i) != 0:
        T.remove(i)
        break
    elif T.count(-i) != 0:
        T.remove(-i)
        break

print(sum(T))

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

if L > 0:
	for i in range(N):
		if i > 0:
			S += L + i
elif (L+N-1) < 0:
	for i in range(N):
		if i < N-1:
			S += L + i
else:
	for i in range(N):
		S += L + i

print(S)

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

absaji = []
for i in range(N):
    absaji.append(abs(aji[i]))


minaji = min(absaji)

if sum(aji) < 0:
    sumaji = sum(aji) + minaji
else:
    sumaji = sum(aji) - minaji
print(sumaji)

Solution (Python):
import numpy as np

def main():

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

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
n,l = map(int,input().split())
s = list(range(1,n+1))
azi = []
ab = 100
for i in range(n):
    azi.append(l + i)
    if abs(ab) > abs(l + i):
        ab = l + i

print(sum(azi)-ab)

Solution (Python):
import numpy as np

def main():
    nl = list(map(int, input().split(" ")))
    apple = list(range(nl[1], nl[0]+nl[1]))
    mi = np.array(list(map(abs, apple)))
    index = np.argsort(mi)

    s = 0
    for i in index[1:]:
        s += apple[i]
    print(s)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
N, L = map(int, input().split())
apples = []
m = 999999999
for i in range(1, N + 1):
    t = L + i - 1
    apples.append(t)
    if abs(m) > abs(t):
        m = t
apples.remove(m)
print(sum(apples))

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

p=l.index(min(l))
li.pop(p)
print(sum(li))

Solution (Python):
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))


N,L=acinput()


aji=L+np.arange(1,N+1)-1
sm=np.sum(aji)

arg=np.argmin(np.abs(aji))
if aji[arg]>=0:
        print(sm-aji[arg])
else:
        print(sm-aji[arg])

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

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

Solution (Python):
N,L = map(int,input().split())
A=[L+i for i in range(N)]
sum = N*(L-1)+(int)(N*(N+1)/2)

eat = 0
tmpabs =101
for i in range(N):
    if abs(A[i])<tmpabs:
        tmpabs =abs(A[i])
        eat = i

print(sum-A[eat])

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

if 0 in taste:
    ans = sum(taste)
else:
    if min(taste) > 0:
        ans = sum(taste) - min(taste)
    else:
        ans = sum(taste) - max(taste)

print(ans)

Solution (Python):
import sys
import numpy as np

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


LL = np.arange(L,L+N)

m = abs(LL[0])

for i in range(N):
    if abs(m) > abs(LL[i]):
        m = LL[i]

print(np.sum(LL)-m)

Solution (Python):
N, L = list(map(int, input().split()))
maxscore = N*(L-1) + N*(N+1)/2
minscore = float("inf")
for i in range(1, N+1):
    if minscore > abs(L - 1 + i):
        minscore = abs(L-1+i)
        keisanyou = L-1+i
print(int(maxscore - keisanyou))

Solution (Python):

N,L = map(int,input().split())
f = 0
k = 0
j = []
for i in range(1,N+1):
    f += L+i-1
for i in range(1,N+1):
    k = L+i-1
    n = f-k
    p = abs(f-n)
    j.append(p)
if f >0:
    print(int(f-min(j)))
else:
    print(int(f+min(j)))

Solution (Python):


import sys

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    tokens = lines[0].split(" ")
    n = int(tokens[0])
    l = int(tokens[1])

    return (n, l)


def solve(n, l):

    min_abs = abs(l)
    removed = l
    sum = 0
    for i in range(l, l+n):
        sum = sum + i
        if abs(i) < min_abs:
            min_abs = abs(i)
            removed = i

    return sum - removed


def main():
    

    print("%s" % solve(*parse_input()))



if __name__ == '__main__':

    main()

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

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

tmp = float("inf")
minn = 0
for a in t:
    if abs(a) < tmp:
        minn = a
        tmp = abs(a)
print(sum(t) - minn)

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

Solution (Python):
import sys
MAX_INT = sys.maxsize

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

s = 0
eat = MAX_INT
for i in range(N):
    taste = L+i
    if abs(eat) > abs(taste):
        eat = taste
    s += taste

print(s-eat)

Solution (Python):
import copy
N,L = map(int,input().split())
flaver = []
for i in range(1,N + 1):
    flaver.append(L + i - 1)
flaver_sum = sum(flaver)
for i in range(len(flaver)):
    c_flaver = copy.deepcopy(flaver)
    del c_flaver[i]
    if i == 0:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
    if abs(flaver_sum - sum(c_flaver)) < tmp_min:
        tmp_min = abs(flaver_sum - sum(c_flaver))
        index = i
del flaver[index]
print(sum(flaver))

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

taist = [0] * n
abs_taist = [0] * n
for ii in range(n):
    taist[ii] = (ii + 1) + l - 1
    abs_taist[ii] = abs(taist[ii])

index = abs_taist.index(min(abs_taist))
taist.remove(taist[index])
print(sum(taist))

Solution (Python):
N, L = [int(s) for s in input().split()]
apples = [i+L for i in range(N)]
abstaste = [abs(i) for i in apples]
if min(apples) == min(abstaste):
  ans = sum(apples) - min(abstaste)
else:
  ans = sum(apples) + min(abstaste)
print(ans)

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

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

absol = []
for i in range(len(summer)):
    absol.append(abs(sum(summer) - sum(summer[0:i]) - sum(summer[i+1:len(summer)])))

s = absol.index(min(absol))

print(sum(summer) - summer[s])

Solution (Python):
import copy

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

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



plan = sum(taste)

diff = []
ans = []

for i in range(0, N):
    apples = copy.deepcopy(taste)
    apples.pop(i)
    diff.append(abs(plan - sum(apples)))
    ans.append(sum(apples))
    




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

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

print(int(taste))

Solution (Python):
import math
import numpy as np
import re


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


def main():
    N, L = inputs()
    apple = range(L, N + L)
    apple = np.array(apple)
    apple = np.delete(apple, np.argmin(np.abs(apple)))
    return sum(apple)


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

Solution (Python):
import numpy as np

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


if 0 in L:
  print(sum(L))
else:
  if min(L) > 0:
    print(sum(L)-min(L))
  else:
    print(sum(L)-max(L))

Solution (Python):
lis=list(map(int,input().split()))
taste=[]
for i in range(lis[0]):
    taste.append(lis[1]+i)
if 0 in taste:
    ans=sum(taste)
else:
    big=min(abs(taste[0]),abs(taste[-1]))
    if big==abs(taste[0]):
        ans=sum(taste)-taste[0]
    else:
        ans=sum(taste)-taste[-1]
print(ans)

Solution (Python):
N,L = map(int, input().split())
A = []
mn = 10**9
for i in range(N):
    A.append(L+i)
sum_A = sum(A)

for i in range(N):
    aji = sum(A[:i]) + sum(A[i+1:])
    tmp = abs(sum_A - aji)
    if tmp < mn:
        mn = tmp
        ans = aji
print(ans)

Solution (Python):

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


if __name__ == "__main__":
    main()

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

if L > 0:
  print(sum(range(L+1, L+N)))
elif N + L >0:
  print(sum(range(L, L+N)))
else:
  print(sum(range(L, L+N-1)))

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

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

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

if L < 0 and 0 not in A:
  A.remove(A[-1])
  print(sum(A))
elif 0 in A:
  print(sum(A))
elif L >= 0:
  A.remove(A[0])
  print(sum(A))

Solution (Python):
import numpy as np

a = input().split(" ")
N = int(a[0])
L = int(a[1])

apple = [L+i for i in range(N)]
N_tast = sum(apple)
sub = [abs(N_tast-(sum(apple)-apple[i])) for i in range(N)]

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

Solution (Python):
from sys import stdin

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

    apple = [L + i for i in range(N)]
    taste = sum(apple)
    n = float('inf')
    for a in apple:
        if n > abs(a):
            eat = a
            n = abs(a)
    print(taste - eat)

input = lambda: stdin.readline()
main()

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

saisho=100000000

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

aji=[l+i for i in range(n)]
absaji=[abs(l+i) for i in range(n)]
absaji.sort()
if absaji[0] in aji:
  print(all-absaji[0])
else:
  print(all+absaji[0])

Solution (Python):



n=input().rstrip().split(" ")
n[0]=int(n[0])
n[1]=int(n[1])
if n[1]>=0:
    terget=0
elif n[1]+n[0]<=0:
    terget=n[0]-1
else:
    terget=-(n[1])
ans=n[1]*(n[0]-1)

ans=ans+int(n[0]*(n[0]-1)/2)

print(ans-terget)

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

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

s = 1 + l - 1
e = n + l - 1
if e < 0:
    ans = ans - e
elif s > 0:
    ans = ans - s

print(ans)

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

Solution (Python):
import sys
from pprint import pprint

def solve(n, l):
    n_min = 100000
    v_min = n_min
    pre_n_min = 100000
    sum_n = 0
    for i in range(1, n+1):
        n_min = min(n_min, abs(l + i - 1))
        if pre_n_min != n_min:
            pre_n_min = n_min
            v_min = l + i - 1

        
        sum_n += (l + i - 1)

    return sum_n - v_min


if __name__ == '__main__':

    n, l = map(int, sys.stdin.readline().strip().split(" "))
    print solve(n, l)

Solution (Python):
n,l = map(int,input().split())
t = range(l,l+n)
if 0 in t:
    a = sum(t)
elif min(t) > 0:
    a = sum(t) - min(t)
else:
    a = sum(t) - max(t)
print(a)

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

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



tmp=list[0]

rem=0

for i in range(1,N):
  if(abs(tmp)<abs(list[i])):
    rem= tmp
    break
  else:
    tmp= list[i]
  if(i== N-1):
    rem= list[i]

print(sum(list)- rem)

Solution (Python):

NL = list(map(int, input().split()))

N = NL[0]
L = NL[1]

tasteSUM = 0
tasteABS = 2000

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

    tasteSUM+=taste

    if abs(taste) < abs(tasteABS):
        tasteABS = taste


tasteSUM = tasteSUM - tasteABS

print(tasteSUM)

Solution (Python):

N, L = map(int,input().split())
lb = L
rb = L+N-1
if lb <= 0 <= rb: 
    pass
elif rb < 0:
    rb -= 1
elif 0 < lb:
    lb += 1
ans = sum(range(lb,rb + 1))
print(ans)

Solution (Python):
def main():
    N, L = [int(n) for n in input().split()]
    arr = [L + (i+1) - 1 for i in range(N)]
    s = sum(arr)
    arr = sorted(arr, key=lambda x: abs(x))
    del arr[0]
    print(sum(arr))

main()

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

taste = 0
judge = True
for i in range(n):
	taste_i = l + (i + 1) - 1 
	if taste_i == 0:
		judge = False
	taste += l + (i + 1) - 1

if judge:
	if taste_i < 0:
		taste = taste - taste_i
	else:
		taste = taste - (l + 1 - 1)

print(taste)

Solution (Python):
n,l=map(int,input().split())
nl=n+l
ls=[]
for i in range(l,nl):
    ls.append(i)
mn=500
for j in ls:
    if abs(j)<abs(mn):
        mn=j
    else:
        continue
ls.remove(mn)
ans=sum(ls)
print(ans)

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

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


min_aji = 10**9+7
ind = 0
for i in range(n):
    if min_aji > abs(aji[i]):
        ind = i
        min_aji = abs(aji[i])

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

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

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

if L >= 0:
  ans = int(0.5*(N-1)*(2*(L+1) + N-2))
elif (L + N - 1 ) >= 0:
  ans = int(0.5*(N)*(2*(L) + N-1))
else:
  ans = int(0.5*(N-1)*(2*(L) + N-2))
  
print(ans)

Solution (Python):
n,l = map(int, input().split())
listA = []
for i in range(n):
    listA.append(l+i)
b = 201
c = -1
for j in range(n):
    if abs(listA[j])<b:
        b=abs(listA[j])
        c=j
listA.pop(c)
print(sum(listA))

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

i = 1 - L
if i < 1:
    i = 1
elif i > N:
    i = N
print(int(N * (L - 1) + N * (N + 1) / 2 - (L + i - 1)))

Solution (Python):
import copy

N, L = map(int, input().split())
aji = [0]*N
for i in range(1, N+1):
    aji[i-1] = L+i-1
aji_sum = sum(aji)
ansl = [0]*N
for i in range(N):
    aji_tmp = copy.copy(aji)
    aji_tmp.pop(i)
    ansl[i] = abs(aji_sum - sum(aji_tmp))
ans_ind = ansl.index(min(ansl))
aji.pop(ans_ind)
print(sum(aji))

Solution (Python):
import sys

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

if __name__ == "__main__":
    n, l = map(int, input().split())

    flavors = [ l + i - 1 for i in range(1, n+1)]
    flavor_abs = [ abs(l + i - 1) for i in range(1, n+1)]
    eat = min(flavor_abs)
    del flavors[flavor_abs.index(eat)]

    print(sum(flavors))

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

a = range(l, l+n)
b = []
for i in a:
  b.append(abs(i))
  
if 0 in a:
  print(sum(a))
elif max(a) < 0:
  print(sum(a)-max(a))
else:
  print(sum(a)-min(b))

Solution (Python):
n,l = map(int,input().split())
alst = [i + l for i in range(n)]
lst2 = [(i+l)**2 for i in range(n)]
del alst[lst2.index(min(lst2))]
  
print(sum(alst))

Solution (Python):
n , l = map(int, input().split())
l_list = [l + i for i in range(n)]
min_l = min(l_list)
max_l = max(l_list)
if max_l <= 0:
    ans = sum(l_list) - max_l
elif min_l >= 0:
    ans = sum(l_list) - min_l
elif (max_l > 0) & (min_l < 0):
    ans = sum(l_list)
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, L = LI()
    per = 0
    for i in range(N):
        per += i + L
    
    cur_min = inf
    ans = inf
    for i in range(N):
        c = i + L
        if abs(c) < cur_min:
            ans = c
            cur_min = abs(c)
    print(per - ans)
main()

Solution (Python):
import sys

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

tastes = []
bestAppleIndex = -1
bestAppleTaste = 9999999999

for i in range(0,n):

    tastes.append( l + i + 1 - 1 )

    if abs(bestAppleTaste) > abs(tastes[i]) :
        bestAppleTaste = tastes[i]
        bestAppleIndex = i

tastes[ bestAppleIndex ] = 0

print(sum(tastes))

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

appletaste = []

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

appletaste.insert(0, 0)

applesum = sum(appletaste)
abslog = 9999
eat = 0


for apple in range(1, N + 1):
    pie = applesum - appletaste[apple]
    if abs(applesum - pie) < abslog:
        abslog = abs(applesum - pie)
        eat = apple

print(applesum - appletaste[eat])

Solution (Python):
def proc(begin_val, end_val, **keyargs):
  if begin_val * end_val > 0:
    return sum(list(range(begin_val, end_val + 1))) - min(abs(begin_val), abs(end_val)) * end_val // abs(end_val)
  
  if begin_val * end_val <= 0:
    return sum(list(range(begin_val, end_val + 1)))


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

begin_val = L
end_val = L + N - 1

print(proc(**locals()))

Solution (Python):
N, L = list(map(int, input().split()))
la = [abs(L+i) for i in range(N)]
min_l = la.index(min(la))
res = 0
for i in range(N):
  if i != min_l:
    res += L+i
print (res)

Solution (Python):
parents = list(map(int,input().split(' ')))
L = parents[1]
if L>0:
    not_add = 0
elif abs(L) > parents[0]-1:
    not_add = parents[0]-1
else:
    not_add = abs(L)
sum = 0
for i in range(parents[0]):
    if not i == not_add:
        sum += (i+L)

print(sum)

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

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

absout = []
for i in outputlist:
  absout.append(abs(i))

a = absout.index(min(absout))

output = sum(outputlist[:a] + outputlist[a+1:])

print(output)

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


if L>=1:
	a = L
elif L<=(-1*N):
	a = L+N-1
else:
	a = 0

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

print(ans)

Solution (Python):
n,l= list(map(int,input().split()))
ans = 0
taste_list = []
for i in range(n):
    taste_list.append(l+i)
    ans += (l+i)
if 0 in taste_list:
    print(ans)
else:
    mini = min(taste_list)
    if mini > 0:
        print(ans-mini)
    else:
        mini2 = taste_list[-1]
        print(ans-mini2)

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

ans = 0
min = min([abs(x + l) for x in range(n)])
if l + n <= 0:
    min = min * -1
for i in range(n):
    ans += l + i

print(ans - min)

Solution (Python):
import sys


def input():
    return sys.stdin.readline()[:-1]


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

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


if __name__ == "__main__":
    main()

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

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

bl = [abs(x) for x in al]
al.pop(bl.index(min(bl)))
print(sum(al))

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

else:
    if 0 <= n + l - 1:
        print(sum(li))
    else:
        print(sum(li) + abs(n + l - 1))

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

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

List = []

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





ans = 0
if(List[-1] < 0):
    ans = int(sum(List)) - List[-1]
else:
    if(List[0] <= 0):
        ans = int(sum(List))
    else:
        ans = int(sum(List)) - List[0]

print(ans)

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

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

if L <= 0:
    if N > -L:
        print(sum)
    else:
        print(sum - (L + N-1))
else:
    print(sum - L)

Solution (Python):


N, L = map(int, input().split())
app_list = []
sum1, sum2, num, ans, min_ans = 0, 0, 0, 0, 1000000000000000000

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

for j in range(N):
    sum1 = sum(app_list)
    sum2 = sum(app_list) - app_list[j]
    ans = abs(sum1 - sum2)
    if ans < min_ans:
        num = j
        min_ans = ans

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

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


if __name__=="__main__": main()

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

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

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

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

print(sum(l) - absn)

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

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


if L >= 0:
    print(taste_n - L)

elif L < 0 and abs(L) < N:
    print(taste_n)

else:
    print(taste_n - (L + N - 1))

Solution (Python):
n,l = map(int,input().split())
aji = []
for i in range(n):
    aji.append(l+i)
sum_aji = sum(aji)
min_diff = float("inf")
ans = 0
for s in aji:
    if abs(s) < min_diff:
        min_diff = abs(s)
        ans = sum_aji-s
print(ans)

Solution (Python):
lm = []
N,L = input().split()
N = int(N)
L = int(L)
for x in range(1,N+1):
    lm.append((abs(L+x-1),L+x-1))
lm.sort()
lm = lm[1::]
s = 0
for u in range(len(lm)):
    s = s + lm[u][1]
print('{}'.format(s))

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

sum_N = int(N*((N+1)/2 + L - 1))

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

Solution (Python):
def resolve():
    N, L = map(int, input().split())
    pie = sorted([i + L for i in range(N)])
    if 0 in pie:
        print(sum(pie))
    elif sum(pie) < 0:
        print(sum(pie[:-1]))
    else:
        print(sum(pie[1:]))

resolve()

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

Sum_a = 0
Sum_b = 0
Min = 1000000

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

for i in range(N):
  Sum_b = Sum_a - (L+i)
  if abs(Sum_a - Sum_b) < Min:
    Min = abs(Sum_a - Sum_b)
    Min_b = Sum_b
    
print(Min_b)

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

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

total = int(N*(2*L+N-1)/2)
if L >= 0:
    answer = total - L
elif L + N - 1 <= 0:
    answer = total - (L + N - 1)
else:
    answer = total

print (answer)

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

tp = []
tm = []
for i in range(1, N+1):
    t = L+i-1
    if t >= 0:
        tp.append(t)
    else:
        tm.append(t)

if len(tp) == 0:
    tm.remove(max(tm))        
elif len(tm) == 0:
    tp.remove(min(tp))
else:
    mtp = min(tp)
    mtm = abs(max(tm))    
    if mtp <= mtm :
        tp.remove(mtp)
    else:
        tm.remove(mtm)

sum = 0
for i in tp:
    sum += i
for i in tm:
    sum += i

print(sum)

Solution (Python):
n, l = input().split()
n,l = int(n),int(l)
taste = []
for i in range(n):
    taste.append(l+i)
min_diff = 100000
for i in range(n):
    total_n = sum(taste) - taste[i]
    diff = abs(sum(taste)-total_n)
    if diff < min_diff:
        min_diff = diff
        min_total = total_n
print(min_total)

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

out=0

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

print(int(out))

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

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

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

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


main()

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

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

Solution (Python):
N, L = map(int, input().split())
lst = [i + L for i in range(N)]
y = sum(lst)
a1 = 10**9
a2 = 10**9
for x in lst:
    if abs(x) < a1:
        a1 = abs(x)
        a2 = x
print(y - a2)

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

N,L = map(int,input().split())
s=0;m=100000
for i in range(1,N+1):
  
  s += L+i-1
  m = m if abs(L+i-1) >= m else abs(L+i-1)

print(s-m if s > 0 else s+m)

Solution (Python):
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n):
  s+=i
print(s+(n-1)*l-num)

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

valsum = l * n
for i in range(n):
    valsum += i

if 0 < minval:
  valsum -= minval
elif maxval < 0:
  valsum -= maxval

print(valsum)

Solution (Python):
N,L=map(int,input().split())
pie=0
li=[]
for i in range(N):
    pie+=L+i
    li.append(abs(L+i))

if pie<0:
    print(pie+min(li))
else:
    print(pie-min(li))

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

aji = []
for a in L:
    aji.append(sum(L)-a)
aji2 = []
for i in range(len(L)):
    aji2.append(abs(aji[i]-sum(L)))

m = 10**7
ans = 1
for i in range(len(L)):
    if m > abs(aji[i]-sum(L)):
        m = min(abs(aji[i]- sum(L)), m)
        ans = aji[i]

print(ans)

Solution (Python):
n, l = map(int, input().split())
apple = [l + i for i in range(n)]
piesum = sum(apple)
different = float("inf")
for i in range(n):
    if different > abs(apple[i]):
        different = abs(apple[i])
        ans = piesum - apple[i]
print(ans)

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

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

minabs = min([abs(a) for a in apples])

if minabs in apples:
    print(sum(apples) - minabs)
else:
    print(sum(apples) + minabs)

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

a = list(range(L,n+L))
tmp = 500
for i in a:
	if abs(tmp) > abs(i):
		tmp = i

print(sum(a)-tmp)

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

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

if min(aji) > 0:
  aji.remove(min(aji))
  print(sum(aji))
elif max(aji) < 0:
  aji.remove(max(aji))
  print(sum(aji))
else:
  print(sum(aji))

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

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

print(taste-ab)