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())
li = []
ind = 0
for i in range(1,n+1):
    li.append(i+l-1)

mi = abs(li[0])
for i in li:
    if abs(i) < mi:
        mi = abs(i)
        ind = li.index(i)

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

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

ringo = []
for i in range(l,l+n):
    ringo.append(i)
ringo.sort(key=int)
if 0 in ringo:
    print(sum(ringo))
else:
    if ringo[0] > 0:
        ringo.pop(0)
    else:
        ringo.pop(-1)
    print(sum(ringo))

Solution (Python):
n, l = map(int, input().split())
t = []
t2 = []
for i in range(n):
    taste = l+(i+1)-1
    t.append(taste)
    t2.append(taste**2)
oa = t[t2.index(min(t2))]
ans = sum(t) - oa
print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    N, L = MI()
    tot = 0
    for i in range(1, N+1):
        tot = tot + L + i - 1
    diff = INF
    ans = 0
    for i in range(1, N+1):
        tmp = tot - L - i + 1
        if abs(tot - tmp) < diff:
            diff = abs(tot - tmp)
            ans = tmp
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
n,l=map(int,input().split())
list_x=[l+x-1 for x in range(1,n+1)]
applepai=sum(list_x)
list_dif=[]
list_sum=[]
for i in range(len(list_x)):
    tmp=list_x.pop(i)
    list_dif.append(abs(applepai-sum(list_x)))
    list_sum.append(sum(list_x))
    list_x.insert(i,tmp)
indx=list_dif.index(min(list_dif))
ans=list_sum[indx]
print(ans)

Solution (Python):
N,L=map(int,input().split())
all = sum([L+i-1 for i in range(1, N+1)])
anss = []
for j in range(1, N+1):
    tmp = sum([L+i-1 for i in range(1, N+1) if i != j])
    anss.append((abs(all-tmp), tmp))
anss.sort()
print(anss[0][1])

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

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

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

abs_apple = list(map(abs, apple))

minimum_idx = abs_apple.index(min(abs_apple))

print(sum(apple) - apple[minimum_idx])

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

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

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

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

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

Solution (Python):
n,l = map(int,input().split())
q = []
p = []
ans = 0
for i in range(1,n+1):
  m = l+i-1
  q.append(m)
  ans += m
for i in range(n):
    p.append(abs(q[i]))

print(ans - q[p.index(min(p))])

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

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

m=10**9
idx=1
for i in range(1,n+1):
  if abs(l+i-1)<m:
    m=abs(l+i-1)
    idx=i
        
print(a-(l+idx-1))

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

Solution (Python):
n,l = map(int,input().split())
ans = l 
k = 0
sum = 0
for i in range(1,n):
    if abs(ans) > abs(l + i):
        ans = l + i
        k = i
for i in range(n):
    if i != k:
        sum += l + i
print(sum)

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

for i in range(n):
    L = l + i
    L_abs = abs(L)
    List1.append(L)
    List2.append(L_abs)

if min(List2) in List1:
    List1.remove(min(List2))
elif -min(List2) in List1:
    List1.remove(-min(List2))

print(sum(List1))

Solution (Python):


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

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

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

if T[-1] >= 0:
    m = min((i for i in T if i >= 0))
else:
    m = T[-1]

print(sum(T)-m)

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

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

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

if T[-1] >= 0:
    m = min((i for i in T if i >= 0))
else:
    m = T[-1]

print(sum(T)-m)

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

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

eat = sorted(apple, key=lambda x: abs(x))
print(sum(apple)-eat[0])

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

if sum(azi) < 0:
    print(sum(azi) + abs(min(diff)))
else:  
    print(sum(azi) - min(diff))

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

apple = []
diff = 1001001001
minus = False
for i in range(1, n+1):
    apple.append(l+i-1)
    if abs(l+i-1) < diff:
        diff = abs(l+i-1)
        if l+i-1 < 0:
            minus = True
        else:
            minus = False

if minus:
    print(sum(apple) + diff)
