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

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())


dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')


ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)


(x >> i) & 1


dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

add = 1 
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)


li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    


org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)




    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


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

    

def main():
    
    tot = 0
    for i in range(1,N+1):
        tot+=L+i-1
    
    if L >= 0:
        tot -= L
    else:
        if N >= 1-L:
            pass
        else:
            tot -= L+N-1
    print(tot)
          
                
                
            
            
                

    
if __name__ == '__main__':
    main()

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

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

Solution (Python):

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

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

min_apple_abs = 10000
min_apple = 10000
for a in apples:
    if abs(a) < min_apple_abs:
        min_apple_abs = abs(a)
        min_apple = a

pie = sum(apples)
_pie = pie - min_apple

print(_pie)

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

ls = []

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

s = sum(ls)

if 0 in ls:
    print(s)
elif L < 0:
    print(s - ls[N - 1])
else:
    print(s - ls[0])

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

ans = 9999999999

for a in A:
  if abs(a) < abs(ans):
    ans = a
    
print(sum(A) - ans)

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

t = [0]*N

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

m = 100
for i in range(N):
    t[i] = L + i
    
    if abs(t[i]) < abs(m):
        m = t[i]
print(S-m)

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

Solution (Python):
n,l = map(int, input().split())
lst = list(range(l,l+n))
lst2 = []
for i in lst:
  if i > 0:
    lst2.append(i)
  else:
    lst2.append(-i)
x = sum(lst)-lst[lst2.index(min(lst2))]
print(x)

Solution (Python):
[N,L]=[int(_) for _ in input().split()]
A=[L+i for i in range(N)]
minabs=1000
for i in range(N):
    if abs(A[i])<minabs:
        eat=i
        minabs=abs(A[i])
A.pop(eat)
print(sum(A))

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

Solution (Python):

from collections import defaultdict
import math
import re

def main():
    N, L = map(int, input().split())
    total = sum(range(L, L+N))

    if L * (L + N - 1) < 0:
        print(total)
        return

    max_val = max([L, L + N - 1])
    max_abs_val = max_val if max_val > 0 else -max_val
    min_val = min([L, L + N - 1])
    min_abs_val = min_val if min_val > 0 else -min_val

    if max_abs_val < min_abs_val:
        print(total - max_val)
    else:
        print(total - min_val)


if __name__ == '__main__':
    main()

Solution (Python):



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

S = []
min_value = int(1e9)
for i in range(N):
    S.append(L+i)
    if abs(min_value) > abs(L+i):
        min_value = L + i
    
print(sum(S) - min_value)

Solution (Python):


n,l=map(int,input().split())
flg=0
ans=0
if l>=0:
    flg=1
else:
    if abs(l)<=n-1:
        flg=2

if flg ==0:
    for i in range(n-1):
        ans+=i+l
if flg==1:
    for i in range(1,n):
        ans+=i+l
if flg==2:
    for i in range(n):
        if i!=abs(l):
            ans+=i+l
print(ans)

Solution (Python):
n, l = list(map(int, input().split()))
ringo = [l+i for i in range(n)]
aji = 10**9
for j in ringo:
    if abs(j) <= aji:
        aji = abs(j)
        eat = j
print(sum(ringo)-eat)

Solution (Python):

import sys
import math
import numpy as np
import itertools


n,l = (int(i) for i in input().split())  

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

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

taste = [L + i for i in range(N)]
taste_abs = list(map(abs, taste))
min_abs_taste = min(taste_abs)
if min_abs_taste != 0 and L < 0:
  min_abs_taste *= -1

print(sum(taste)-min_abs_taste)

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

Solution (Python):
s =input().split()
N = int(s[0])
L = int(s[1])

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

MIN = 10000000000
num = 0
for i in range(N):
    if MIN > abs(apple[i]):
        MIN = abs(apple[i])
        num = i
apple.pop(num)

print(sum(apple))

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

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


ajisum = sum(aji)

res = 0
minres = 999999999
for x in aji:
    if minres > abs(x):
        minres = abs(x)
        res = ajisum - x

