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())
total = 0
if l < 0 and (l + n - 1) > 0:
        for i in range(n):
                total += l + i
elif l < 0 and (l + n - 1) <= 0:
        for i in range(n):
                total += l + i
        total -= l + n - 1
elif l >= 0:
        for i in range(n):
                total += l + i
        total -= l
print(total)

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

a = []
flag = False
for i in range(n):
	if l + i == 0:
		flag = True
	a.append(l+i)

if flag == True:
	print(sum(a))
elif a[0] < 0:
	 print(sum(a[:-1]))
else:
	print(sum(a[1:]))

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
 
n,l = map(int,input().split())

ans = 0

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

hiku = 0

if l > 0:
    hiku = l
elif l+n-1 < 0:
    hiku = l+n-1
else:
    hiku = 0

print(sum(l_a)-hiku)

Solution (Python):
[N,L] = list(map(int,input().split()))
T = [0]*N
for i in range(N):
    T[i] = L+(i+1)-1
T_abs = T[::]
for i in range(N):
    T_abs[i] = abs(T_abs[i])
apple_remove = min(T_abs)
if sum(T) >= 0:
    print(sum(T)-apple_remove)
else:
    print(sum(T) + apple_remove)

Solution (Python):
import numpy as np

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

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

ans = np.sum(a)

k = np.abs(a)
m = np.where(k == np.amin(k))

ans = ans - a[m]
ans = int(ans)

print(ans)

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

arr.remove(min)

print("{}".format(sum(arr)))

Solution (Python):
N,L=(int(x) for x in input().split())
def val(i):
    return L+i

S = 0
for i in range(N):
    S+=val(i)

ans=0
err=max(abs(val(0)),abs(val(N-1)),abs(S))*2
for i in range(N):
    tmp = S - val(i)
    tmp_err = abs(tmp-S)
    if tmp_err < err:
        ans = tmp
        err = tmp_err
print(ans)

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

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

min_taste = l
max_taste = l + n - 1

ans = (min_taste + max_taste) * n // 2
if max_taste * min_taste > 0:
  if min_taste > 0:
    ans -= min_taste
  else:
    ans -= max_taste

print(ans)

Solution (Python):
def f(N, L):
    if L > 0:
        return (N - 1) * (N + L * 2) // 2
    elif 1 - L > N:
        return (N - 1) * (N + L * 2 - 2) // 2
    else:
        return N * (N - 1 + 2 * L) // 2


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

Solution (Python):
inputs = [int(s) for s in input().split()]
n = inputs[0]
l = inputs[1]

if l >= 0:
    taste = int(n*l + n*(n+1)/2 - n - l)
elif -l >= n:
    taste = int(n*l + n*(n+1)/2 - n - (l + n - 1))
else:
    taste = int(n*l + n*(n+1)/2 - n)

print(taste)

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

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

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

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

taste_n = sum(a_s)
a_min = min(a_s)
a_max = max(a_s)

if l + n - 1 < 0:
  ans = taste_n - a_max
elif l > 0:
  ans = taste_n - a_min
else:
  ans = taste_n
  
print(ans)

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

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

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

print(sum(azi) - azi[azi_abs.index(min(azi_abs))])

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

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

N=int(input[0])
L=int(input[1])

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

min_abs=200
for j in aji_list:
    if abs(j)<abs(min_abs):
        min_abs=j

output=sum(aji_list)-min_abs
print(output)

Solution (Python):



if __name__ == "__main__":
    N, L = map(int, input().split())
    apples = []
    for i in range(1,N+1):
        apples.append(L + i - 1)

    applesabs = [abs(i) for i in apples]
    index = applesabs.index(min(applesabs))

    del apples[index]

    print(sum(apples))

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

apple = [l+i for i in range(n)]
a_ = 10**9
idx = apple.index(min(apple, key=abs))
ans = sum(apple) - apple[idx]

print(ans)

Solution (Python):

import sys;
import string;
sys.setrecursionlimit(20000) 

import copy
import itertools

from functools import lru_cache


PPP = 1000000007






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

























import re

