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

res = 0

a = [(abs(L + i - 1), L + i - 1) for i in range(1, N + 1)]
a.sort()
min_a = a[0][1]

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

print(res)

Solution (Python):
n,l=map(int,input().split())
s1=(l-1)*n+(n*(n+1))//2
m=9999999999
ans=0
for k in range(1,n+1):
    s2=s1-(l+k-1)
    if m>abs(s1-s2):
        m=abs(s1-s2)
        ans=s2
print(ans)

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

tmp = [i for i in range(l, n + l)]
original = sum(tmp)

if l >= 0:
    result = original - tmp[0]
elif 0 in tmp:
    result  = original
else:
    result = original - tmp[len(tmp) - 1]

print(result)

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

Solution (Python):
n, l = [int(i) for i in input().split()]
ans = n*l + n * (n+1)//2 - n



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(' '))
result = 0
res = 10 ** 10
count = 0
for i in range(1,n+1):
    count += l+i-1
    if res > abs(l + i -1):
        res = abs(l + i  -1)
        result = l + i -1

print(count -result)

Solution (Python):
n,l=map(int,input().split())
li=[]
zm=1e10
f=0
for i in range(n):
    li.append(i+l)
    
    if abs(zm)>=abs(i+l):
        zm=i+l
print(sum(li)-zm)

Solution (Python):
def main():
    n, m = map(int, input().split())
    print(solve(n, m))

def solve(n, m):
    a = m
    b = m + n - 1

    if a >= 0 and b >= 0:
        return sum(range(a + 1, b + 1))
    elif a < 0 and b < 0:
        return sum(range(a, b))
    else:
        return sum(range(a, b + 1))

main()

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

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

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

Solution (Python):
n,l=map(int,input().split())
s=0
eat=float('inf')
for i in range(n):
    s+=l+i
    if abs(eat)>abs(l+i):
        eat=l+i
print(s-eat)

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

Solution (Python):
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=100000000000000000
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(int(s-l-x))

Solution (Python):
import numpy as np

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

taste = [L + i - 1 for i in range(1, N+1)]
abs_taste = [abs(i) for i in taste]
min_t_i = abs_taste.index(min(abs_taste))

print(sum(taste)-taste[min_t_i])

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

A=[]
total=0
min=1000
min_index=0
for i in range(N):
    a=L+i
    A.append(a)
    total+=a
    if abs(a) < min:
        min_index = i
        min=abs(a)



pie=total-A[min_index]
print(pie)

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

a=[]
for i in range(n):
    a.append([abs(l+i),i])
a.sort(key=lambda x:x[0])
b=[]
for k in range(n):
    b.append(l+k)

print(sum(b)-(l+a[0][1]))

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

Solution (Python):
line = input().split()
n, l = tuple([int(s) for s in line])
v = [0] * n
for i in range(n):
    v[i] = l + i
    
sum_l = sum(v)

if l >= 0:
    print(sum_l - v[0])
elif l < 0 and l+n <= 0:
    print(sum_l - v[-1])
else:
    print(sum_l)

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

tmp = float('inf')
for v in range(N):
    if tmp > abs(v+L):
        tmp = abs(v+L)
        eat = v
sumALL = sum([v+L for v in range(N)])

print(sumALL-eat-L)

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

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

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

sum1 = 0
absMin = 101
for i in range(N):
	taste = L + (i+1) -1
	
	sum1 += taste
	if abs(taste) < abs(absMin):
		absMin = taste
	

print(sum1-absMin)

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

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

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

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

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

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

print(sum(l)-l[l_abs.index(min(l_abs))])

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

Solution (Python):
N, L = map(int, input().split())
ajiList = []
absList = []
for i in range(N):
    ajiList.append(i + L)
    absList.append(abs(i + L))
s = sum(ajiList)
m = min(absList)
if s > 0:
    ans = s - min(absList)
else:
    ans = s + min(absList)
print(ans)

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

start = li[0]
end = li[n-1]

if start >= 0:
    li[0] = 0
elif end <= 0:
    li[n-1] = 0
    
print(sum(li))

Solution (Python):
import sys

input=sys.stdin.readline()
n,l=map(int,input.split())
min_a=l
max_a=l+n-1
if min_a>0:
    min_a+=1
elif max_a<0:
    max_a-=1
print(sum(range(min_a,max_a+1,1)))

Solution (Python):
from sys import stdin
input = stdin.readline().split()
N, L = int(input[0]), int(input[1])
val = 0
for i in range(1,N+1):
    
    val +=  L + i - 1

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

