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())
apl_val = [L + i - 1 for i in range(1, N+1)]
# print(apl_val)
sumpi = sum(apl_val)

diff = 1000
for j in apl_val:
  if diff >= abs(j):
    diff = abs(j)
    ans = sumpi - j
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

A = []
for i in range(N):
  A.append(L+i+1-1)
A = np.array(A)
j = np.argmin(np.abs(A))
A = np.delete(A, j)
print(np.sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [L+i for i in range(N)]
eat = 10**9
total = 0
for ti in taste:
    if abs(ti) < abs(eat):
        eat = ti
    total += ti
print(total - eat)

Submission status: Accepted

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

S = []

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

mi = min(S)

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

if su < 0:
    print(su+mi)
else:
    print(su-mi)

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
min_aji = abs(L)
min_aji_index = 0
for i in range(1,N):
  abs_aji = abs(L + (i+1) - 1)
  if abs_aji < min_aji:
    min_aji = abs_aji
    min_aji_index = i
    
aji = 0
for i in range(N):
  if i != min_aji_index:
    aji += L + (i+1) - 1
    
print(aji)

Submission status: Accepted

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

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

minumum=10000
for i in range(1,N+1):
    if abs(minumum) > abs(L+i-1):
        minumum = L+i-1
    
print(int(sums-minumum))

Submission status: Accepted

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

total = 0
for i in range(n):
    total += l+i

if l <= 0 and l+n-1 >= 0:
    print(total)

elif l+n-1 < 0:
    print(total-l-n+1)

else:
    print(total-l)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = 0
nums = [i for i in range(L, N+L)]
to_delete = min(range(N), key=lambda x: abs(nums[x]))
print(sum(nums) - nums[to_delete])

Submission status: Accepted

Solution code:
N, L = [int(x) for x in input().split()]
mini = -111
data = [i for i in range(L, L+N)]
for i in data:
    if abs(i) < abs(mini):mini = i
    if i == 0:break
print(sum(data) - mini)

Submission status: Accepted

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

a = sum(taste)
tmp = abs(a - (a - taste[0]))
ans = a - taste[0]
for i in range(N - 1):
    if abs(a - (a - taste[i + 1])) < tmp:
        tmp = abs(a - (a - taste[i + 1]))
        ans = a - taste[i + 1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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


ate=L
if L<=-1:
    if L+N-1<0:
        ate=L+N-1
    else:
        ate=0
else:
    ate=L

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

print(int(suma-ate))

Submission status: Accepted

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

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

cur_diff = float('inf') 
ans = float('inf')
Sum = sum(A)
for a in A:    
    tmp = Sum - a
    diff = abs(Sum - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp

print(ans)

Submission status: Accepted

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

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

if 0 in apple:
    print(sum(apple))
elif max(apple) < 0:
    print(sum(apple) - max(apple))
elif min(apple) > 0:
    print(sum(apple) - min(apple))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

ans = 0
if l>=0:
    for i in range(n):
        if i != 0:
            ans += l+i
else:
    if l>-1*n:
        for i in range(n):
            ans += l+i
    else:
        for i in range(n-1):
            ans += l+i

print(ans)

Submission status: Accepted

Solution code:
import scipy as sp

N, L = map(int, input().split())
taste = sp.arange(L, L+N)
s = sum(taste)

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

Submission status: Accepted

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

print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
list=[]
List=[]
for i in range(a):
  list.append(b+i)
for j in range(a):
  List.append(abs(b+j))
LIST=sum(list)
List=min(List)
if int(LIST)<0:
  print(int(LIST)+int(List))
else:
  print(int(LIST)-int(List))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

apples = []

for index in range(1, n + 1):
    apples.append(l + index - 1)

sum = sum(apples)
maybe_ans_list = []

for apple in apples:
    maybe_ans_list.append((abs(sum - (sum - apple)), sum - apple))

ans = min(maybe_ans_list,key=lambda x:x[0])

print(ans[1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = 0
ringo = [0]*N
for i in range(N):
    ringo[i] = L+i

ringo.sort(key= lambda x:abs(x))
ringo[0] = 0
print(sum(ringo))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    a=l+i
    if(a==0):
        f=1
    else:
        s+=a
if(f==0):
    if(l<0):
        s-=(l+n-1)
    else:
        s-=l
print(s)

Submission status: Accepted

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

score=[]
for i in range(N):
    score.append(L+i+1-1)
score.remove(min(score, key=lambda x: abs(x)))
print(sum(score))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N, L = tuple(li())
total = N * (L + N + L - 1) // 2
delta = 1 - L
if delta < 1:
    print(total - L)
elif delta > N:
    print(total - (L - 1 + N))
else:
    print(total)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,L=MAP()

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

mn=INF
idx=0
for i, a in enumerate(A):
    if abs(a)<mn:
        idx=i
        mn=abs(a)

print(sum(A)-A[idx])

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(data) - data[taste.index(min(taste))] )

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [L + n for n in range(N)]
minimum = 999999999
for t in taste:
    minimum = t if abs(t) < abs(minimum) else minimum

print(sum(taste) - minimum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
sum = N * L + (N * (N - 1) //2)

if 1-L < 1:
    print(sum - L)
elif 1 - L > N:
    print(sum - (L + N - 1))
else:
    print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

price = []

for n in range(N):
  price.append(n+L)
  
p2 = np.array(price)
p2 = p2**2
m = min(p2)
index = np.where(p2==m)[0]


price.pop(index)

print(sum(price))

Submission status: Accepted

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

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

num = [L+i-1 for i in range(1, N+1)]
result = sum(num)
print(result-eat)

Submission status: Accepted

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

output = sum(aji)-min(list(map(abs,aji)))

if aji[list(map(abs,aji)).index(min(list(map(abs,aji))))]<0:
    output += 2*min(list(map(abs,aji)))

print(output)

Submission status: Accepted

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

taste = [l+i for i in range(n)]
if min(taste)>=0:
  ans = sum(taste) - min(list(map(abs, taste)))
else:
  ans = sum(taste) + min(list(map(abs, taste)))

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

apples = list(range(l,l+n))

delapple = list(map(abs,apples))

delindex = delapple.index(min(delapple))

del(apples[delindex])

print(sum(apples))

Submission status: Accepted

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

def func(x):
  return(x+l)

a = list(range(n))
b = list(map(func, a))

m = l
for i in range(len(b)):
  if abs(m) > abs(b[i]):
    m = b[i]

ans = sum(a)+l*n-m
print(ans)

Submission status: Accepted

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

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


buff = sorted(buff, key=lambda x: abs(x[0]))

ans = 0
for i in range(len(buff)):
    if i > 0:
        ans += buff[i][0]
print(ans)

Submission status: Accepted

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

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

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

print(Sum-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
taste = [l+i-1 for i in range(1, n+1)]
total = sum(taste)
diff = []
score = []
for i in range(n):
  tmp = sum(taste[i+1:])+sum(taste[:i])
  diff.append(abs(total - tmp))
  score.append(tmp)
print(score[diff.index(min(diff))])

Submission status: Accepted

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

Submission status: Accepted

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

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

output = [0] * N

summation = sum(taste)

import itertools

for i, item in enumerate(list(itertools.combinations(taste, N - 1))):
    output[i] = [sum(item), abs(summation - sum(item))]

print(sorted(output, key=lambda x: x[1])[0][0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = [int(_) for _ in input().split()]
n = [L+i-1 for i in range(1,N+1)]
s = 0
m = 10000

for i in n:
    s += i
    if abs(i) < abs(m):
        m = i

s -= m
print(s)

Submission status: Accepted

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

m = 1000
sum = 0
for i in range(n):
  sum += l + i
  if m > abs(l + i):
    m = abs(l+i)
if sum < 0:
  print(sum + m)
else:
  print(sum - m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    apples = []
    isMinus = False
    isPlus = False
    for i in range(N):
        if L+i < 0:
            isMinus = True
        else:
            isPlus = True
        apples.append(L+i)

    if isMinus == True and isPlus == True:
        print(sum(apples))
    elif isMinus == True and isPlus == False:
        print(sum(apples[:-1]))
    else:
        print(sum(apples[1:]))

Submission status: Accepted

Solution code:
import fractions
import numpy as np
import os
import sys

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

s=0
ss=[]
for i in range(N):
    s+=i+L
    ss.append(i+L)

S=10000000000000
ans=0
for i in range(N):
    sss=0
    for j in range(N):
        if(i!=j):
            sss+=ss[j]
    if(abs(sss-s)<S):
        S=abs(sss-s)
        ans=sss
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#  --*-coding:utf-8-*--


def main():
    N,L = map(int, input().split())
    
    L2 = L+N-1
    x = (L-1)*N + N*(N+1)//2 - (L if L > 0 else L2 if L2 < 0 else 0)
    
    print(x)





if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans=l*n-n+(1+n)*n//2
if 0<l:
  ans=ans-l
elif l < 1-n:
  ans=ans-(l+n-1)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Ta=[]
T=[]
for i in range(N):
    t=L+i
    T.append(t)
    Ta.append(abs(t))
#print(T)
#print(Ta)
trg=Ta.index(min(Ta))
#print(trg)
#print(T)
s=sum(T[:trg]+T[trg+1:])
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input = list(map(int, input().split(' ')))
N = input[0]
L = input[1]
taste_list = [L + i -1 for i in range(1, N+1)]
abs_taste_list = [abs(t) for t in taste_list]
print(sum(taste_list) - taste_list[abs_taste_list.index(min(abs_taste_list))])

Submission status: Accepted

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

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

aji_zettaichi = [abs(i) for i in aji]

aji_zettaichi_min_id = 0
aji_zettaichi_min = aji_zettaichi[0]

for i in range(len(aji_zettaichi)):
    if aji_zettaichi_min > aji_zettaichi[i]:
        aji_zettaichi_min_id = i
        aji_zettaichi_min = aji_zettaichi[i]

aji.pop(aji_zettaichi_min_id)

print(sum(aji))

Submission status: Accepted

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

a = []
flag = False
for i in range(n):
	if l + i == 0:
		flag = True
	a.append(l+i)

if flag == True:
	print(sum(a))
elif a[0] < 0:
	 print(sum(a[:-1]))
else:
	print(sum(a[1:]))

Submission status: Accepted

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

ans = 0

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

hiku = 0

if l > 0:
    hiku = l
elif l+n-1 < 0:
    hiku = l+n-1
else:
    hiku = 0

print(sum(l_a)-hiku)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.arange(L, L + N)

ans = np.sum(a)

k = np.abs(a)
m = np.where(k == np.amin(k))

ans = ans - a[m]
ans = int(ans)

print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
arr = []
min = N+abs(L)
for i in range(1, N+1):
  if abs(L+i-1) < abs(min):
    min = L+i-1
  arr.append(L+i-1)

arr.remove(min)

print("{}".format(sum(arr)))

Submission status: Accepted

Solution code:
N,L=(int(x) for x in input().split())
def val(i):
    return L+i

S = 0
for i in range(N):
    S+=val(i)

ans=0
err=max(abs(val(0)),abs(val(N-1)),abs(S))*2
for i in range(N):
    tmp = S - val(i)
    tmp_err = abs(tmp-S)
    if tmp_err < err:
        ans = tmp
        err = tmp_err
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

min_taste = l
max_taste = l + n - 1

ans = (min_taste + max_taste) * n // 2
if max_taste * min_taste > 0:
  if min_taste > 0:
    ans -= min_taste
  else:
    ans -= max_taste

print(ans)

Submission status: Accepted

Solution code:
def f(N, L):
    if L > 0:
        return (N - 1) * (N + L * 2) // 2
    elif 1 - L > N:
        return (N - 1) * (N + L * 2 - 2) // 2
    else:
        return N * (N - 1 + 2 * L) // 2


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

Submission status: Accepted

Solution code:
inputs = [int(s) for s in input().split()]
n = inputs[0]
l = inputs[1]

if l >= 0:
    taste = int(n*l + n*(n+1)/2 - n - l)
elif -l >= n:
    taste = int(n*l + n*(n+1)/2 - n - (l + n - 1))
else:
    taste = int(n*l + n*(n+1)/2 - n)

print(taste)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a_s = []
for i in range(1, n + 1):
  a_s.append(l + i - 1)

taste_n = sum(a_s)
a_min = min(a_s)
a_max = max(a_s)

if l + n - 1 < 0:
  ans = taste_n - a_max
elif l > 0:
  ans = taste_n - a_min
else:
  ans = taste_n
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

azi = []
azi_abs = []
for i in range(N):
    azi.append(i+L)
    azi_abs.append(abs(i+L))

print(sum(azi) - azi[azi_abs.index(min(azi_abs))])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
input=stdin.readline().rstrip().split()

N=int(input[0])
L=int(input[1])

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

min_abs=200
for j in aji_list:
    if abs(j)<abs(min_abs):
        min_abs=j

output=sum(aji_list)-min_abs
print(output)

Submission status: Accepted

Solution code:



if __name__ == "__main__":
    N, L = map(int, input().split())
    apples = []
    for i in range(1,N+1):
        apples.append(L + i - 1)

    applesabs = [abs(i) for i in apples]
    index = applesabs.index(min(applesabs))

    del apples[index]

    print(sum(apples))

Submission status: Accepted

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

apple = [l+i for i in range(n)]
a_ = 10**9
idx = apple.index(min(apple, key=abs))
ans = sum(apple) - apple[idx]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#a = [int(x) for x in input().split()]
n, l = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#p, q, r = map(int, input().split())
#s = [int(x) for x in input().split()]
#t = [int(x) for x in input().split()]

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(l, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re

def doit():
  m = 0
#  print(l, file=sys.stderr)
  if l > 0:
    m = l
  elif l + n - 1 < 0:
    m = n + l -1
  else:
    m = 0
  return (l + (l + n - 1)) * n // 2 - m

#print(doit([0] * 4))
#doit(s)
#print(doit())
try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)

Submission status: Accepted

Solution code:
import numpy as np

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

#print(hog)

ab = np.abs(np.array(hoge))
#print(ab)

amin = ab.argmin()
del hoge[amin]
print(sum(hoge))

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
ans = 0
minimum = 1145148101919
for i in range(L,L+N):
    if abs(minimum) > abs(i):
        minimum = i
    ans += i
print(ans - minimum)

Submission status: Accepted

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

sum_ans=0
eat_ans=10000
flag=10000
for i in range(N):
	sum_ans+=L+i
	eat_ans=min(abs(eat_ans),abs(L+i))
	if eat_ans==abs(L+i):
		if L+i<0:
			flag=-1
		if L+i==0:
			flag=0
		if L+i>0:
			flag=1

print(sum_ans-eat_ans*flag)

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
ll = list(range(L,N+L))
a = list(map(abs, ll))
print(sum(ll) - ll[a.index(min(a))])

Submission status: Accepted

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






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

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

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

# リンゴiの味は L+i-1
taste = []
for i in range(1, N+1):
    taste.append(L+i-1)

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

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

Submission status: Accepted

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

ans = 0
apple = L
for i in range(2, N + 1):
    x = L + i - 1
    if abs(x) < abs(apple):
        ans += apple
        apple = x
    else:
        ans += x

print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
N_ = [i for i in range(1,N+1)]
L_ = [L+i-1 for i in range(1,N+1)]
t = 1000000
ans = 0
sum_L = sum(L_)
for i in range(N):
  target = sum_L - L_[i] 
  if abs(target - sum_L) < t:
    ans = target
    t = abs(target - sum_L)
print(ans)

Submission status: Accepted

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

s=n*(2*l+n-1)//2

if l>0:
    s-=l
elif l==0:
    pass
elif l+n<=0:
    s-=l+n-1

print(s)

Submission status: Accepted

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

Submission status: Accepted

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

A = list(range(L, L+N))
print(sum(A) - A[min(enumerate(A), key = lambda x:abs(x[1]))[0]])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

N,L = na()
a=[]
b = 10000000000

for i in range(L,L+N):
    a.append(i)
    b = i if min(abs(b),abs(i)) == abs(i) else b

print(sum(a)-b)

Submission status: Accepted

Solution code:
N, L = [int(x) for x in input().split(' ')]
f = [x + L for x in range(N)]
a = [abs(x) for x in f]
i = a.index(min(a))
f.pop(i)
print(sum(f))

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
L = []
for i in range(n):
    L.append(i+l)
S = sum(L)
e = 10**9+7
ans = 0
for i in range(n):
    A = L.copy()
    A.pop(i)
    s = sum(A)
    d = abs(S-s)
    if d < e:
        e = d
        ans = s
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

apples = [l + i for i in range(n)]
total = int(n * (l - 1) + n * (n + 1) / 2)

absmin = float('inf')
for val in apples:
    if abs(val) < abs(absmin):
        absmin = val

print(total - absmin)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
        li.append(L+i)
        sa.append(abs(L+i))

ans = sum(li) - li[sa.index(min(sa))]
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
n, l = list(map(int, input().split()))
t = [l + i - 1 for i in range(1, n + 1)]
ta = [abs(i) for i in t]
minarg = ta.index(min(ta))
t.pop(minarg)
print(sum(t))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(S-de)

Submission status: Accepted

Solution code:
n,l=[int(i) for i in input().split()]
app=[0]*(n)
for i in range(n):
    app[i]=l+i
m=1000000000000000000
num=0
for i,j in enumerate(app):
    if m>j and j>=0:
        m=j
        num=i
if m==1000000000000000000:
    m,num=max(app),app.index(max(app))
print(sum(app[0:num]+app[num+1:]))