def doit():
  m = 0

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




try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)

Solution (Python):
import numpy as np

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



ab = np.abs(np.array(hoge))


amin = ab.argmin()
del hoge[amin]
print(sum(hoge))

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

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

sum_ans=0
eat_ans=10000
flag=10000
for i in range(N):
	sum_ans+=L+i
	eat_ans=min(abs(eat_ans),abs(L+i))
	if eat_ans==abs(L+i):
		if L+i<0:
			flag=-1
		if L+i==0:
			flag=0
		if L+i>0:
			flag=1

print(sum_ans-eat_ans*flag)

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

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






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

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

INF = 10 ** 10

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


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

if 0 in taste:
    print(sum(taste))
    exit()

if abs(taste[0]) < abs(taste[-1]):
    print(sum(taste[1:]))
else:
    print(sum(taste[:N-1]))

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

ans = 0
apple = L
for i in range(2, N + 1):
    x = L + i - 1
    if abs(x) < abs(apple):
        ans += apple
        apple = x
    else:
        ans += x

print(ans)

Solution (Python):
N,L = map(int,input().split())
N_ = [i for i in range(1,N+1)]
L_ = [L+i-1 for i in range(1,N+1)]
t = 1000000
ans = 0
sum_L = sum(L_)
for i in range(N):
  target = sum_L - L_[i] 
  if abs(target - sum_L) < t:
    ans = target
    t = abs(target - sum_L)
print(ans)

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

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

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

print(s)

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

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

A = list(range(L, L+N))
print(sum(A) - A[min(enumerate(A), key = lambda x:abs(x[1]))[0]])

Solution (Python):
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

N,L = na()
a=[]
b = 10000000000

for i in range(L,L+N):
    a.append(i)
    b = i if min(abs(b),abs(i)) == abs(i) else b

print(sum(a)-b)

Solution (Python):
N, L = [int(x) for x in input().split(' ')]
f = [x + L for x in range(N)]
a = [abs(x) for x in f]
i = a.index(min(a))
f.pop(i)
print(sum(f))

Solution (Python):
n,l = map(int, input().split())
L = []
for i in range(n):
    L.append(i+l)
S = sum(L)
e = 10**9+7
ans = 0
for i in range(n):
    A = L.copy()
    A.pop(i)
    s = sum(A)
    d = abs(S-s)
    if d < e:
        e = d
        ans = s
        
print(ans)

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

Solution (Python):

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

apples = [l + i for i in range(n)]
total = int(n * (l - 1) + n * (n + 1) / 2)

absmin = float('inf')
for val in apples:
    if abs(val) < abs(absmin):
        absmin = val

print(total - absmin)

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

Solution (Python):
n, l = map(int, input().split())
apple = []
for i in range(n):
    apple.append(l+i)
apple_sum = sum(apple)
abs_list = []
ans_list = []
for i in range(n):
    abs_list.append(abs(sum(apple[:i])+sum(apple[i+1:])-apple_sum))
    ans_list.append(sum(apple[:i])+sum(apple[i+1:])-apple_sum)
if min(abs_list) in ans_list:
    print(min(abs_list)+apple_sum)
else:
    print(-min(abs_list)+apple_sum)

Solution (Python):
N,L = map(int, input().split())
ajilist = []
minaji = 100000
for i in range(N):
    aji = L+i
    if abs(minaji) > abs(aji):
        minaji = aji
    ajilist.append(aji)
answer = sum(ajilist)-minaji
print(answer)

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

for i in range(N):
        li.append(L+i)
        sa.append(abs(L+i))

ans = sum(li) - li[sa.index(min(sa))]
print(ans)

Solution (Python):

n, l = list(map(int, input().split()))
t = [l + i - 1 for i in range(1, n + 1)]
ta = [abs(i) for i in t]
minarg = ta.index(min(ta))
t.pop(minarg)
print(sum(t))

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

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

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

print(S-de)

Solution (Python):
n,l=[int(i) for i in input().split()]
app=[0]*(n)
for i in range(n):
    app[i]=l+i
