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

import sys


def solve(N: int, L: int):
    apple_taste_list = [L+i for i in range(N)]

    min_abs = 100000
    for i in apple_taste_list:
        if abs(i) < abs(min_abs):
            min_abs = i

    sum_of_taste = sum(apple_taste_list)
    
    print(sum_of_taste - min_abs)
    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):
inf = float('inf')

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

s = 0
eat = inf

for i in range(L, L + N):
    if abs(i) < abs(eat):
        eat = i
    s += i

print(s - eat)

Solution (Python):
import numpy as np

n, l = map(int, input().split())
apples = list(range(l, n + l))

if 0 in apples:
    print(sum(apples))
else:
    print(sum(apples) - sorted(apples, key=abs)[0])

Solution (Python):
intxt = input().split()
n = int(intxt[0])
l = int(intxt[1])
taste = n * (n + 2 * l - 1) // 2
if l + n - 1 <= 0:
    taste -= l + n - 1
elif l >= 0:
    taste -= l

print(taste)

Solution (Python):
import numpy as np
N, L = map(int, input().split())
total_taste = 0
pi = []
result = []
for i in range(1, N+1):
    taste = i + L - 1
    total_taste = taste + total_taste
for i in range(1, N+1):
    taste = i + L - 1
    pi.append(total_taste - taste)
for i in pi:
    result.append(total_taste - i)
print(pi[np.argmin(np.abs(result))])

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

tastes= [x for x in range(L,L+n,1)]

abs_tastes=[abs(x) for x in tastes]

eat = tastes[abs_tastes.index(min(abs_tastes))]

ans = sum(tastes) - eat

print(ans)

Solution (Python):

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

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

a = np.array(range(1,N+1))
t = a + L - 1

s = t.sum()

min = 90000000
min_ans = -90000000
for i in range(len(t)):
    x = abs(s - (s - t[i]))
    if x < min:
        min = x
        min_ans = s - t[i]

print(min_ans)

Solution (Python):

import sys


def solve(N: int, L: int):
    taste_max = L + N - 1
    taste_min = L
    if taste_min <= 0 and 0 <= taste_max:
        return (taste_min + taste_max) * N // 2
    elif taste_max < 0:
        return (taste_min + taste_max - 1) * (N - 1) // 2
    else:
        return (taste_min + 1 + taste_max) * (N - 1) // 2



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))  
    print(solve(N, L))

if __name__ == '__main__':
    main()

Solution (Python):
N, L = map(int, input().split())
eat = L + N - 1
if eat > 0:
  eat = L
  if eat < 0:
    eat = 0

print("%d" % (1/2*N*(N+1)+(L-1)*N-eat))

Solution (Python):
n, l = list(map(int, input().split()))
li = []
a = 500
for i in range(n):
    li.append(i+l)
    if abs(a) > abs(i+l):
        a = i + l
print(sum(li) - a)

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

applePie = L*N
min = 20000

for i in range(N):
    applePie += i
    if (L+i)*(L+i) < min*min:
        min = L+i

applePie -= min

print(applePie)

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

Solution (Python):
N, L = map(int, input().split())
A = []
B = []
for i in range(N):
  A.append(L+i)
  B.append(abs(L+i))
C = sum(A[0:N])
D = max(A)
if D>0 :
  E=min(B)
else:
  E=D
print(C-E)

Solution (Python):


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

L=l
R=l+n-1
if R<=0:
 temp=R
elif L>=0:
 temp=L
else:
 temp=0
print (R+L)*(R-L+1)/2-temp

Solution (Python):
n, l = map(int, input().split())
cnt = 10000
a = []
m = 0
for i in range(n):
    a.append(i + l)
    if cnt > abs(i + l):
        cnt = abs(i + l)
        m = i + l
print(sum(a) - m)

