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



Sample input:
5 2


Sample output:
18

Submission status: Accepted

Solution code:
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    n, l = map(int, input().split())
    a = [i for i in range(l, l+n)]
    if l < 0 and abs(l) < n:
        print(sum(a))

    elif l < 0 and abs(l) >= n:
        print(sum(a)-max(a))
    else:
        print(sum(a)-min(a))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

bl = [abs(x) for x in al]
al.pop(bl.index(min(bl)))
print(sum(al))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,L = input().split()
N = int(N)
L = int(L)
tastes = []
abs_tastes = []
for i in range(N):
  tastes.append(L + i)
  abs_tastes.append(abs(L+i))
abs_min = min(abs_tastes)
if L>0:
  abs_min = abs_min
else:
  abs_min = - abs_min
print(sum(tastes)-abs_min)

Submission status: Accepted

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

List = []

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

# List.sort()

# print(int((L - 1) * N + N * (N + 1) / 2) - List[0])

ans = 0
if(List[-1] < 0):
    ans = int(sum(List)) - List[-1]
else:
    if(List[0] <= 0):
        ans = int(sum(List))
    else:
        ans = int(sum(List)) - List[0]

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

N, L = map(int, input().split())
app_list = []
sum1, sum2, num, ans, min_ans = 0, 0, 0, 0, 1000000000000000000

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

for j in range(N):
    sum1 = sum(app_list)
    sum2 = sum(app_list) - app_list[j]
    ans = abs(sum1 - sum2)
    if ans < min_ans:
        num = j
        min_ans = ans

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

Submission status: Accepted

Solution code:
def main():
    n, l= map(int, input().split())
    a = [i for i in range(l, l+n)]
    ans = sum(a) - a[list(map(abs, a)).index(min(list(map(abs, a))))]
    print(ans)


if __name__=="__main__": main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(l) - absn)

Submission status: Accepted

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

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

# 1番目のりんごを食べる
if L >= 0:
    print(taste_n - L)
# 味が0にりんごを食べる
elif L < 0 and abs(L) < N:
    print(taste_n)
# n番目のりんごを食べる
else:
    print(taste_n - (L + N - 1))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
aji = []
for i in range(n):
    aji.append(l+i)
sum_aji = sum(aji)
min_diff = float("inf")
ans = 0
for s in aji:
    if abs(s) < min_diff:
        min_diff = abs(s)
        ans = sum_aji-s
print(ans)

Submission status: Accepted

Solution code:
lm = []
N,L = input().split()
N = int(N)
L = int(L)
for x in range(1,N+1):
    lm.append((abs(L+x-1),L+x-1))
lm.sort()
lm = lm[1::]
s = 0
for u in range(len(lm)):
    s = s + lm[u][1]
print('{}'.format(s))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

Sum_a = 0
Sum_b = 0
Min = 1000000

for i in range(N):
  Sum_a += L+i

for i in range(N):
  Sum_b = Sum_a - (L+i)
  if abs(Sum_a - Sum_b) < Min:
    Min = abs(Sum_a - Sum_b)
    Min_b = Sum_b
    
print(Min_b)

Submission status: Accepted

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

Submission status: Accepted

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

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

print (answer)

Submission status: Accepted

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

tp = []
tm = []
for i in range(1, N+1):
    t = L+i-1
    if t >= 0:
        tp.append(t)
    else:
        tm.append(t)

if len(tp) == 0:
    tm.remove(max(tm))        
elif len(tm) == 0:
    tp.remove(min(tp))
else:
    mtp = min(tp)
    mtm = abs(max(tm))    
    if mtp <= mtm :
        tp.remove(mtp)
    else:
        tm.remove(mtm)

sum = 0
for i in tp:
    sum += i
for i in tm:
    sum += i

print(sum)

Submission status: Accepted

Solution code:
n, l = input().split()
n,l = int(n),int(l)
taste = []
for i in range(n):
    taste.append(l+i)
min_diff = 100000
for i in range(n):
    total_n = sum(taste) - taste[i]
    diff = abs(sum(taste)-total_n)
    if diff < min_diff:
        min_diff = diff
        min_total = total_n
print(min_total)

Submission status: Accepted

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

out=0

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

print(int(out))