m=1000000000000000000
num=0
for i,j in enumerate(app):
    if m>j and j>=0:
        m=j
        num=i
if m==1000000000000000000:
    m,num=max(app),app.index(max(app))
print(sum(app[0:num]+app[num+1:]))

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


abc()

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

L_list = [] * N

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

tmp = float('inf')
ans = 0
for i in range(N):
    diff = sum(L_list) - L_list[i]
    if tmp > abs(sum(L_list) - diff):
        tmp = abs(sum(L_list) - diff)
        ans = diff

print(ans)

Solution (Python):

from sys import stdin
import sys
import numpy as np

n, l = stdin.readline().rstrip().split()
n, l = int(n), int(l)


array = np.arange(l, l+n)
abs_min = 300
index = 300

for i in range(n):
    if abs_min > np.abs(array[i]):
        abs_min = np.abs(array[i])
        index = i


ans = np.sum(array) - array[index]
print(ans)

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

aji_sort = sorted(aji)
min_aji = -10000
for j in range(N):
    if aji_sort[j] >= 0:
        min_aji = aji_sort[j]
        break

if min_aji == -10000:
    min_aji = aji_sort[-1]

print(sum(aji)-min_aji)

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

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

temp1=list(map(lambda x2:abs(x2),x))
temp2=min(temp1)

I=temp1.index(temp2)

x.remove(x[I])

print(sum(x))

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

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

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

Solution (Python):
def main():
    N, L = map(int, input().split())
    
    apples = [L+i-1 for i in range(N+1)]
    taste = 0
    eaten = False
    for a in apples[1:]:
        if (not eaten) and a >= 0:
            eaten = True
            continue
        taste += a
    if not eaten:
        taste -= a
    print(taste)


main()

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

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

Solution (Python):
N,L=map(int,input().split())
list1=[]
list2=[]
for i in range(1,N+1):
    list1.append(N*L+(N-1)*N/2-L+1-i)
    list2.append(abs(N*L+N*(N-1)/2-((N-1)*(L+N/2)+1-i)))
print(int(list1[list2.index(min(list2))]))

Solution (Python):
n,l = map(int,input().split())
taste = [l+i for i in range(n)]
taste = sorted(taste,key=lambda x: abs(x))
taste.pop(0)
print(sum(taste))

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

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

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

Solution (Python):

import numpy as np
N,L = map(int,input().split())
ls = list(range(N))
ls = [i+L for i in ls]
ls = np.array(ls)
idx = np.argsort(np.abs(ls))[1:]

print (sum(ls[idx]))

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

Solution (Python):
N, L = map(int, input().split())
eat_one = 101+N
ideal_pie = 0
for i in range(N):
    taste = L+i
    ideal_pie += taste
    eat_one = taste if abs(eat_one) > abs(taste) else eat_one
print(ideal_pie - eat_one)

Solution (Python):

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

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

pi = sum(aji)
ans = 0
diff = []
for i in range(N):
  if pi - aji[i] == pi:
    print(pi)
    exit()
  diff.append(pi - aji[i])
if pi > 0:
  print(max(diff))
else:
  print(min(diff))

Solution (Python):
import numpy as np

n, l = [int(i) for i in input().split()]
tastes = []
for i in range(n):
    tastes.append(i + l)
if 0 in tastes:
    print(sum(tastes))
elif np.abs(tastes[0]) > np.abs(tastes[-1]):
    print(sum(tastes[:-1]))
elif np.abs(tastes[0]) == np.abs(tastes[-1]):
    print(sum(tastes))
else:
    print(sum(tastes[1:]))

Solution (Python):
N, L = [int(nl) for nl in input().split()]
T = []
for n in range(N):
  T.append(L + n)
T_abs = [abs(t) for t in T]
mn_T_abs = min(T_abs)
idx_mn_T_abs = T_abs.index(mn_T_abs)
T.pop(idx_mn_T_abs)
ans = sum(T)
print(ans)

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

aji = 0

min = 999

for i in range(N):
    tmp = L + i
    aji += tmp
    if abs(tmp) < abs(min):
        min = tmp

print(aji-min)

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

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

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

