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:
# -*- coding: utf-8 -*-

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

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

A_abs = [abs(x) for x in A]
abs_min = min(A_abs)
index = A_abs.index(abs_min)
eat = A[index]
ans = sum(A) - eat
print(ans)

Submission status: Accepted

Solution code:
"""
- https://atcoder.jp/contests/abc131/tasks/abc131_b
- 最もおいしさの絶対値の小さいりんごを食べるのが、最適
"""
base = 0
n, l = map(int, input().split())
eat = min([abs(i+l-1) for i in range(1, n+1)])
for i in range(1, n+1):
    base+=(i+l-1)
    pie = base-eat if l>=0 else base+eat
print(pie)

Submission status: Accepted

Solution code:
N,L=list(map(int, list(input().split())))
N=[i+1 for i in range(N)]
F=[i+L-1 for i in N]
Fmin=min(map(abs, F))
f=[i for i in F if abs(i) != Fmin]
print(sum(f))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#17 ABC131B
n,l=map(int,input().split())
x=[l+i for i in range(n)]
y=[abs(x[i]) for i in range(n)]
a,b=sum(x)-min(y), sum(x)+min(y)
if abs(a)<abs(b):
    print(a)
else:
    print(b)

Submission status: Accepted

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

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

aji.sort(key=abs)
print(sum(aji[1:]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import logging
logging.basicConfig(level=logging.DEBUG)
logging.disable(logging.CRITICAL)

def main(N, L):
    min_val = 1000
    apples = list(range(L, L+N))
    for apple in apples:
        if abs(apple) < abs(min_val):
            min_val = apple
    ans = (apples[0] + apples[N-1]) * N / 2 - min_val
    return ans

if __name__ == '__main__':
    N, L = list(map(int, input().split()))
    print(int(main(N, L)))

Submission status: Accepted

Solution code:
import numpy as np

N, L = map(int, input().split())
print(int(N*L+N**2/2-N/2-L+1-np.clip(-L+1, 1, N)))

Submission status: Accepted

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

plus = []
minus = []
for i in range(N):
    taste = L + i
    if taste >= 0:
        plus.append(taste)
    else:
        minus.append(taste)

if plus and minus:
    ans = sum(plus) + sum(minus)  
elif plus:
    ans = sum(plus) - plus[0]
else:
    ans = sum(minus) - minus[-1]

print(ans)

Submission status: Accepted

Solution code:

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

# 味リストはL, L+1, L+2...
tastes = []
for i in range(n):
    tastes += [l+i]

# 味0があったらそれを食えばいい
if 0 in tastes:
    print(sum(tastes))
else:
    # 差が最小なのを食えばいい
    tastes.sort(key=abs)
    print(sum(tastes[1:]))

Submission status: Accepted

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

# 味リスト
tastes = []
for i in range(n):
    tastes += [l+i]

# 全部
all_tastes = sum(tastes)

# 食ったあとの味リスト
ptn = []
for x in tastes:
    ptn += [all_tastes - x]

# 元との差(abs)
di = []
for i in range(n):
    di += [abs(all_tastes - ptn[i])]

min_value = min(di)
print(ptn[di.index(min_value)])

Submission status: Accepted

Solution code:
import numpy as np

def main():
    N, L = map(int, input().split())
    apple = np.zeros(N)
    R = L + N - 1
    eat = 0
    if R <= 0:
        eat = R
    elif L >= 0:
        eat = L
    print(int((R + L) * (R - L + 1)/2 - eat))



       

if __name__ == '__main__':
    main()

Submission status: Accepted

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

tmp = float("inf")

for i in range(N):
    if abs(tmp) > abs(L+i):
        tmp = L+i
answer = 0
for i in range(N):
    answer += L+i
answer -= tmp
print(answer)

Submission status: Accepted

Solution code:
#coding : utf-8　

import os
import sys

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

t = [0 for i in range(N)]

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

t0 = sum(t)

min_diff = 10**9
min_idx = -1
min_t = 10**9

for i in range(N):
	tmp = t[i]
	t[i] = 0
	tt = sum(t)
	diff = abs(tt - t0)
	if diff < min_diff:
		min_diff = diff
		min_idx = i
		min_t = tt
	t[i] = tmp

print(min_t)

Submission status: Accepted

Solution code:
import numpy as np


def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


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

num = list(range(1, n+1))
aji = list(range(d, d+n))

aji.pop(aji.index(getNearestValue(aji, 0)))

print(sum(aji))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
A = [L + i for i in range(N)]
v = min(np.abs(A))
b = 0
for j in range(N):
    b += A[j]
if A.count(v) >= 1:
    print(b-v)
else:
    print(b+v)

Submission status: Accepted

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

l = list(range(l, l+n))
print(sum(l)-min(l, key=abs))

Submission status: Accepted

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

arr = []
e = l
for i in range(1, n+1):
    tmp = l+i-1
    if abs(e) > abs(tmp):
        e = tmp
    arr.append(tmp)

print(sum(arr)-e)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sa = 1000
sum = 0
for i in range(1,n+1):
    if sa != min(abs(l+i-1), sa):
        sa = min(abs(l+i-1), sa)
        app = l+i-1
    sum += l+i-1

print(sum-app)

Submission status: Accepted

Solution code:
N,L=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき

aji_sum=0
eat=99999

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

print(aji_sum-eat)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

edge=[L, L+N-1]
if edge[0]*edge[1]<=0:
  ans=sum(edge)*N/2
elif edge[0]>0:
  ans=(L+1+L+N-1)*(N-1)/2
else:
  ans=(L+L+N-2)*(N-1)/2
  
print(int(ans))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = [x + l for x in range(n)]
m = 1000
for i in range(len(a)):
    if abs(a[i]) < abs(m):
        m = a[i]
print(sum(a) - m)

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int, input() . split())
x=[]
M = 0
N_list = np.array([])

for i in range(N):
  M += L + (i+1) - 1
  N_list = np.append(N_list, L + (i+1) - 1)
  
m = np.abs(N_list).argmin()

#M - N_list[m]
print(int(M - N_list[m]))

Submission status: Accepted

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

absmini = 60000
mini = 60000
sum = 0

for i in range(b, b + a):
	if(absmini > abs(i)):
		absmini = abs(i)
		mini = i
	
	sum += i

print(sum - mini)

Submission status: Accepted

Solution code:

N,L = list(map(int, input().split()))
Ni = []
mI = 0
ab = abs(L - 1)
for i in range(N):
    if ab > abs(L + i):
        mI = i
        ab = abs(L + i)

    Ni.append(L + i)

del Ni[mI]
print(sum(Ni))

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
if L>=0:
  print(np.sum([L+i-1 for i in range(2, N+1)]))
elif (L<0)and(abs(L)>=N):
  print(np.sum([L+i-1 for i in range(1, N)]))
else:
  print(np.sum([L+i-1 for i in range(1, N+1)]))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
t_1=0
t=[]
for i in range(1,N+1):
    t_1+=L+i-1
for j in range(1,N+1):
    t.append(abs(L+j-1))
print( t_1 - L - t.index(min(t)) )

Submission status: Accepted

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


def solve(N: int, L: int):
    abs_val = sys.maxsize
    flavor = 0
    for i in range(N):
        a = L + i
        flavor += a
        if abs(a) < abs_val:
            abs_val = abs(a)
            index = i
    print(flavor - (L + index))
    
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
min = None
sum = 0
for i in range(N):
  i += 1
  num = abs(L + i - 1)
  if min == None:
    min = num
    count = i
    continue
  if min > num:
    min = num
    count = i
for i in range(N):
  i += 1
  if i != count:
    num = L + i - 1
    sum += num
print(sum)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
a = [0]*n
# a = list(range(n+1))
# a.pop(0)
for i in range(n):
    t = l + i
    a[i] = t
if 0 in a:
    a.remove(0)
    print(sum(a))
elif max(a)>0:
    a.pop(0)
    print(sum(a))
else:
    a.pop(n-1)
    print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

taste_list = []

for i in range(1, n+1):
    taste = l + i - 1
    taste_list.append(taste)

abs_taste_list = [abs(x) for x in taste_list]
target_index = abs_taste_list.index(min(abs_taste_list))
taste_list.remove(taste_list[target_index])
ans = sum(taste_list)
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
llist = []
p = 0
zeronear = {}
for i in range(N):
    llist.append(L+i)
for i in range(len(llist)):
    zeronear[i] = abs(llist[i]-0)
a = min(zeronear, key=zeronear.get)
del llist[a]
print(sum(llist))

Submission status: Accepted

Solution code:

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

t = list(map(lambda i: L + i, range(N)))

targ = sum(t)
m = 10000000000000
res = 0
for c in t:
    now = targ - c
    if m > abs(targ - now):
        m = abs(targ - now)
        res = now

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=input().split()
n=int(n)
l=int(l)
taste_1=[]
for x in range(1,n+1):
    taste_1.append(l+x-1)
taste_2=[]
for x in range(n):
    if taste_1[x]<0:
        taste_2.append(-taste_1[x])
    else:
        taste_2.append(taste_1[x])
t=sorted(taste_2)
#print(taste_1)
#print(taste_2)
#print(t)
ans=0
for a in range(n):
    ans+=taste_1[a]
if t[0] in taste_1:
    ans=ans-t[0]
else:
    ans=ans+t[0]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC132 B
N, L = (int(_) for _ in input().split())
Dmin = 1000
Dsum = 0
for i in range(N):
    D = L + i
    Dsum += D
    Dmin = min(abs(D), Dmin)
if D < 0:
    print(Dsum + Dmin)
else:
    print(Dsum - Dmin)

Submission status: Accepted

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

if l>=0:
    for val in range(n-1):
        s += val+l+1
        


elif l < 0 and n > -l:
    for val in range(n):
        s += val + l
        
else:
    for val in range(n-1):
        s += val + l



print(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

    for i in range(1,N+1):
        aji_i = aji_all - (L + i - 1)
        if i == 1:
            best_score =  abs(aji_all - aji_i)
            best_num = i
            ans = aji_i
            
        if best_score > abs(aji_all - aji_i):
            best_score = abs(aji_all - aji_i)
            ans = aji_i
            best_num = i

    print(ans)

if __name__ == '__main__' :
    main()

Submission status: Accepted

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

N = [0 for i in range(n)]
NN = [0 for i in range(n)]

for j in range(n):
    N[j] = l + j
    NN[j] = abs(l+j)


if 0 in N:
    print(sum(N))
else:
    if min(N) == min(NN):
        N.remove(min(N))
    else:
        N.remove(max(N))


    print(sum(N))

Submission status: Accepted

Solution code:
import numpy as np
N, L = [int(x) for x in input().split(" ")]
quality = [(L + i - 1) + 1 for i in range(N)]

abs_quality = [abs(q) for q in quality]
ind = np.argmin(abs_quality)

taste = np.sum([q for i, q in enumerate(quality) if i != ind])
print(taste)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
tot = 0
for i in range(0, n):
    tot += l + i
dif = 100000000000
ans = 0
for i in range(0, n):
    a = tot - (l + i)
    if abs(tot - a) < dif:
        ans = a
        dif = abs(tot - a)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


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

    apple_list = []

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

    s = sorted(apple_list, key=abs)
    s.pop(0)
    print(sum(s))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

# 1/2 * N * (L + L+N-1)
value = L*N + N *(N-1)//2

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

print(value)

Submission status: Accepted

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

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

Submission status: Accepted

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

left = L
right = L + N - 1

sum = 0
for i in range(left, right + 1):
    sum += i

ans = sum
if left * right > 0:
    if abs(left) < abs(right):
        ans -= left
    else:
        ans -= right

print(ans)

Submission status: Accepted

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

def main():
	n, l = map(int, input().strip().split())
	a = [0] * n
	m = 10**9
	u = None
	for i in range(n):
		a[i] = l + i
		if abs(a[i]) < m:
			m = abs(a[i])
			u = i
	print(sum(a) - a[u])

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
T=[]
for i in range(n):
  t=int(abs(l+i))
  T.append(t)
#print(T)
eat=T.index(min(T))+1
#print(eat)
print(int(n*l+n*(n-1)/2-(l+eat-1)))

Submission status: Accepted

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

taste_list = [l+i-1 for i in range(1,n+1)]
abs_taste_list = [abs(i) for i in taste_list]
min_index = abs_taste_list.index(min(abs_taste_list))
min = taste_list[min_index]
print(sum(taste_list)-min)

Submission status: Accepted

Solution code:
# ABC 131, B - bite eating
X = [int(el) for el in input().split(' ')]
n = X[0]
l = X[1]

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

j = A.index(min(A)) + 1
B = [(l + i - 1) for i in range(1, n+1) if i != j]
print(sum(B))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(x)-min(x,key = abs))

Submission status: Accepted

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

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

min = 10000000

for apple in apples:
    if abs(apple) < min:
        min_index = apples.index(apple)
        min = abs(apple)
        
        
print(sum(apples)-apples[min_index])

Submission status: Accepted

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

for i in range(1,N+1):
  X.append(L+i-1)
res = float('inf')
print(sum(X)-min(X,key=abs))

Submission status: Accepted

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

max = N + L - 1
min = L

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

if max < 0:
    taste -= max
elif min > 0:
    taste -= min

print(taste)

Submission status: Accepted

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

Submission status: Accepted

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

x = 1000
p = -1

for i in range(N):
    y = abs(L + i)
    if y < x:
        x = y
        p = i
        
ans = (L-1) * N + N * (N + 1)/2 -(L + p)
print(int(ans))

Submission status: Accepted

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

for i in range(n):
    if i == 0:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[i+1:])
    elif abs(sum(apple[:i]+apple[i+1:]) - org) < dif:
        dif = abs(sum(apple[:i]+apple[i+1:]) - org)
        ans = sum(apple[:i]+apple[i+1:])