else:
    print(sum(apple) - diff)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, L = mapint()
apples = [L+i for i in range(N)]
pos_apples = [abs(a) for a in apples]
apples.pop(pos_apples.index(min(pos_apples)))
print(sum(apples))

Solution (Python):
N,L = map(int,input().split())
a = N*L+(N*(N-1))//2
d = 1000
ans = -1000
for i in range(L,L+N):
    b = a-i
    if abs(a-b)<d:
        d = abs(a-b)
        ans = b
print(ans)

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[-1])
else:
    print(sum(a)-a[0])

Solution (Python):
n,l=map(int,input().split())
sum=0
m=1e9
for i in range (n):
    sum+=l+i
    if abs(m)>abs(l+i):m=l+i
print(sum-m)

Solution (Python):
n, l = map(int, input().split())
S = n*l + (n * (n + 1)) // 2 - n
pd = S + 1
for x in range(1, n + 1):
    d = - l - x + 1
    if pd > abs(d):
        ans = S + d
    pd = d

print(ans)

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

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

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

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

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

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

basic = abs(sum(aji_list))
min_diff = 9999999 
for i in aji_list:
    diff = abs(basic - abs(basic - abs(i)))
    min_diff = min(min_diff, diff)

for i in aji_list:
    if abs(basic - abs(basic - abs(i))) == min_diff:
        if basic == sum(aji_list):
            print(basic - abs(i))
        else:
            print(-1*(basic - abs(i)))
        break

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

for i in flavor:
    S += i

for i in range(N):
    flavorabs.append(abs(flavor[i]))

a = min(flavorabs)
print(S - flavor[flavorabs.index(a)])

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

aji = [l+i for i in range(n)]
ans = None
sa=10**10
for i in range(n):
    sa_tmp=abs(aji[i])
    if sa>sa_tmp:
        sa=sa_tmp
        ans=sum(aji)-aji[i]
print(ans)

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

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

apples = []
ans = 300
for i in range(1, n + 1):
    taste = i + l - 1
    apples.append(taste)
    if abs(taste) < abs(ans):
        ans = taste

apples.remove(ans)
print(sum(apples))

Solution (Python):
N, L = map(int, input().split())
A = []
for i in range(N):
  A.append(L+i)
i = 0
ans = False
while ans == False:
    x, y = abs(i), -abs(i)
    for k in A:
      if k == x or k == y:
        ans = True
        A.remove(k)
    i += 1
print(sum(A))

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, L = LI()

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

    print(ans)

if __name__ == '__main__':
    resolve()

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

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

if A[0] < 0:
    if A[-1] < 0:
        print(sum(A) - max(A))
    else:
        print(sum(A))
else:
    print(sum(A) - min(A))

Solution (Python):








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







azi2=[]
azi=[L+i for i in range(N)]
for i in azi:
    azi2.append(abs(i))
if 0 in azi:
    print(sum(azi))
else:
    mi=azi2.index(min(azi2))
    del azi[mi]
    print(sum(azi))

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

total = N * (L - 1) + N * (N + 1) / 2
lowest = 10 ** 10
for i in range(1, N + 1):
    y = L + i - 1
    lowest = min(lowest, abs(y))
print(int(total) - lowest) if total >= 0 else print(int(total) + lowest)

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

Solution (Python):
N, L = map(int,input().split())
def f(i):
	return L+i-1
def eat(bad):
	return sum([f(i) for i in range(1,N+1) if i!=bad])
best = 10**18
best_val = -1
for i in range(1,N+1):
	x = abs(eat(i)-eat(-1))
	if x < best:
		best = x
		best_val = eat(i)
print(best_val)

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

taste=[l+i-1 for i in range(1,n+1)]
dif=10**10
for i in taste:
    if dif>abs(i):
        ans=sum(taste)-i
        dif=abs(i)
print(ans)

Solution (Python):


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

each_taste = []
for x in range(1,n+1):
  each_taste.append(l+x-1)
  
if min(each_taste) >= 0:
  print(sum(each_taste[1:]))
  