s = sum(li)

res = 1000
ans = 0

for i in li:
    t = s-i
    if res > abs(s-t):
        ans = i
        res = abs(s-t)
    
print(sum(li)-ans)

Solution (Python):
N, L = map(int, input().split())
taste = [(L + i) for i in range(N)]
eat = 500
ans = 0

for i in range(N):
    if abs(taste[i]) < abs(eat):
        eat = taste[i]

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

Solution (Python):
N,L=map(int,input().split())
ans=0
temp=10**9
A=sum([L+i for i in range(N)])
for i in range(N):
    B=0
    for j in range(N):
        if j!=i:
            B+=L+j
    if temp>=abs(A-B):
        ans=B
        temp=abs(A-B)
print(ans)

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

apples = [L+i-1 for i in range(1, N+1)]
abs_apples = [abs(L+i-1) for i in range(1, N+1)]
try:
    apples.remove(min(abs_apples))
except ValueError:
    apples.remove(-1 * min(abs_apples))

result = sum(apples)
print(result)

Solution (Python):
import sys
input = sys.stdin.readline
N, L = map(int, input().split())
tastes = [None] * N
abs_tastes = [None] * N

for i in range(1, N + 1):
  tastes[i - 1] = L + i - 1
  abs_tastes[i - 1] = abs(tastes[i - 1])

print(sum(tastes) - tastes[abs_tastes.index(min(abs_tastes))])

Solution (Python):
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,L = IL()

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

if L < 0:
  if num > 0:
    print(ans)
  else:
    print(ans-num)
else:
  print(ans-L)

Solution (Python):
n, l = map(int, input().split())
totalTaste = 0
tastes = []
minAbs = 9999
minIdx = 9999

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

for i in range(n):
    temp = abs(tastes[i])
    if temp < minAbs:
        minAbs = temp
        minIdx = i




print(totalTaste - tastes[minIdx])

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

Solution (Python):
import numpy as np

N, L = map(int, input().split())
apples = np.array([L]*N)
apples = apples + np.arange(0, N)

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

Solution (Python):
n,l = map(int,input().split())
m = 400
e = []
ii = -1
tmp = 400
for i in range(1,n+1):
    e.append(l + i - 1)
for i,v in enumerate(e):
    if m > abs(v):
        ii = i
        m = abs(v)
        tmp = v
print(sum(e) - tmp)

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

Solution (Python):
n,l=map(int,input().split())
s=l*n+((1+n)*n)//2-n
lst=[]
for i in range(n):
	lst.append(l+i)
sorted_lst=sorted(lst,key=abs)
A = s - sorted_lst[0]
print(A)

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

k = l + n - 1

sum_pp = l * n + n * (n - 1) / 2
sum_p = int(sum_pp)

if l >= 0:
    ans = sum_p - l
elif k<= 0:
    ans = sum_p - k
else:
    ans = sum_p

print(ans)

Solution (Python):










import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    N, L = map(int, sys.stdin.readline().split())
    origin = 0
    for i in range(N):
        origin += (L + i)
    diffmin = mod

    comp_min = mod
    for i in range(N):
        comp = 0
        for j in range(N):
            if j == i:
                continue
            comp += (L + j)
        if abs(origin - comp) < diffmin:
            diffmin = abs(origin - comp)
            comp_min = comp
    print(comp_min)

Solution (Python):

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

abs_list = list()
sum_score = 0

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

    abs_list.append(abs(score))
    sum_score += score

low = abs_list.index(min(abs_list))

print(sum_score - (L + (low + 1) - 1))

Solution (Python):
from math import copysign
n, l = map(int, input().split())
eat=200
ans=0
for i in range(l, l+n):
  ans+=i
  eat=int(min(abs(eat), abs(i))*copysign(1,i))
ans-=eat
print(ans)

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

if l > 0:
    print(sum(range(l+1,l+n)))
elif l <= 0 and n > abs(l):
    ans = 0
    for i in range(l,l+n):
        ans += i
    print(ans)
else:
    
    print(sum(range(l,l+n-1)))

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