print(res)

Solution (Python):
a,b=input().split()
a=int(a)
b=int(b)
z=a+b-1
ans=0
for i in range(b,z+1):
    ans+=i
    
if b<=0 and z>=0:
    print(ans)
elif z>=0:
    print(ans-b)
elif b<=0:
    print(ans-z)

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

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

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

min = 1000000000000000
min_val = 0
for i in range(1, N + 1):
	if min > abs(L + i - 1):
		min = abs(L + i - 1)
		min_val = L + i - 1
		
print(int(N_taste - min_val))

Solution (Python):
N, L = [int(n) for n in input().split()]
S = -L
if S < 0:
    S = 0
elif S >= N:
    S = N - 1

A = 0
for i in range(N):
    if i != S:
        A += L + i

print(A)

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

print(ans)

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

nearZero = -10000
tgt = 0
ajiSum = 0

for i in range(1,N+1):
    aji = L + i - 1
    ajiSum += aji
    if abs(nearZero) > abs(aji):
        nearZero = aji
        tgt = i
        
print(ajiSum - nearZero)

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

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


taste_chosen_applepie = None
cur_diff = float('inf')

for i in range(1, N + 1):
    taste_apple = L + i - 1
    taste_applepie = sum_taste - taste_apple
    diff = abs(taste_applepie - sum_taste)
    
    if diff < cur_diff:
        
        cur_diff = diff
        taste_chosen_applepie = taste_applepie
print(taste_chosen_applepie)

Solution (Python):

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

se=[]

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


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

Solution (Python):
n, l = map(int, input().split())
aji = []
for i in range(n):
  aji.append(l+i)
eat = 1000
for i in aji:
  if abs(eat)>abs(i):
    eat=i
ans = sum([i for i in aji if i!=eat])
print(ans)

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

total = 0
min_abs = 114514
eat = 0
for i in range(1,N+1):
    taste = L+i-1
    total += taste
    if abs(taste) < min_abs:
        min_abs = abs(taste)
        eat = taste

total -= eat
print(total)

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

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

ts = [L + i for i in range(N)]
target = abs(ts[0])
target_i = 0
for i, t in enumerate(ts):
    if target > abs(t):
        target = abs(t)
        target_i = i

ts.pop(target_i)
print(sum(ts))

Solution (Python):
from sys import stdin


def main():
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [L + i - 1 for i in range(1, N + 1)]
    ham = [abs(x) for x in spam]
    if min(ham) in spam:
        print(sum(spam) - min(ham))
    else:
        print(sum(spam) + min(ham))


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

n, l = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
ll = range(l,l+n)
m = min(ll, key=abs)
ans = sum(ll) - m
print(ans)

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

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

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

a  = sum(val)
p = 10**9+7
for i in range(N):
    if abs(val[i]) < p :
        p = abs(val[i])
        q = val[i]
print(a-q)

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

mn = 100000000
ans = 0
for a in range(L, L+N):
    if abs(mn) > abs(a):
        mn = a
    ans += a
    
ans -= mn

print(ans)

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

Min = L
Max = L + N - 1
Pie =(2*L+N-1)*N//2

if Min * Max <= 0:
    print(Pie)
else:
    if Min > 0:
        print(Pie - Min)
    else:
        print(Pie - Max)

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

Solution (Python):
import numpy as np

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

apple = []

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

idx = np.abs(np.asarray(apple) - 0).argmin()
print(sum(apple) - apple[idx])

Solution (Python):
N, L = map(int, input().split())
T = 0
for i in range(N):
    T += L + i

ans = 0
mina = 10**9
for i in range(N):
    tmp = T - L - i
    if mina > abs(tmp - T):
        ans = tmp
        mina = abs(tmp - T)
print(ans)

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

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


main()

Solution (Python):
N, L = map(int, input().split())
S = sum([L + i for i in range(N)])
result_d = 10 ** 9
result = 0
for i in range(N):
    r = S - (L + i)
    if abs(S - r) < result_d:
        result_d = abs(S - r)
        result = r
print(result)