Solution (Python):
N, L = map(int, input().split())
apple = [ L + int(_) - 1 for _ in range(1, N + 1)]
sumA = sum(apple)
ans = float("INF")
for i in range(N):
    l = sum(apple[0:i])
    r = sum(apple[i + 1:N])
    ans = min(abs(sumA - (l + r)), ans)

if sumA < 0:
    print(sumA + ans)
else:
    print(sumA - ans)

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

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

tasteabs = [abs(l+i) for i in range(n)]
taste = [l+i for i in range(n)]

m = min(tasteabs)

if m in taste:
  print(sum(taste) - m)
else:
  print(sum(taste) + m)

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

taste = []
taste_z = []
taste_f = []
Sum = 0
for i in range(N):
  taste.append(L+i)
  if (L+i)!=0:
    taste_z.append(abs(L+i))
    taste_f.append(int((L+i)/abs(L+i)))
  else:
    taste_z.append(0)
    taste_f.append(0)

for i in range(N):
  Sum += taste[i]

print(Sum-taste[taste.index(taste_f[taste_z.index(min(taste_z))]*min(taste_z))])

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline






















def main():

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

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

	tmp = bisect_left(azi, 0)

	ans = 0
	flg = False
	for i,val in enumerate(azi):
		if i == tmp:
			flg = True
			continue
		ans += val
	
	if flg == False:
		ans -= azi[-1]
	print(ans)

if __name__ == "__main__":
	main()

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

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

Solution (Python):
import sys

S = input().split()

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

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

org_taste_sum = sum(taste)
abs_min = sys.maxsize
ans = 0

for i in range(0, N):
    tmp_taste_sum = 0
    for x in taste:
        if x == taste[i]:
            continue
        else:
            tmp_taste_sum += x

    abs_val = abs(org_taste_sum - tmp_taste_sum)
    if abs_val < abs_min:
        ans = tmp_taste_sum
        abs_min = abs_val

print(ans)

Solution (Python):

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

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

total = 0
m = 100000
for i in range(1, 1+n):
  a = l + i - 1
  total += a
  if abs(m) > abs(a):
    m = a

print(total-m)

Solution (Python):

N, L = map(int, input().split())
L1 = [L+i for i in range(N)]
L2 = [abs(L1[i]) for i in range(N)]
idx = L2.index(min(L2))
min_ = L1[idx]
print(sum(L1) - min_)

Solution (Python):

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

aji = [l+i for i in range(n)]
sumaji = sum(aji)
sa = abs(sumaji - (sumaji - aji[0]))
ansind = 0
for i in range(n):
  if sa >  abs(sumaji - (sumaji - aji[i])):
    sa = abs(sumaji - (sumaji - aji[i]))
    ansind = i

print(sumaji-aji[ansind])

Solution (Python):
lis=input().split(' ')
N=int(lis[0])
L=int(lis[1])
sum=int((2*L+N-1)*N*0.5)
if(L<0 and N+L-1<0):
  print(sum-(N+L-1))
elif(L>0 and N+L-1>0):
  print(sum-L)
else:
  print(sum)

Solution (Python):
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

INF = 100000000

def main():
    N, L = map(int, input().split())
    apples = [i for i in range(L, L + N)]
    sum_ = sum(apples)
    without_self_sum = [sum_ - apples[i] for i in range(N)]
    abs_minimum = INF
    ans = 0
    for i in range(N):
        if abs(sum_ - without_self_sum[i]) < abs_minimum:
            abs_minimum = abs(sum_ - without_self_sum[i])
            ans = without_self_sum[i]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def B():
    N, L = map(int, input().split())
    apples = [L + i for i in range(N)]
    taste_sum = sum(apples)
    if 0 in apples:
        print(taste_sum)
    elif taste_sum>0:
        print(taste_sum-min(apples))
    else:
        print(taste_sum-max(apples))

B()

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

taste = [i + l for i in range(n)]
abs_taste = [abs(i) for i in taste]
min_index = abs_taste.index(min(abs_taste))

del taste[min_index]
print(sum(taste))

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


def taste(i):
    return L + i - 1


all_taste = 0
for i in range(1, N + 1):
    all_taste += taste(i)


ans = 1000000
final_taste = all_taste
for i in range(1, N + 1):
    sub_taste = 0
    for j in range(1, N + 1):
        if not i == j:
            sub_taste += taste(j)
    if abs(all_taste - sub_taste) < ans:
        ans = abs(all_taste - sub_taste)
        final_taste = sub_taste

print(final_taste)

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

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

