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

taste = [(L + i - 1) + 1 for i in range(N)]
pie = {}
ab, tas = 0, 0
for i in range(N):
    tmp0 = sum(taste)
    tmp = taste[:]
    tmp.pop(i)
    tmp1 = sum(tmp)
    if i == 0:
      ab, tas = abs(tmp0 - tmp1), tmp1
    else:
        if ab > abs(tmp0 - tmp1):
            ab, tas = abs(tmp0 - tmp1), tmp1
     	
print(tas)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple = []
for i in range(n):
        apple.append(l+(i+1)-1)
pie = sum(apple)
piev2 = []
abs_pie = []
for i in apple:
        piev2.append(pie - i)
        abs_pie.append(abs(i))
num = 0
print(piev2[abs_pie.index(min(abs_pie))])

Submission status: Accepted

Solution code:
N,L=map(int,raw_input().split())
def F(i):
    return L+i
m=114514
r=None
s=0
for i in range(N):
    if abs(F(i))<m:
        m=abs(F(i))
        r=F(i)
    s+=F(i)
print(s-r)

Submission status: Accepted

Solution code:
intCount, intBase = map(int, input().split())

intSum = 0
# everythins is minus
if intBase + intCount -1 < 0:
    intSum += -1 * (intBase + intCount -1)
# everything is plus
## --miss-- elif intBase > 1:
elif intBase >= 1:
    intSum -= intBase

for intTmp in range(1, intCount+1):
    intSum += intBase + intTmp -1

print(intSum)

Submission status: Accepted

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

for i in range(1,n+1) :
    taste += l+i-1
    tst_l.append(l+i-1)