Solution (Python):
n, l = map(int, input().split())
ans = 1000000
s = sum(range(l, l + n))
for i in range(l, l + n):
    if ans > abs(s - (s - i)):
        ans = abs(s - (s - i))
        t = i
print(s - t)

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

loss = float('inf')
total = 0
for i in range(N):
    x = L + i
    total += x
    if abs(x) < abs(loss):
        loss = x
print(total - loss)

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

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

diff = 1e10
ans = 0
for i in range(N):
    pred = sum(t) - t[i]
    if abs(pred - real) <= diff:
        diff = abs(pred - real)
        ans = pred
        
print(ans)

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

A = [0]*N
sm = 0
m = -100
for i in range(N):
    A[i] = L+i
    sm+= L+i
    if L+i == 0:
        m = i 

if m >=0:
    print(sm)
elif L > 0:
    print(sm-A[0])
elif L+N-1 <0:
    print(sm-A[-1])

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

t=[]
sum=0
min=10**10
for i in range(n):
    sum+=l+i
    if abs(min)>abs(l+i):
        min=l+i

print(sum-min)

Solution (Python):
n,l=map(int,input().split())
apples = [l+i for i in range(n)]
sumap = sum(apples)
minap=10**9
diff=10**9
for ap in apples:
	if abs((sumap-ap)-sumap)<=diff:
		diff = abs((sumap-ap)-sumap)
		minap = ap
print(sumap-minap)

Solution (Python):
import sys

def main():
    N,L = map(int, input().split())
    apples = [L+i-1 for i in range(1,N+1)]
    mmin = sys.maxsize
    allsum = sum(apples)
    ans = 0
    for i in range(N):
        tmpsum = sum(apples[:i])
        if i != N-1:
            tmpsum += sum(apples[i+1:])
        tmp = abs(allsum-tmpsum)
        if tmp < mmin:
            mmin = tmp
            ans = tmpsum
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):


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

azi = 0
for l in range(L, L+N):
    azi += l

azi_l = L
azi_r = L+N-1

if ( azi_l * azi_r < 0):
    azi_min = 0
else:
    if (abs(azi_l) < abs(azi_r)):
        azi_min = azi_l
    else:
        azi_min = azi_r

azi = azi - azi_min
print(azi)

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

l = []
tmp = 1000000
ans_tmp = 0

for i in range(N):
    l.append(L+i)
    if(abs(l[i]) < tmp):
        tmp = abs(l[i])
        ans_tmp = l[i]



ans = sum(l) - ans_tmp
print(ans)

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

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

Solution (Python):
import numpy as np
N, L = map(int, input().split())
taste = [L+i for i in range(N)]
taste = np.array(taste)
print(sum(taste) - taste[np.argmin(np.abs(taste))])

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

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

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

eat = aji_abs.index(min(aji_abs))

ans = 0
for i in range(N):
    if i != eat:
        ans += aji[i]

print(ans)

Solution (Python):
def main():
     n,l=map(int,input().split())
     a=[l+i-1 for i in range(1,n+1)]
     a.sort(key=lambda x:abs(x) )
     print(sum(a[1:]))
     
if __name__=='__main__':
     main()

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

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

if l <= 0 and l + n > 0:
    eat = 0
else:
    if l < 0:
        eat = l + n - 1
    else:
        eat = l

print(s - eat)

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

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

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

print(sum)

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

apples = [L+i for i in range(N)]
apples_abs = list(map(abs,apples))
print(sum(apples)-apples[apples_abs.index(min(apples_abs))])

Solution (Python):
n,l=map(int,input().split())
ll=[]
lll=[]
mi=False
for i in range(1,n+1):
    ll.append(l+i-1)
    lll.append(abs(l+i-1))
    if (l+i-1)<0:
        mi=True
if 0 in ll:
    print(sum(ll))
elif mi:
    print(sum(ll)+min(lll))
else:
    print(sum(ll)-min(ll))

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

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

Solution (Python):
N, L = map(int, input().split())
apples = list(range(L, L+N))
s = sum(apples)
print(s - sorted(apples, key=lambda x:abs(x))[0])

