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:
n, l = map(int, input().split())
apple = [i for i in range(l, l+n)]
total = sum(apple)

ans = float('inf')
ans2 = 0
for i in range(n):
    tmp = total - apple[i]
    if ans > abs(total - tmp):
        ans = abs(total - tmp)
        ans2 = tmp

print(ans2)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
aji = [L+i for i in range(N)]
#print(aji)
total = sum(aji)
#print(total)

eat = 1000
j=0
for i in range(N):
  if eat > abs(aji[i]):
    eat = abs(aji[i])
    # eat  は正の値

if min(aji) >0:
  print(total-eat)
else:
  print(total+eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import accumulate

def solve():
    N, M = map(int, input().split())
    l = []
    for i in range(N):
        l.append(M + i)
    
    s = list(accumulate(l))
    
    if 0 in l:
        return s[-1]

    if M >= 0:
        return s[-1] - s[0]
    else:
        return s[-1] - l[-1]
    
print(solve())

Submission status: Accepted

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

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

z = [abs(i) for i in y]
zi = z.index(min(z))

ans = 0
for i,name in enumerate(y):
    if i == zi: continue
    ans += name

print(ans)

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, L = lr()
total = sum(range(L, L+N))
sub = min(range(L, L+N), key=abs)
print(total-sub)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
t = list(range(l, l + n))
s = [abs(_) for _ in t]
print(sum(t) - t[s.index(min(s))])

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, L = lr()
A = np.arange(1, N+1)
A += (L - 1)
answer = A.sum() - A[np.argmin(np.abs(A))]
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apple = [0]*N
for i in range(N):
  apple[i] = L+i
sum = sum(apple)  
ans = float("INF")
k = -1
for j in range(N):
  sub = abs(sum - (sum - apple[j]))
  if ans > sub:
    ans = sub
    k = j
print(sum - apple[k])

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, l = list(map(int,ipti().split()))
    a = [i+l for i in range(n)]

    if l > 0:
        print(sum(a[1:]))
    elif (n - 1) >= abs(l):
        print(sum(a))
    else:
        print(sum(a[:n-1]))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

abs_min = float('Inf')
for i in apple:
    if abs(i) < abs(abs_min):
        abs_min = i

apple.remove(abs_min)
print(sum(apple))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = list(range(1, N+1))
ans = 0
saisyo = float("inf")
saidai = -float("inf")
for i in range(N):
    x = A[i] + L-1 
    saisyo = min(x, saisyo)
    saidai  = max(x, saisyo)
    ans += x
if saidai < 0:
    print(ans-saidai)
elif saidai >= 0 and saisyo <= 0 :
    print(ans)
else:
    print(ans-saisyo)

Submission status: Accepted

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

ans=0
t=[]

for i in range(n):
  ans+=l+i
  t.append(l+i)

t.sort(key=lambda x:abs(x))
print(ans-t[0])

Submission status: Accepted

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

ans=0
min_a=10**9
for i in range(n):
  ans+=l+i
  if abs(min_a)>abs(l+i):
    min_a=l+i
print(ans-min_a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
s = 0
m = 10**3
for i in range(n):
  s += l+i
  if abs(m) > abs(l+i):
    m = l+i
print(s-m)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
diff_min = 100 + 200 - 1
apples = list()
remove_apple = 0

for i in range(N):
    taste = L + i
    apples.append(taste)
    if abs(taste) < diff_min:
        diff_min = abs(taste)
        remove_apple = taste

print(sum(apples) - remove_apple)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,L=list(map(int,input().split()))
l=[]
for i in range(1,n+1):
    l.append(L+i-1)
m=abs(l[0])
t=l[0]
for i in range(1,len(l)):
    if abs(l[i])<m:
        m=abs(l[i])
        t=l[i]

print(sum(l)-t)

Submission status: Accepted

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

Submission status: Accepted

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

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

if a[-1] >= 0:
  print(sum(a) - min(b))
else:
  print(sum(a) + min(b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    N, L = map(int, input().split())
    Ns = np.array(range(1, N+1)) + L - 1
    abs_Ns = np.where(Ns < 0, Ns*-1, Ns)
    eat_indx = np.where(abs_Ns == np.min(abs_Ns))[0][0]
    ans = np.sum(np.delete(Ns, eat_indx, 0))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
azi = float("inf")
for i in range(N):
    ans += L + i
    if abs(azi) > abs(L + i):
        azi = L + i

ans -= azi

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = []
for i in range(N):
  taste.append(L+i)
if L>=0:
  eat = min(taste)
else:
  eat = (-1)*min(list(map(abs,taste)))

print(sum(taste)-eat)

Submission status: Accepted

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

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

eat = float('inf')
for a in apples:
  eat = a if abs(a)< abs(eat) else eat
  

print(sum(apples) - eat)

Submission status: Accepted

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

py=0
lostpy=0

for i in range(1,N+1):
  py=py+(L+i-1)
tmp=10000000
ans=0
for i in range(1,N+1):
  lostpy=py-(L+i-1)
  if abs(py-lostpy) < tmp:
    ans=lostpy
    tmp=abs(py-lostpy)
print(ans)

Submission status: Accepted

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

yotei = sum(a)

if 0 in a:
    print(yotei)
    exit()

if abs(a[0]) < abs(a[n-1]):
    print(yotei-a[0])
else:
    print(yotei-a[n-1])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans=[]
sum=0
for i in range(n):
    ans.append([abs(l+i),l+i])
    sum+=l+i
ans.sort()
print(sum-ans[0][1])

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
ans = 0
min = 99999999
for i in range(1, N+1):
  t = L + i - 1
  if abs(t) < abs(min) : min = t
  ans += t
ans -= min
print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
a = list()
ans = 0
wa = 0
for i in range(1,N+1):
    a.append(L+i-1)
    ans += L+i-1
mi = 10**7
for i in range(N):
    if abs(a[i]) < mi:
        mi = abs(a[i])
        wa = a[i]
print(ans-wa)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=[l+i for i in range(n)]
b=[abs(l+i)for i in range(n)]
b.sort()
m=b[0]
if not m in a:m*=-1
print(sum(a)-m)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mm = []
for i in range(n):
    mm.append(l + i)
mn = 10 ** 100
a = -1
for i in mm:
    if mn > abs(i):
        mn = abs(i)
        a = i
print(sum(mm) - a)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N,L = [ int(s) for s in input().split() ]
    pie_all = 0
    pie_taste = [0]* N
    for i in range(N):
        pie_taste[i] = L + (i+1) -1
        pie_all += pie_taste[i]

    min_index = 0
    min_value = 100000000000
    pie_mean = pie_all / N
    for i in range(N):
        if min_value > abs(pie_taste[i]):
            min_index = i
            min_value = abs(pie_taste[i])

    print(pie_all - pie_taste[min_index])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

n_sum = (l*n)+sum(list(range(1,n+1)))-n
ans = n_sum

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

Submission status: Accepted

Solution code:
# B - Bite Eating

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

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

mi = 200+100

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

print(w-mi)

Submission status: Accepted

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


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


m = 10 ** 12
k = 10 ** 12
for i in range(n):
    diff = abs(x[i])
    if m >= diff:
        m = diff
        k = x[i]

        
print(sum(x) - k)

Submission status: Accepted

Solution code:
import math
import itertools
import statistics
#n = int(input())
n, l = list(map(int, input().split()))
total = 0
for i in range(1, n+1):
    total += (l+i-1)
    #print(l+i-1)
total2 = total

m = abs(total)
for i in range(1, n+1):
    if abs(total-(total2-(l+i-1))) < m:
        m = abs(total-(total2-(l+i-1)))
        #print(total2-(l+i-1))

#print(total)
#print(total2)
#print(m)
if total > 0:
    print(total2-m)
else:
    print(total+m)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
li=[]
ans=0
for i in range(n):
  li.append(i+l)
  ans+=i+l
for i in range(n):
    li[i]=abs(li[i])
if ans<0:
  print(ans+min(li))
else:
  print(ans-min(li))

Submission status: Accepted

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

n_sum = (l*n)+sum(list(range(1,n+1)))-n
ans = n_sum

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

print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
a = list()
ans = 0
wa = 0
for i in range(1,N+1):
  a.append(L+i-1)
  ans += L+i-1
mi = 10**7
for i in range(N):
  if abs(a[i]) < mi:
    mi = abs(a[i])
    wa = a[i]
print(ans-wa)

Submission status: Accepted

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

if l >= 0:
    print(sum(taste)-taste[0])
elif l+n-1 < 0:
    print(sum(taste)-taste[-1])
else:
    print(sum(taste)-taste[-l])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
aji = [l + i for i in range(n)]
Sum = sum(aji)
# print(Sum)
dif = float('inf')
# print(aji)
for a in aji:
    SSum = Sum - a
    # print(SSum, Sum, dif,  Sum - SSum)
    if abs(Sum - SSum) < dif:
        dif = abs(Sum - SSum)
        ans = SSum
    
print(ans)
# abs_aji = []
# for a in aji:
#     abs_aji.append(abs(a))
# abs_aji.sort()
# print(abs_aji)
# print(aji)

# ans = sum(aji)
# if abs_aji[0] < 0:
#     ans += abs_aji[0]
# else:
#     ans -= abs_aji[0]
# print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n, l = map(int, input().split())
data = [l] * n
ans = 0

for i in range(n):
    data[i] += i
    ans += data[i]

mini = abs(data[0])
temp = data[0]

for i in range(n):
    if mini > abs(data[i]):
        mini = abs(data[i])
        temp = data[i]

print(ans - temp)

Submission status: Accepted

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

A = []
min_app = 100100100100
for i in range(1, N+1):
    app = L + i - 1
    A.append(app)
    if abs(min_app) > abs(app):
        min_app = app
print(sum(A) - min_app)

Submission status: Accepted

Solution code:
from sys import stdin

n, l = (int(x) for x in stdin.readline().rstrip().split())
t = [l+i-1 for i in range(1, n+1)]
if 0 in t:
    print(sum(t))
else:
    if sum(t) < 0:
        t.pop(-1)
        print(sum(t))
    else:
        t.pop(0)
        print(sum(t))

Submission status: Accepted

Solution code:
#131_B
n,l=map(int,input().split())
a=[l+i for i in range(n)]
a_abs=[abs(l+i) for i in range(n)]
s=(2*l+n-1)*n//2
print(s-a[a_abs.index(min(a_abs))])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
taste = [l+i-1 for i in range(1, n+1)]
sm = sum(taste)
mn = 10**4
ans = 0
for i in range(n):
  if abs(sm - (sm-taste[i])) < mn:
    mn = abs(sm - (sm-taste[i])) 
    ans = sm-taste[i]
print(ans)

Submission status: Accepted

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

tastes = [L + i for i in range(N)]
print(sum(tastes) - min(tastes, key=abs))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=[]
for i in range(n):
    a.append(i+l)
x=10**10
for i in range(n):
    if abs(a[i])<x:
        x=abs(a[i])
        y=a[i]

print(sum(a)-y)

Submission status: Accepted

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

allpie = 0
for i in range(n):
    a = l+(i+1)-1
    allpie += a
    if i == 0:
        t = abs(a)
        num = i
    elif t > abs(a):
        t = abs(a)
        num = i
# print(t)
# print(num)
print(allpie-(l+(num+1)-1))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
sum=k
tmp=k
for i in range(1,n):
  sum+=k+i
  if abs(tmp)>abs(k+i):
    tmp=k+i
print(sum-tmp)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = 0
t = L
for i in range(0, N):
    s = s+L+i
    if abs(t) > abs(L+i):
        t = L+i
print (s-t)

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n , l = IN()
	al = [l+i-1 for i in range(1,n+1)]
	al=sorted(al, key = lambda v : abs(v))
	ret = sum(al)-al[0]
	#pa(al[0])
	print(ret)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

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

ans=0
mn=10**9
for i in range(n):
        sm=0
        for j in range(n):
                if i==j:
                        continue
                sm+=l+j
        dif = abs(org-sm)
        if mn > dif:
                ans=sm
                mn=dif
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

if L * L_max <= 0:
    print(ans)
elif ans > 0:
    print(ans - L)
else:
    print(ans - L_max)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
import bisect
A = [i+L for i in range(N)]
ans = sum(A)-A[min(bisect.bisect_left(A,0),len(A)-1)]
print(ans)

Submission status: Accepted

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

apples = [l + i for i in range(n)]
taste = sum(apples)
apple_min = 1000
for i in range(n):
    if abs(apples[i]) < abs(apple_min):
        apple_min = apples[i]
taste -= apple_min
print(taste)

Submission status: Accepted

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

p = [0]*n
for i in range(n):
  p[i] = l + (i + 1) - 1

s = p[0]
for i in p:
  if abs(i) < abs(s):
    s = i

print(sum(p) - s)

Submission status: Accepted

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

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

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

print(s-eat)

Submission status: Accepted

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

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

min_diff = 1000
min_taste = 0
for i in range(N):
    apple = L + i
    diff = abs(apple)
    if min_diff > diff:
        min_diff = diff
        min_taste = total - apple

print(min_taste)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

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

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
n, l = [int(i) for i in input().split()]
lst = [(i + 1 + l - 1) for i in range(n)]
lst_abs = [abs(i) for i in lst]
idx = lst_abs.index(min(lst_abs))
print (sum(lst[0:idx] + lst[idx + 1:]))

Submission status: Accepted

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

b = n + a - 1
s = (a + b) * n // 2

if a * b <=  0: 
    print(s)
else: 
    print(s - a) if s > 0 else print(s - b)

Submission status: Accepted

Solution code:
N, L = [int(s) for s in input().split(' ')]
ret = 0
start = L + 1 - 1
end = L + N - 1
if start * end <= 0:
    ret = [L + i - 1 for i in range(1, N + 1)]
elif start < 0:
    ret = [L + i - 1 for i in range(1, N)]
else:
    ret = [L + i - 1 for i in range(2, N + 1)]

print(sum(ret))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a, b = sorted([l, l + n - 1])
print(sum(range((a + 1 if a > 0 else a),
                (b - 1 if b < 0 else b) + 1)))

Submission status: Accepted

Solution code:
import os, sys, re, math

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

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

apples.sort()
if apples[0] in apples2:
    print(sum(apples2) - apples[0])
else:
    print(sum(apples2) + apples[0])

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split(' ')))
m = 9999999999
apples = []
for i in range(n):
    if abs(m) > abs(i+l):
        m = i+l
    apples.append(i+l)
print(sum(apples) - m)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N_ko, L_aji = map(int, input().split())

taste = list(L_aji + i for i in range(N_ko))
taste.sort()

if (taste.count(0) > 0):
    ans = sum(taste)
elif (min(taste) > 0):
    ans = sum(taste[1:])
else:
    ans = sum(taste[:-1])

print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
a = [l+i for i in range(n)]
b = [abs(a[j]) for j in range(n)]
c = b.index(min(b))

print(sum(a)-a[c])

Submission status: Accepted

Solution code:
import numpy as np

N,L=map(int,input().split())
taste=list(range(L,L+N))
#print(sum(taste))
min_abs=10**5
for i in range(N):
    if abs(sum(taste)-(sum(taste)-taste[i]))<min_abs:
        min_abs=abs(taste[i])
        rec=taste[i]
        #print(rec)
        
        
print(sum(taste)-rec)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
Ringo = sum([i+L-1 for i in range(1,N+1)])
ans = 1e+09
for j in range(1,N+1):
  Ringo2 = sum([i+L-1 for i in range(1,N+1) if i != j])
  tem = abs(Ringo - Ringo2)
  ans = min(ans, tem)
print(Ringo-ans if Ringo > Ringo2 else Ringo+ans)

Submission status: Accepted

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

k = []

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

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

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

Submission status: Accepted

Solution code:
# min(, key=abs)ってやつがあるのか・・・
n,l = map(int, input().split())
ans = sum(range(l,l+n)) - min(range(l,l+n), key=abs)
print(ans)

Submission status: Accepted

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

def min_index(list):
    return [i for i, x in enumerate(list) if x == min(list)][0]

abs_ringo = [abs(i) for i in ringo]
ans = sum(ringo) - ringo[min_index(abs_ringo)]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

sa = abs(all_app-aji[0])
ans = 0
for i in aji:
    if abs(all_app - i) <= sa: #=も含める事でaji[0]についても考慮する
        sa = abs(all_app - i)
        ans = i

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

apple.sort(key=abs)
print(sum(apple)-apple[0])

Submission status: Accepted

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

aji_total = int(N * L + N * (N-1) / 2)
aji_min = L
aji_max = L + N - 1

ans = 0
if aji_min >= 0:
  ans = aji_total - aji_min
elif aji_max >= 0:
  ans = aji_total
else:
  ans = aji_total - aji_max

print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
l=range(L,L+N)
print(sum(l)-min(l,key=abs))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
cumulative=[L+i for i in range(N)]
print(sum(cumulative)-min(cumulative,key=abs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

d = [l + i for i in range(n)]
pre_d = sum(d)
mi = 100 * 200
for i in d:
    if i == 0:
        ans = pre_d
        break
    else:
        dif = abs(pre_d - (pre_d - i))
        if dif < mi:
            mi = dif
            ans = pre_d - i

print(ans)

Submission status: Accepted

Solution code:
#両端のりんごの味は、(L, L+N-1)
N, L = map(int, input().split())
sum_all = N*(L+((N+1)/2)-1)

if L*(L+N-1) <= 0:
  print(int(sum_all))
elif L < 0:
  print(int(sum_all - L - N + 1))
else:
  print(int(sum_all - L))

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
ans = 1000000000000000000000000000000
apple = 0
for i in range(1, x+1):
    apple += i+y-1
    ans = min(ans, abs(i+y-1))
#print(ans, apple)

if abs(apple-ans) <= abs(apple+ans):
    print(apple-ans)
else:
    print(apple+ans)

Submission status: Accepted

Solution code:


def readints():
    return list(map(int, input().split()))


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

Submission status: Accepted

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

ans=0
_list=[]
for i in range(n):
    _list.append(l+i)

min_index=0
_min=10**10

for i in range(n):
    if abs(_list[i])<=_min:
        min_index=i
        _min=abs(_list[i])

print(sum(_list[:min_index])+sum(_list[min_index+1:]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()

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

mi = INF
for i in range(N):
	if azi[i] < 0:
		d = azi[i]*-1
	else:
		d = azi[i]
	if d < mi:
		mi = d
		index = i

print(sum(azi[0:index]) + sum(azi[index + 1:N]))

Submission status: Accepted

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

ans=10**6
p=-1
for j in range(N):
  tmp = abs(L+j)
  if tmp < ans:
    ans = tmp
    p = j
print(taste -(L+p))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = [0 for i in range(n)]

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

apples.sort(key=lambda x: abs(x))
print(sum(apples[1:]))

Submission status: Accepted

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

Submission status: Accepted

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

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

tmp = [sum(tastes) - tastes[i] for i in range(n)]
tmp2 = [abs(sum(tastes)-v) for v in tmp]
print(tmp[tmp2.index(min(tmp2))])

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ls=[]
total=0
for i in range(1,N+1):
    total+=L+i-1
    v=abs(L+i-1)
    ls.append(v)
    x=min(ls)
    if L+i-1>=0:
        x=x
    else:x=-x
total=total-x
print(total)