print(taste-min(tst_l, key=abs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
i = 0
apple_taste = []
pi_taste = 0
while N > i:
    apple_taste.append(L + i)
    if(L>0):
        if i>0:
            pi_taste += apple_taste[i]
    elif(L+(N-1)>=0):
            pi_taste += apple_taste[i]
    elif(L<0):
        if i>0:
            pi_taste += apple_taste[i-1]
    i += 1 
print(pi_taste)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
aji=0
minaji=300
realaji=300
for i in range(1,n+1):
    apple=l+i-1
    if minaji> abs(apple):
        minaji=abs(apple)
        realaji=apple
    aji+=apple
print(aji-realaji)

Submission status: Accepted

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

max_taste = L + N - 1
# おいしさの絶対値が最も小さいりんごを食べ、残りでアップルパイを作る
if max_taste <= 0:
    eat_taste = max_taste
elif L >= 0:
    eat_taste = L
else:
    eat_taste = 0
print((L + max_taste) * (max_taste - L + 1) // 2 - eat_taste)

Submission status: Accepted

Solution code:
N,L = [int(x) for x in input().split()]
min_taste=float('inf')
x = 0
for i in range(N):
    if(min_taste>abs(L+i)):
        min_taste = abs(L+i)
        x = i
print((N+1)*N//2+(L-1)*N-(L+x))

Submission status: Accepted

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

apple_pi = sum(taste)

min_val = 0
idx = 0
for i in range(N):
    if i == 0:
        min_val = abs(taste[i])
        idx = i
    else:
        tmp = abs(taste[i])
        if min_val > tmp:
            min_val = tmp
            idx = i

print apple_pi - taste[idx]

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
b = [0] * n
for i in range(n):
    b[i] = l + i
# b.sort()
s = sum(b)
k1 = 10000000000
k2 = 0
for i in range(n):
    s1 = s - b[i]
    # print(s1, s-s1, k1)
    if abs(abs(s)-abs(s1)) < k1:
        k1 = abs(abs(s)-abs(s1))
        k2 = s1


print(k2)

Submission status: Accepted

Solution code:
import numpy as p;n,l=map(int,input().split());m=p.arange(n)+l;print(p.sum(p.delete(m,p.abs(p.asarray(m)).argmin())))

Submission status: Accepted

Solution code:
line = input().strip()
N,K = line.split(" ")
N = int(N)
K = int(K)

flavors = 0
min_data = 10000000000000000
flag = False

for i in range(N):
    flavor = K  + i
    flavors += flavor
    if abs(min_data) > abs(flavor): min_data = flavor
    if flavor == 0: flag = True

if flag: print(flavors)
else: print(flavors - min_data)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np;n,l=map(int,input().split());m=np.arange(0,n)+l;print(np.sum(np.delete(m,np.abs(np.asarray(m)).argmin())))

Submission status: Accepted

Solution code:
# ABC131B - Bite Eating
def main():
    n, l = list(map(int, input().rstrip().split()))
    lst = sorted([i for i in range(l, l + n)], key=abs)
    print(sum(lst[1:]))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

s = L
e = L + N - 1
t = (s + e) * N // 2

if s < 0 and e > 0:
    result = t
elif s >= 0:
    result = t - s
else:
    result = t - e

print(result)

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N, L = map(int,input().split())
minval = 10**6
minindex = 0
for i in range(1,N+1):
    if abs(L+i-1) < minval:
        minval = abs(L+i-1)
        minindex = i
ans = 0
for i in range(1,N+1):
    if i != minindex:
        ans += (L+i-1)
print(ans)

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
 
sum = 0
lower = 100000
for i in range(1, N+1):
    sum = sum + L + i -1
for i in range(1, N+1):
    s = abs(L + i -1)
    if s < lower:
        lower = s
        ij = i
 
print(sum - (L + ij -1))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
# リンゴN個から1個リンゴを抜いたときの和と抜かないときの和の差を最小にする、その時の値を求める
Input = input()

n, l = Input.split(' ')
n, l = int(n), int(l)

# i個目の味を出す関数
def ni_taste(i,l=l):
    return l+i-1

taste_list = [ni_taste(i) for i in range(1, n+1)] # リンゴは1, 2, 3, ...と数えられる
taste_abs_list = [abs(abs_taste) for abs_taste in taste_list]

print( reduce((lambda x, y: x + y), taste_list) - taste_list[taste_abs_list.index(min(taste_abs_list))] ,end='' )

Submission status: Accepted

Solution code:
N,L = (int(x) for x in input().split())
taste = []
for x in range(int(N)):
  taste.append(str(L+(x+1)-1))
p_taste = sum(int(x) for x in taste)
n_1_taste = []
t_taste= taste.copy()
t_i = 0
for y in t_taste:
  taste.remove(str(y))
  sum_taste = sum(int(x) for x in taste)
  n_1_taste.append(sum_taste)
  taste.append(str(y))
  t_i+=1
if p_taste in n_1_taste:
  print(p_taste)
elif str(L).startswith("-"):
  print(min(n_1_taste))
else:
  print(max(n_1_taste))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = [int(x) for x in input().split()]
if L >= 0:
    print(L * N + sum(list(range(N))) - L)
elif L < 0 and N <= abs(L):
    print(sum(list(range(L, L + N -1))))
elif L < 0 and N > abs(L):
    print( L * N + sum(list(range(N))) )

Submission status: Accepted

Solution code:
N,L = [int(s) for s in input().split(' ')]
tastes = [(L + i -1) for i in range(1,N+1)]
tmp_tastes = [ abs(i) for i in tastes ]
min_index = tmp_tastes.index(min(tmp_tastes))
tastes.pop(min_index)
print(sum(tastes))

Submission status: Accepted

Solution code:
n, l = [ int(i) for i in input().split()]
nl = [l+i-1 for i in range(1,n+1)]
tmp = [-i if i<0 else i for i in nl]
min_index = tmp.index(min(tmp))
del nl[min_index]

print(sum(nl))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
tastes = range(l, n + l)
ijo = [taste for taste in tastes if taste >= 0]
under = [taste for taste in tastes if taste < 0]
if len(ijo) == 0:
    print(sum(under[:-1]))
elif len(under) == 0:
    print(sum(ijo[1:]))
else:
    print(sum(tastes))

Submission status: Accepted

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

Submission status: Accepted

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

L = int(L)

taste = []

total = 0


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

mini = min(taste, key=lambda x: -x if x < 0 else x)
total = total - mini
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

nl = input().split(" ")
apple_aji = []

#欲しかった味の値
for tsumugi in range(int(nl[0])):
  apple_aji.append(int(nl[1]) + tsumugi)
  
apple_abs = np.abs(apple_aji)
apple_abs = apple_abs.tolist()
le_apple = apple_abs.index(min(apple_abs))

apple_aji[le_apple] = 0

aji = 0
for matsuri in range(len(apple_aji)):
  aji += apple_aji[matsuri]

print(aji)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = [l + i for i in range(n)]
try:
    min_index = apples.index(min([abs(aps) for aps in apples]))
except ValueError:
    min_index = apples.index(-1*min([abs(aps) for aps in apples]))
print(sum(apples)-apples[min_index])

Submission status: Accepted

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

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

al_te = []
for i in range(N):
    T = L + (i+1) -1
    al_te.append(T)
#print(al_te)

ab_te = []
for i in range(N):
    T = L + (i+1) -1
    ab_te.append(abs(T))
#print(ab_te)
x = ab_te.index(min(ab_te))
#print(x)

al_te.pop(x)
print(sum(al_te))

Submission status: Accepted

Solution code:
# ABC131B - Bite Eating
def main():
    n, l = list(map(int, input().rstrip().split()))
    total = (n + 1) * n // 2 + (l - 1) * n
    first, last = 1 + l - 1, n + l - 1
    if first >= 0:
        print(total - first)
    else:
        if last >= 0:
            print(total)
        else:
            print(total - last)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

N=int(input[0])
L=int(input[1])
taste=0
if L>0:
	for i in range(N-1):
		L+=1
		taste+=L
		
	print(taste)

elif L<0 and -L>=N:
	for i in range(N-1):
		taste+=L
		L+=1

	print(taste)
else:
	for i in range(N):
		taste+=L
		L+=1
		#print("taste",taste)
		#print("LA",L)
	print(taste)

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
Taste = [0] * (N+1)
min = 999
mini = -999

for i in range(1,N+1):
    Taste[i] = L+i-1
for j in range(1,N+1):
    if min > abs(Taste[j]):
        min = abs(Taste[j])
        mini = j
s = sum(Taste) - Taste[mini]
print(s)

Submission status: Accepted

Solution code:
N,L= [int(i) for i in input().split()]
n=[]
for i in range(1,N+1):
    n.append(i)
taste=[]
for j in range(len(n)):
    taste.append(L+n[j]-1)
taste_a=[]
for x in range(len(taste)):
    taste_a.append(abs(taste[x]))
del taste[taste_a.index(min(taste_a))]
sum=0
for y in range(len(taste)):
    sum+=taste[y]
print(sum)

Submission status: Accepted

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

sum = 0
min = 300
for i in range(N):
  if abs(L+i) < abs(min):
    min = L+i
  sum += L+i
  
sum -= min

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

l = [x for x in range(L, L+N)]

if 0 < L:
    print(sum(l) - l[0])
elif L <= 0 <= L+N-1:
    print(sum(l))
else:
    print(sum(l) - l[-1])

Submission status: Accepted

Solution code:
N = input().split()

num = int(N[0])

L = int(N[1])

taste = []

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

sum_taste = sum(taste)
#print(sum_taste)
#print(taste)
temp = 999
ans = 0

for index, j in  enumerate(taste):
    t_num = sum(taste[:index]) + sum(taste[index+1:])
    #print(t_num)
    if abs(sum_taste - t_num) < temp:
        temp = abs(sum_taste - t_num)
        ans = t_num

print(ans)

Submission status: Accepted

Solution code:

n,l = map(int,input().split())
azi = 0
eat = -1

for i in range(n):
	ringo = l+i
	if (i == 0 and ringo >= 0):
		eat = ringo
	if (ringo == 0):
		eat = 0
	azi += ringo


if (eat < 0):
	eat = ringo

print(azi-eat)

Submission status: Accepted

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

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

taste = n*(2*l+n-1)/2-minL

print(int(taste))

Submission status: Accepted

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

s = (N + 2*L - 1) / 2 * N
max_t = L + N - 1
if L >= 0:
    min_t = L
else:
    if max_t < 0:
        min_t = max_t
    else:
        min_t = 0

print(int(s - min_t))

Submission status: Accepted

Solution code:
a = [int(i) for i in input().split()]
diff = a[1]-1
taste = []
for i in range(1,a[0]+1):
    taste.append(diff+i)

all_t = sum(taste)
lists=[]
tmp = []
for i in range(a[0]):
    tmp = taste[:]
    del taste[i]
    lists.append(abs(all_t - sum(taste)))
    taste.clear()
    taste = tmp
    
del taste[lists.index(min(lists))]
print(sum(taste))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L =map(int, input().split())
goukei = 0
ans =0
agi_list=[]
for i in range(N):
    agi = L+i
    agi_list.append(agi)
    goukei = agi +goukei
    
if L>0:
    ans = goukei-min(agi_list)
elif L==0:
    ans =goukei
elif (N > abs(L)) :
    ans = goukei
else:
    ans = goukei-(max(agi_list))
print(ans)

Submission status: Accepted

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

N = int(n)
L = int(l)

lst = [x + L for x in range(0, N) ]

smallest = lst[0]
smallestIndex = 0;
for i in range(len(lst)):
  if lst[i]**2 < smallest**2:
    smallest = lst[i]
    smallestIndex = i;

lst.pop(smallestIndex)
result = sum(lst)
print(result)

Submission status: Accepted

Solution code:
from sys import stdin

# N, L = stdin.readline().rstrip()
N, L = map(int, input().split(' '))
# print(N, L)
# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value
    
print(summation)

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

n, l = getList()
#
# if l >= 0:
#     ans = sum([l + i for i in range(1,n)])
#
# elif l >= -(n+1):
#     ans = sum([l+i for i in range(n)])
#
# else:
#     ans = sum([l+i for i in range(n-1)])
#
# print(ans)

aji = [l + i for i in range(n)]
if 0 in aji:
    print(sum(aji))

elif min(aji) > 0:
    print(sum(aji[1:]))

else:
    print(sum(aji[:-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

nl = np.array([i for i in range(n)]) + 1
ll = nl + l - 1

mini = np.where(np.absolute(ll) == np.min(np.absolute(ll)))
ll = list(ll)
del ll[mini[0][0]]

print(np.sum(ll))

Submission status: Accepted

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

Submission status: Accepted

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

aji_pie = []
for i in range(0,n):
    v = abs(sum(aji_apple) - (sum(aji_apple) - aji_apple[i]))
    aji_pie.append(v)

min_index = aji_pie.index(min(aji_pie))

print(sum(aji_apple) - aji_apple[min_index])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
resultList = []
tasteList = []
for i in range(N):
    x = int(L + i)
    resultList.append(x)
    tasteList.append(abs(x))

listMin = min(tasteList)
listNum = tasteList.index(listMin)

if resultList[listNum] > 0:
    listSum = sum(resultList) - listMin
else:
    listSum = sum(resultList) + listMin

print(listSum)

Submission status: Accepted

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

taste=l-1

apples=[]
for i in range(1,n+1):
    apples.append(i+taste)
#print(apples)

plus=[]
for j in apples:
    if j>=0:
        plus.append(j)

minas=[]
for k in apples:
    if k<0:
        minas.append(k)

if len(plus)>0:
    print(sum(plus[1:])+sum(minas))

else:
    print(sum(minas[:-1]))

Submission status: Accepted

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


if __name__=="__main__": main()

Submission status: Accepted

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

min = abs(taste[0])
sum = taste[0]
index = 0
for i in range(1, N):
    if abs(taste[i]) < min: 
        index = i
        min = abs(taste[i])
    sum += taste[i]
sum = sum - taste[index]
print(sum)

Submission status: Accepted

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

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

tstall = sum(APS)
TSTL = []
for nn in range(N):
    tst = APS[nn]
    TSTL.append((abs(tst), tstall - tst))

R = sorted(TSTL, key=lambda x: x[0])[0][1]

print(R)

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
#リンゴiの味はL+i-1で与えられる。（i=1~N）
#作る予定のアップルパイの味の総和はN*(L-1) + 1/2*(N+1)*N
#出力はN-1個からアップルパイを作るとき、元の味との差が最小になる味
#味が0に最も近いものを探して、引けばよい。
aji = [L+i for i in range(N)]
#i=1~Nなので注意
#print(aji)
#0に一番近いものを探索
left = 0
while (aji[left] < 0):
    if left < N-1:
        left += 1
    else:
        break
#print(left)
ans = sum(aji) - aji[left]
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = 0
A = L-1+N # 末尾
if L*A >=0 and L>0:
    s = sum(range(L+1, A+1))
    
elif L*A <= 0:
    s = sum(range(L, A+1))

else:  # 両方マイナス
    s = sum(range(L, A))
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,L=map(int,input().split())
arr=[]
flg=0
sumall=0
for c in range(N):
    if(L+c==0):
        flg=1
    arr.append(L+c)
    sumall+=L+c
arr.sort()
sum=0

if(flg==0):
    if(sumall>0):
        for c in range(N-1):
           sum+=arr[c+1]
    else:
        for c in range(N-1):
            sum+=arr[c]
else:
    sum=sumall
print(sum)

Submission status: Accepted

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

if L>=0:
    for i in range(N):
        sum += i+L
    print(sum-L)
elif L<0 and N+L>0:
    for i in range(N):
        sum += i+L 
    print(sum)
else:
    for i in range(N-1):
        sum += i+L 
    print(sum)

Submission status: Accepted

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

ans = 0
min_abs = float('inf')

for i in range(1, n + 1):
   ans += l + i - 1 
   min_abs = min(min_abs, abs(l + i - 1))

if 0 < ans:
    ans -= min_abs
else:
    ans += min_abs

print(ans)

Submission status: Accepted

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

    
if l > 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
    print(sum(ans)-ans[0])
        
        
        
if l == 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1    
    print(sum(ans))
    
    
if l < 0:
    for i in range(n-1):
        ans.append(l+1)
        l=l+1
    
    for j in range(n-1):
        b.append(abs(ans[j]))
        
    m = min(b)
    if m == 0:
        print(sum(ans)+m)
    else:
        print(sum(ans)+m-1)

Submission status: Accepted

Solution code:
N, L = [int(_) for _ in input().split()]
#L...L+N-1
if L * (L + N - 1) <= 0:
    print((2 * L + N - 1) * N // 2)
else:
    print((2 * L + N - 1) * N // 2 - min([L, L + N - 1], key=abs))

Submission status: Accepted

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

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

aji_n = sum(aji)
diff_min = 9999
ans = 0
for li in aji:
    aji_n1 = aji_n - li
    diff = abs(aji_n - aji_n1)
    if diff < diff_min:
        ans = aji_n1
        diff_min = diff

print(ans)

Submission status: Accepted

Solution code:
num = list(map(int,input().split()))
apple=[]
for i in range(num[0]):
    apple.append(num[1]+i)
apple1=list(map(abs,apple))
apple.remove(apple[apple1.index(min(apple1))])
print(sum(apple))

Submission status: Accepted

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

orig = int((n*(n+1))/2) + (l-1)*n
min = 1000000
flag = 0
for i in range(1, n+1):
    temp = l + i - 1
    # if temp == 0:
    #     min = 0
    #     break
    if abs(temp) < min:
        min = abs(temp)
        if temp < 0:
            flag = 1

if flag == 1:
    print(orig + min)
else:
    print(orig - min)

# orig = 0
# a = []
# low = 10000000
# for i in range(1, n+1):
#     orig += l + i - 1
#     if abs(l + i - 1) < low:
#         low = abs(l + i - 1)
#     # a.append(l + i - 1)
# # b = a
# # a = list(map(abs, a))
# # a = sorted(a)
# print(orig)
# print(orig - low)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
p = N * L + N * (N - 1) / 2
l = list(range(L, L + N))
t = [(x, abs(x)) for x in l]
m = min(t, key=lambda x: x[1])
print(sum(l) - m[0])

Submission status: Accepted

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

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

for n in range(1, N+1):
    if n == 1:
        m = abs(s - (s - (L + n - 1)))
        ans = s - (L+n-1)
    if m > abs(s - (s - (L+n-1))):
        m = abs(s - (s - (L + n - 1)))
        ans = s - (L+n-1)

print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
aji = []
for i in range(n):
    aji.append(l+i)
ap = sum(aji)
salist = []
salist2 = []
for j in range(len(aji)):
    ap2 = ap-aji[j]
    salist.append(ap2)
# print(salist)
for l in range(len(salist)):
    sa = abs(ap-salist[l])
    salist2.append(sa)
print(salist[salist2.index(min(salist2))])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

a = [int(i) for i in input().split()]
x=0
i=0
b=a[1]
while i < a[0]:
  x+=b
  b+=1
  i+=1
if a[1]>=0:
  x-=a[1]
  print(x)
elif a[1]<0 and a[0]+a[1]<=0:
  x=x-b+1
  print(x)
else:
  print(x)

Submission status: Accepted

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

Submission status: Accepted

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

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

if min(ajilist) <0 and max(ajilist)>=0:
    abso = 0
elif min(ajilist)<0 and max(ajilist)<0:
    abso = abs(max(ajilist))
else:
    abso=abs(min(ajilist))
    

for i in range(len(ajilist)):
    temp = abs(ajilist[i])
    if abso==temp:
        ajilist.pop(i)
        break
print(sum(ajilist))

Submission status: Accepted

Solution code:

N,L = map(int,input().split())
L2 = L
count=0
while L2 < 0:
    L2+=1
    count+=1

sum =0
if L < -49:
    j = N
else:
    j = N+1
for i in range(1,j):
    if i-1 != count:
        sum += L+i-1
print(sum)

Submission status: Accepted

Solution code:
from sys import stdin

class B:
	def __init__(self,N,L):
		self.N = int(N)
		self.L = int(L)
		self.taste = list()
		self.taste_abs = list() #絶対値


	def CollectTaste(self):
		for i in range(1,self.N+1):
			i = self.CulTasteFirst(i)
			self.taste.append(i)
			self.taste_abs.append(abs(i)) #絶対値リストの作成

		#絶対値の小さい要素を削除して計算する味リストの決定
		min_num = min(self.taste_abs)
		try:
			self.taste.remove(min_num)
		except ValueError:
			min_num *= -1
			self.taste.remove(min_num)

		ans = 0
		for i in self.taste:
			ans += i
		print(ans)
	def CulTasteFirst(self,i):
		i = int(i)
		return self.L+i-1


Inp = stdin.readline()
Inp = Inp.replace('\n','')
Inp = Inp.split()

do = B(Inp[0],Inp[1])
do.CollectTaste()

Submission status: Accepted

Solution code:
N,L = map(int,input().rstrip().split(' '))
apple_pie = 0
ex = abs(L * N)
apple = []
for i in range(N):
    a = L + i 
    apple.append(a)
    apple_pie += a
for i in range(len(apple)):
    if abs(ex) > abs(apple[i]):
        ex = apple[i]
apple_pie-= ex
print(apple_pie)

Submission status: Accepted

Solution code:
#   B

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

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

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



print(ans)

Submission status: Accepted

Solution code:
N, L = map(int,input().split(' '))
l=list(range(L,N+L,1))
s = sum(l)
ans=-10000
for x in l:
    if abs(ans)>x:
        ans=x
print(s-ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,L =  list(map(int,input().split()))
ringo=0
min=99999999
kekka = []

for i in range(N):
    ringo+=(i+L)
 
    if i+L>0:
        if min >i+L:
            min = i+L
    elif i+L<0:
        if 0 <abs(i+L):
            min = i+L
    elif i+L == 0:
        min = 0
        

print(ringo-min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
orig_taste = int(0.5 * N * (N + 1)) - N + L * N

if L > 0:
    eaten_apple = L
elif L > -N:
    eaten_apple = 0
else:
    eaten_apple = L + N - 1
    
print(orig_taste- eaten_apple)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b= map(int, input().split())
list=[]
list2=[]
sum=0
for n in range(a):
    list.append(n+b)
for n in range(a):
    list2.append(n+b)

if list.count(0)==1:
    for w in list:
        sum += w
    print(sum)
else:
    if list[len(list)-1] > 0:
        for w in list:
            sum += w
        print(sum-list[0])
    else:
        for w in list:
            sum += w
        print(sum-list[len(list)-1])

Submission status: Accepted

Solution code:
import numpy as np

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

tastes = np.arange(N) + L
total_taste = tastes.sum()

tastes_wo_ith_apple = total_taste - tastes
abs_tastes = np.abs(total_taste - tastes_wo_ith_apple)

print(tastes_wo_ith_apple[abs_tastes.argmin()])