Solution (Python):
def main():

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

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

    list2 = []
    for i in range(N):
        list2.append(abs(list[i]))

    list2.sort()
    tmp = list2.pop(0)

    if tmp in list:
        list.remove(tmp)
    elif -tmp in list:
        list.remove(-tmp)

    ans = 0
    for i in list:
        ans += i

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
quantity, basis = map(int, input().split())

totalTaste = 0

eatApple = basis

for i in range(1, quantity + 1):
  
  appleTaste = basis + i - 1
  
  totalTaste += appleTaste
  
  if (abs(appleTaste) < abs(eatApple)):
    eatApple = appleTaste

print(totalTaste - eatApple)

Solution (Python):
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    n, l = list(map(int, input().split()))
    t = list(range(l, l+n))
    t_abs = list(map(abs,t))
    eat_ap = t_abs.index(min(t_abs))
    t.pop(eat_ap)
    print(sum(t))


if __name__ == "__main__":
    main()

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

eat = apple[0]
for j in apple:
  if j < 0:
    if j > eat:
      eat = j
  elif j == 0:
  	eat = 0
  else:
    if j < eat:
      eat = j
print(sum(apple) - eat)

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

list=[]

num = 0

for i in range(N):
  
  num += L+i
  list.append(abs(L+i))
  
min_num = min(list)

if L+i-1 >=0:
  print(num - min_num)

else:
  print(num+min_num)

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

sum1 = sum(range(N)) + N * L
sum2 = [abs(L+ i) for i in range(N)]
select_num = sum2.index(min(sum2))
print(sum1 - (L + select_num))

Solution (Python):
N,L = map(int,input().split())
List = []
ans = 0
Min = float('inf') 
for i in range(1,N+1):
    List.append(L+i-1)
    Min = min(Min,abs(L+i-1))
    if L+i-1 <0:
        ans = (-1)*Min
    else:
        ans = Min
print(sum(List)-ans)

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

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

taste = 0
for n in range(1, N+1):
    taste+=n+L-1
if (L > 0):
    taste-=L
elif (0 > N+L-1):
    taste-=N+L-1

print(taste)

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

azilist = range(L,L+N)
eatindex = -1

for i,a in enumerate(azilist):
    if i == len(azilist)-1:
        break
    else:
        b=abs(a)
        c=abs(azilist[i+1])
        if b<c:
            eatindex=i
            break
print(sum(azilist) - azilist[i])

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

Solution (Python):
N,L = map(int,input().split())
ans = 101
all_sum = 0
for i in range(N):
    if ans > abs(L+i):
        ans = abs(L+i)
for i in range(N):
    if abs(L+i) == ans:
        continue
    else :
        all_sum += (L+i)
print(all_sum)

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

Solution (Python):
N, L = map(int, input().split())
temp = 10000
count = 0
for i in range(1, N+1):
    if abs(temp) > abs(L+i-1):
        temp = (L+i-1)

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

count -= temp
print(count)

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

sum = 0
for i in range(n):
  if i != min_index:
    sum += taste[i]

print(sum)

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

Solution (Python):
a, b=input().split(" ")
a=int(a)
b=int(b)

total=a*(b-1)+a*(a+1)/2

c=abs(b)
d=1
for i in range (1, a+1):
    if abs(b+i-1)<c:
        d=i
        c=abs(b+i-1)

print(int(total-(b+d-1)))

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


b=10000
j=0 
for i in range(N):
    if abs(A[i]) < b:
        j=i
        b =abs(A[i])
print(total-A[j])

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

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

total = sum(A) 


b = 1000000
j = 0 
for i in range(N):
    if abs(A[i]) < b:
        j = i
        b = abs(A[i])

print(total - A[j])

Solution (Python):
N,L = list(map(int,input().split()))
sum = 0
list1 = []
list2 = []
for i in range(N):
    sum = sum+i+L

    list1.append(abs(i+L))
    list2.append(i+L)
print(sum - list2[list1.index(min(list1))])