Submission status: Accepted

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

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

if l > 0:
    print(a-l)
elif n + l > 0:
    print(a)
else:
    print(a-(n+l)+1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
lst = [i + L for i in range(N)]
y = sum(lst)
a1 = 10**9
a2 = 10**9
for x in lst:
    if abs(x) < a1:
        a1 = abs(x)
        a2 = x
print(y - a2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N,L = map(int,input().split())
s=0;m=100000
for i in range(1,N+1):
  #print(L+i-1)
  s += L+i-1
  m = m if abs(L+i-1) >= m else abs(L+i-1)
#print(s)
print(s-m if s > 0 else s+m)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
d=114514
num=114514
for j in range(n):
  if abs(l+j)<d:
    d=abs(l+j)
    num=j
s=0
for i in range(n):
  s+=i
print(s+(n-1)*l-num)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
minval = l
maxval = l + n - 1

valsum = l * n
for i in range(n):
    valsum += i

if 0 < minval:
  valsum -= minval
elif maxval < 0:
  valsum -= maxval

print(valsum)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
pie=0
li=[]
for i in range(N):
    pie+=L+i
    li.append(abs(L+i))
#print(min(li))
if pie<0:
    print(pie+min(li))
else:
    print(pie-min(li))

Submission status: Accepted

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

aji = []
for a in L:
    aji.append(sum(L)-a)
aji2 = []
for i in range(len(L)):
    aji2.append(abs(aji[i]-sum(L)))

m = 10**7
ans = 1
for i in range(len(L)):
    if m > abs(aji[i]-sum(L)):
        m = min(abs(aji[i]- sum(L)), m)
        ans = aji[i]

print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple = [l + i for i in range(n)]
piesum = sum(apple)
different = float("inf")
for i in range(n):
    if different > abs(apple[i]):
        different = abs(apple[i])
        ans = piesum - apple[i]
print(ans)

Submission status: Accepted

Solution code:
def LI(): return list(map(int, input().split()))

n, l = LI()
apples = []
for i in range(n):
    apples.append(l + i)

minabs = min([abs(a) for a in apples])

if minabs in apples:
    print(sum(apples) - minabs)
else:
    print(sum(apples) + minabs)

Submission status: Accepted

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

a = list(range(L,n+L))
tmp = 500
for i in a:
	if abs(tmp) > abs(i):
		tmp = i

print(sum(a)-tmp)

Submission status: Accepted

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

ringo = []
aji = []
for i in range(n):
  ringo.append(i+1)
  aji.append(l + i)

if min(aji) > 0:
  aji.remove(min(aji))
  print(sum(aji))
elif max(aji) < 0:
  aji.remove(max(aji))
  print(sum(aji))
else:
  print(sum(aji))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
taste = 0
ab = l

for i in range(1,n+1):
    taste += l+i-1
    if abs(l+i-1) < abs(ab):
        ab = l+i-1

print(taste-ab)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line1 = input().split()
line1 = list(map(int,line1))
ate = None
if line1[1] > 0:
    ate = line1[1]
elif line1[1] == 0:
    ate = 0
else:
    if abs(line1[1]) < line1[0]:
        ate = 0
    elif abs(line1[1]) >= line1[0]:
        ate = line1[0] + line1[1] - 1

print(sum(range(line1[1],line1[1]+line1[0])) - ate)

Submission status: Accepted

Solution code:
n,l = map(int,input().split(" "))
ans = 0

#すべて正の数の場合：最小の値を除けば良い
if l > 0:
    for i in range(n-1):
        ans += l + i + 1
#すべて負の数の場合：最大の値を除けば良い
elif l + n <= 0:
    for i in range(n-1):
        ans += l + i
#０を含む場合：０を除けば良い
else:
    for i in range(n):
        ans += l + i
        
print(ans)

Submission status: Accepted

Solution code:
hoge = input().split()
N = int(hoge[0])
L = int(hoge[1])

if L > 0:
  erase_apple = 0
elif L+N >= 0:
  for i in range(N+1):
    if i + L == 0:
      erase_apple = i
      break
else:
  erase_apple = N-1

if erase_apple == N:
  erase_apple = N-1

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

apples.pop(erase_apple)
print(sum(apples))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
list = [0]*N
list_abs = [0]*N
for i in range(N):
    list[i] = L+i
    list_abs[i] = abs(L+i)
index = sorted(range(N), key=lambda k: list_abs[k])
list.pop(index[0])
print(sum(list))

Submission status: Accepted

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

aji = [0] * N
aji2 = [0] * N
flag = 0

for i in range(N):
    aji[i] = L + (i+1) - 1
    aji2[i] = abs(aji[i])
    if aji[i] >= 0:
        flag = 1

if flag == 0:
    print(sum(aji) + min(aji2))
else:
    print(sum(aji) - min(aji2))

Submission status: Accepted

Solution code:
array = input().split(' ')

n = int(array[0])
ll = int(array[1])

sum_n = 0
have_zero = False
for i in range(n):
    sum_n += ll + i
    if sum_n == 0:
        have_zero = True

if have_zero:
    print(sum_n)
else:
    if ll >= 0:
        print(sum_n - ll)
    else:
        print(sum_n - (n + ll - 1))

Submission status: Accepted

Solution code:
import numpy as np

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

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

abs_aji = [abs(a) for a in aji]
index = np.argmin(abs_aji)
aji.pop(index)

print(sum(aji))

Submission status: Accepted

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

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

# 0が含まれるか
if 0 in aji:
  print(sum(aji))

# 正の数か
elif sum(aji) > 0:
  print(sum(aji[1:]))
  
else:
  print(sum(aji[:-1]))

Submission status: Accepted

Solution code:

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

for i in range(N):
    i += 1

    lis.append(L + i - 1)

#print (lis)

mini = 0


for i in range(len(lis)):

    j = max(lis[i],-lis[i])
    k = max(lis[mini],-lis[mini])
        
    if i == 0 or k >= j:

        mini = i
    
        
        #print ("最小は",lis[i],i)



ans = 0
for i in range(len(lis)):

    if i != mini:
        ans += lis[i]
   

print (ans)

Submission status: Accepted

Solution code:
import numpy as np

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

aji = []
for i in range(n):
    aji.append(L + i)

sa = 1000
for i in range(len(aji)):
    tmp = aji[i]
    if abs(tmp) <= abs(sa):
        sa = tmp
        idx = i

sum_ = np.sum(aji)
ans = sum_ - sa

# min_ab_aji = np.min(np.abs(aji))
# sum_ = np.sum(aji)
# ans = sum_ - min_ab_aji

print(ans)

Submission status: Accepted

Solution code:
n,l=list(map(int,input().split(" ")))
t=sum(range(l,l+n))
tmax=l+n-1
if l<0:
    if tmax>0:
        print(t)
    else:
        print(t-tmax)
else:
    print(t-l)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

minv = 1000
for i in range(N):
    if abs(minv) > abs(L+i):
        minv = L+i

s = sum([L+i for i in range(N)])
print(s-minv)

Submission status: Accepted

Solution code:
import numpy as np
n, l = map(int, input().split())
r = np.arange(l, n + l)
print(r.sum() - r[np.abs(r).argmin()])

Submission status: Accepted

Solution code:
n, l = (int(x) for x in input().split())
a = [0]*n
for i in range(n):
    a[i] = l + i

b = [i ** 2 for i in a]
index = b.index(min(b))

print(int(n * l + n*(n+1)/2 - n - a[index]))

Submission status: Accepted

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

apples = []
minval = 200

for i in range(n):
    apples.append(i+l)

for i in apples:
    minval = min(minval, abs(i))

for i in apples:
    if minval == abs(i):
        print(sum(apples)-i)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
true_sum = 0
false_sum = 0

for i in range(n):
    true_sum += l+i

for j in range(n):
    tmp = 0
    for k in range(n):
        if k == j:
            continue
        else:
            tmp += l+k
    if abs(tmp - true_sum) < abs(false_sum - true_sum):
        false_sum = tmp

print(false_sum)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
import numpy as np
A=np.arange(L,L+N)
B=np.abs(A)
#print(B)
m=np.argmin(B)
#print(m)
#A.pop(A[2])
r=sum(A)-int(A[m])
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

def get_score(n):
    return L + n

score_total = 0
# select the apple to eat
for i in range(N):
    score_ = get_score(i)
    score_total += score_

if L >= 0:
    score_min = score_total - L
elif (L < 0) and (L + N <= 0):
    #print("2")
    score_min = score_total - get_score(N-1)
else:
    #print("3")
    score_min = score_total
print(score_min)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
T = [L + n for n in range(N)]
del_taste = []
for i in range(N):
    del_taste.append(sum(T) - T[i])
diff = []
for i in range(N):
    diff.append(abs(sum(T)-del_taste[i]))
print(del_taste[diff.index(min(diff))])

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
azi = 0
ls = []
for i in range(n):
    azi += l+i
    ls.append(abs(l + i))
if l + n-1 < 0:
    print(azi + min(ls))
else:
    print(azi - min(ls))

Submission status: Accepted

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

taste=0

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

elif abs(L) < N:
    for i in range(N):
        taste = taste + L + i

else:
    for i in range(N-1):
        taste = taste + L + i
    
        
        
print(taste)

Submission status: Accepted

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

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


print(sum)

Submission status: Accepted

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

true_pie = (2 * L + N - 1) * N // 2
min_diff = None
answer = None
for i in range(1, N + 1):
    apple = L + i - 1
    pie = (2 * L + N - 1) * N // 2 - apple
    diff = abs(true_pie - pie)
    
    if (min_diff is None) or (diff <= min_diff):
        min_diff = diff
        answer = pie

print(answer)

Submission status: Accepted

Solution code:
n,L=(int(i) for i in input().split())

mylist=[i+1 for i in range(n)]

maxval=0
for i in range(n):
  maxval+=L+mylist[i]-1
  
#print(maxval)

ans=float('inf')
for i in range(n):
  mylist=[i+1 for i in range(n)]
  tmp=0
  del mylist[i]
  for i in range(n-1):
    tmp+=L+mylist[i]-1
  tmp2=abs(maxval-tmp)
  if tmp2<ans:
    ans=tmp2
    ans2=tmp
    
print(ans2)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=0
b=300
c=300
for i in range(1,n+1):
    b=min(abs(b),abs(l+i-1))
    if c>b:
        c=b
        d=i
    a+=(l+i-1)
if l+d-1>=0:
    print(a-b)
else:
    print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
dat = [];ans = []
for i in range(n):
  dat += [abs(l+i)]
  ans += [l+i]

i = dat.index(min(dat))

print(sum(ans[:i])+sum(ans[i+1:]))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, L= map(int, input().split())

n = np.arange(N) + L
ab = np.abs(n)
min_index = np.argmin(ab)

print(np.sum(n) - n[min_index])

Submission status: Accepted

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

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

m=min(s_list,key=abs)
ans=sum(s_list)-m
print(ans)

Submission status: Accepted

Solution code:
inp = list(map(int, input().split()))

N = inp[0]
L = inp[1]

start = L
sum = 0
max_min = 99999999999
for i in range(N):
    x = start + i
    sum += x
    max_min = min(abs(x), max_min)

if sum < 0:
    sum += max_min
else:
    sum -= max_min

print(sum)
# print(max_min)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())  # N個のりんご, 味の根拠L

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

apple_pie = sum(Apples)

min_apple = 99999999999999
for i in range(len(Apples)):
    if min_apple > abs(Apples[i]):
        min_apple = abs(Apples[i])
        if Apples[i] > 0:
            flag = True
        else:
            flag = False

if flag:
    print(apple_pie - min_apple)
else:
    print(apple_pie + min_apple)

Submission status: Accepted

Solution code:

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

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

Taste.sort()

if 0 in Taste:
    ans = sum(Taste)
    print(ans)
    exit(0)


T_max = sum(Taste)
T_sum1 = sum(Taste[1:])
T_sum2 = sum(Taste[:-1])
if abs(T_max - T_sum1) < abs(T_max - T_sum2):
    ans = T_sum1
else:
    ans = T_sum2

print(ans)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
aji=[]
m = 1000
for i in range(a[0]):
    aji.append(a[1]+i)
    if abs(m)>=abs(aji[i]):
        m=aji[i]
sum1 = sum(aji)
print(sum1-m)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())

c=[]

for i in range(a):
    c.append(i+b)

d=sum(c)
dif=99999
f=99999
for j in c:
    e=d-j
    if abs(d-e)<dif:
        dif=abs(d-e)
        f=j
print(d-f)

Submission status: Accepted

Solution code:
n,l=[int(k) for k in input().split(" ")]

res=sum(range(l,n+l))
if l<0:
    res-=min(0,l+n-1)
else:
    res-=l

print(res)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
N,L = [int(x) for x in stdin.readline().rstrip().split()]
aji = [0] * (N)
for i in range(N):
    aji[i] = i + L
min_aji = 100000
min_ = 0
for k in aji:
    if abs(k) < min_aji:
        min_aji = abs(k)
        min_ = k
ans = sum(aji) - min_
print(ans)

Submission status: Accepted

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

b = [i for i in range(l,n+l)]
# print(b)
m = 1000
t = 1
for i in b:
    if m > abs(i):
        m = abs(i)
        if i<0:
            t = -1
        else:
            t = 1
print(sum(b)-m*t)

Submission status: Accepted

Solution code:
N,L=input().split()
A=[]
m=300
index=0
i=0
sum=0
for i in range(int(N)):
    A.append(int(L)+i)
    if abs(m)>abs(int(A[i])):
        m=int(A[i])
        index=i
for j in range(int(N)):
    if index==j:
        continue
    sum=sum+A[j]
print(sum)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s=0
syou = l
for i in range(0,n):
    ss = l+i
    s+=ss
    if ss*ss < syou*syou:
        syou=ss
s-=syou
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

alist = []
testlist = []
for i in range(n):
    if i == 0:
        alist.append(l)
        testlist.append(abs(l))
    else:
        alist.append(l+i)
        testlist.append(abs(l+i))
k = testlist.index(min(testlist))
alist.pop(k)
print(sum(alist))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
list_ = [L + i - 1 for i in range(1, N + 1)]
min_ = min(list_)
max_ = max(list_)
sum_ = sum(list_)

if min_ >= 0:
    print(sum_ - min_)
elif max_ <= 0:
    print(sum_ - max_)
else:
    print(sum_)

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int,input().split())
s = []
for i in range(N):
    s.append(L+i)