elif max(each_taste) >= 0:
  print(sum(each_taste))

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

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

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

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

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


print(s - eat)

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


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

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

print(s - (L+l.index(min(l))))

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

print(s - (L+l.index(min(l))))

Solution (Python):
apple_num, taste = map(int, input().split())
total = 0
table = []
total_ans = 0
manual = 100000000
ans = 0
for i in range(apple_num):
    table.append(i+1)

for j in range(apple_num):
    table[j] = taste + j
    total += taste + j

for k in range(apple_num):
    if manual > abs(table[k]):
        manual = abs(table[k])
        ans = k
for l in range(apple_num):
    if l == ans:
        continue
    else:
        total_ans += table[l]
print(total_ans)

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

y = sum(A)
B = sorted(A)

if L <= 0 and L + N - 1 >= 0:
    print(y)
elif L >= 0:
    y -= B[0]
    print(y)
elif L + N - 1 < 0:
    y -= B[N - 1]
    print(y)

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

Solution (Python):
n, l = map(int, input().split())
s = n*(l-1) + n*(n+1)/2
c = abs(s)
j = 1
for i in range(n):
  t = s - (l+i)
  T = abs(s-t)
  if T < c:
    c = T
    j = i
ans = s -(l+j)
print(int(ans))

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

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

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

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

Solution (Python):



N,L=map(int,input().split())
minabs=10**9
apples=[]
for i in range (N):
    t=L+i
    apples.append(t)
    if abs(t)<abs(minabs):
        minabs=t

full=sum(apples)

print(full-minabs)

Solution (Python):
N, L = map(int, input().split())
l = []
idx = (10**6, -1)

for i in range(1, N + 1):
    l.append(L + i - 1)
    if abs(L + i - 1) < idx[0]:
        idx = (abs(L + i - 1), i)
ans = 0
for i in range(1, N + 1):
    if i != idx[1]:
        ans += l[i - 1]
print(ans)

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

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

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

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

ans = 0
for i in range(1,len(A)):
    ans += A[i][1]
print(ans)

Solution (Python):
import sys
N, L = map(int, input().split())
tastes = [ L+x for x in range(N) ] 

if 0 in tastes:
    print(sum(tastes))
    sys.exit(0)
    

if L<0:
    absmin = max(tastes)
    print(sum(tastes)-absmin)
elif L>0:
    absmin = min(tastes)
    print(sum(tastes)-absmin)

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

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

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

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

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

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

Solution (Python):
n,l=map(int,input().split())
l1=list(int(l)+i-1 for i in range(1,n+1))
n1=sum(l1)
ans=min(l1,key=abs)

print(n1-(ans))

Solution (Python):
n, l = map(int, input().split())
apple_list = [l + i for i in range(n)]
abs_min = min([abs(apple) for apple in apple_list])
apple_list.remove(abs_min if abs_min in apple_list else -abs_min)
print(sum(apple_list))

Solution (Python):
lst = input()
lst = lst.split()


for i in range(len(lst)):
    lst[i]= int(lst[i])
N = lst[0]
L = lst[1]
q = L
l = 0
lste = [abs(L)]
tlst = []
for i in range(2,N+1):
    t = L+i-1
    q += t
    tlst.append(t)
    t = abs(t)
    lste.append(t)


slst = sorted(lste)
l = slst[0]
if tlst.count(-l) > 0:
    print(q+l)
else:
    print(q-l)

Solution (Python):
details = input().split()
N = int(details[0])
L = int(details[1])
counter = 0
new_list = []
number = 0
checker = True
for i in range(N):
    counter += L
    new_list.append(L+i)
    if number == 0 and ((L + i) >= 0) and checker == True:
        number += L + i
        checker = False
    elif number == 0 and (i == N-1) and checker == True:
        number += L + i
        checker = False
print(sum(new_list) - number)

Solution (Python):

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

N = lst[0]
L = lst[1]

apple_flavours = []

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


abs_apple_flavours = []

for apple in apple_flavours:
    abs_apple_flavours.append(abs(apple))

