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())
end = L + N -1
sum = int((L + end)*N/2)
if L < 0 and end > 0:
    print(sum)
elif abs(L)<abs(end):
    print(sum - L)
else:
    print(sum - end)

Submission status: Accepted

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


def solve(N: int, L: int):
    ls = [L + x for x in range(0, N)]

    if L > 0:
        del ls[0]
        print(sum(ls))

        return

    elif ls.__contains__(0):
        print(sum(ls))

        return
    else:
        del ls[-1]
        print(sum(ls))

        return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()

    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split()) 
arr = np.array(list(range(L, L + N)))
square_arr = np.square(arr)
min_value = square_arr.min()
print(np.sum(arr[~(square_arr==min_value)]))

Submission status: Accepted

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

A=[0]*N
B=[0]*N

for i in range(N):
  A[i]=L+i
  B[i]=abs(L+i)
  if MM>abs(A[i]):
    MM=A[i]
  
#print(A)  
#print(min(B))

if MM>0:
  print(sum(A)-min(B))
else:
  print(sum(A)+min(B))

Submission status: Accepted

Solution code:
def main(str):
    input = str.split()
    n = int(input[0])
    l = int(input[1])
    apples = [l + i for i in range(n)]
    abs_apples = list(map(lambda x: abs(x), apples))
    return sum(apples) - apples[abs_apples.index(min(abs_apples))]


if __name__ == "__main__":
    str = input()
    print(main(str))

Submission status: Accepted

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

al = []
for i in range(n):
    aji = l + i
    aji_ = abs(aji)
    al += [aji_]

x = abs(l)
an = 0
for i in range(n):
    if al[i] < x:
        x = al[i]
        an = i

ans = (l + l+n-1)*n/2 - (l+an)
print(int(ans))

Submission status: Accepted

Solution code:
import copy

line = list(map(int, input().split()))

apple_count = line[0]
apple_taste = line[1]

apple_list = []
taste_list = []

for i in range(1, apple_count+1):
  apple_list.append(i)
  taste_i = apple_taste+i-1
  taste_list.append(taste_i)

risou = sum(taste_list)
results = []

for a in range(len(taste_list)):
  tastes = copy.copy(taste_list)
  tastes.pop(a)
  hikaku = sum(tastes)
  
  abs_a = abs(risou-hikaku)
  results.append(abs_a)

pop_index = results.index(min(results))
taste_list.pop(pop_index)

print(sum(taste_list))

Submission status: Accepted

Solution code:
a = input().split()
num = int(a[0])
L = int(a[1])
apple = dict()
orig_taste = 0
for i in range(1, num + 1) :
    apple[i] = L + i - 1
    orig_taste += L + i - 1

if(L + num - 1 > 0 and L > 0):
    print(orig_taste - L)
elif(L + num - 1 > 0 and L < 0):
    print(orig_taste)
elif(L + num - 1 < 0 and L < 0):
    print(orig_taste - L - num + 1)
else:
    print(orig_taste)

Submission status: Accepted

Solution code:
import numpy as np

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

taste_list = []
for i in range(N):
  taste_i = M + (i+1) - 1
  taste_list.append(taste_i)
  
taste_list = np.array(taste_list)

if M >= 0:
	ind = np.argmin(taste_list)
else:
  if N - 1 >= M * -1:
    ind = M * -1
  else:
    ind = N -1
    

taste_n1 = 0
for i in range(N):
  if i != ind:
  	taste_n1 += M + (i+1) -1
    