Solution (Python):
a,b = map(int,input().split())
c = []
d = []
e = 0
for i in range(a):
     c.append(i+b)
     d.append(abs(i+b))
     e += i+b
d = sorted(d)
if c[-1] < 0:
     print(e+d[0])
else:
     print(e-d[0])

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

ans = sum - eat
print(ans)

Solution (Python):
N,L = map(int,input().split())
eat = 301
eatNum = 0
for i in range (0,N):
    if abs(i + L) < eat:
        eat = abs(i + L)
        eatNum = i
ans = 0
for i in range(0,N):
    if i != eatNum:
       ans += i + L
print(ans)

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

Solution (Python):

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


R = L + N - 1
S = N * (L + R) // 2
ans = S - max(0, L) - min(0, R)


print(ans)

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

Solution (Python):
n,l = map(int,input().split())
apple_sum = 0
eat_apple = float('inf')

for i in range(1,n+1):
	apple_sum += l + i - 1
	if abs(eat_apple) > abs(l+i-1):
		eat_apple = l+i-1

ans = apple_sum - eat_apple

print(ans)

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

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

sum = sum(tastes) - mintaste

print(sum)

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

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

sum = 0
for i in range(n):
  if abs(tastes[i]) != minabs:
    sum += tastes[i]

print(sum)

Solution (Python):
if __name__ == '__main__':
  n, l = map(int, input().split(" "))
  app_list = []
  abs_min = 10000000000
  delete_member = 0
  for i in range(n):
    score = l + i
    app_list.append(score)
    if abs(score) < abs_min:
      delete_member = score
      abs_min = abs(score)
  app_list.remove(delete_member)
  print(sum(app_list))

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

Solution (Python):
mylistA=[]
mylistB=[]
N,L=map(int,input().split())
for i in range(1,N+1):
  y=L+i-1
  mylistA.append(y)
  
mylistB=list(map(abs,mylistA))
x=min(mylistB)
z=mylistB.index(x)
print(sum(mylistA)-mylistA[z])

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

Solution (Python):
n, l = map(int, input().split(' '))
a = []
b = []
for i in range(0, n):
    a.append(l + i)
    b.append(abs(l + i))
a.pop(b.index(min(b)))
print(sum(a))

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

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

min_abs = 300
diff = 300

for i in range(1, N+1):
  if abs(L + i - 1) < min_abs:
  	min_abs = abs(L + i - 1)
  	diff = L + i - 1
print(total - diff)

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

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

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

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

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

Solution (Python):
N, L = map(int, input().split())
L = list(range(L, N+L))
L_abs=list(map(lambda x: abs(x), L))
L.pop(L_abs.index(min(L_abs)))
print(sum(L))

Solution (Python):


List = [int(x) for x in input().split()]
N = List[0]
L = List[1]

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

print(int(N*L-N+N*(N+1)/2-Choose))

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

taste = 0
taste_sum = 0
eat = 0
temp_eat = 0

for i in range(1,N+1):
  taste = L+i-1
  taste_sum += taste
  
  if i == 1:
    eat = taste
    temp_eat = abs(taste)
    
  elif abs(taste) < temp_eat:
    temp_eat = abs(taste)
    eat = taste

print(taste_sum - eat)

Solution (Python):
Amin = 10**9
ans = 0
N,L = (int(x) for x in input().split())
for i in range(N):
    Atmp = L + i
    ans += Atmp
    if abs(Amin) > abs(Atmp):
        Amin = Atmp
ans -= Amin
print(ans)

Solution (Python):
N, L = map(int, input().split())
min = 10**100
total_taste = 0
for i in range(N):
    taste = L + i
    if abs(min) > abs(taste):
        min = taste
    total_taste += taste
ans = total_taste - min
print (ans)

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

if min(lst)>0:
    ans=sum(lst)-min(lst)
elif max(lst)<0:
    ans=sum(lst)-max(lst)