min_val = min(abs_apple_flavours)

index = abs_apple_flavours.index(min_val)

total_flavour = 0

for apple in apple_flavours:
    total_flavour += apple

print(total_flavour - apple_flavours[index])

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

nin=10**6
for i in range(N):
    if abs(L+i)<nin:
        nin=abs(L+i)
        nn=L+i

ans=N*(L-1)+N*(N+1)*0.5-(nn)

print(int(ans))

Solution (Python):
n, l =list(map(int, input().split()))
arr = []
arr2 = []
for k in range(1, n+1):
  arr.append(abs(l + k - 1))
for k in range(1, n+1):
  arr2.append(l + k - 1)
arr2.pop(arr.index(min(arr)))
print(sum(arr2))

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

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

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

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


ab_list=[abs(i) for i in l_list]
num=ab_list.index(min(ab_list))

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

Solution (Python):
n,l=map(int,input().split())
aji = []
m = 100000
flg = 0
for i in range(n):
  aji.append((l+i))
  if abs(aji[i]) <= m:
    m = abs(aji[i])
    if aji[i] <= 0:
      flg = 1
    else:
      flg = 0
print(sum(aji)- m if flg==0 else sum(aji) +m)

Solution (Python):
r=input().split()
N=int(r[0])
L=int(r[1])
ans=0
ans_li=[]
for i in range(N):
    ans+=L+(i+1)-1
    ans_li.append(L+(i+1)-1)
if 0 in ans_li:
    print(ans)
elif max(ans_li)>0:
    print(ans-min(ans_li))
else:
    print(ans-max(ans_li))

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

li = [x+l for x in range(n)]
if 0 in li:
    print(sum(li))
elif min(li) > 0:
    print(sum(li)-min(li))
else:print(sum(li)-max(li))

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

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

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

Solution (Python):



N, L = map(int, input().split())
A = 0
a = 1000
for i in range(1,N+1):
    x = L + i - 1
    A += x
    if abs(x) < a:
        a = abs(x)
if A >= 0:
    print(A-a)
else:
    print(A+a)

Solution (Python):
n,a = map(int,input().split())
x = [a+i-1+1 for i in range(n)]
y = sorted(x, key=lambda i: abs(i))
del y[0]
print(sum(y))

Solution (Python):
import numpy as np

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

taste = np.arange(1, N+1) + L -1
min_ind = np.argmin(np.abs(taste))

mask_1 = np.ones(N, dtype=bool)
mask_1[min_ind] = False

ans = np.sum(taste[mask_1])

print(ans)

Solution (Python):
n,a = map(int,input().split())
c = 0
d = 1000
for i in range(1,n+1):
    c+=a+i-1
    d = min(abs(a+i-1),d)
if a<0 and a-n <= 0:
    print(c+d)
else:
    print(c-d)

Solution (Python):
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def sum_applepie(list1, l):
    r = [i+l-1 for i in list1]
    return sum(r)


def main():
    n, l = Input()
    applepie = sum_applepie(list(range(1, n+1)), l)
    list2 = []
    for i in range(1, n+1):
        temp = []
        for j in range(1, n+1):
            if i == j:continue
            temp.append(j)
        k = sum_applepie(temp, l)
        list2.append((abs(applepie - k), k))
    print(sorted(list2, key=lambda x:x[0])[0][1])


main()

Solution (Python):
n,l=map(int,input().split())
apple=[l+i for i in range(n)]
s=0
while True:
    if s in apple:
        apple.remove(s)
        break
    elif abs(s) in apple:
        apple.remove(abs(s))
        break
    s-=1
print(sum(apple))

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, l = MI()
    ans = 0
    temp = l
    for i in range(n):
        ans += l+i
        if abs(temp) > abs(l+i):
            temp = l+i
        
    ans -= temp
    print(ans)

if __name__ == '__main__':
    main()

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

