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())
r=[]
t=0
for i in range(1,n+1):
    r.append(int(l+i-1))
zero =0 in r
if zero==0 and r[0]>0:
    r.pop(0)
elif zero==0 and r[0]<0:
    r.pop(n-1)
elif zero==1:
    r.remove(0)
for i in range(n-1):
    t+=r[i]
print(t)

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
t = []
for i in range(N):
    t.append(L+i)
# print(t)
base = sum(t)
ans = -1
r = float('inf')
for j in range(N):
    if abs(t[j]) < r:
        r = abs(t[j])
        ans = j
print(base-t[ans])

Submission status: Accepted

Solution code:
import numpy as np

# 2つの整数の入力
N, L = map(int, input().split())

# 味を数列化
taste = np.arange(L, L + N, 1)

# 味の最小・最大ともに0以上の場合は最小値を選ぶ
if np.min(taste) >= 0 and np.max(taste) >= 0:
  print("{}".format(np.sum(taste) - np.min(taste)))

# 味の最小・最大ともに0以下の場合は最大値を選ぶ
elif np.min(taste) <= 0 and np.max(taste) <= 0:
  print("{}".format(np.sum(taste) - np.max(taste)))

# それ以外の場合は0を選ぶ
else:
  print("{}".format(np.sum(taste)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


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

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

    total = sum(a)
    mini = INF
    ans = INF
    for i in range(N):
        x = total - a[i]
        if abs(total - x) < mini:
            mini = abs(total - x)
            ans = x
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

# main
for i in range(len(flavour)):
    sum2.append(abs(sum1 - sum(flavour[:i] + flavour[i+1:])))

# output
print(sum1 - flavour[sum2.index(min(sum2))])

Submission status: Accepted

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

Submission status: Accepted

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

pai = 0

for n in range(N):
    if L < 0:
        if L+n == 0:
            next

    pai = pai + L + n

if L+N <= 0:
    pai = pai - (L + N - 1)

if L > 0:
    pai = pai - L

print(pai)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
least = 1000000
res = 0
for i in range(1,n+1):
    f = l + i - 1
    if least > abs(f):
        least = abs(f)
        least_f = f
    res += f
print(res - least_f)

Submission status: Accepted

Solution code:
import numpy as np

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

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

if apple[0]*apple[-1]<=0:
  print(sum(apple))
elif apple[0]<0:
  print(sum(apple[:-1]))
else:
  print(sum(apple[1:]))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
name = [i for i in range(1, N+1)]
all_taste = [j + L -1 for j in name]
all_sum = sum(all_taste)
if 0 in all_taste:
  print(all_sum)
else:
  abs_li = [abs(k) for k in all_taste]
  mi = min(abs_li)
  if not mi in all_taste:
    mi = -1 * mi
  print(all_sum - mi)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
lst = []
n, l = map(int, input().split())
lst = list(range(l, l+n))
if lst.count(0) == 1:
	ans = sum(lst)
elif max(lst) > 0:
	del lst[0]
	ans = sum(lst)
else:
	del lst[-1]
	ans = sum(lst)
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = [L + i for i in range(N)]
b = list(map(lambda x:abs(x), a))
c = b.index(min(b))
del a[c]
print(sum(j for j in a))

Submission status: Accepted

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

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

m = res[0]
for r in res:
    if abs(r) < abs(m):
        m = r
res.remove(m)

print(sum(res))

Submission status: Accepted

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

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

diff = 99999999
ans_taste = 0
ans_i = 9999
for i in range(1,N+1) :
    taste = taste_all - (L+i-1)
    d = abs(taste_all - taste)
    if (d < diff ) :
        diff = d
        ans_taste = taste
        ans_i = i

print(ans_taste)

Submission status: Accepted

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

if 0 in taste:
    print(sum(taste))
else:
    if taste[0] > 0:
        print(sum(taste) - taste[0])
    else:
        print(sum(taste) - taste[N - 1])

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
arr = [_ for _ in range(l, l + n)]
_sum = sum(arr)
tmp = 1000
for i in range(1, n + 1):
    n_sum = sum(arr[:i - 1] + arr[i:])
    if abs(_sum - n_sum) < tmp:
        tmp = abs(_sum - n_sum)
        ans = n_sum
print(ans)

Submission status: Accepted

Solution code:
def solve(l:list)->int:
    ab_l = list(map(abs, l))
    del l[ab_l.index(min(ab_l))]
    return sum(l)


def main():
    n, k = map(int, input().split())
    l = [i + k for i in range(n)]
    print(solve(l))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = []
check = 1000
eat = 0

for i in range(1, n+1):
    apples.append(l+i-1)
    if abs(l+i-1) < check:
        eat = l+i-1
        check = abs(l+i-1)

ans = sum(apples) - eat
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


apples_taste = []
abs_apples_taste = []

for i in range(int(N)):
  apples_taste.append(i+int(L))
  abs_apples_taste.append(abs(i+int(L)))

abs_apples_taste.sort()
if abs_apples_taste[0] in apples_taste:
  print(sum(apples_taste) - abs_apples_taste[0])
else:
  print(sum(apples_taste) + abs_apples_taste[0])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
v=[l+i-1for i in range(1,n+1)]
if l>=0:
  v.pop(0)
elif n<=abs(l): #v=0となるiがあるということ
  v.pop(n-1)
print(sum(v))

Submission status: Accepted

Solution code:
#coding:utf-8
import math
n, l = map(int,input().split())
#print(n, l)

all_taste = 0
#全てのりんごを使った時の味
for i in range(1, n+1):
    #print(i)
    tmp = l + i - 1
    all_taste = all_taste + tmp

#print(all_taste)
act_taste = 0

#食べるりんご（味がいちばん低いもの）を求める
eat_apple = l + 1 - 1
for i in range(1, n+1):
    cmp_apple = l + i - 1
    #print(eat_apple, cmp_apple)
    if abs(cmp_apple) <= abs(eat_apple):
        eat_apple = cmp_apple
        act_taste = all_taste - eat_apple

#print(eat_apple)
print(act_taste)

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    tot = 0
    remove = float('inf')
    for i in range(1, N+1):
        tot += L+i-1
        if abs(remove) > abs(L+i-1):
            remove = L+i-1
    return tot - remove

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ringo=[L+i for i in range(N)]
idealy = sum(ringo)
min_ringo = min(list(map(abs, ringo)))

if min_ringo in ringo:
    ringo.append(-min_ringo)
else:
    ringo.append(min_ringo)

print(sum(ringo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N, L = map(int, sys.stdin.readline().split())
tastes= [L+i-1 for i in range(1, N+1)]

if 0 <= L:
  tastes.pop(0)

elif L+N <= 0:
  tastes.pop(-1)

print(sum(tastes))
exit()

Submission status: Accepted

Solution code:
N,L = list(map(int, input().split()))
s = []
min = 1000
for i in range(N):
    s.append(i+L)
    if abs(s[i]) < min:
        min = abs(s[i])
        i_min = i
print(sum(s)-s[i_min])

Submission status: Accepted

Solution code:
#B - Bite Eating(ABC131)
A=list(map(int, input().split()))
aji1=0
B=[]
C=[]
for i in range(1,A[0]+1):
    aji1+=A[1]+i-1
    B.append(abs(A[1]+i-1))
    C.append(A[1]+i-1)
print(aji1-C[B.index(min(B))])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
val = [l + i for i in range(n)]
min_v = 100
min_i = 0

for i in range(n):
    abs_v = abs(val[i])
    if abs_v < min_v:
        min_v = abs_v
        min_i = i

print(sum(val) - val[min_i])

Submission status: Accepted

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

# 絶対値が一番小さいものを選択し、それ以外での合計を出力

list_aji = []
abs_aji_min = 100000
index_abs_aji_min = 0
for n in range(1,N+1):
  aji = n + L - 1
  if abs(aji) < abs_aji_min:
    abs_aji_min = abs(aji)
    index_abs_aji_min = n-1
  
  list_aji.append(aji)
  
ans = sum(list_aji) - list_aji[index_abs_aji_min]
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, L = map(int, input().split())
v = np.arange(N) + L

if v[0] >= 0:
    s = v[1:].sum()
else:
    d  = v[np.argmin(abs(v))]
    s = v.sum() - d

print (s)

Submission status: Accepted

Solution code:
I=input()
N=int(I.split()[0])
L=int(I.split()[1])
x=1
A=[]
R=0

for i in range(N):
    A.append(x+L-1)
    R+=x+L-1
    x+=1
    
B=[]
for w in A:
    B.append(abs(w))

print(R-A[B.index(min(B))])

Submission status: Accepted

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

eat_taste = 99999
sum_taste = 0
for i in range(n):
  taste = l + i
  sum_taste += taste
  if abs(taste) < abs(eat_taste):
    eat_taste = taste
print(sum_taste - eat_taste)

Submission status: Accepted

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

full = int(N*L + N*(N+1)/2 - N)
absdiff = []
diff = []
for i in range(1,N+1):
    absdiff.append(abs(L+i-1))
    diff.append(full-(L+i-1))

print(diff[absdiff.index(min(absdiff))])

Submission status: Accepted

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

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

if (l-1) < 0:
  if (l+n-1) < 0:
    ret = sum(apples[:-1])
  else: #(l+n-1) >= 0:
    ret = sum(apples)
else: #(l-1) >= 0:
  ret = sum(apples[1:])

print(ret)

Submission status: Accepted

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

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

total = sum(score)


ans = 9999999999
for i in range(n):
  temp = score[i]
  score[i] = 0
  culTotal = sum(score)  
  score[i] = temp
  diff = abs(total-culTotal)
  if ans > diff:
    ans = diff
    result = culTotal
  
print(result)

Submission status: Accepted

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

t_all = 0
t_bite = 0

for i in range(N):
    t_all += (L+i)
#print t_all

for i in range(N):
    t_tmp = 0
    for j in range(N):
        if i == j:
            continue
        else:
            t_tmp += (L+j)
#    print t_tmp,i
    if abs(t_all - t_bite) > abs(t_all - t_tmp):
        t_bite = t_tmp

print t_bite

Submission status: Accepted

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

ans=0
for i in apple[1:]:
    ans+=i[1]

print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
L = l
R = n+l-1
eat = 0

if L >= 0 : eat = L
elif R <= 0 : eat = R
else : eat = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
r = 10 ** 9
v = 0
ans= 0

for i in range(l, n + l):
    ans += i
    if abs(i) < r:
        v = i
        r = abs(i)

ans -= v
print(ans)

Submission status: Accepted

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


for i in range(N):
    p = abs(sum(taste) - sum(taste[:i] + taste[i+1:]))
    if i == 0:
        minnum = p
        min_i = 0
    elif p < minnum:
        minnum = p
        min_i = i


print(sum(taste[:min_i] + taste[min_i + 1:]))

Submission status: Accepted

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

m = 300
cnt = 0
for i in range(n):
    if abs(l+i) < m:
        m = abs(l+i)
        cnt = i
ans = int(l*n + (1/2)*(n-1)*n - (l+cnt))
print(ans)

Submission status: Accepted

Solution code:
#1番目の味はL,最後の味はL＋N－１
N,L=map(int,input().split())
taste=[]
for i in range(N):
  taste.append(i+1+L-1)
if L>=1:
  print(sum(taste)-L)
elif L==0:
  print(sum(taste))
elif L<0:
  if L+N-1<0:
    print(sum(taste)-(L+N-1))
  else:
    print(sum(taste))

Submission status: Accepted

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

for i in range(n):
    lis.append(l+i)
som=0
for i in range(n):
    som+=lis[i]
a=abs(lis[0])
for i in range(n-1):
    if abs(lis[i+1])<abs(a):
        a=lis[i+1]

print(int(som-a))

Submission status: Accepted

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


def solve(N: int, L: int):
    
    taste_perfect_pi = 0
    firstTaste = L
    lastTast = L + N - 1

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

    if L >= 0:
        print(taste_perfect_pi - firstTaste)
    elif L + N -1 >= 0:
        print(taste_perfect_pi)
    else:
        print(taste_perfect_pi - lastTast)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    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)=input().split(' ')
N = int ( N )
L = int ( L )
A =[]
B =[]
for i in range ( N ) :
   A.append ( abs ( L + i ) )
   B.append ( L + i )

A.sort()   

if  ( L < 0 ) :
    print ( sum ( B ) + A[0] )

else :
    print ( sum ( B ) - A[0] )

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
flavors = [x + L - 1 for x in range(1, N + 1)]
flavors.remove(min(flavors, key=abs))
# flavors.pop(flavors.index(min(flavors, key=abs)))
print(sum(flavors))

Submission status: Accepted

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

Submission status: Accepted

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

state = [0 for _ in range(N)]

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

tmp = 10 ** 9

for i in range(N):
    if tmp > abs(sum(state) - sum(state)-state[i]):
        tmp = abs(sum(state) - sum(state)-state[i])
        res = sum(state) - state[i]

print(res)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
min_abs = 10**9
tmp = 10**9
for i in range(n):
    if abs(l + i) < min_abs:
        min_abs = abs(l+i)
        tmp = i
ans = 0
for i in range(n):
    if i == tmp:
        continue
    else:
        ans += l + i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import numpy as np
N, L = map(int, input().split())
taste = []
for i in range(N):
  taste.append(L + i)

pie = []
for i in range(N):
  temp = copy.deepcopy(taste)
  del temp[i]
  pie.append(abs(sum(taste) - sum(temp)))
del taste[np.argmin(pie)]
print(sum(taste))

Submission status: Accepted

Solution code:
n,l=[int(x) for x in input().split()]
ringo=list(range(l,l+n))

if ringo[0]>0 and ringo[-1]>0:
  print(sum(ringo[1:]))
elif ringo[0]<0 and ringo[-1]<0:
  print(sum(ringo[:-1]))
else:
  print(sum(ringo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, l = map(int, input().split(' '))
    a = 199
    for i in range(1, n+1):
        if abs(taste(i, l)) < abs(a):
            a = taste(i, l)
    print(sum([taste(j, l) for j in range(1, n+1)]) - a)


def taste(i, l):
    return l + i - 1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Bite Eating
N, L = map(int,input().split())
aji = 0
for i in range(1, N+1):
    if i == 1:
        aji = aji
    elif i == N:
        if L + i - 1 <= 0:
            aji = aji + (L + 1 - 1) # N番目の味がマイナスの場合、N番目のリンゴを食べて1番目のリンゴは残す
        else:
            aji = aji + (L + i - 1)
    else:
        if L + i - 1 == 0:
            aji = aji + L
        else:
            aji = aji + (L + i - 1)

print(aji)

Submission status: Accepted

Solution code:
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

# listb = []
# listb = [int(n) for n in inputb]

sum = 0

smallest = -1
idx = 0

for i in range(a):
    sum += b + i

    if smallest == -1:
        smallest = abs(b + i)
    elif smallest > abs(b + i):
        smallest = abs(b + i)
        idx = i

ans = sum - (b + idx)
print(int(ans))

Submission status: Accepted

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

x=[l+i-1 for i in range(1,n+1)]
x.remove(min(x, key=abs))
print(sum(x))

Submission status: Accepted

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

Submission status: Accepted

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

x=[l+i-1 for i in range(1,n+1)]
min_val=None
idx=0
for i in range(1,n+1):
  tmp=abs(l+i-1)
  if min_val is None or tmp < min_val:
    min_val=tmp
    idx=i-1

x.pop(idx)
print(sum(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,l = map(int,input().split())

apple=np.array(list(range(1,n+1,1))) 
taste = np.array(list(range(1,n+1,1))) + l -1

if n+l > 0:
    ans=np.sum(taste)-min(np.abs(taste))
else:
    ans=np.sum(taste)+min(np.abs(taste))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


sumtaste=0
if taste[0]*taste[-1]<0:
    for i in taste:
        sumtaste+=i
elif taste[0]>=0:
    del taste[0]
    for i in taste:
        sumtaste+=i
else:
    taste.pop()
    for i in taste:
        sumtaste+=i
print(sumtaste)

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)
if N+L>0:
  print(sum(li)-min(np.abs(li)))
else:
  print(sum(li)+min(np.abs(li)))

Submission status: Accepted

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

apples=[a+i for i in range(n)]
eat=min(apples,key=lambda x:abs(x))
res=sum(apples)-eat

print(res)

Submission status: Accepted

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

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

import numpy as np
b=min(np.abs(l))

if b==0:
  l.remove(0)
elif b in l:
  l.remove(b)
elif -b in l:
  l.remove(-b)
  
print(sum(l))

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
s = []
cnt = 0
min_apple = 9999
sub_apple = 0
for i in range(n):
    s.append(l + i)
    if min_apple > abs(l + i):
        min_apple = abs(l + i)
        sub_apple = s[i]
print(sum(s) - sub_apple)

Submission status: Accepted

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

apples = [L + i for i in range(N)]
eat = min(apples, key=lambda x: abs(x))
res = sum(apples) - eat
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
list_taste = [l+i for i in range(n)]
 
if 0 in list_taste:
  ans = sum(list_taste)
else:
  if list_taste[0] > 0:
  	ans = sum(list_taste) - min(list_taste)
  else:
    ans = sum(list_taste) - max(list_taste)

print(ans)

Submission status: Accepted

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

apples = [l+i-1 for i in range(1, n+1)]
del apples[list(map(abs, apples)).index(min(list(map(abs, apples))))]
print(sum(apples))

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
a=sum(i+l for i in range(n))
c=10000
id=0
for i in range(n):
    if abs((a-i-l)-a)<c:
        c=abs((a-i-l)-a)
        id=i
print(a-id-l)

Submission status: Accepted

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

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

absmin = -1
absi   = -1
for i in range(N):
    absval = abs( L + i )
    if absmin == -1 or absmin > absval:
        absmin = absval
        absi = i

print( allpi - (L+absi))

Submission status: Accepted

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

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

if 0 in ans:
    print(sum(ans))
else:
    mn = min(ans)
    mx = max(ans)
    if abs(mn) <= abs(mx):
        ans.remove(mn)
        print(sum(ans))
    else:
        ans.remove(mx)
        print(sum(ans))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
lst = []
for i in range(n):
    lst.append([i + l, abs(i + l)])
lst = sorted(lst, key=lambda x: x[1])
total = 0
for i in range(1, len(lst)):
    total += lst[i][0]
print(total)

Submission status: Accepted

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

_list = list(range(L, L+N))

k = [abs(i) for i in _list].index(min([abs(i) for i in _list]))

_list.pop(k)
ans = sum(_list)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

apples = [0] * (N + 1)
applepie = 0
eaten = 100 + 200

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

    if eaten**2 > apples[i]**2:
        eaten = apples[i]

print(applepie - eaten)

Submission status: Accepted

Solution code:
def resolve():
    n,l = map(int,input().split())
    min1,sum1 = 10*10,0
    for i in range(n):
        if abs(min1)>abs(i+l):
            min1 = i+l
        sum1 += i+l
    print(sum1-min1)
resolve()

Submission status: Accepted

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

min = 10000
min_raw = 100000
ans = 0

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

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

print(ans-min_raw)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = list(map(int,input().split()))
ans = int((2*l-1+n)*(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())
sum=0
A=[]
ans=-1
for x in range(0,N):
    A.append(-L-x)
for i in range(0,N):
    sum=sum+L+i
for i in range(0,N):
    for j in range(0,N):
        A[i]=A[i]+L+j
    if sum==A[i]:
        ans=i
        break
if ans>-1:
    print(A[ans])
elif A[0]<sum:
    print(A[0])
else:
    print(A[N-1])

Submission status: Accepted

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

m = abs(L)+abs(N)
j = 0
for i in range(N):
    if abs(L+i) < m:
        m = min(abs(L+i), m)
        j = i

t = 0
for i in range(N):
    if i != j:
        t += L+i

print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, a = map(int,input().split())
l = a
r = a+n-1
if r<=0: e = r
elif l>=0: e = l
else: e = 0

print(int((r+l)*(r-l+1)/2-e))

Submission status: Accepted

Solution code:
#nはリンゴの数　lは味の係数
n, l = list(map(int, input().split()))
#味のリスト
tastes = [l+x for x in range(n)]
#味の総和
all_tas = sum(tastes)
#一つだけ食べた総和のリスト
ptn = [all_tas - x for x in tastes]
#総和との差
di  = [abs(all_tas - x) for x in ptn]
#差が一番小さいものを取得
val = min(di)
#答え
print (ptn[di.index(val)])

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
import numpy as np
N,L=map(int,input().split())
a=[]
for i in range(1,N+1):
  b=L+i-1
  a.append(b)
c=sum(a)
if L>0:
  d=min(a)
  print(c-d)
elif L<=0 and L>-N:
  print(c)
elif L<=-N:
  d=max(a)
  print(c-d)

Submission status: Accepted

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

import numpy as np

a=[]
m=1e1000
for i in range(N):
    tmp=L+i+1-1
    a.append(tmp)
    if np.abs(m)>np.abs(tmp):
        m=tmp
a.remove(m)
print(sum(a))

Submission status: Accepted

Solution code:
def solve():
    n, l = map(int, input().split())
    tastes = [l + i for i in range(n)]
    if 0 in tastes:
        return sum(tastes)
    elif all([t > 0 for t in tastes]):
        return sum(tastes) - min(tastes)
    elif all([t < 0 for t in tastes]):
        return sum(tastes) - max(tastes)


if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N,L = map(int, input().split())
A = []
ans = 0

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

if A[0] > 0:
	for j in range(1, N):
		ans += A[j]

elif A[N - 1] < 0:
	for j in range(0, N - 1):
		ans += A[j]

else:
	for j in range(N):
		ans += A[j]
print(ans)

Submission status: Accepted

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

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

B = list(map(lambda x: abs(x), A))
print (sum(A) - A[B.index(min(B))])

Submission status: Accepted

Solution code:
[n,l]=[int(x) for x in input().split()]
su=n*l+(n*n+n)//2-n
if l<=0 :
    if l+n-1>=0:
        print(su)
    else:
        print(su-(l+n-1))
elif l>0:
    print(su-l)

Submission status: Accepted

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

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

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