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:
import numpy as np

n,l=list(map(int, input().split()))
tastes=list(range(l,n+l))
abs_tastes=np.abs(tastes)
tastes.pop(np.argmin(abs_tastes))
print(sum(tastes))

Submission status: Accepted

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

min_ = L
max_ = L + N -1

def eat_apple(N, L, max_):
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L, max_))

Submission status: Accepted

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

min_ = L
max_ = L + N -1

def eat_apple():
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print((min_+max_)*(max_-min_+1)//2 - eat_apple())

Submission status: Accepted

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

min_ = L
max_ = L + N -1

def eat_apple(N, L):
    if max_<0:
        return max_ 
    if L < 0:
        return 0
    return L

print((min_+max_)*(max_-min_+1)//2 - eat_apple(N, L))

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
ju=False
for i in range(n):
  if k+i==0:
    ju=True
    break
ans=0
if not ju:
  if k<0:
    for i in range(n-1):
      ans+=k+i
  else:
    for i in range(1,n):
      ans+=k+i
else:
  for i in range(n):
    ans+=k+i
print(ans)

Submission status: Accepted

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

min_ = L
max_ = L + N -1

def eat_apple(N, L):
    if L < 0:
        if max_<0:
            return max_ 
        return 0
    return L

print(int((min_+max_)*(max_-min_+1)/2 - eat_apple(N, L)))

Submission status: Accepted

Solution code:
n,l = map(int,input().split(" "))
ll = []
total=0;
for i in range(0,n):
	s = l+i
	total = total+s
	ll.append(s)
kam = 1000000
for i in range(0,n):
	if(abs(ll[i])<abs(kam)):
		kam=ll[i]
print(total-kam)

Submission status: Accepted

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

val_of_apples = [L+i for i in range(N)]
val_of_apples.sort(key= lambda apple: abs(apple))

print(sum(val_of_apples[1::]))

Submission status: Accepted

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

c = 0
d = 999999

for i in range(b, a + b):
    c += i
    if abs(i) < d:
        d = abs(i)

if c > 0:
    print(c - d)
else:
    print(c + d)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_b
import math
inp = input().split()

n = int(inp[0])
l = int(inp[1])

min_abs = abs(l)
min_num = 0
for i in range(n):
    if abs(l+i) < min_abs:
        min_abs = abs(l+i)
        min_num = i


print(math.ceil(0.5*n*n + n*l - 0.5*n - l - min_num ))

Submission status: Accepted

Solution code:
N, L = [int(n) for n in input().split()]
ans = [L+i-1 for i in range(1,N+1)]
if 0 in ans:
    print(sum(ans))
elif L < 0 and N <= abs(L):
    print(sum(ans)-max(ans))
else:
    print(sum(ans)-min([abs(n) for n in ans]))

Submission status: Accepted

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

a = [i for i in range(l,n+l)]
s = sum(a)
ans = 1e9
for i in range(n):
    t = s-a[i]
    if abs(t-s) < abs(ans-s):
        ans = t 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    lst = []
    for i in range(N):
        lst.append(L+i+1-1)
    convertLst = list(map(abs, lst))
    minElement = min(convertLst)
    lst.pop(convertLst.index(minElement))
    print(sum(lst))
main()

Submission status: Accepted

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

n_diff_abs = []
for a in apple_tastes:
    # 差分の絶対値を格納
    n_diff_abs.append(abs(sum(apple_tastes) - (sum(apple_tastes)-a)))

# 一番小さい値のindexを取得
diff_abs_min_index = n_diff_abs.index(min(n_diff_abs))
print(sum(apple_tastes) - apple_tastes[diff_abs_min_index])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sum_ = int(n * (2 * l + (n - 1)) / 2)
min_ = l
max_ = l + n - 1
if min_ * max_ < 0:
  eaten = 0
else:
  eaten = min_ if abs(min_) < abs(max_) else max_
print(sum_ - eaten)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
Full=int((N**2)/2+N*(L-0.5))
ans=-101
for i in range(L,L+N):
    if abs(ans)>=abs(i):ans=i
    else:pass
print(Full-ans)

Submission status: Accepted

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

error = abs(L)
num = 0

for i in range(N):
    if abs(apples[i]) < error:
        error = abs(apples[i])
        num = i
apples.pop(num)

print(sum(apples))

Submission status: Accepted

Solution code:
def output(in_):
    import numpy as np
    N, L = [int(el) for el in in_.split(' ')]
    tastes = np.arange(L,N+L)
    return sum(tastes) - tastes[np.argmin(abs(tastes))]

  
in_ = input()
print(output(in_))

Submission status: Accepted

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

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

sum1 = sum(li)
ans = 0
abs1 = 10 ** 10

for i in li:
    sum2 = sum1 - i
    if abs(sum2-sum1) < abs1:
        abs1 = abs(sum2-sum1)
        ans = sum2

print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste=[0] #0は数合わせ
sum1=0
for i in range(1,N+1): #1～N
    a=L+i-1
    sum1+=a
    taste.append(a)

#print(sum1)
#print(taste)

ans=0
best=100000
for i in range(1,N+1): #どれを食べるか
    sum2=sum1-taste[i]
    dif=abs(sum1-sum2)
    #print(str(i)+" "+str(sum2)+" "+str(dif))
    if dif<best:
        best=dif
        ans=sum2
print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
Ans=[0]*N
for i in range(N):
    Ans[i]=L+i
remove=1000000000
for i in range(N):
    if remove>=abs(Ans[i]):
        remove=abs(Ans[i])
        re=i
print(sum(Ans)-Ans[re])

Submission status: Accepted

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

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

if 0 <= taste[0]:
    print(sum(taste) - taste[0])
else:
    if 0 <= taste[-1]:
        print(sum(taste))
    else:
        print(sum(taste) - taste[-1])

Submission status: Accepted

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

AJI=[ L+i-1 for i in range(1,N+1) ]
total=sum(AJI)

sa_min=float("inf")
for x in AJI:
	sa_min=min(sa_min, abs(x))

if sa_min in AJI:
	print total-sa_min
else:
	print total-(-1*sa_min)

Submission status: Accepted

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

AJI=[ L+i-1 for i in range(1,N+1) ]
total=sum(AJI)

sa_min=float("inf")
for x in AJI:
	sa_min=min(sa_min, abs(x))

if sa_min in AJI:
	print total-sa_min
else:
	print total+sa_min

Submission status: Accepted

Solution code:
n,l=[int(x) for x in input().split(' ')]
arr=sorted([x+l-1 for x in range(1,n+1)])
arr2=[abs(x) for x in arr]
print(sum(arr)-arr[arr2.index(min(arr2))])

Submission status: Accepted

Solution code:
# B - Bite Eating
# https://atcoder.jp/contests/abc131/tasks/abc131_b
"""
1~Nの数字がある
数列iの対応する値はL+i-1である

N = [1,2,3,4,5]
l = 1
対応する値=[2,3,4,5,6]

a = 対応する値の総和の絶対値を取得する
b = 1つだけ除外し、残った対応する値の総和の絶対値を取得する
aとbの差をなるべく小さくするには？
対応する値は負になることもある
"""

n, L = list(map(int, input().split()))

"""
L + i - 1の対応する値の配列を作成する 
"""
apple_taste = []
taste_total = 0
for i in range(1, n + 1):
    apple_taste.append(L + i - 1)
    taste_total += L + i - 1


"""
要素数が少ないので愚直に一つずつ除外していって差がより小さい箇所を探す
"""

abs_taste_total = abs(sum(apple_taste))
ans = 10 ** 9 # これを差の絶対値が少ないときに入れ替えるようにする
diff = 10 ** 9 # この子は差の絶対値を保持しておく

for i in apple_taste:
    current_total = taste_total - i # iを食べたときの合計値
    abs_current_total = abs(abs(taste_total) - abs(i)) # 現在の値の絶対値。マイナス同士で引くと右辺が正の数として扱われるので絶対値にする

    current_abs = abs(abs(abs_taste_total) - abs(current_total))
    if current_abs < diff:
        diff = current_abs
        ans = current_total

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

taste = []
taste_abs = []
for i in range(N):
    taste.append(L+i)
    taste_abs.append(abs(L+i))
    
minidx = taste_abs.index(min(taste_abs))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

val = range(L, L+N, 1)
total = sum(val)
top = float("inf")

for i in range(len(val)):
    if top > abs(total-(total-val[i])):
        top = abs(total-(total-val[i]))
if total<0:
    print(int(abs(total)-top)*-1)
else:
    print(int(total-top))

Submission status: Accepted

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

zero_include = False

ans = 0
current = l - 1

for i in range(n):
    current += 1
    ans += current

    if current == 0:
        zero_include = True
    
if zero_include == False:
    if current < 0:
        ans -= current
    else:
        ans -= l

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split(' '))
azi = np.array([L+(i+1)-1 for i in range(N)])
azi_abs = abs(azi).tolist()
print(sum(azi)-azi[azi_abs.index(min(azi_abs))])

Submission status: Accepted

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

apple=[]
eat=[]
minim=100000000
for i in range(1,N+1):
    tmp=L+i-1
    apple.append(tmp)
    eat.append([abs(tmp), i])

eat.sort()
print(sum(apple)-apple[eat[0][1]-1])

Submission status: Accepted

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

Submission status: Accepted

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

pie = 0
min_abs = 10000
min_abs_apple = None
for i in range(N):
    if min_abs > abs(i + L):
        min_abs = abs(i + L)
        min_abs_apple = i + L
    pie += i + L

print(pie - min_abs_apple)

Submission status: Accepted

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

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

if x < 1:
    i = 1
elif x < N:
    i = x
else:
    i = N

print(int(S- (L+i-1)))

Submission status: Accepted

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

sum = int(n * (2 * l + n - 1) / 2)

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

Submission status: Accepted

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

print(ans-m)

Submission status: Accepted

Solution code:
[n,l] = [int(i) for i in input().split()]
taste = []
for i in range(n):
  taste.append(l + i)
a = 100000000
for i in range(n):
  if abs(taste[i]) < abs(a):
    a = taste[i]
print(sum(taste) - a)

Submission status: Accepted

Solution code:
import sys
import math

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

all = []
for i in range(n):
    all.append(l+i)
all_sum = sum(all)

minus = 10000
ans = 0
for i in range(len(all)):
    if math.fabs(all_sum - (all_sum - all[i])) < math.fabs(minus):
        minus = math.fabs(all_sum - (all_sum -all[i]))
        ans = all_sum -all[i]
print(ans)

Submission status: Accepted

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

#print(m)  
#inn =m.index(min(m))
z = (list(map(abs,m)))
inn = z.index(min(z))
     
#print(z)
del m[inn]
print(sum(m))

Submission status: Accepted

Solution code:
a,b = map(int,input().split(" "))
ar = []
mn = 10000
for i in range(a):
  ar.append(i+b)
mx = sum(ar)
ans = 0
for r in ar:
    if mn > abs(mx - (mx - r)):
        mn = abs(mx - (mx - r))
        ans = mx - r
print(ans)

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
taste = [0] * N
FLAG = False

for i in range(N):
    taste[i] = L + i
    if taste[i]==0:
        FLAG = True

if FLAG==True:
    print(sum(taste))
if FLAG==False:
    if sum(taste)>0:
        print(sum(taste)-min(taste))
    if sum(taste)<0:
        print(sum(taste)-max(taste))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 14:10:18 2019

@author: Enya
"""

X = input()
N = int(X.split()[0])
L = int(X.split()[1])

A = 0
B = N*(L - 1)

for i in range(N):
    A += i + 1

if B >= 0:
    print(A + B - L)

elif B == -1:
    print(A + B)

else:
    if abs(B) > abs(A):
        print(A + B - L - N + 1)
    
    else:
        print(A + B)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = (int(i) for i in input().split())
d = (l-1)*n+(n+1)*n//2
if l<1: print(d+1-l-min(n,1-l))
else: print(d-l)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = [L+i for i in range(N)]
s = sum(a)
d = float('inf')
ans = 0
for i in a:
    k = s - i
    l = abs(s - k)
    if l < d:
        ans = k
        d = l

print(ans)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
#-------------------------------------

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

ans = 0
minimum = 999
minimum_v = 0
for i in range(n):
        ans += i+l
        if abs(i+l) < minimum:
                minimum = abs(i+l)
                minimum_v = i+l

ans -= minimum_v
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Bite Eating
https://atcoder.jp/contests/abc131/tasks/abc131_b

"""
import sys


def solve(N, L):
    apples = sorted([a  for a in range(L, L+N)], key=lambda x: abs(x))
    return sum(apples[1:])


def main(args):
    N, L = map(int, input().split())
    ans = solve(N, L)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

if __name__ == '__main__':
	main()

Submission status: Accepted

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



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

eat = 0
for i,a in enumerate(An):
  if abs(An[eat]) > abs(a):
    eat = i

print(sum(An)-An[eat])

Submission status: Accepted

Solution code:
n, l = (int(i) for i in input().split())
ap=[]
 
for i in range(n):
	ap.append(l+i)
 
mn=min(map(abs,ap))
 
if mn not in ap:
	mn=-mn
 
res=int((l-1)*n+(1+n)*n/2-mn)
print(res)

Submission status: Accepted

Solution code:

from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

def main():
    num, l = map(int, input().split())
    data = [i + l for i in range(num)]

    ans = data[0]
    for i in range(num):
        if abs(ans) > abs(data[i]):
            ans = data[i]

    print(sum(data) - ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

if L >= 0:
	A = range(2,N+1)
elif L <= 0 and N <= abs(L):
	A = range(1,N)
else:
	A = range(1,N+1)

for i in A:
	ans += L + i - 1

print(ans)

Submission status: Accepted

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

r1, rN = L, L + N - 1          # リンゴ1, N
s  = N * L + N * (N - 1) // 2  # 総和
if r1 * rN > 0:                # 同符号
    s -= r1 if r1 > 0 else rN
print(s)

Submission status: Accepted

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

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

ans = 10 ** 9
cnt = 10 ** 9
for i in range(N):
  num = L + i
  if cnt >= abs(num):
    cnt = abs(num)
    ans = sums - num

print(ans)

Submission status: Accepted

Solution code:
#5 2
#18

#3 -1
#0

#30 -50
#-1044

input_line = input()
lines = input_line.split()
N = int(lines[0])
L = int(lines[1])
total = 0
for i in range(1,N+1):
  taste = L + i - 1
  total += taste
best_diff = None
best = None
for i in range(1,N+1):
  this_total = 0
  for j in range(1,N+1):
    if i == j:
      continue
    this_total += L + j - 1
  score = abs(total - this_total)
  if None == best_diff:
    best_diff = score
    best = this_total
  else:
    if score < best_diff:
      best_diff = score
      best = this_total
print(best)

Submission status: Accepted

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

r1 = L          # リンゴ1
rN = L + N - 1  # リンゴN
s  = sum(range(r1, rN + 1))

if not (r1 <= 0 <= rN):
    s -= r1 if abs(r1) < abs(rN) else rN
print(s)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 23 09:58:29 2019

@author: Yamazaki Kenichi
"""

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

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

eat = 999
for a in Apple:
    if abs(a) < abs(eat):
        eat = a

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

Submission status: Accepted

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

p=999

for i in range(N):
    if abs(ap[i]) < p:
        ans = ap[i]
        p = abs(ap[i])

print(sum(ap)-ans)

Submission status: Accepted

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

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

al = sum(apple)

pies = [al-a for a in apple]

if 0 in apple :
    ans = al
elif abs(al - pies[0]) < abs(al - pies[-1]) :
    ans = pies[0]
else :
    ans = pies[-1]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, l):
    target = sum([l + i for i in range(n)])
    best = 10**10
    ans = 0
    for i in range(n):
        d = abs(l + i)
        if best > d:
            best = d
            ans = target - l - i
    return ans

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

Submission status: Accepted

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

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

if t[0] >= 0:
    p = sum(t) - l
elif t[-1] > 0:
    p = sum(t)
else:
    p = sum(t) - t[-1]

print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split());print(sum(sorted(range(l,l+n),key=abs)[1:]))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = [i for i in range(L, L+N)]
apples_abs = [abs(i) for i in apples]
min_idx = apples_abs.index(min(apples_abs))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
x=[b+i for i in range(a)]
y=sum(x)
print(min([(abs(y-(y-i)),y-i) for i in x],key=lambda x:x[0])[1])

Submission status: Accepted

Solution code:
def solve(N, L):
  A = [L + x for x in xrange(N)]
  A.sort(key = abs)
  A.pop(0)
  return sum(A)
print solve(*map(int, raw_input().split()))

Submission status: Accepted

Solution code:
import numpy as np
 
 
def taste(N, L):
    all_abs = np.array([np.abs(L + i - 1) for i in range(1, N + 1)])
    all_base = np.array([L + i - 1 for i in range(1, N + 1)])
 
    return all_abs, all_base
 
N, L = map(int, input().split())
 
all_abs, all_base = taste(N, L)
 
N_1_all = all_base[np.min(all_abs) != all_abs]
 
re = np.sum(N_1_all)
print(re)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = input().split()
N = int(a[0])
L = int(a[1])
a = [0]*N
for i in range(N):
  a[i] = abs(L+i)
for i in range(N):
  if a[i] == min(a):
    c = int((L-1)*N+N*((N+1)/2)-(L+i))
    print(c)
    break

Submission status: Accepted

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

apples = []
zerochk = False
taste_sum = 0
for i in range(N):
    taste = L + i
    apples.append(taste)
    taste_sum += taste
    if taste == 0: zerochk = True


minval = 100

if zerochk:

    print('{}'.format(taste_sum))

elif L > 0:

    print('{}'.format(taste_sum - apples[0]))

else: # zerochk == True and L < 0

    for i in range(1, len(apples)):
        minval = min(minval, abs(apples[i]))

    ans = 0
    if taste_sum < 0:
        ans = abs(taste_sum) - abs(minval)
        ans *= -1
    else: # taste_sum >= 0
        ans = taste_sum - abs(minval)
    print('{}'.format(ans))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
pi = [L+i-1 for i in range(1, N+1)]
minval = 100 + 200 -1
minindex = 0
for o in range(N):

  if minval>abs(pi[o]):
    minval = abs(pi[o])
    minindex = o

print(sum(pi) - pi[minindex])

Submission status: Accepted

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

r = l + n -1
eat = 0

if r <= 0:
    eat = r
elif l >= 0:
    eat = l
else:
    eat = 0

ans = int((r+l)*(r-l+1)/2-eat)

print(ans)

Submission status: Accepted

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

#最後の味を求める(最初の味はL)
R = l + n - 1

#食べるリンゴを決める
if R <= 0:
  eat = R
elif l >= 0:
  eat = l
else:
  eat = 0

#総和を求めて食べたリンゴを引く
answer = round((R+l) * (R-l+1) / 2 - eat)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

#N個のリンゴ
#リンゴiの味＝L+i-1

#入力（数値）
spline = input().split()
N = int(spline[0])
L = int(spline[1])

#リンゴの味
taste = []
for i in range(1,N+1): #リンゴNは１から数える
    taste.append(L+i-1)  #味の設定
#print(taste)

#1つも食べなかった場合の味
taste_max = sum(taste)
#print("max"+str(taste_max))


#1つ食べた場合の味のリスト
taste_any = []
for k in range(0,N):
    taste_any.append(sum(taste) - taste[k])
#print(taste_any)

#maxとanyの差
#numpy配列にしてから計算
taste_any = np.asarray(taste_any)
diff = abs(sum(taste) - taste_any)
#numpy配列からリストに戻す（.indexメソッドが使いたいから）
diff_list = diff.tolist()
#print("diff_list"+str(diff_list))
#最小値のインデックスを取得する
coef = diff_list.index(min(diff_list))
#print(coef)

print(taste_any[coef])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1,N + 1):
    if abs(min) > abs(L + i - 1):
        min = L + i - 1
    sum += L + i - 1

sum -= min
print(sum)

Submission status: Accepted

Solution code:
#ABC131-B

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,l=LI()

  a=[]
  for i in range(n):
    a.append(l+i)

  sm=sum(a)

  mn=inf
  mn_i=-1
  for i in range(n):
    x=a[i]
    if mn>abs(x):
      mn=abs(x)
      mn_i=i

  return sm-a[mn_i]

print(main())

Submission status: Accepted

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

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

sum = 0
b= min(np.abs(taste))
for i in taste:
    if b != abs(i):
        sum += i

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import re
import time

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

total=(L-1)*N+((1+N)/2)*N
mn=1e9
ans=1e9
for a in range(N):
    l=L+(a+1)-1
    if abs(l)<mn:
        mn=min([mn,abs(l)])
        ans=l
print(int(total-ans))

Submission status: Accepted

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

a = 10**6
b = 0
ans = 0
for i in range(1,N+1):
    if abs(L+i-1) < a:
        a = abs(L+i-1)
        b = i

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

print(ans)

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-1)*(2*l+n-2)//2)
else:
  print(n*(2*l+n-1)//2)

Submission status: Accepted

Solution code:
n , k = [int(x) for x in input().split()]
s = n * k + (n*(n-1))//2
g = 100000
v = 100000
for x in range(n):
    if(g > abs(k + x)):
      g = abs(k+x)
      v = k + x
    
print(s - v)

Submission status: Accepted

Solution code:
n , L = map(int, input().split())
taste = 0

if L >= 0:
    taste = L * (n-1) - n + n*(n+1)/2

elif -L >= n:
    taste = L * (n-1) - (n-1) + n*(n-1)/2

else:
    taste = L * n + n*(n+1)/2 - n

print(int(taste))

Submission status: Accepted

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

Submission status: Accepted

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

def result(min_, max_):
  out = 0
  for i in range(min_, max_+1):
    out += i
  return out

min_taste = L
max_taste = L + N -1

if (min_taste <= 0) and (max_taste <= 0):
  print(result(min_taste, max_taste-1))
elif (min_taste <= 0) and (max_taste > 0):
  print(result(min_taste, max_taste))
else:
  print(result(min_taste+1, max_taste))

Submission status: Accepted

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

R=[0]*N

for kai in range(N):
    R[kai]=L+kai


kotoae=0
kotae=0
if(R[0]>0):
    for kai1 in range(N):
        kotoae=kotoae+R[kai1]
    print(kotoae-R[0])
elif(R[N-1]<0):
    for kai1 in range(N):
        kotae=kotae+R[kai1]
    print(kotae-R[N-1])
else:
    for kai in range(N):
        kotae=kotae+R[kai]
    print(kotae)

Submission status: Accepted

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