ans_pre = abs(np.array([s]))
if L + N <= 0:
    print(-1*(sum(ans_pre[0])-min(ans_pre[0])))
else:
    print(sum(s)-min(ans_pre[0]))

Submission status: Accepted

Solution code:
import math
n,l = map(int,input().split())
ans=0
min=9999
for i in range(n):
    ans+=l+i
    a=int(math.fabs(l+i))
    if int(math.fabs(min))>a:
        min=l+i
print(ans-min)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
# S=list(input())
# pre_i=-1
# result="Good"
# for i in S:
#     if i==pre_i:
#         result="Bad"
#         break
#     else:
#         pre_i=i
# print(result)
temp=list(map(lambda x:int(x),input().split()))
N,L=temp[0],temp[1]

pie_aji_n=0

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

apples_aji=[]
for nuki in range(1,N+1):
    pie_aji_temp=0
    for i in range(1,N+1):
        if i==nuki:continue
        else:pie_aji_temp+=L+i-1
    apples_aji.append(pie_aji_temp)
best=1000000
for a in apples_aji:
    kyori=(pie_aji_n-a)**2
    if kyori<(pie_aji_n-best)**2:
        best=a

print(best)

Submission status: Accepted

Solution code:
def A(test=None):

    if test:
        pass
    else:
        S = input()

    continuous = 0
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            continuous += 1

    if continuous > 0:
        answer = 'Bad'
    else:
        answer = 'Good'

    print(answer)