Solution (Python):
n,l = map(int,input().split())
ringos = list(range(l,l+n))
minmin = 1000
for ringo in ringos:
    if abs(ringo)<abs(minmin):
        minmin = ringo
ringos.remove(minmin)
print(sum(ringos))

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

tmp = np.array([L+i for i in range(N)])
tmp2 = np.argmin(np.abs(tmp))
print(sum(tmp) - tmp[tmp2])

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

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

for i in range(l,n+l):
    m = min(abs(m),abs(i))
    if i < 0:
        m *= -1
else:
    print(sum(range(l,n+l))-m)

Solution (Python):



def main():
    n, l = map(int, input().split())
    taste = [l + i for i in range(n)]
    total = sum(taste)
    value_min = min(taste)
    value_max = max(taste)

    if value_min > 0:
        print(total - value_min)
    elif 0 in taste:
        print(total)
    elif value_max < 0:
        print(total - value_max)


if __name__ == '__main__':
    main()

Solution (Python):
N,L =  list(map(int,input().split(" ")))
m = 100000
su = 0
apples = []
for i in range(N):
    apples.append(L+i)
apples.sort(key=lambda x:abs(x))

print(sum(apples[1:]))

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

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

Solution (Python):
n,l = map(int,input().split())
aji = [l+i-1 for i in range(1,n+1)]
reuslt = []
sum_aji = sum(aji)
for x in range(n):
    reuslt.append((abs(aji[x]),sum_aji-aji[x]))
reuslt = sorted(reuslt,key=lambda x:x[0])
print(reuslt[0][1])

Solution (Python):


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

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

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

Solution (Python):

def sumof(begin, end):
    l = [i for i in range(begin, end + 1)]
    return sum(l)

N, L = [int(x) for x in input().split(' ')]
min_aji = L
max_aji = L + N - 1


if 0 <= min_aji:
    aji = sumof(min_aji + 1, max_aji)
elif 0 < max_aji:
    aji = sumof(min_aji, max_aji)
else:
    aji = sumof(min_aji, max_aji - 1)

print(aji)

Solution (Python):
N, L = map(int, input().split())
scores = [abs(L + n) for n in range(N)]
idx = scores.index(min(scores))
print(sum([L + n for n in range(N) if n != idx]))

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

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

for i in range(n):
    lists.append(l)
    l += 1

    c = 0
if 0 in lists:
    lists.remove(0)
    print(sum(lists))
else:
    for j in lists:
        if j > -1:
            c += 1           
    if c == len(lists):
        lists.remove(min(lists))
        print(sum(lists))
    else:
        lists.remove(max(lists))
        print(sum(lists))

Solution (Python):
from bisect import bisect

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

apple = [i for i in range(l,l+n)]
eat_idx = bisect(apple,0)
if eat_idx == n:
	eat_idx -= 1


if abs(apple[eat_idx]) > abs(apple[eat_idx-1]):
	eat = apple[eat_idx-1]
else:
	eat = apple[eat_idx]
print(sum(apple)-eat)

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

tas = []

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

tas.sort(key=lambda x:x[1])

ans = 0

for i,abs in tas[1:]:
    ans += i

print(ans)

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

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

Solution (Python):
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left

class Solution:
    def main(self):
        N, L = map(int, input().split())
        
        if L <= 0 < L+N:
            print(sum(list(range(L, L+N))))
        elif L + N <= 0:
            print(sum(list(range(L, L+N-1))))
        else:
            print(sum(list(range(L+1, L + N))))


if __name__ == '__main__':
    Solution().main()

Solution (Python):
n,m=map(int,input().split())
c=0
absc=10000
for i in range(1,n+1):
  if absc>abs(m+i-1):
    absc=abs(m+i-1)
    c1=m+i-1
  c+=m+i-1
print(c-c1)

Solution (Python):
N,L=[int(x) for x in input().split()]
pi=0
mini=1000
for i in range(N):
  pi+=L+i
  if abs(L+i) < abs(mini):
    mini=L+i
  
print(pi-mini)