print(ans)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
mx = 100000000
sum = 0
flag = False
for i in range(1,a+1):
    if mx > abs(b+i-1):
        mx = abs(b+i-1)
    if b+i-1 < 0 :
        flag = True
    sum+=b+i-1
if flag:
    print(sum+mx)
else:
    print(sum-mx)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
l = []
k = []
s = 0
aa = 1000000000
for i in range(a):
    l.append(b+i)
m = sum(l)
for i in l:
    if abs(i)<aa:
        aa = abs(i)
        s = i

print(sum(l)-s)

Submission status: Accepted

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

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

sm = sum(a)

d = 1000000

ch = 0

for i in range(len(a)):
    n = sm - a[i]
    if abs(n - sm) < d:
        d = abs(n-sm)
        ch = n

print(ch)

Submission status: Accepted

Solution code:
n, a = map(int, input().split())
L = a
R = a + n - 1
eat = 0
if R <= 0:
    eat = R
elif L >= 0:
    eat = L

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

Submission status: Accepted

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

mi = 1000000000000000000000
for i in range(n):
    b = a - l - i
    c = abs(a-b)
    if c < mi:
        mi = c
        minsum = b

print(minsum)

Submission status: Accepted

Solution code:
S = input()

S = list(map(int, S.split()))

N = S[0]
L = S[1]