Solution (Python):
def ApplePie():
    N, L = input().split()
    N = int(N)
    L = int(L)
    flavors = []
    for i in range(N):
        flavors.append(L+i)
    
    if 0 in flavors:
        flavors.remove(0)
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
    elif L >= 0:
        del flavors[0]
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
    else:
        del flavors[-1]
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
        
ApplePie()

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
def main():
    lines = input()

    n, l = list(map(int, lines[0].split()))

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

    if l >= 0:
        print(Sum_ - l)
        return
    else:
        if n+l-1 <= 0:
            print(Sum_ - (l+n-1))
        else:
            print(Sum_)


main()

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

for i in range(1, n + 1):
    apples.append(l + i - 1)
    if abs(l + i - 1) < abs(min_val):
        min_val = (l + i - 1)
apples.remove(min_val)

print(sum(apples))

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

    total = 0
    min_taste = 10 ** 12

    for i in range(1, N + 1):
        taste = L + i - 1
        if abs(taste) < min_taste:
            min_taste = abs(taste)
            min_taste_index = i

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

    print(ans)


if __name__ == "__main__":
    main()

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

    total = 0
    min_taste = 10 ** 12

    for i in range(1, N + 1):
        taste = L + i - 1
        if abs(taste) < min_taste:
            min_taste = abs(taste)
            min_taste_index = i

    for i in range(1, N + 1):
        if i == min_taste_index:
            continue
        total += L + i - 1

    print(total)


if __name__ == "__main__":
    main()

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

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

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

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

for i in range(N):
  tmp1 = sum(stk)
  tmp = stk[i]
  stk[i] = 0
  tmp2 = sum(stk)
  stk[i] = tmp
  ans.append(abs(tmp1 - tmp2))

tmp = min(ans)

if tmp in stk:
  stk.remove(tmp)
  print(sum(stk))
else:
  stk.remove(-tmp)
  print(sum(stk))

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

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

ans = float("inf")
res = float("inf")

for apple in apples:
  if ans > abs(apple):
    ans = min(ans,abs(apple))
    res = apple
  
print(sum(apples) - res)

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

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

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

a = []
b = float('inf')
for i in range(1,n+1):
    a.append(i+l-1)
    if abs(i+l-1) < b:
        c = i+l-1
        b = abs(i+l-1)

A = sum(a)

print(A-c)

Solution (Python):
n, l = map(int, input().split())
num = 200
for i in range(1, n+1):
    if abs(num) >= abs(l+i-1):
        num = abs(l+i-1)
        x = i
cnt = 0
for j in range(1, n+1):
    cnt += j
print((l-1)*(n-1) + cnt - x)

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

Solution (Python):
n,l=[int(x) for x in input().split()]
a=l
pie=0
app=[]
for i in range(n):
  apple=l+i
  pie+=apple
  app.append(apple)
b=[]
for i in app:
  j=abs(i)
  b.append(j)
c=min(b)
d=b.index(c)
pie-=app[d]
print(pie)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

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

if 0 in A:
    print(sum(A))
else:
    AA = [abs(a) for a in A]
    b = min(AA)
    if b in A:
        print(sum(A) - b)
    else:
        print(sum(A) + b)

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, l = LI()
origin = 0
m = inf
for i in range(n):
    origin += l + i
    if m > abs(l + i):
        m = min(m, abs(l + i))
        x = l + i
ans = origin - x
print(ans)

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

Solution (Python):
N,L = map(int,input().split())
min = 10**4
sum = 0
for i in range(N) :
    t = i+L
    sum += t
    if abs(t) < abs(min) :
        min  = t


print(sum - min)

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

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,l=mp()
x=0
if l>0:
    x=l
elif l+n-1<0:
    x=l+n-1
print((l-1)*n+n*(n+1)//2-x)

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

t=[] 

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

t_total=sum(t) 


t2=[] 

for j in t:
  b=t_total-j
  t2.append(b)

ans=[]

for k in t2:
  c=t_total-k
  ans.append(abs(c))

ind=ans.index(min(ans))

print(t_total-t[ind])

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

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

print(sum(Ls)-min(Ls, key=abs))

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