else:  
    m = abs(lst[0])
    for i in range(n):
        if abs(lst[i])<m:
            m=abs(lst[i])
    ans=sum(lst)-m
print(ans)

Solution (Python):

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

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

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

apples = [L+n for n in range(N)]
apples = sorted(apples, key=lambda a: abs(a))

print(sum(apples[1:]))

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

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

print(ans)

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

sum = 0

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

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

  if abs(sum-x) < abs(sum-ans):
    ans = x
print(ans)

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

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

if apple[0]>0:
    print(sum(apple)-apple[0])
elif apple[n-1]<0:
    print(sum(apple)-apple[n-1])
else:
    print(sum(apple))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
n,l=map(int,input().split())
aa=[l+i for i in range(n)]
s=sum(aa)
m=min(aa, key=abs)
print(s-m)

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

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



min_apple = 99999999
for i in range(len(apples)):
    if min_apple > abs(apples[i]):
        min_apple = abs(apples[i])
        omit = i

ans = 0
for i in range(len(apples)):
    if i == omit:
        continue
    else:
        ans += apples[i]

print(ans)

Solution (Python):
N, L = [int(x) for x in input().split()]
pie = 0
for i in range(1, N + 1):
	pie += L + i - 1
	if i == 1:
		minimum = L + i - 1
	elif i == N:
		maximum = L + i - 1

if minimum < 0:
	if maximum > 0:
		eat = 0
	else:
		eat = maximum
else:
	eat = minimum

print(pie - eat)

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

pie = 0
minimum = [0, float('inf')]
for i in range(1, N + 1):
	pie += L + i - 1
	if abs(L + i - 1) < minimum[1]:
		minimum[0] = i
		minimum[1] = abs(L + i - 1)

print(pie - (L + minimum[0] - 1))

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

Solution (Python):
import numpy as np
n,l = map(int,input().split())
taste = np.array([l+i-1 for i in range(1,n+1)])
taste[np.fabs(taste).argmin()]=0
print(taste.sum())

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

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

avg = [sum(lst) - i for i in lst]

cnt = 0
tmp = 999
for n in range(len(avg) ):
    ans = abs(sum(lst) - avg[n])
    if abs(sum(lst) - avg[n]) < tmp:
        cnt = n
        tmp = ans
print(sum(lst) - lst[cnt])

Solution (Python):
N,L = map(int,input().split())
S = 0
b = abs(L)
for i in range(1,N+1):
  a = L + i - 1
  S += a
  b = min(abs(a),b)
if -N < L:
  ans = S - b
else:
  ans = S + b
print(ans)

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

Solution (Python):


def solve():
    N, L = list(map(int, input().split()))
    all_taste = 0
    eat_taste = float("inf")
    for i in range(1, N+1):
        all_taste += L+i-1
        eat_taste = min(eat_taste, abs(L+i-1))
    
    if all_taste > 0:
        ans = all_taste - eat_taste
    else:
        ans = all_taste + eat_taste
    print(ans)



if __name__ == "__main__":
    solve()

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

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

a = sorted(a)

if 0 in a:
    print(sum(a))
    
elif a[-1] < 0:
    print(sum(a[:-1]))
    
else:
    print(sum(a[1:]))

Solution (Python):
from sys import exit

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

taste = list(range(L, L + N))
n_sum = sum(taste)

exclude = min(list(map(abs, taste)))

if exclude in taste:
    print(n_sum - exclude)
else:
    print(n_sum + exclude)

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



minimum = -1000
i = 0
flavor = 0
sum = 0

X = 1 - L
if X >= 2 and X <= N:
    for x in range(1,N+1):
        if x != 1 - L:
            flavor = L + x - 1
            sum += flavor
elif X > N:
    for x in range(1,N+1):
        if x != N:
            flavor = L + x - 1
            sum += flavor
else:
    for x in range(1,N+1):
        if x != 1:
            flavor = L + x - 1
            sum += flavor