mylist = []

negagivecheck = 0

for i in range(N):
  mylist += [i+L]
  if i+L < 0:
    negagivecheck =1
  
if negagivecheck == 0:
  print(sum(mylist[1:]))
else:
  if 0 in mylist:
    print(sum(mylist))
  else:
    print(sum(mylist[:-1]))

Solution (Python):

import sys


def solve(N: int, L: int):
    scores = [L + i   for i in range(N)]
    ans = sum(scores)
    mi = min([abs(x) for x in scores])
    if ans > 0:
        ans -= mi
    else:
        ans += mi
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)

if __name__ == '__main__':
    main()

Solution (Python):


import numpy as np

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

s = np.array(list(range(l,l+n)))
m = np.argmin(np.abs(s))
m = s[m]

print(np.sum(s)-m)

Solution (Python):
n,l=list(map(int,input().split()))
a=[0]*(n+1)
for i in range(1,n+1):
    a[i]=l+i-1
dp=[0]*(n+1)
for i in range(1,n+1):
    if a[i]<0:
        dp[i]=-1
    else:
        dp[i]=1
b=[]+a
for i in range(1,n+1):
    a[i]=abs(a[i])
a[0]=float('inf')
mini=min(a)

index=a.index(mini)

sum1=0
for i in range(1,n+1):
    if i==index:
        pass
    else:
        sum1+=b[i]
print(sum1)

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

app = []
for i in range(n):
    app.append(l+i)

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

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

ringo = []
for i in range(1,n+1):
  ringo += [l + i - 1]
ans_list = []

sr = sum(ringo)
dic = {}
for x in ringo:
  tmp = sum(ringo) - x
  ans = abs(sum(ringo) - tmp)
  dic[ans] = tmp
x = min(dic)
print(dic[x])

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

sumpi = sum(apl_val)

diff = 1000
for j in apl_val:
  if diff >= abs(j):
    diff = abs(j)
    ans = sumpi - j
  
print(ans)

Solution (Python):
import numpy as np

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

A = []
for i in range(N):
  A.append(L+i+1-1)
A = np.array(A)
j = np.argmin(np.abs(A))
A = np.delete(A, j)
print(np.sum(A))

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

Solution (Python):
N, L = map(int, input().split())
taste = [L+i for i in range(N)]
eat = 10**9
total = 0
for ti in taste:
    if abs(ti) < abs(eat):
        eat = ti
    total += ti
print(total - eat)

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

S = []

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

mi = min(S)

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

if su < 0:
    print(su+mi)
else:
    print(su-mi)

Solution (Python):
N,L=map(int, input().split())
min_aji = abs(L)
min_aji_index = 0
for i in range(1,N):
  abs_aji = abs(L + (i+1) - 1)
  if abs_aji < min_aji:
    min_aji = abs_aji
    min_aji_index = i
    
aji = 0
for i in range(N):
  if i != min_aji_index:
    aji += L + (i+1) - 1
    
print(aji)

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

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

minumum=10000
for i in range(1,N+1):
    if abs(minumum) > abs(L+i-1):
        minumum = L+i-1
    
print(int(sums-minumum))

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

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

if l <= 0 and l+n-1 >= 0:
    print(total)

elif l+n-1 < 0:
    print(total-l-n+1)

else:
    print(total-l)

Solution (Python):
N, L = map(int, input().split())
s = 0
nums = [i for i in range(L, N+L)]
to_delete = min(range(N), key=lambda x: abs(nums[x]))
print(sum(nums) - nums[to_delete])

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

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

a = sum(taste)
tmp = abs(a - (a - taste[0]))
ans = a - taste[0]
for i in range(N - 1):
    if abs(a - (a - taste[i + 1])) < tmp:
        tmp = abs(a - (a - taste[i + 1]))
        ans = a - taste[i + 1]
print(ans)

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

Solution (Python):

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


ate=L
if L<=-1:
    if L+N-1<0:
        ate=L+N-1
    else:
        ate=0
else:
    ate=L

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

print(int(suma-ate))

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

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