taste_min = 100000000
taste = 0
for i in range(1, N+1, 1):
    taste = taste + L + i - 1

for i in range(1, N+1, 1):
    taste_temp = 0
    for j in range(1, N + 1, 1):
        if i != j:
            taste_temp = taste_temp + L + j - 1
    if abs(taste_temp-taste) < abs(taste_min-taste):
        taste_min = taste_temp

print(taste_min)

Submission status: Accepted

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

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

if tastes[0] * tastes[-1] < 0:
    ans = sum(tastes)
elif tastes[0] >= 0:
    ans = sum(tastes) - tastes[0]
else:
    ans = sum(tastes) - tastes[-1]

print(ans)

Submission status: Accepted

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

ret = -1
ans = 1e100
for x in X:
    if abs(x) <= ans:
        ans = min(ans, abs(x))
        ret = sum_X - x
print(ret)

Submission status: Accepted

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

ans_dif = float('inf')
ans = 0

for i in range(n):
  dif = abs(l+i)
  if dif < ans_dif:
    ans_dif = dif
    ans = n*l+n*(n+1)/2-n-(l+i)
print(int(ans))

Submission status: Accepted

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

elif a[0]>0:
    print(sum(a)-a[0])
elif a[n-1]<0:
    print(sum(a)-a[n-1])