print(sum)

Solution (Python):
N,L = [int(a) for a in input().split(" ")]
tastes = [L + n for n in range(N)]
min_tastes = min(tastes,key=lambda a: abs(a))
print(sum(tastes)-min_tastes)

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

taste = 0
for i in range(1,n+1):
  if i == ate_ix:
    pass
  else:
    taste = taste+l+i-1
print(taste)

Solution (Python):

import numpy as np

def main():
    
    N, L = map(int, input().split())
    each_aji = [L + i - 1 for i in range(1,N+1)]
    abs_arg_min = np.argmin(np.abs(each_aji))
    each_aji.pop(abs_arg_min)
    print(sum(each_aji))


if __name__=='__main__':
    main()

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

Solution (Python):
if __name__ == '__main__':
    N, A = input().split()[0:]
    assert 2<=int(N)<=200
    assert -100<=int(A)<=100

    L = int(A)
    R = int(A)+int(N)-1

    if R <= 0:
        eat = R
    elif L >= 0:
        eat = L
    else:
        eat = 0

    ans = (R+L)*(R-L+1)//2-eat
    print(ans)

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

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

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

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

u = 100
y = 0
is_minus = False
for i in range(int(x[0])):
    if abs(i+int(x[1])) < u:
        u = abs(i + int(x[1]))
        if (i + int(x[1])) < 0:
            is_minus = True
        else:
            is_minus = False
    y += i + int(x[1])

if is_minus:
    print(y + u)
else:
    print(y-u)

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


if __name__ == "__main__":
    main()

Solution (Python):
n, l = map(int, input().split())
 
total = 0
min_taste = 1000000000
 
for i in range(n):
    taste = l + i
    total += taste
    if abs(taste) < abs(min_taste):
        min_taste = taste
 
print(total - min_taste)

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

values = [L + i for i in range(N)]
sorted_values = sorted(values, key=lambda x: abs(x))

print(sum(sorted_values[1:]))

Solution (Python):
import math

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


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





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

result_taste = taste_all - taste_abs_min

print(result_taste)

Solution (Python):
s=list(map(int,input().split()))
list=[]
i=0
p=abs(i+s[1])
for i in range(s[0]):
  list.append(i+s[1])
  if min(list)+s[1]==0:
    p=0
  else:
    if p>abs(i+s[1]):
      p=abs(i+s[1])
a=sum(list)
if a<0:
  print(a+p)
else:
  print(a-p)

Solution (Python):
N, L = map(int, input().split())
eat = 300
x = 0
for i in range(1, N + 1):
    aji = abs(L + i - 1)
    if eat > aji:
        eat = aji
        x = L + i - 1
print(sum(range(1, N + 1)) + N * (L - 1) - x)

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

taste = list(map(int, list(range(L, N + L))))
dam = [0] * N

for c in range(N):
    dam[c] = abs(taste[c])
print(sum(taste) - taste[dam.index(min(dam))])

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,l = LI()
    a = [l+i for i in range(n)]
    s = sum(a)

    if 0 in a:
        return s

    if a[0] < 0:
        return s - a[-1]

    return s - a[0]


print(main())

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

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

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

abs_tastes = list(map(abs, tastes))

min_v = min(abs_tastes)
min_i = abs_tastes.index(min_v)

del tastes[min_i]
print(sum(tastes))

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

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

total = 0
dis_min = 1000000000

for i in range(n):
    taste = l + i
    total += taste
    if abs(taste) < abs(dis_min):
        dis_min = taste

print(total - dis_min)

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

taste_list = []

dis_min = 1000000000

for i in range(n):
    taste = l + i
    taste_list.append(taste)
    if abs(taste) < abs(dis_min):
        dis_min = taste

print(sum(taste_list) - dis_min)

Solution (Python):
N, L = map(int, input().split())
min = 10000
for i in range(1,N+1):
    if min > abs(L+i-1):
        min = abs(L+i-1)
        num = L+i-1