def B(test=None):

    if test:
        N, L = test
    else:
        N, L = map(int, input().split())

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

    if L <= 0:
        ate = min(0, L + N - 1)
    else:
        ate = max(0, L)

    print(_sum - ate)

def main():
    # A()
    B()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
sum_n = 0
for i in range(N):
    sum_n += (L + i)
mini = 9999
for i in range(N):
    # print("test", abs(L+i))
    if abs(L + i) <= abs(mini):
        mini = (L + i)
# print(mini)
print(sum_n - mini)

Submission status: Accepted

Solution code:
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
def ddprint(x):
  if DBG:
    print(x)

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

Submission status: Accepted

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

all = N * L + (N - 1) * N // 2
eat = float("inf")
for i in range(N):
  if abs(L + i) < abs(eat):
    eat = L + i
print(all - eat)

Submission status: Accepted

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

A.sort()

Ans=999
x=0
for n in range(N):
  if abs(A[n])<Ans:
    Ans=abs(A[n])
    x=A[n]

print(sum(A)-x)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# input
n, l = map(int, input().split())
o = [l+i-1 for i in range(1, n+1)]
oabs = [abs(l+i-1) for i in range(1, n+1)]
# calc
# output
o.pop(oabs.index(min(oabs)))
print(sum(o))