cur_diff = float('inf') 
ans = float('inf')
Sum = sum(A)
for a in A:    
    tmp = Sum - a
    diff = abs(Sum - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp

print(ans)

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

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

if 0 in apple:
    print(sum(apple))
elif max(apple) < 0:
    print(sum(apple) - max(apple))
elif min(apple) > 0:
    print(sum(apple) - min(apple))

Solution (Python):
N, L = [int(x) for x in input().split()]
head = L
tail = L+N-1
s = (N * (head+tail)) // 2
if (head <= 0 and tail >= 0):
    print(s)
else:
    if (tail<0):
        print(s-tail)
    elif (head>0):
        print(s-head)

Solution (Python):


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

ans = 0
if l>=0:
    for i in range(n):
        if i != 0:
            ans += l+i
else:
    if l>-1*n:
        for i in range(n):
            ans += l+i
    else:
        for i in range(n-1):
            ans += l+i

print(ans)

Solution (Python):
import scipy as sp

N, L = map(int, input().split())
taste = sp.arange(L, L+N)
s = sum(taste)

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

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

print(sum)

Solution (Python):
N, L = map(int, input().split())
apple = []
for i in range(N):
    apple.append(L+i)
apple.sort(key = abs)
apple = apple[1:]
ans = sum(apple)
print(ans)

Solution (Python):
a,b=map(int,input().split())
list=[]
List=[]
for i in range(a):
  list.append(b+i)
for j in range(a):
  List.append(abs(b+j))
LIST=sum(list)
List=min(List)
if int(LIST)<0:
  print(int(LIST)+int(List))
else:
  print(int(LIST)-int(List))

Solution (Python):
n,l=map(int,input().split())
apple=[]
for i in range(n):
    apple.append(l+i)
tabeta=1e9
for i in apple:
    if abs(tabeta)>=abs(i):
        tabeta=i
print(sum(apple) - tabeta)

Solution (Python):
import sys

input = sys.stdin.readline

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

apples = []

for index in range(1, n + 1):
    apples.append(l + index - 1)

sum = sum(apples)
maybe_ans_list = []

for apple in apples:
    maybe_ans_list.append((abs(sum - (sum - apple)), sum - apple))

ans = min(maybe_ans_list,key=lambda x:x[0])

print(ans[1])

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

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

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

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

s = 0
ringo = [0]*N
for i in range(N):
    ringo[i] = L+i

ringo.sort(key= lambda x:abs(x))
ringo[0] = 0
print(sum(ringo))

Solution (Python):
import numpy as np
n,l = map(int,input().split())
sc = []
for i in range(n):
  sc.append(l+i)
sc2 = sc
sc = np.array(sc)
out = sum(sc2)
for i in range(len(sc)):
  sc[i] = abs(sc[i])
out = out - sc2[np.argmin(sc)]
print(out)

Solution (Python):
n,l=input().split()
n=int(n)
s=f=0
l=int(l)

for i in range(n):
    a=l+i
    if(a==0):
        f=1
    else:
        s+=a
if(f==0):
    if(l<0):
        s-=(l+n-1)
    else:
        s-=l
print(s)

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

score=[]
for i in range(N):
    score.append(L+i+1-1)
score.remove(min(score, key=lambda x: abs(x)))
print(sum(score))

Solution (Python):
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N, L = tuple(li())
total = N * (L + N + L - 1) // 2
delta = 1 - L
if delta < 1:
    print(total - L)
elif delta > N:
    print(total - (L - 1 + N))
else:
    print(total)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,L=MAP()

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

mn=INF
idx=0
for i, a in enumerate(A):
    if abs(a)<mn:
        idx=i
        mn=abs(a)

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

Solution (Python):
N,L = map(int,input().split())
azi = list(range(L,L+N))
if(L >= 0):
    ans = sum(azi) - L
elif(L <= 0 and L+N-1 >= 0):
    ans = sum(azi)
else:
    ans = sum(azi) - (L+N-1)
    
print(ans)

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

print(sum(data) - data[taste.index(min(taste))] )

Solution (Python):
N, L = map(int, input().split())
taste = [L + n for n in range(N)]
minimum = 999999999
for t in taste:
    minimum = t if abs(t) < abs(minimum) else minimum

print(sum(taste) - minimum)

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

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

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

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

Solution (Python):
import numpy as np

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

price = []

for n in range(N):
  price.append(n+L)
  
p2 = np.array(price)
p2 = p2**2
m = min(p2)
index = np.where(p2==m)[0]


price.pop(index)

print(sum(price))

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

MAX = 10000
eat = 10000
for i in range(1, N+1):
    if abs(L+i-1) < MAX:
        MAX = abs(L+i-1)
        eat = L + i - 1

num = [L+i-1 for i in range(1, N+1)]
result = sum(num)
print(result-eat)

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

output = sum(aji)-min(list(map(abs,aji)))

if aji[list(map(abs,aji)).index(min(list(map(abs,aji))))]<0:
    output += 2*min(list(map(abs,aji)))

print(output)

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

taste = [l+i for i in range(n)]
if min(taste)>=0:
  ans = sum(taste) - min(list(map(abs, taste)))
else:
  ans = sum(taste) + min(list(map(abs, taste)))

print(ans)

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

sum = 0
for n in range(1,N+1):
    sum += n + L - 1

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

Solution (Python):
n, l = map(int, input().split())
sum = 0
for i in range(n):
    sum += l+i
abst = 10 ** 9
for i in range(l,l+n):
    if abs(i) < abs(abst):
        abst = i
print(sum-abst)

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

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

delapple = list(map(abs,apples))

delindex = delapple.index(min(delapple))

del(apples[delindex])

print(sum(apples))

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

def func(x):
  return(x+l)

a = list(range(n))
b = list(map(func, a))

m = l
for i in range(len(b)):
  if abs(m) > abs(b[i]):
    m = b[i]

ans = sum(a)+l*n-m
print(ans)

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

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


buff = sorted(buff, key=lambda x: abs(x[0]))

ans = 0
for i in range(len(buff)):
    if i > 0:
        ans += buff[i][0]
print(ans)

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

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

apple = 100000000000
for i in range(1, N+1):
    tmp = abs(L + (i - 1))
    if tmp < apple:
        eat = L + i - 1
        apple = tmp

print(Sum-eat)

Solution (Python):

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

Solution (Python):
n, l = list(map(int, input().split()))
taste = [l+i-1 for i in range(1, n+1)]
total = sum(taste)
diff = []
score = []
for i in range(n):
  tmp = sum(taste[i+1:])+sum(taste[:i])
  diff.append(abs(total - tmp))
  score.append(tmp)
print(score[diff.index(min(diff))])

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):
import itertools
N, L = map(int, input().split())

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

