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

t = [0]*N

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

m = 100
for i in range(N):
    t[i] = L + i
    
    if abs(t[i]) < abs(m):
        m = t[i]
print(S-m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
lst = list(range(l,l+n))
lst2 = []
for i in lst:
  if i > 0:
    lst2.append(i)
  else:
    lst2.append(-i)
x = sum(lst)-lst[lst2.index(min(lst2))]
print(x)

Submission status: Accepted

Solution code:
[N,L]=[int(_) for _ in input().split()]
A=[L+i for i in range(N)]
minabs=1000
for i in range(N):
    if abs(A[i])<minabs:
        eat=i
        minabs=abs(A[i])
A.pop(eat)
print(sum(A))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = [L+t for t in range(N)]
if L > 0:
    print(sum(apples[1:]))
elif N+L > 0:
    print(sum(apples))
else:
    print(sum(apples[:-1]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    N, L = map(int, input().split())
    total = sum(range(L, L+N))

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

    max_val = max([L, L + N - 1])
    max_abs_val = max_val if max_val > 0 else -max_val
    min_val = min([L, L + N - 1])
    min_abs_val = min_val if min_val > 0 else -min_val

    if max_abs_val < min_abs_val:
        print(total - max_val)
    else:
        print(total - min_val)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

S = []
min_value = int(1e9)
for i in range(N):
    S.append(L+i)
    if abs(min_value) > abs(L+i):
        min_value = L + i
    
print(sum(S) - min_value)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,l=map(int,input().split())
flg=0
ans=0
if l>=0:
    flg=1
else:
    if abs(l)<=n-1:
        flg=2

if flg ==0:
    for i in range(n-1):
        ans+=i+l
if flg==1:
    for i in range(1,n):
        ans+=i+l
if flg==2:
    for i in range(n):
        if i!=abs(l):
            ans+=i+l
print(ans)

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
ringo = [l+i for i in range(n)]
aji = 10**9
for j in ringo:
    if abs(j) <= aji:
        aji = abs(j)
        eat = j
print(sum(ringo)-eat)

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools

# いくつか入力
n,l = (int(i) for i in input().split())  

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

Submission status: Accepted

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

taste = [L + i for i in range(N)]
taste_abs = list(map(abs, taste))
min_abs_taste = min(taste_abs)
if min_abs_taste != 0 and L < 0:
  min_abs_taste *= -1

print(sum(taste)-min_abs_taste)

Submission status: Accepted

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

Submission status: Accepted

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

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

MIN = 10000000000
num = 0
for i in range(N):
    if MIN > abs(apple[i]):
        MIN = abs(apple[i])
        num = i
apple.pop(num)

print(sum(apple))

Submission status: Accepted

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

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


ajisum = sum(aji)

res = 0
minres = 999999999
for x in aji:
    if minres > abs(x):
        minres = abs(x)
        res = ajisum - x

print(res)

Submission status: Accepted

Solution code:
a,b=input().split()
a=int(a)
b=int(b)
z=a+b-1
ans=0
for i in range(b,z+1):
    ans+=i
    
if b<=0 and z>=0:
    print(ans)
elif z>=0:
    print(ans-b)
elif b<=0:
    print(ans-z)

Submission status: Accepted

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

Submission status: Accepted

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

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

min = 1000000000000000
min_val = 0
for i in range(1, N + 1):
	if min > abs(L + i - 1):
		min = abs(L + i - 1)
		min_val = L + i - 1
		
print(int(N_taste - min_val))

Submission status: Accepted

Solution code:
N, L = [int(n) for n in input().split()]
S = -L
if S < 0:
    S = 0
elif S >= N:
    S = N - 1

A = 0
for i in range(N):
    if i != S:
        A += L + i

print(A)

Submission status: Accepted

Solution code:
n, l=map(int, input().split())
ans=0
if l>=0:
    for i in range(2, n+1):
        ans=ans+l+i-1
else:
    if n+l>=1:
        for i in range(1, n+1):
            if not l+i-1==0:
                ans=ans+l+i-1
    else:
        for i in range(1, n):
            ans=ans+l+i-1

print(ans)

Submission status: Accepted

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

nearZero = -10000
tgt = 0
ajiSum = 0

for i in range(1,N+1):
    aji = L + i - 1
    ajiSum += aji
    if abs(nearZero) > abs(aji):
        nearZero = aji
        tgt = i
        
print(ajiSum - nearZero)

Submission status: Accepted

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

sum_taste = N * L + (N - 1) * N // 2
# print(sum_taste)
# print(sum_taste - L)
taste_chosen_applepie = None
cur_diff = float('inf')

for i in range(1, N + 1):
    taste_apple = L + i - 1
    taste_applepie = sum_taste - taste_apple
    diff = abs(taste_applepie - sum_taste)
    # print(taste_apple, taste_applepie, diff)
    if diff < cur_diff:
        # print("hoge")
        cur_diff = diff
        taste_chosen_applepie = taste_applepie
print(taste_chosen_applepie)

Submission status: Accepted

Solution code:

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

se=[]

for i in range(N):
    se.append(L+i)
#print(se)

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
aji = []
for i in range(n):
  aji.append(l+i)
eat = 1000
for i in aji:
  if abs(eat)>abs(i):
    eat=i
ans = sum([i for i in aji if i!=eat])
print(ans)

Submission status: Accepted

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

total = 0
min_abs = 114514
eat = 0
for i in range(1,N+1):
    taste = L+i-1
    total += taste
    if abs(taste) < min_abs:
        min_abs = abs(taste)
        eat = taste

total -= eat
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

ts = [L + i for i in range(N)]
target = abs(ts[0])
target_i = 0
for i, t in enumerate(ts):
    if target > abs(t):
        target = abs(t)
        target_i = i

ts.pop(target_i)
print(sum(ts))

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [L + i - 1 for i in range(1, N + 1)]
    ham = [abs(x) for x in spam]
    if min(ham) in spam:
        print(sum(spam) - min(ham))
    else:
        print(sum(spam) + min(ham))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin

n, l = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0
ll = range(l,l+n)
m = min(ll, key=abs)
ans = sum(ll) - m
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
azi = []
for i in range(N):
    azi.append(L+i)
azi.sort()
if L+1-1 >= 0:
    ans = sum(azi[1:])
elif L+N-1 < 0:
    ans = sum(azi[:-1])
else:
    ans = sum(azi)
print(ans)

Submission status: Accepted

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

a  = sum(val)
p = 10**9+7
for i in range(N):
    if abs(val[i]) < p :
        p = abs(val[i])
        q = val[i]
print(a-q)

Submission status: Accepted

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

mn = 100000000
ans = 0
for a in range(L, L+N):
    if abs(mn) > abs(a):
        mn = a
    ans += a
    
ans -= mn

print(ans)

Submission status: Accepted

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

Min = L
Max = L + N - 1
Pie =(2*L+N-1)*N//2

if Min * Max <= 0:
    print(Pie)
else:
    if Min > 0:
        print(Pie - Min)
    else:
        print(Pie - Max)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
key=0
Min=1000
for i in range(n):
    key+=l+i
    if abs(l+i)<abs(Min):
        Min=l+i
print(key-Min)

Submission status: Accepted

Solution code:
import numpy as np

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

apple = []

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

idx = np.abs(np.asarray(apple) - 0).argmin()
print(sum(apple) - apple[idx])

Submission status: Accepted

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

ans = 0
mina = 10**9
for i in range(N):
    tmp = T - L - i
    if mina > abs(tmp - T):
        ans = tmp
        mina = abs(tmp - T)
print(ans)

Submission status: Accepted

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

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


main()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
S = sum([L + i for i in range(N)])
result_d = 10 ** 9
result = 0
for i in range(N):
    r = S - (L + i)
    if abs(S - r) < result_d:
        result_d = abs(S - r)
        result = r
print(result)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ans = 1000000
s = sum(range(l, l + n))
for i in range(l, l + n):
    if ans > abs(s - (s - i)):
        ans = abs(s - (s - i))
        t = i
print(s - t)

Submission status: Accepted

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

loss = float('inf')
total = 0
for i in range(N):
    x = L + i
    total += x
    if abs(x) < abs(loss):
        loss = x
print(total - loss)

Submission status: Accepted

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

t = []
for i in range(N):
    t.append(L + i)
    
real = sum(t)

diff = 1e10
ans = 0
for i in range(N):
    pred = sum(t) - t[i]
    if abs(pred - real) <= diff:
        diff = abs(pred - real)
        ans = pred
        
print(ans)

Submission status: Accepted

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

A = [0]*N
sm = 0
m = -100
for i in range(N):
    A[i] = L+i
    sm+= L+i
    if L+i == 0:
        m = i 

if m >=0:
    print(sm)
elif L > 0:
    print(sm-A[0])
elif L+N-1 <0:
    print(sm-A[-1])

Submission status: Accepted

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

t=[]
sum=0
min=10**10
for i in range(n):
    sum+=l+i
    if abs(min)>abs(l+i):
        min=l+i

print(sum-min)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
apples = [l+i for i in range(n)]
sumap = sum(apples)
minap=10**9
diff=10**9
for ap in apples:
	if abs((sumap-ap)-sumap)<=diff:
		diff = abs((sumap-ap)-sumap)
		minap = ap
print(sumap-minap)

Submission status: Accepted

Solution code:
import sys

def main():
    N,L = map(int, input().split())
    apples = [L+i-1 for i in range(1,N+1)]
    mmin = sys.maxsize
    allsum = sum(apples)
    ans = 0
    for i in range(N):
        tmpsum = sum(apples[:i])
        if i != N-1:
            tmpsum += sum(apples[i+1:])
        tmp = abs(allsum-tmpsum)
        if tmp < mmin:
            mmin = tmp
            ans = tmpsum
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#ABC131B

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

azi = 0
for l in range(L, L+N):
    azi += l

azi_l = L
azi_r = L+N-1

if ( azi_l * azi_r < 0):
    azi_min = 0
else:
    if (abs(azi_l) < abs(azi_r)):
        azi_min = azi_l
    else:
        azi_min = azi_r

azi = azi - azi_min
print(azi)

Submission status: Accepted

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

l = []
tmp = 1000000
ans_tmp = 0

for i in range(N):
    l.append(L+i)
    if(abs(l[i]) < tmp):
        tmp = abs(l[i])
        ans_tmp = l[i]



ans = sum(l) - ans_tmp
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
taste = [L+i for i in range(N)]
taste = np.array(taste)
print(sum(taste) - taste[np.argmin(np.abs(taste))])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
tastes = [L + i - 1 for i in range(1, N+1)]
apple_eaten = min([abs(t) for t in tastes])
if apple_eaten in tastes:
    print(sum(tastes) - apple_eaten)
else:
    print(sum(tastes) + apple_eaten)

Submission status: Accepted

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

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

eat = aji_abs.index(min(aji_abs))

ans = 0
for i in range(N):
    if i != eat:
        ans += aji[i]

print(ans)

Submission status: Accepted

Solution code:
def main():
     n,l=map(int,input().split())
     a=[l+i-1 for i in range(1,n+1)]
     a.sort(key=lambda x:abs(x) )
     print(sum(a[1:]))
     
if __name__=='__main__':
     main()

Submission status: Accepted

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

s = (l + n - 1) * (l + n) // 2 - (l - 1) * l // 2

if l <= 0 and l + n > 0:
    eat = 0
else:
    if l < 0:
        eat = l + n - 1
    else:
        eat = l

print(s - eat)

Submission status: Accepted

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

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

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

print(sum)

Submission status: Accepted

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

apples = [L+i for i in range(N)]
apples_abs = list(map(abs,apples))
print(sum(apples)-apples[apples_abs.index(min(apples_abs))])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ll=[]
lll=[]
mi=False
for i in range(1,n+1):
    ll.append(l+i-1)
    lll.append(abs(l+i-1))
    if (l+i-1)<0:
        mi=True
if 0 in ll:
    print(sum(ll))
elif mi:
    print(sum(ll)+min(lll))
else:
    print(sum(ll)-min(ll))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L+i for i in range(N)]
k = 0
for i in range(N):
    if abs(A[i]) < abs(A[k]):
        k = i
print(sum(A)-A[k])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = list(range(L, L+N))
s = sum(apples)
print(s - sorted(apples, key=lambda x:abs(x))[0])

Submission status: Accepted

Solution code:
from sys import exit
INF = 10**21
N, L= [int(n) for n in input().split()]
apples = [L +i - 1 for i in range(1,N+1)]
ans = INF
val = INF
# print(apples)
for i in range(N):
    eat = apples[i]
    tmp = abs(eat)
    if tmp < val:
        ans = sum(apples) - eat
        val = tmp
print(ans)

Submission status: Accepted

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

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

s = sum(t)

a = sorted([ (abs(i), i) for i in t ], key=lambda b: b[0])[0][1]

print(s - a)

Submission status: Accepted

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

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

if L + N - 1 < 0:
    print(sums - (L + N - 1))

elif L > 0:
    print(sums - L)

else:
    print(sums)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B

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

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

if azi_list[0]<=0 and azi_list[-1]>=0:
#     print(1)
    print(sum(azi_list))
elif abs(azi_list[0]) < abs(azi_list[-1]):
#     print(2)
    print(sum(azi_list[1:]))
else:
#     print(3)
    print(sum(azi_list[:-1]))

Submission status: Accepted

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

sc=l*(n+l-1)
eat=0

if sc>0:
    if l>0:
        eat=l
    else:
        eat=n+l-1

taste=0
for app in range(n):
    taste+=app+l

print(taste-eat)

Submission status: Accepted

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

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

eat_apple = aji[less_effect.index(min(less_effect))]

ans = sum(aji) - eat_apple

print(str(ans))

Submission status: Accepted

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

mini = 10000
eat = 0
for i in apple:
    if mini > abs(i):
        eat = i
        mini = abs(i)


print(sum(apple)-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getFlavour(eat):
    ret = 0
    for i in range(1, n + 1):
        if i != eat:
            ret += l + i - 1
    return ret

n, l = map(int, input().split())
orig = getFlavour(0)
flavour = diff = float('inf')
for eat in range(1, n + 1):
    curFlavour = getFlavour(eat)
    curDiff = abs(orig - curFlavour)
    if curDiff < diff:
        diff = curDiff
        flavour = curFlavour
print(flavour)

Submission status: Accepted

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

Submission status: Accepted

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

a = []
min_v = float('inf')
min_i = 0
for i in range(N):
    value = L + i
    if abs(value) < min_v:
        min_v = abs(value)
        min_i = i
    a.append(value)

newa = a[:min_i] + a[min_i+1:]

print(sum(newa))

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_b

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

a = list(range(l,l+n))
b = []
for i in range(len(a)):
    b.append(abs(a[i]))
c = b.index(min(b))

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

Submission status: Accepted

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

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

c = float("inf")
ans = 0
for i in range(1 , n+1):
  taste = l + i - 1
  a = sum - taste
  x = abs(sum - a)
  if x < c:
    c = x
    ans = a
print(ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans=0
chk=10000
for i in range(n):
    ans+=i+l
    if abs(chk)>abs(i+l):
        chk=i+l
print(ans-chk)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

N, L = [int(x) for x in stdin.readline().rstrip().split()]

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = 0
for i in range(1, n + 1):
    s += l + i - 1
 
x = 1 - l
if x <= n and x >= 1:
    print(s)
else:
    a = l
    b = l + n - 1
    if abs(a) < abs(b):
        print(s - a)
    else:
        print(s - b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
ls = [x + l - 1 for x in range(1,n+1)]
c = 10000000000;check = 1
for i in range(len(ls)):
    if c > abs(ls[i]):
        c = abs(ls[i])
        if ls[i] < 0:check = -1
        else:check = 1
print(sum(ls) - c*check)

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-

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

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

m = 1e10
for i in range(1, N + 1):
    a = L + i - 1
    b = total - a
    if abs(total - b) < m:
        m = abs(total - b)
        ans = b

print(ans)

Submission status: Accepted

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

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

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

if L <= 0 and 0<=L+N-1:     apple = 0
else:
    if abs(L) > abs(L+N-1): apple = L+N-1
    else:   apple = L

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

print(int(ans-apple))

Submission status: Accepted

Solution code:

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

#N = int(input())

#list(map(int,input().split()))

l = list(range(L,L+N))
ans = sum(l)
if l[-1] < 0:
    ans -= l[-1]
elif l[0] > 0:
    ans -= l[0]
print(ans)

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
a = [(abs(L+i-1), L+i-1) for i in range(1, N+1)]
b = [L+i-1 for i in range(1, N+1)]
a = sorted(a, key=lambda x: x[0])

print(sum(b)-sorted(a)[0][1])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, l = li()

apples = [l+i for i in range(n)]
minabs = float("inf")

for ai in apples:
    if abs(ai) < abs(minabs):
        minabs = ai

print(sum(apples) - minabs)

Submission status: Accepted

Solution code:
def solve():
    n, l = map(int, input().split())
    R = []
    for i in range(1, n + 1):
        t = l + i - 1
        R.append([abs(t), t])
    print(sum(list(zip(*R))[1]) - min(R)[1])
solve()

Submission status: Accepted

Solution code:
import numpy as np

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

del_i = np.argmin([abs(L+i-1) for i in range(1, N+1)]) + 1
#print(del_i)

tmp = [L+i-1 for i in range(1, N+1) if i != del_i ]
#print(tmp)
out = sum(tmp)
print(out)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
a = [l+i for i in range(n)]
t = sum(a)
diff = float('inf')
for c in a:
    if abs(c) < diff:
        diff = abs(c)
        ans = t-c
print(ans)

Submission status: Accepted

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

x = [L + i for i in range(N)]
total = sum(x)
d = 1000
for v in x:
    if abs(d) > abs(v):
        d = v
print(total - d)

Submission status: Accepted

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

s = list()
score = 0
for i in range(1, N+1):
    c = i + M - 1
    score += c
    s.append((abs(c), c))

m = min(s)
print(score-m[1])

Submission status: Accepted

Solution code:
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N,L = map(int,input().split())
a  =[0]*(N)
b = [0]*(N)
for i in range(N):
    a[i] = L+i
    b[i] = abs(a[i])
s = sum(a)
c = inf
index = 0
for i in range(N):
    if b[i]<c:
        c = b[i]
        index = i
print(s-a[index])

Submission status: Accepted

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

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

smallest = min(apples)
biggest = max(apples)

if smallest >= 0:
    print(sum(apples) - smallest)
    exit()

if biggest <= 0:
    print(sum(apples) - biggest)
    exit()

print(sum(apples))

Submission status: Accepted

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

azi = [l + i - 1 for i in range(1, n + 1)]
azi.sort(key=lambda x: abs(x))
s = 0
for a in azi[1:]:
    s += a
print(s)

Submission status: Accepted

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

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

minabs = abs(apples[0])
minabsidx = 0
for i, a in enumerate(apples):
    if abs(a) < minabs:
        minabs = abs(a)
        minabsidx = i

print(sum(apples) - apples[minabsidx])

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
x = sum([L+i-1 for i in range(1, N+1)])
ls = []
for i in range(1, N+1):
    ls.append(x-(L+i-1))
ls.sort(key=lambda y:abs(x-y))
print(ls[0])

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret
    
def mod_modify(a,mod):
    return (a+mod)%mod
    
def main():
    ans =0
    N,L = ints_raw()
    if L<0:
        if L+N-1 >=0:
            return sum([L+i for i in range(N)])
        else:
            return sum([L+i for i in range(N-1)])
    for i in range(1,N):
        ans+=(L+i)
    return ans

print(main())

Submission status: Accepted

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

ts = [L+i for i in range(N)]
sumT = sum(ts)

if 0 in ts:
    print(sumT)
else:
    if ts[0] > 0:
        print(sumT-ts[0])
    else:
        print(sumT-ts[-1])

Submission status: Accepted

Solution code:
N, L =map(int,input().split())
c = 400
k = 400
wa = 0
for i in range(N):
	a = L + i
	wa += a
	if abs(a) < c:
		c = abs(a)
		k = a
print(wa-k)

Submission status: Accepted

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

A = [L + i for i in range(N)]
j = 10 ** 10
t = sum(A)
ans = 0
for i in range(N):
  k = abs(t - (t - A[i]))
  if k <= j:
    j = k
    ans = t - A[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

absmin = 99999999
flg = -1
for i in range(1, N+1):
    apples.append(L + i - 1)
    if absmin > abs(L + i - 1):
        absmin = min(absmin, abs(L + i - 1))
        flg = ((L + i - 1) > 0)
if flg:
    print(sum(apples)-absmin)
else:
    print(sum(apples)+absmin)

Submission status: Accepted

Solution code:
import sys

def main():
    # a = sys.stdin.readline().strip()
    n, l = [int(i) for i in sys.stdin.readline().strip().split()]
    # [[int(i) for i in sys.stdin.readline().strip().split()] for _ in range(2)]

    mi = l
    ma = l + n - 1

    if mi <= 0 <= ma:
        return (mi + ma) * n // 2
    elif ma < 0:
        return (mi + ma-1) * (n-1) // 2
    elif mi > 0:
        return (mi+1 + ma) * (n-1) // 2

print(main())

Submission status: Accepted

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

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

ans = 0
for a in apple[1:]:
    ans += a[1]
print(ans)

Submission status: Accepted

Solution code:
inf = input().split()
N = int(inf[0])
L = int(inf[1])
ans = L*N+N*(N-1)//2
m = L*N
for i in range(N):
  if abs(L+i)<abs(m):
    m = L+i

print(ans-m)

Submission status: Accepted

Solution code:
n,k=map(int, input().split())
lin=[k+i for i in range(n)]
ablin=[abs(i) for i in lin]

print(sum(lin)-lin[ablin.index(min(ablin))])

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
x = [L+i-1 for i in range(1, N+1)]
total = sum(x)

n = 10**20
for a in x:
    if abs(a) < abs(n):
        n = a

print(total-n)

Submission status: Accepted

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

ans=0

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

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ans = 1000000000
r = []
for i in range(n):
    r.append(l+i)
total = sum(r)
for i in r:
    if(abs(i) < abs(ans)):
        ans = i
print(total - ans)