print(taste_n1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
number, taste_base = map(int, input().split(' '))

pie_all = int(number * ((number + 1) / 2 + taste_base - 1))

taste_range = range(taste_base, taste_base + number)
taste_range_abs = [abs(i) for i in taste_range]
abs_min = min(taste_range_abs)
minimum = 0

if abs_min in taste_range:
    minimum = abs_min
else:
    minimum = -abs_min

print(pie_all - minimum)

Submission status: Accepted

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

apple =[]

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

pie = 0
flag = 1
min = abs(L)
for i in range(N):
    pie = pie + apple[i]
    if abs(apple[i]) < min:
        min = abs(apple[i])
        if apple[i]<0:
            flag = -1
        else:
            flag = 1

pie = pie - flag * min

print(pie)

Submission status: Accepted

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

ans -= m
print(ans)

Submission status: Accepted

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

for i in range(n):
    dat_a.append(l + i)

total = sum(dat_a)
# print("total" + str(total))

res = 100000
m = 10000

for i in range(n):
    if abs(dat_a[i] < m):
        m = abs(dat_a[i])
        res = dat_a[i]

print(total - res)

Submission status: Accepted

Solution code:
import bisect
N,L=map(int,input().split())
S=[]
M=[]
a=0
for i in range(N):
    S.append(abs(L+i))
    M.append(L+i)
S.sort()
for i in range(N):
    if abs(M[i])==S[0]:
        a=M[i]
print(sum(M)-a)

Submission status: Accepted

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

apples = [x+1 for x in range(N)]
tastes =  [L+i-1 for i in apples]
#print(apples,tastes)
pie = sum(tastes)
absmin = max(abs(tastes[-1]),abs(tastes[0]))
#print(absmin)
for i in tastes:
    if abs(i) < abs(absmin):
        absmin = i
print(pie-absmin)

Submission status: Accepted

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

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

sa=1000000000
for i in range(N):
    a = (L+i)
    if(a<0):
      a=-a
    if(sa > a):
        sa=a

if(Nsum<0):
	print(Nsum+sa)
else:  
	print(Nsum-sa)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
total_taste = N*(L-1)+N*(N+1)/2
min_diff = 10**8
for i in range(1,N+1):
    #print(i)
    apple_taste = L+i-1
    pie_taste = total_taste - apple_taste
    taste_diff = abs(total_taste-pie_taste)
    #print(i,total_taste,pie_taste)
    if taste_diff < min_diff:
        min_diff = taste_diff
        ans = pie_taste
        #print(i,pie_taste)
print(int(ans))

Submission status: Accepted

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

all_taste = N*(L-1)+N*(N+1)/2
tastes_list=[0]*N

for i in range(1,N+1):
    tastes_list[i-1] = L+i-1
abs_list = [abs(x) for x in tastes_list]
min_idx = abs_list.index(min(abs_list))
ans = sum(tastes_list) - tastes_list[min_idx]
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
n,l  = map(int, input().split())
a = np.arange(l,l + n, 1)
amax = l + n -1
amin = l
if amax * amin >0:
    if abs(amax) - abs(amin)>0:
        print(sum(a) - (amin))
    else:
        print(sum(a) - (amax))
elif amax * amin <= 0:
    print(sum(a))
else:
    pass

Submission status: Accepted

Solution code:
import numpy as np

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

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

if sum(apple) >= 0:
	m = min(np.abs(apple))
else:
	m = -min(np.abs(apple))

ans = sum(apple) - m
print(ans)

Submission status: Accepted

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

b = l
s = 0
for a in range(n+1)[1::]:
  m = l + a - 1
  if abs(b) > abs(m):
    b = m
  s += m

print(s - b)

Submission status: Accepted

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

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

abs_lst = list(map(abs, lst))
min_lst = abs_lst.index(min(abs_lst))

lst.remove(lst[min_lst])
res = sum(lst)

#print(abs_lst)
print(res)

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    pia = 0
    for i in range(1, N+1):
        pia += L + i - 1

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

    print(pia - eat)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def sumSuccessionNum(n):
    s = 0
    for i in range(n):
        s += i + 1
    
    return s

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

ans = sumSuccessionNum(N) + (L - 1) * N
tasteMax = L + N - 1
tasteMin = L

if(tasteMax > 0 and tasteMin > 0):
    ans -= tasteMin
elif(tasteMax < 0 and tasteMin < 0):
    ans -= tasteMax

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

elif L <= 0 and N + L -1 >= 0:
    s = ( (L+1-1) + (L+N-1) )*( (N)/2 )
    print(int(s))

else:
    s = ( (L+1-1) + (L+N-1-1) )*( (N-1)/2 )
    print(int(s))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
l=[0]*N
for i in range(N):
	l[i]=L+i
if 0 not in l:
	l.remove(l[-1] if l[0] < 0 else l[0])
print(sum(l))

Submission status: Accepted

Solution code:
N,L = [int(x) for x in input().split()]
A = list(range(L,L+N))
Min = 100
for i in A:
    if Min >= abs(i):
        youso = i
        Min = abs(i)
A.remove(youso)
print(sum(A))

Submission status: Accepted

Solution code:
x = input().split()
x = [int(i) for i in x]
apples = []
for i in range(x[0]):
  apples.append(i+x[1])
ab_apples = [abs(i) for i in apples]
max_ap = max(apples)
min_ab = min(ab_apples)
if max_ap > min_ab:
  apples.remove(min_ab)
  print(sum(apples))
else:
  apples.remove(max_ap)
  print(sum(apples))

Submission status: Accepted

Solution code:
import numpy as np

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

tastes = np.array([L+(i+1)-1 for i in range(N)])

if 0 in tastes:
    print(tastes.sum())
else:
    if np.sign(tastes[0]) == 1:
        print(tastes[1:].sum())
    else:
        print(tastes[:-1].sum())

Submission status: Accepted

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

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

n_sum = sum(a)
answer = 0    
calc = []
for i in range(n) :
    diff = n_sum - a[i]
    calc.append((diff,abs(n_sum-diff)))    

from operator import itemgetter
calc = sorted(calc, key=itemgetter(1), reverse=False)    
    
print(calc[0][0])

Submission status: Accepted

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

Submission status: Accepted

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

x = []
for i in range(n):
        x.append(l + i)
        # print(i)

# print(x)
num = 0

def nearvalue(x, num):
        idx = np.abs(np.asarray(x) - num).argmin()
        del x[idx]
        # print(x)
        print(sum(x))

nearvalue(x, 0)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
sum_list=[]
l2=[]
l3=[]
for i in range(1,N+1):
  sum_list.append(L+i-1)
  
if 0 in sum_list:
  print(sum(sum_list))
else:
  for j in sum_list:
    l3.append(abs(j))

l2=[k for k in sum_list if not 0 in sum_list and abs(k) == min(l3)]

if not 0 in sum_list:
  print(sum(sum_list)-l2[0])

Submission status: Accepted

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

for i in azi:
    if abs(i) < abs(mini):
        mini = i
azi.remove(mini)
print(sum(azi))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
sum=L
m=abs(L)
b=L
for i in range(1,N):
    a=L+i
    sum+=L+i
    if(abs(a)<=m):
        m=abs(a)
        b=a
print(sum-b)

Submission status: Accepted

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

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

idx_eaten = -1
if taste[0] <= 0:
    if taste[n-1] < 0:
        idx_eaten = n - 1
    else:
        idx_eaten = -taste[0]
else:
    idx_eaten = 0
    
result = 0
for i in range(n):
    if i == idx_eaten:
        continue
    result += taste[i]
    
print(result)

Submission status: Accepted

Solution code:
sowa=0
hajime=[]

for x in input().split(" "):
    hajime.append(int(x))

if hajime[1]>0:
    i=2
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

elif hajime[1]==0:
    i=1
    while i<=hajime[0]:
        sowa+=hajime[1]+i-1
        i+=1

else:
    if hajime[0]+hajime[1]-1>=0:
        i=1
        while i<=hajime[0]:
            sowa+=hajime[1]+i-1
            i+=1
    else:
        i=1
        while i<=hajime[0]-1:
            sowa+=hajime[1]+i-1
            i+=1

print(sowa)

Submission status: Accepted

Solution code:
lista = input().split(" ")
a, b = lista
a = int(a)
b = int(b)
s = 0
a1=[]

while(a!=0):
    s+=b
    a1.append(b)
    b+=1
    a-=1
if 0 in a1:
    print((int(s)))
elif(b>0):
    print((int(s)-min(a1)))
else:
    print((int(s)-max(a1)))

Submission status: Accepted

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

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

ap = float("inf")

for a in A :
    if ap > abs(a) :
        ap = abs(a)

applepie = sum(A)


if abs(applepie-ap) < abs(applepie+ap) :
    ans = applepie-ap
else :
    ans = applepie+ap


#ans = min(applepie - ap, applepie + ap)


print(ans)

Submission status: Accepted

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


import sys
import math
from pprint import pprint
import numpy as np


text =input()
N=int(text.split()[0])
sentounoaji=int(text.split()[1])


saigonoaji=sentounoaji+N-1

goukei = int((sentounoaji*N) + (saigonoaji-sentounoaji)*N/2)

if sentounoaji<=0 and 0<=saigonoaji : #0をまたいでいるので何も引かなくてOK。
    print(goukei)
elif 0<sentounoaji :
    print(goukei-sentounoaji)
else :
    print(goukei-saigonoaji)

Submission status: Accepted

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

total_number = 0
abs_min = -1
abs_l = 0
for i in range(l, l+n):
    # print(i)
    if abs_min == -1:
        abs_min = abs(i)
        abs_l = i
    elif abs(i) < abs_min:
        abs_min = abs(i)
        abs_l = i
    total_number += i
print(total_number - abs_l)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
t = [0]*N
for i in range(N):
    t[i] = L+i
a = list(map(abs, t))
idx = a.index(min(a))
t.pop(idx)
print(sum(t))

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int,input().split())
aji_all = aji_all = N*L + (N-1)*N/2
aji_list = np.arange(L,L+N,1)
idx = np.argmin(np.abs(aji_list))
ans = aji_all - aji_list[idx]
print(int(ans))