Solution (Python):
n,l = (int(i) for i in input().split())
eating = float('inf')
apples = [i+l-1 for i in range(1,n+1)]
if 0 in apples:
    print(sum(apples))
elif sum(apples) < 0:
    print(sum(apples)-apples[-1])
else:
    print(sum(apples)-apples[0])

Solution (Python):
import sys, itertools, collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n, l = lmi()
a = [(abs(l + i), i) for i in range(n)]
i = sorted(a)[0][1]


print(sum([l+i for i in range(n)]) - (l+i))

Solution (Python):

n, l = map(int, input().split())
data = list(range(l, l + n))
if 0 in data:
    print(sum(data))
elif data[0] > 0:
    print(sum(data) - data[0])
else:
    print(sum(data) - data[-1])

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

A = [i+L for i in range(N)]
A = np.array(A)
if L >= 0:                                                                                                                                                                                                  
    print(np.sum(A[1:]))                                                                                                                                                                                    
                                                                                                                                                                                                            
elif L < 0:                                                                                                                                                                                                 
    if N + L - 1 <=0:                                                                                                                                                                                       
        print(np.sum(A[:-1]))                                                                                                                                                                               
    else:                                                                                                                                                                                                   
        print(np.sum(A[:]))

Solution (Python):
N, L = list(map(int, input().split()))
aji = []
min_abs = 10000
min_i = -1
for i in range(N):
    ab = abs(L+i)
    if ab<min_abs:
        min_i = i
        min_abs = ab
    aji.append(L+i)
print(sum([a for i, a in enumerate(aji) if i!=min_i]))

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

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

if 0 in a:
    print(sum(a))

elif a[0] > 0:
    print(sum(a) - a[0])

else:
    print(sum(a) - a[-1])

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

cnt = 10**9
ans = 0
for i in range(n):
    a = s-ls[i]
    if abs(s-a)<cnt:
        cnt = abs(s-a)
        ans = a

print(ans)

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

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

b2 = sorted(b, key=abs)

print(sum(b2[1:]))

Solution (Python):
n, l = map(int, input().split())
tastes = [l+i-1 for i in range(1, n+1)]
mintaste = 1000000
index = 0
for i in range(n):
    if abs(tastes[i]) < mintaste:
        mintaste = abs(tastes[i])
        index = i
tastes[index] = 0
print(sum(tastes))

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

for i in range(n):
  list.append(l+i)
tmp = 9999
for i in range(n):
  ans.append(sum(list)-list[i])
for i in range(n):
  if abs(sum(list) - ans[i]) < tmp:
    tmp = abs(sum(list) - ans[i])
    answer = ans[i]
print(answer)

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

org = 0
ab_taste = 100
for n in range(N):
    taste = L + n +1 -1
    org += taste

    if abs(ab_taste) > abs(taste):
        ab_taste = taste

ret = org - ab_taste

print(ret)

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

    taste = [L+i-1 for i in range(1, N+1)]
    abs_taste = [abs(x) for x in taste]
    delete_index = abs_taste.index(min(abs_taste))
    taste.pop(delete_index)
    print(sum(taste))

if __name__ == '__main__':
    main()

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

taste_abs = [abs(L+i-1) for i in range(1,N+1)]
taste = [L+i-1 for i in range(1,N+1)]
pie_all = sum(taste)

dec = min(taste_abs)
idx = taste_abs.index(dec)

print(pie_all-taste[idx])

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

apples = []

min_apple = 99999999
min_i = -1
for i, apple in enumerate(range(l, l+n)):
    apples.append(apple)
    if min_apple > abs(apple):
        min_apple = abs(apple)
        min_i = i

res = sum(apples) - apples[min_i]
print(res)

Solution (Python):
n,l=map(int,input().split())
li1=[0]*n
li2=[0]*n
cnt=0
for i in range(n):
    li1[i]=l+i
    li2[i]=abs(li1[i])
    cnt+=li1[i]

li1.sort()
li2.sort()

c=0
for i in range(n):
    if li1[i]==li2[0]:
        c+=1

if c>=1:
    print(cnt-li2[0])
else:
    print(cnt+li2[0])