Solution (Python):
from sys import exit
INF = 10**21
N, L= [int(n) for n in input().split()]
apples = [L +i - 1 for i in range(1,N+1)]
ans = INF
val = INF

for i in range(N):
    eat = apples[i]
    tmp = abs(eat)
    if tmp < val:
        ans = sum(apples) - eat
        val = tmp
print(ans)

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

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

s = sum(t)

a = sorted([ (abs(i), i) for i in t ], key=lambda b: b[0])[0][1]

print(s - a)

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

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

if L + N - 1 < 0:
    print(sums - (L + N - 1))

elif L > 0:
    print(sums - L)

else:
    print(sums)

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

Solution (Python):


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

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

if azi_list[0]<=0 and azi_list[-1]>=0:

    print(sum(azi_list))
elif abs(azi_list[0]) < abs(azi_list[-1]):

    print(sum(azi_list[1:]))
else:

    print(sum(azi_list[:-1]))

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

sc=l*(n+l-1)
eat=0

if sc>0:
    if l>0:
        eat=l
    else:
        eat=n+l-1

taste=0
for app in range(n):
    taste+=app+l

print(taste-eat)

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


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

eat_apple = aji[less_effect.index(min(less_effect))]

ans = sum(aji) - eat_apple

print(str(ans))

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

mini = 10000
eat = 0
for i in apple:
    if mini > abs(i):
        eat = i
        mini = abs(i)


print(sum(apple)-eat)

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

Solution (Python):
def getFlavour(eat):
    ret = 0
    for i in range(1, n + 1):
        if i != eat:
            ret += l + i - 1
    return ret

n, l = map(int, input().split())
orig = getFlavour(0)
flavour = diff = float('inf')
for eat in range(1, n + 1):
    curFlavour = getFlavour(eat)
    curDiff = abs(orig - curFlavour)
    if curDiff < diff:
        diff = curDiff
        flavour = curFlavour
print(flavour)

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

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

a = []
min_v = float('inf')
min_i = 0
for i in range(N):
    value = L + i
    if abs(value) < min_v:
        min_v = abs(value)
        min_i = i
    a.append(value)

newa = a[:min_i] + a[min_i+1:]

print(sum(newa))

Solution (Python):


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

a = list(range(l,l+n))
b = []
for i in range(len(a)):
    b.append(abs(a[i]))
c = b.index(min(b))

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

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


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


c = float("inf")
ans = 0
for i in range(1 , n+1):
  taste = l + i - 1
  a = sum - taste
  x = abs(sum - a)
  if x < c:
    c = x
    ans = a
print(ans)

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

Solution (Python):
from sys import stdin
import numpy as np

N, L = [int(x) for x in stdin.readline().rstrip().split()]

maxL = L+N-1
sumL = (L+maxL)*N//2
if L*maxL<=0:
    print(sumL)
else:
    if L>0:
        print(sumL-L)
    else:
        print(sumL-maxL)

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

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

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

Solution (Python):
n,l = map(int,input().split())
ls = [x + l - 1 for x in range(1,n+1)]
c = 10000000000;check = 1
for i in range(len(ls)):
    if c > abs(ls[i]):
        c = abs(ls[i])
        if ls[i] < 0:check = -1
        else:check = 1
print(sum(ls) - c*check)

Solution (Python):


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

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

m = 1e10
for i in range(1, N + 1):
    a = L + i - 1
    b = total - a
    if abs(total - b) < m:
        m = abs(total - b)
        ans = b

print(ans)

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

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

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

print(int(ans))

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

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

if L <= 0 and 0<=L+N-1:     apple = 0
else:
    if abs(L) > abs(L+N-1): apple = L+N-1
    else:   apple = L

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

print(int(ans-apple))

Solution (Python):

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





l = list(range(L,L+N))
ans = sum(l)
if l[-1] < 0:
    ans -= l[-1]
elif l[0] > 0:
    ans -= l[0]
print(ans)