Submission status: Accepted

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

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

print(int(n*(n-1)/2) + n*l -(taste))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def B_BiteEating():
    N, L = map(int,input().split())
    eat = 0
    if L >= 0:
        eat = L
    elif L + N <= 0:
        eat = L + N - 1
    else:
        eat = 0
    print(sum([i for i in range(L, L + N)]) - eat)
    
if __name__ =="__main__":
    B_BiteEating()

Submission status: Accepted

Solution code:
def solve(string):
    n, l = map(int, string.split())
    _sum = l * n + n * (n - 1) // 2
    if l >= 0:
        _sum -= l
    elif l + n - 1 < 0:
        _sum -= l + n - 1
    return str(_sum)


if __name__ == '__main__':
    print(solve(input()))

Submission status: Accepted

Solution code:
kosu, aji = map(int, input().split())
mikaku = []
for k in range(1, kosu + 1):
  mikaku.append(k + aji - 1)
mikaku_dash = [abs(m) for m in mikaku]
point = mikaku_dash.index(min(mikaku_dash))
mikaku.remove(mikaku[point])
print(sum(mikaku))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
ls = []
minNum = 0
num = float('inf')
for i in range(1,n+1):
    ls.append(i+l -1)
    if num > abs(ls[i-1]):
        num = abs(ls[i-1])
        minNum = ls[i-1]
ls.pop(ls.index(minNum))
print(sum(ls))

Submission status: Accepted

Solution code:
import numpy as np
n,l=map(int,input().split())
li=[]
for i in range(n):
  li.append(l+i)
li2=sorted(li, key=abs)
print(sum(li2[1:]))

Submission status: Accepted

Solution code:
_input = input()
N, L = tuple([int(a) for a in _input.split(' ')])