Submission status: Accepted

Solution code:

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

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

ans = 100000000

for i in a:
    ans = min(ans, abs(i))

if ans in a:
    print(sum(a)-ans)
else:
    print(sum(a)+ans)

Submission status: Accepted

Solution code:
n, l = (int(_) for _ in input().split())
mi = 100000
ans = 0

for i in range(n):
    fla = l + i
    if abs(fla) < mi:
        minus = False
        mi = abs(fla)
        if abs(fla) != fla:
            minus = True
    ans += fla

if ans < 0:
    if minus:
        print(ans + mi)
    else:
        print(ans - mi)
else:
    print(ans - mi)

Submission status: Accepted

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

apples = []

m = abs(L)
ind = 0

for i in range(N):
    apples.append(L+i)
    if m > abs(L+i):
        m = abs(L+i)
        ind = i
        
apples.remove(apples[ind])

print(sum(apples))

Submission status: Accepted

Solution code:
from sys import stdin

N, L = map(int,stdin.readline().rstrip().split())

taste=0
absMin=1000
min=1000
for i in range (L,L+N,1):
  if abs(i) < absMin:
    absMin=abs(i)
    min=i
  taste+=(i)
  
print(taste-min)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
sum = 0
flag0 = False
notallminus = False
for i in range(L, N+L):
    sum += i
    if i == 0:
        flag0 = True
    elif i > 0:
        notallminus = True
    else:
        pass