print(sum(range(1,N+1))+L*N-N-num)

Solution (Python):
N,L = map(int,input().split())
taste = [(L+i) for i in range(N)]
taste_abs = [abs(taste[i]) for i in range(N)] 
p = taste_abs.index(min(taste_abs))
taste[p] = 0
print(str(sum(taste)))

Solution (Python):

N, L = map(int,input().split())
s = []
eat = 9999

for i in range(1,N+1):
    value = i + L - 1
    s.append(value)
    if abs(eat) > abs(value):
        eat = value

print(sum(s) - eat)

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

del taste[apple.index(min(apple))]
print(sum(taste))

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

Solution (Python):
lis = [int(i) for i in input().split()]

N = lis[0]
L = lis[1]

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

Solution (Python):
N,L=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(N):
  A.append(L+i)
a=sum(A)
for i in range(N):
  B.append(a-A[i])
for i in range(N):
  C.append(abs(a-B[i]))
c=float('inf')
ans=0
for i in range(N):
  if C[i]<c:
    ans=i
    c=C[i]
print(B[ans])

Solution (Python):







import sys
sys.setrecursionlimit(10**5+1)

inf     =  int(10 ** 20)
max_val =  inf
min_val = -inf

RW  = lambda : sys.stdin.readline().strip()
RI  = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]


n, L = RMI()
arr = [ L + i -1  for i in range(1, n + 1)]
count_0 = arr.count(0)
sums    = sum(arr)
if count_0 == 1: del arr[arr.index(0)]
elif count_0 == 0 and sums >= 1: del arr[arr.index(min(arr))]
elif count_0 == 0 and sums <= -1:del arr[arr.index(max(arr))]
else:pass
print(sum(arr))

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

print(int(res))

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

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

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

import itertools
c = itertools.combinations(Apple, N-1)
apple_sum = sum(Apple)
near = (apple_sum + 1 )* 100
ans = 0

if 0 in Apple:
  print(apple_sum)
else:
  for v in c:
    vv = sum(v)
    if abs(apple_sum - vv) <= abs(near):
      near = apple_sum - vv
      ans = vv
  print(ans)

Solution (Python):
import math

N, L = list(map(int, input().split(" ")))
apples = [L + i - 1 for i in range(1, N + 1)]
abss = list(map(abs, apples))
m = apples[abss.index(min(abss))]
print(sum(apples) - m)

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

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



if N_all.count(0) == 1:
    x = N_all.index(0)
    del N_all[x]
elif N_all.count(0) == 0 and sum(N_all) >= 1:
    x = min(N_all)
    x = N_all.index(x)
    del N_all[x]
elif N_all.count(0) == 0 and sum(N_all) <= -1:
    x = max(N_all)
    x = N_all.index(x)
    del N_all[x]
else:
    pass
print(sum(N_all))

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)





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

arr = [None] * N

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

minV = 1e20

for i in range(N):
    if abs(arr[i]) < abs(minV):
        minV = abs(arr[i])
        d = arr[i]

print(sum(arr) - d)

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

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

for i in range(1, N+1):
    tmp = L+i-1
    ans += tmp
    if abs(eat) > abs(tmp):
        eat = tmp

print(ans - eat)

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

eats = 999
is_minus = False

for i in range(n):
    azi = l + (i + 1) - 1

    if eats > abs(azi):
        eats = abs(azi)
        is_minus = True if azi < 0 else False


w = eats if is_minus == False else eats * -1

print(sum([l + (e + 1) - 1 for e in range(n)]) - w)

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

T=[]
t=1000
for i in range(N):
    if t>abs(L+i+1-1):
        t=abs(L+i+1-1)
        x=i
    T.append(L+i+1-1)
print(sum(T)-T[x])

Solution (Python):
n,l=map(int,input().split())
ans = l*n + n*(n-1)//2

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