Submission status: Accepted

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

aji = 0  
mini = 1000
for i in range(0, n) :
    aji = aji + i + l
    if (abs(mini) > abs(i + l)) :
        mini = (i + l)

print(aji-mini)

Submission status: Accepted

Solution code:
n, l = [int(i)  for i in input().split()]
apple=[]
sub=[]
for i in range(1,n +1):
    apple.append(l + i -1)
    
for i in range(n):
    ap=apple.copy()
    ap[i]=0
    sub.append(sum(apple) - sum(ap))


a=list(map(abs, sub))
b=a.index(min(a))
apple.pop(b)
print(sum(apple))

Submission status: Accepted

Solution code:
n, l = [int(v) for v in input().split()]

pre_t = (n * (n-1) // 2) + (n * l)
if l >= 0:
    fix = -l
elif l + n - 1 < 0:
    fix = -(l + n -1)
else:
    fix = 0
print(pre_t + fix)

Submission status: Accepted

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

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

Submission status: Accepted

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

sum_n = []
for i in range(1,n+1):
    sum_n.append(l + i - 1)
num = 1000000000
for i in range(len(sum_n)):
    t = abs(sum_n[i])
    if num > t:
        num = t
        ans = i
print(sum(sum_n) - sum_n[ans])

Submission status: Accepted

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

Submission status: Accepted

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

A = []

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

if A[0] > 0:
    A[0] = 0

elif A[N-1] < 0:
    A[N-1] = 0

else:
    pass

print(sum(A))

Submission status: Accepted

Solution code:
a=[]#入力画面の二文字を別々の文字に格納
a=input().split(" ")
N=int(a[0])
L=int(a[1])


if L>=0 :
    X=N*L+N*(N-1)*0.5-L
    print(int(X))
else:
    if abs(L)>=N:
        X=N*L+N*(N-1)*0.5-(L+N-1)
        print(int(X))
    else:
        X=N*L+N*(N-1)*0.5
        print(int(X))

Submission status: Accepted

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

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

if L<=0 and L+N-1 >= 0:
    ans = sum(N_list)
if L > 0:
    ans = sum(N_list)-L
if L+N-1 < 0:
    ans = sum(N_list)-(L+N-1)

print(ans)

Submission status: Accepted

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

	ans, tmp = 10 ** 8, 0
	for i in range(N):
		tmp = f_all - f_apple[i]
		if abs(tmp - f_all) < abs(ans - f_all):
			ans = tmp

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

if L>=1:
  for i in range(1,N):
    sum=sum+(L+i)
else:
  if N>-1*L:
    for i in range(0,N):
      sum=sum+(L+i)
  else:
    for i in range(0,N-1):
      sum=sum+(L+i)

print(sum)

Submission status: Accepted

Solution code:
import numpy as np

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

# リンゴの味は L, L+1, L+2, ... となる
nums = np.arange(L, L + N)
# 絶対値が最も小さい値のリンゴを選べば良い
# 0を含むなら0を食べる
# それ以外の場合、マイナススタートならラスト、プラススタートなら先頭を食べる
if 0 in nums:
    pass
elif L < 0:
    nums = nums[:-1]
elif L > 0:
    nums = nums[1:]

# 食べた後の合計値を出す
print(np.sum(nums))

Submission status: Accepted

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

wa = 0
ans = []
for i in range(N):
    wa += L + i

b = 0
for i in range(N):
    b = wa - (L + i)
    ans.append([abs(wa - b), b])

ans.sort()
print(min(ans)[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if 0 in b:
  print(sum(b))
  exit()

c = [abs(0-x) for x in b]

d = c.index(min(c))
print(sum(b)-b[d])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split(' '))
apples = []
for i in range(1, n+1):
  apples.append(l + i - 1)
pie = sum(apples)
for i in range(n):
  partial = pie - apples[i]
  if i == 0:
    diff = abs(pie - partial)
    ans = pie - partial
  else:
    d = abs(pie - partial)
    if d < diff:
      diff = d
      ans = pie - partial
print(pie - ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if L < 0 and L+N-1 < 0:
    ans = amount_taste - max(taste)
elif L <= 0 and 0 <= L+N-1:
    ans = amount_taste
elif 0 < L and 0 < L+N-1:
    ans = amount_taste - min(taste)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n, l = map(int, input().split())
sum = 0
a = float('inf')
for i in range(1,n+1):
    sum += l + i - 1
    if a > abs(l + i - 1):
        a = abs(l + i - 1)

# print(sum)

# print(a)
# print(sum)
# print("***************")
if sum >= 0:
    print(sum - a)
else:
    print(sum + a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

    m = INF
    ind=0
    s = l*n + sum(list(range(1, n + 1))) - n

    
    for i in range(1, n + 1):
        if m>abs((l+i-1)*2):
            m = min(m, abs((l+i-1)*2))
            ind=i

    print(s - l - ind + 1)

    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
 
ans = float('inf')
diff_ = float('inf')
max_taste = (L-1) * N + (N*(N+1)) // 2

for i in range(1, N+1):
    tgt = L+i-1
    taste = max_taste - tgt
    diff = abs(max_taste - taste)
    if diff < diff_:
        diff_ = diff
        ans = taste

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import copy
N, L = [int(_) for _ in stdin.readline().rstrip().split()]
tastes = [(L+i-1) for i in range(1, N+1)]
origin = sum(tastes)
ans = 10**9
ans_sum = 0
for i in range(N):
    c_tastes = copy.deepcopy(tastes)
    c_tastes.pop(i)
    tmp = abs(origin-sum(c_tastes))
    if ans > tmp:
        ans = tmp
        ans_sum = sum(c_tastes)
print(ans_sum)

Submission status: Accepted

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

Submission status: Accepted

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

if l < 0 and n+l <= 0:
    kei = sum(list(x for x in range(l,l+n-1)))
    # print(list(x for x in range(l,l+n-1)))
if l < 0 and n+l > 0:
    kei = sum(list(x for x in range(l,l+n)))
    # print(list(x for x in range(l,l+n)))
if l >= 0:
    kei = sum(list(x for x in range(l+1,l+n)))
    # print(list(x for x in range(l+1,l+n)))
print(kei)

Submission status: Accepted

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

mi = 300
choice = 0

for i in range(1, n+1):
  tmp = abs(l + i - 1)
  if tmp < mi:
    mi = tmp
    choice = i
    
ans = 0

for i in range(1, n+1):
  if i == choice:
    continue
  ans += l + i - 1
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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



sum = 0
tmp_list = []
tmp_abs  = []
for i in range(1,n+1):
  tmp = l + i -1
  sum += tmp
  
  tmp_list.append(tmp)
  tmp_abs.append(abs(tmp))

index = tmp_abs.index(min(tmp_abs))
print(sum-tmp_list[index])

Submission status: Accepted

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

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
taste_list = list(map(lambda x:l+x-1, list(range(1,n+1))))
pre_sum = sum(taste_list)

min_sum = 10000000
n_taste_list = list(map(abs, taste_list))

for i in taste_list:
    if abs(min_sum) > abs(i):
        min_sum = i

print(sum(taste_list)-min_sum)

Submission status: Accepted

Solution code:
N,L = (int(i) for i in input().split())
onon = 10000
for i in range(L,L+N):
    if abs(i) <= abs(onon):
        onon = i
print(N*(L*2+N-1)//2-onon)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ls = [int(l+i) for i in range(n)]
absl = [abs(l) for l in ls]
z = min(absl)
s = sum(ls)
if l < 0:
    print(s+z)
else :
    print(s-z)

Submission status: Accepted

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

ans = 10 ** 9
ans2 = 0
tmp = sum(taste)


for i in range(n):

    tmp2 = sum(taste) - taste[i]

    if abs(tmp - tmp2) < ans:

        ans = abs(tmp - tmp2)
        ans2 = tmp2



print(ans2)

Submission status: Accepted

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

Submission status: Accepted

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

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

sum = 0
for i in range(N) :
	sum += l[i]
list = []
for i in range(N) :
	s = 0
	for j in range(N) :
		if (i != j) :
			s += l[j]
	list.append(s)
k = 0
min = 0
for i in range(N) :
	if (i == 0) :
		min = abs(sum - list[0])
		k = list[0]
	else :
		if (min > abs(sum - list[i])):
			min = abs(sum - list[i])
			k = list[i]
print(k)

Submission status: Accepted

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

sum=0

if(L>=0):
    for i in range(2,N+1):
        sum += L+i-1
#        print(i)
else:
    if(abs(L)>=N):
        for i in range(1,N):
            sum += L+i-1
#            print("i=",i,"L+i-1=",L+i-1)
            #print(i)
    else:
        for i in range(1,N+1):
            sum += L+i-1
#            print("i=",i,"L+i-1=",L+i-1)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nl = input().split(" ")
ls = []
al = []
for i in range(int(nl[0])):
    ls.append(int(nl[1])+i)
    al.append(abs(int(nl[1])+i))
if max(ls) < 0:
    print(sum(ls) + min(al))
    exit()
print(sum(ls) - min(al))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
tmp = L
total = 0
aLst = [0] * N
for i in range(N):
    aLst[i] = tmp + i
    total += aLst[i]

ansL = [0] * N
ansM = [0] * N
for i in range(N):
    tmp = 0
    for j in range(N):
        if i == j:
            continue
        tmp += aLst[j]
    ansL[i] = tmp
    ansM[i] = abs(total - tmp)

ans = ansL[0]
tmp = ansM[0]
for i in range(1, N):
    if tmp > ansM[i]:
        tmp = ansM[i]
        ans = ansL[i]


print(ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans=888
SUM=0
s=0
for i in range(l,l+n):
        SUM+=i
        s=i
        if i<0:
                s=1
                i*=-1
        else:
                s=-1
        if ans>i:
                ans=i
       
y=range(l,l+n)
ANS=SUM+s*ans
print(ANS)

Submission status: Accepted

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

for i in range(n):
    point = abs(l+i)
    abs_taste.append(point)
    apple_taste.append(l+i)
 
min_point = min(abs_taste)
index = abs_taste.index(min_point)


 
sums = (n**2)/2 + (l-1/2)*n
print(int(sums - apple_taste[index]))

Submission status: Accepted

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

R=[]
for i in range(N):
    R.append(M+i)
#print(R)

n=10**9
for i in range(N):
    if abs(R[i])<abs(n):
        n=R[i]
#print(n)
if n>0:
    print(sum(R)-n)
else:
    print(sum(R)-n)
#print(sum(R))

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
if L > 0:
    s = np.sum(np.arange(L+1, L+N))
elif L < -N+1:
    s = np.sum(np.arange(L, L+N-1))
else:
    s = np.sum(np.arange(L, L+N))
print(s)

Submission status: Accepted

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

apples = []
apples_abs = []

for i in range(1, N+1):
    apple = L+i - 1
    apples.append(apple)
    apples_abs.append(abs(apple))

min_apple_idx = apples_abs.index(min(apples_abs))
apples.pop(min_apple_idx)
print(sum(apples))

Submission status: Accepted

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

find = 10**9
data = 0
for i in x:
    if abs(i)<find:
        find = abs(i)
        data = i

print(s-data)

Submission status: Accepted

Solution code:

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

if L >= 0:
    sub = L
elif L < 0 and abs(L) < N:
    sub = 0
elif L < 0 and abs(L) >= N:
    sub = L+N-1

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

print(result)