Solution (Python):
N, L = list(map(int, input().split()))
a = [(abs(L+i-1), L+i-1) for i in range(1, N+1)]
b = [L+i-1 for i in range(1, N+1)]
a = sorted(a, key=lambda x: x[0])

print(sum(b)-sorted(a)[0][1])

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

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, l = li()

apples = [l+i for i in range(n)]
minabs = float("inf")

for ai in apples:
    if abs(ai) < abs(minabs):
        minabs = ai

print(sum(apples) - minabs)

Solution (Python):
def solve():
    n, l = map(int, input().split())
    R = []
    for i in range(1, n + 1):
        t = l + i - 1
        R.append([abs(t), t])
    print(sum(list(zip(*R))[1]) - min(R)[1])
solve()

Solution (Python):
import numpy as np

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

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


tmp = [L+i-1 for i in range(1, N+1) if i != del_i ]

out = sum(tmp)
print(out)

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

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

x = [L + i for i in range(N)]
total = sum(x)
d = 1000
for v in x:
    if abs(d) > abs(v):
        d = v
print(total - d)

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

s = list()
score = 0
for i in range(1, N+1):
    c = i + M - 1
    score += c
    s.append((abs(c), c))

m = min(s)
print(score-m[1])

Solution (Python):
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,L = map(int,input().split())
a  =[0]*(N)
b = [0]*(N)
for i in range(N):
    a[i] = L+i
    b[i] = abs(a[i])
s = sum(a)
c = inf
index = 0
for i in range(N):
    if b[i]<c:
        c = b[i]
        index = i
print(s-a[index])

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

apples = list(range(l, l + n))

smallest = min(apples)
biggest = max(apples)

if smallest >= 0:
    print(sum(apples) - smallest)
    exit()

if biggest <= 0:
    print(sum(apples) - biggest)
    exit()

print(sum(apples))

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

azi = [l + i - 1 for i in range(1, n + 1)]
azi.sort(key=lambda x: abs(x))
s = 0
for a in azi[1:]:
    s += a
print(s)

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

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

minabs = abs(apples[0])
minabsidx = 0
for i, a in enumerate(apples):
    if abs(a) < minabs:
        minabs = abs(a)
        minabsidx = i

print(sum(apples) - apples[minabsidx])

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

Solution (Python):
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret
    
def mod_modify(a,mod):
    return (a+mod)%mod
    
def main():
    ans =0
    N,L = ints_raw()
    if L<0:
        if L+N-1 >=0:
            return sum([L+i for i in range(N)])
        else:
            return sum([L+i for i in range(N-1)])
    for i in range(1,N):
        ans+=(L+i)
    return ans

print(main())

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

ts = [L+i for i in range(N)]
sumT = sum(ts)

if 0 in ts:
    print(sumT)
else:
    if ts[0] > 0:
        print(sumT-ts[0])
    else:
        print(sumT-ts[-1])

Solution (Python):
N, L =map(int,input().split())
c = 400
k = 400
wa = 0
for i in range(N):
	a = L + i
	wa += a
	if abs(a) < c:
		c = abs(a)
		k = a
print(wa-k)

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

A = [L + i for i in range(N)]
j = 10 ** 10
t = sum(A)
ans = 0
for i in range(N):
  k = abs(t - (t - A[i]))
  if k <= j:
    j = k
    ans = t - A[i]

print(ans)

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

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

absmin = 99999999
flg = -1
for i in range(1, N+1):
    apples.append(L + i - 1)
    if absmin > abs(L + i - 1):
        absmin = min(absmin, abs(L + i - 1))
        flg = ((L + i - 1) > 0)
if flg:
    print(sum(apples)-absmin)
else:
    print(sum(apples)+absmin)

Solution (Python):
import sys

def main():
    
    n, l = [int(i) for i in sys.stdin.readline().strip().split()]
    

    mi = l
    ma = l + n - 1

    if mi <= 0 <= ma:
        return (mi + ma) * n // 2
    elif ma < 0:
        return (mi + ma-1) * (n-1) // 2
    elif mi > 0:
        return (mi+1 + ma) * (n-1) // 2

print(main())