if flag0 is True and notallminus is True:
    print(sum)
elif flag0 is False and notallminus is True:
    print(sum - L)
else:
    print(sum - (N+L-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
array=[l+i-1 for i in range(1,n+1)]
f = sum(array)
closest = -10 ** 100
for i in range(n):
    tmp = [t for t in array]
    del tmp[i]
    if abs(f - sum(tmp)) < abs(f - closest):
        closest = sum(tmp)
print (closest)

Submission status: Accepted

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

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

if all([i > 0 for i in T]):
    print(sum(T)-min(T))
elif any([i==0 for i in T]):
    print(sum(T))
else:
    print(sum(T)-max(T))

Submission status: Accepted

Solution code:
K,L = map(int,input().split())
apple = [i for i in range(L,L+K)]
apple.sort(key=lambda x:abs(x))
print(sum(apple[1:]))

Submission status: Accepted

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

aji = []
abs_min_aji = abs(l)
abs_min_aji_i = 0
for i in range(n):
    v = l + i+1 - 1
    aji.append(v)
    if abs_min_aji > abs(v):
        abs_min_aji = abs(v)
        abs_min_aji_i = i

print(sum(aji)-aji[abs_min_aji_i])

Submission status: Accepted

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

tmp = L+N-1
tmp_ind = 0
taste = []
for i in range(N):
  taste.append(L+int(i))

for j in range(N):
  if abs(taste[j]) < tmp:
    tmp = abs(taste[j])

print(sum(taste)-tmp)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
L = [i+l for i in range(n)]
mi = min(L)
if 0 in L:
  print(sum(L))
elif mi>0:
  print(sum(L)-min(list(map(abs,L))))
else:
  print(sum(L)+min(list(map(abs,L))))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
list_apple=[] # 0 index is i1
eat_taste=300 
for i in range(N):
    taste=L+i-1+1
    list_apple.append(taste)
    #print(abs(taste))
    if abs(eat_taste)>=abs(taste):
        eat_taste=taste
    
print("{}".format(sum(list_apple)-eat_taste))