def ans_func(I):
    return int(N*N/2 - N/2 + (N-1)*L + 1 - I)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import io
import sys


def IN_S():
  return input()


def IN_I():
  return int(input())


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


def IN_L_S():
  return list(map(str, input().split()))


def STR_SPLIT(s, n):
  for l in range(0, len(s), n):
    yield s[0 + l:n + l]


def T_IN():
  global test_str
  sys.stdin = io.StringIO(test_str[1:-1])


test_str = '''
5 2
'''


def MAIN():
  # T_IN()
  A()


def A():
  n, l = IN_L_I()
  li = list([ i + l for i in range(0,  n)])
  if li.count(0) == 0:
    j = li.pop(0)
    k = li.pop(-1)
    if abs(j) < abs(k):
      li.append(k)
    else:
      li.append(j)

  print(sum(li))

  return None
 

def B():
  return None


def C():
  return None


MAIN()

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
S = 0
T = 1000
ans = 0
flag = 1

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

for i in range(N):
    if T > abs(L+i) and L+i>=0:
        T = abs(L+i)
        flag = 1
    elif T > abs(L+i) and L+i<0:
        T = abs(L+i)
        flag = -1
        
ans = int(S-T*flag)
print(ans)

Submission status: Accepted

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

l = [L + i for i in range(N)]
item = l.index(min(l, key=abs))
ans = 0
for i, v in enumerate(l):
    if i == item:
        continue
    ans += v

print(ans)

Submission status: Accepted

Solution code:
n,l=[int(i) for i in input().split()]
arr=[]
for i in range(1,n+1):
    arr.append(l+i-1)
tot = sum(arr)
diff = 10**9
ans=0
for i in range(len(arr)):
    cur_diff = abs(tot - (tot-arr[i]))
    if(abs(tot-(tot-arr[i]))<diff):
        diff = abs(tot-(tot-arr[i]))
        ans = tot-arr[i]
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [L + i - 1 for i in range(1, N+1)]
abs_diff_taste = [abs(x) for x in taste]
sum_taste = sum(taste)
min_diff = min(abs_diff_taste)
if sum_taste >= 0:
  print(sum_taste - min_diff)
else:
  print(sum_taste + min_diff)

Submission status: Accepted

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

def apple_aji(i):
  return int(l) + int(i) - 1

def remove_min(p):
  minimun = min(list(map(abs, p)))
  if minimun not in p:
    minimun = minimun * -1
  p.remove(minimun)
  return p

def apple_pie(n):
  ajis = [apple_aji(x) for x in n]
  return sum(remove_min(ajis))

print(apple_pie(range(1, int(n)+1)))

Submission status: Accepted

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

diff = float("inf")
ans = 0

for i in range(1, N+1):
    before = sum([L+k-1 for k in range(1, N+1)])
    after = sum([L+j-1 for j in range(1, N+1) if j != i])
	
    if abs(before-after) < diff:
    	diff = abs(before-after)
    	ans = after
print(ans)

Submission status: Accepted

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

ap = [L+i for i,v in enumerate(range(N))]

min_=10000
for c in ap:
    if abs(c)<min_:
        min_=abs(c)
        v=c

ap.remove(v)

print(sum(ap))

Submission status: Accepted

Solution code:
num, taste = map(int, input().split())

list = []

for i in range(taste, taste + num):
    list.append(i)

if list[0] > 0:
    list.pop(0)
    print(sum(list))
elif list[num-1] < 0:
    list.pop(num-1)
    print(sum(list))
else:
    print(sum(list))

Submission status: Accepted

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

minl = min(l)
if a == 1 :
    minl = -minl
    print(sum(ll)-minl)
else :
    print(sum(ll)-minl)

Submission status: Accepted

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

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

min = 1000000
value = 0

for i, t in enumerate(T):
    if abs(t) < min:
        min = abs(t)
        value = t
    else:
        continue

print(sum(T) - value)

Submission status: Accepted

Solution code:
import math

def main():
    N, L  = list(map(int, input().split(" ")))
    minimum = abs(L-1+1)
    argmin = 1
    for i in range(2, N+1):
        value = abs(L-1+i)
        if value < minimum:
            minimum = value
            argmin = i
    ans = (N-1)*(L-1) + N*(N+1)/2 - argmin
    print(int(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n):
    if diff > abs(l + i):
        diff = abs(l + i)
        ans = taste - (l + i)
    
print(ans)

Submission status: Accepted

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

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

for i in range(n):
    if diff > abs(taste - (taste - (l + i))):
        diff = abs(taste - (taste - (l + i)))
        ans = taste - (l + i)
    
print(ans)

Submission status: Accepted

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