output = [0] * N

summation = sum(taste)

import itertools

for i, item in enumerate(list(itertools.combinations(taste, N - 1))):
    output[i] = [sum(item), abs(summation - sum(item))]

print(sorted(output, key=lambda x: x[1])[0][0])

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

Solution (Python):
N, L = [int(_) for _ in input().split()]
n = [L+i-1 for i in range(1,N+1)]
s = 0
m = 10000

for i in n:
    s += i
    if abs(i) < abs(m):
        m = i

s -= m
print(s)

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

m = 1000
sum = 0
for i in range(n):
  sum += l + i
  if m > abs(l + i):
    m = abs(l+i)
if sum < 0:
  print(sum + m)
else:
  print(sum - m)

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

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    apples = []
    isMinus = False
    isPlus = False
    for i in range(N):
        if L+i < 0:
            isMinus = True
        else:
            isPlus = True
        apples.append(L+i)

    if isMinus == True and isPlus == True:
        print(sum(apples))
    elif isMinus == True and isPlus == False:
        print(sum(apples[:-1]))
    else:
        print(sum(apples[1:]))

Solution (Python):
import fractions
import numpy as np
import os
import sys

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

s=0
ss=[]
for i in range(N):
    s+=i+L
    ss.append(i+L)

S=10000000000000
ans=0
for i in range(N):
    sss=0
    for j in range(N):
        if(i!=j):
            sss+=ss[j]
    if(abs(sss-s)<S):
        S=abs(sss-s)
        ans=sss
        
print(ans)

Solution (Python):
n,l=map(int, input().split())
List=[l+i-1 for i in range(1,n+1)]
m=min(abs(0-L) for L in List)
s=sum(List)
print(s+abs(m)if s<0 else s-abs(m))

Solution (Python):



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





if __name__ == '__main__':
    main()

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

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

ans=l*n-n+(1+n)*n//2
if 0<l:
  ans=ans-l
elif l < 1-n:
  ans=ans-(l+n-1)

print(ans)

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

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

if L > 0:
  print(sum([i + L for i in range(1, N)]))
elif L + N > 0:
  print(sum([i + L for i in range(0, N)]))
else:
  print(sum([i + L for i in range(0, N - 1)]))

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

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


trg=Ta.index(min(Ta))


s=sum(T[:trg]+T[trg+1:])
print(s)

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

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

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

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

aji_zettaichi = [abs(i) for i in aji]

aji_zettaichi_min_id = 0
aji_zettaichi_min = aji_zettaichi[0]

for i in range(len(aji_zettaichi)):
    if aji_zettaichi_min > aji_zettaichi[i]:
        aji_zettaichi_min_id = i
        aji_zettaichi_min = aji_zettaichi[i]

aji.pop(aji_zettaichi_min_id)

print(sum(aji))