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

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

if N>0 and L>0:
    print(sum-L)
elif 0 in list:
    print(sum)
else:
    print(sum-L-N+1)

Submission status: Accepted

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

taste = []

def checkio(numbers_array):
    return sorted(numbers_array, key=lambda x: abs(x))

for i in range(N):
    x=0
    x=(i+1)+L-1
    taste.append(x)

target = checkio(taste)
perfect = sum(taste)
ans = perfect - target[0]
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
original_pi_taste = sum([L + i - 1 for i in range(1, N + 1)])
incomplete_pis_tastes = [original_pi_taste - (L + i - 1) for i in range(1, N + 1)]
taste_diffs = [abs(original_pi_taste - incomplete_pi_taste) for incomplete_pi_taste in incomplete_pis_tastes]
print(incomplete_pis_tastes[taste_diffs.index(min(taste_diffs))])

Submission status: Accepted

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

abs_tastes = []
tastes = []
for i in range(1, N + 1):
    taste = L + i - 1
    abs_tastes.append(abs(taste))
    tastes.append(taste)
min_taste = min(abs_tastes)
argmin = abs_tastes.index(min_taste)
sum_taste = sum(tastes)
print(sum_taste - tastes[argmin])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
y=l
k=[]
m=100000
for i in range(n):
    k.append(y)
    y+=1
for i in range(n):
    if abs(k[i])<abs(m):
        m=k[i]
k.pop(k.index(m))
print(sum(k))

Submission status: Accepted

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

sum = 0
sum2 = 0
min = 10000000000
ans = 0
for i in range(1,N+1):
    sum = sum + L + i - 1

# print(sum)

for i in range(1,N+1):
    for j in range(1,N+1):
        if j == i:
            continue
        else:
            sum2 = sum2 + L + j - 1
    # print(sum2)
    if abs(sum - sum2) < min:
        min = abs(sum-sum2)
        ans = sum2
    sum2 = 0

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
ans = 0
e = 10**10
for i in range(1,N+1):
    tmp = L+i-1
    if abs(tmp) < abs(e):
        e = tmp
    ans += tmp
print(ans-e)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    for i in range(3):
        if s[i] == s[i + 1]:
            print("Bad")
            return
    print("Good")
    return

#B
def B():
    n, l = LI()
    lis = [l + i for i in range(n)]
    s = sum(lis)
    a = inf
    for i in lis:
        if abs(a) > abs(i):
            a = i
    print(s-a)
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    def lcm(a, b):
        return a * b // gcd(a, b)
    a, b, c, d = LI()
    x = b // c - (a-1) // c
    y = b // d - (a-1) // d
    z = b // lcm(c , d) - (a-1) // lcm(c , d)
    print(b-a+1-(x+y-z))
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

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
    print(ans)
elif L + N > 0:
    for i in range(L, L + N):
        ans += i
    print(ans)
else:
    for i in range(L, L + N - 1):
        ans += i
    print(ans)

Submission status: Accepted

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

total = 0
list = []
ajilist = []
for i in range(N):
    aji = i + L
    total += aji
    list.append(abs(aji))
    ajilist.append(aji)

I = list.index(min(list))

ans = total - ajilist[I]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=[int(i) for i in input().split()]
min=L
max=N+L-1
eat=0
if min<=0 and max>=0:eat=0
elif max<0:eat=max
else:eat=min
print(L*N+(N-1)*(N)//2-eat)

Submission status: Accepted

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

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

Submission status: Accepted

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


if 0 in aji:
    ans=sum(aji)
else:
    if aji[0]>0:
        del aji[0]
    else:
        del aji[-1]
    ans=sum(aji)
print(ans)

Submission status: Accepted

Solution code:
N,J = map(int,input().split())
score = sorted([n+J for n in range(N)])
num = 100000000000
absscore = [abs(s) for s in score]
num = absscore.index(min(absscore))
print(sum(score)-score[num])

Submission status: Accepted

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


ans = [0]*N
INF = 10**9
myabs = INF
a_num = 0

for i in range(N):
    ans[i] = L+i
    if myabs > abs(ans[i]):
        myabs = abs(ans[i])
        a_num = i
    
out = 0
for i in range(N):
    if i == a_num:
        pass
    else:
        out += ans[i]

print(out)

Submission status: Accepted

Solution code:
# 2019 6/22
# ABC 131 B Bite Eating

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

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

if L >= 0:
    print("%d" % (apple_pie - L))

elif L <= 0 and (L + N - 1) >= 0:
    print("%d" % apple_pie)

else:
    print("%d" % (apple_pie - (L + N - 1)))

Submission status: Accepted

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

#print(N, L)

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

#print(before_apple_pie)

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

min = 1000
for i in range(N):
    if(min > abs(apple[i])):
        min = abs(apple[i])
        min_i = i

after_apple_pie = int(before_apple_pie - apple[min_i])

print(after_apple_pie)

Submission status: Accepted

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

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

s = sum(aji)
ans = 0
dif = []
for i in range(n):
    sd = s - aji[i]
    b = abs(s-sd)
    dif.append(b)
    
ans = s - aji[dif.index(min(dif))]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ajiabs = [abs(i) for i in (range(L,L+N))]
ajiabssort = sorted(ajiabs)
min_idx = ajiabs.index(ajiabssort[0])

aji = [i for i in (range(L,L+N))]
aji.pop(min_idx)

print(sum(aji))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int,input().split())
array = np.arange(L, L+N)
abs_array=abs(array)
ate=abs_array.argmin()
array=np.delete(array, ate)
answer=sum(array)

print(answer)

Submission status: Accepted

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

a = [l+i for i in range(n)]
b = [abs(a[i]) for i in range(n)]
b.sort()
c = b[0]
cnt = 0
t = 0
for i in range(n):
  if abs(a[i]) != c :
    t += a[i]
  elif abs(a[i]) == c and cnt == 0:
    cnt += 1
print(t)

Submission status: Accepted

Solution code:
line = list(map(int, input().split(" ")))
N = line[0]
L = line[1]
sum = 0
for i in range(N):
	sum = sum + L+i

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    taste = L+i
    if mini == abs(taste):
        continue
    T.append(taste)

print(sum(T))

Submission status: Accepted

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

Submission status: Accepted

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

if L >= 0:
    print( sum(list(range(L+1, L+N))) )
elif N + L > 0:
    print( sum(list(range(L, L+N))) )
else:
    print( sum(list(range(L, L+N-1))) )

Submission status: Accepted

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

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

for i in range(len(taste)):
    taste[i] = n_applepie - taste[i]

ans_index = 0
for i in range(len(taste)):
    if abs(taste[i]-n_applepie) < abs(taste[ans_index]-n_applepie):
        ans_index = i

print(taste[ans_index])

Submission status: Accepted

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

ans = 0
zettaichi = 101
ttt = 0

for i in range(N):
    t = i + L
    ans += i + L
    if zettaichi > abs(t):
        zettaichi = abs(t)
        ttt = t
print(ans - ttt)

Submission status: Accepted

Solution code:
N ,L= map(int,input().split())
one_aji = 0
aji = []
answer = []
for i in range(N):
    one_aji = L+i
    if one_aji < 0:
        answer.append(one_aji)
        one_aji *= -1
        aji.append(one_aji)
    else:
        aji.append(one_aji)
        answer.append(one_aji)
zettai = 500
ind = 0
for i, a in enumerate(aji):
    a = int(a)
    if a < zettai:
        zettai = a
        ind = i
         
answer.pop(ind)
print(sum(answer))

Submission status: Accepted

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

def solve(N: int, L: int):
    li = [i for i in range(L,L+N)]

    # print(li)
    if(L < 0 and L+N-1 <= 0):
        print(sum(li)-li[-1])
    elif(L < 0 and L+N-1 > 0):
        print(sum(li))
    elif(L >= 0):
        print(sum(li) - li[0])

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

v=[]
for i in range(n):
    v.append(l+i)
if min(v)>=0:
    del v[0]
elif min(v)<0 and max(v)>=0:
    v.remove(0)
else:
    del v[-1]
print(sum(v))

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


N, L = map(int, input().split())
a = [0]*( N+1)

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

tmp = sum(a)

cnt = int(1e18)
ans = int(1e18)

for i in range(1, N+1):
    now = tmp - (tmp - a[i])
    if abs(now) < cnt:
        cnt = abs(now)
        ans = tmp - a[i]
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
List = [L + i for i in range(N) ]
abs = [abs(num) for num in List]
index = abs.index(min(abs))
Answer = sum(List) -List[index]

print(Answer)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0

a = [(abs(L + i - 1), L + i - 1) for i in range(1, N + 1)]
a.sort()
min_a = a[0][1]

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

print(res)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s1=(l-1)*n+(n*(n+1))//2
m=9999999999
ans=0
for k in range(1,n+1):
    s2=s1-(l+k-1)
    if m>abs(s1-s2):
        m=abs(s1-s2)
        ans=s2
print(ans)

Submission status: Accepted

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

tmp = [i for i in range(l, n + l)]
original = sum(tmp)

if l >= 0:
    result = original - tmp[0]
elif 0 in tmp:
    result  = original
else:
    result = original - tmp[len(tmp) - 1]

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = [int(i) for i in input().split()]
ans = n*l + n * (n+1)//2 - n

# apples are l, l+1, ... l+n-1
# when does 0 in them? when l<=0 and 0 <= l+n-1
if l <= 0 and 0<= l+n-1:
    print(ans)
elif l > 0:
    print(ans - l)
else:
    print(ans - (l+n-1))

Submission status: Accepted

Solution code:
n, l = map(int, input().split(' '))
result = 0
res = 10 ** 10
count = 0
for i in range(1,n+1):
    count += l+i-1
    if res > abs(l + i -1):
        res = abs(l + i  -1)
        result = l + i -1

print(count -result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    print(solve(n, m))

def solve(n, m):
    a = m
    b = m + n - 1

    if a >= 0 and b >= 0:
        return sum(range(a + 1, b + 1))
    elif a < 0 and b < 0:
        return sum(range(a, b))
    else:
        return sum(range(a, b + 1))

main()

Submission status: Accepted

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

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

if lis[0] < 0 and lis[N-1] < 0:
  print(sum(lis[:N-1]))
elif lis[0] < 0 and lis[N-1] >= 0:
  print(sum(lis))
elif lis[0] >= 0:
  print(sum(lis[1:]))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s=0
eat=float('inf')
for i in range(n):
    s+=l+i
    if abs(eat)>abs(l+i):
        eat=l+i
print(s-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s=n*l+n*(n+1)/2-n
d2=100000000000000000
x=0
for i in range(n):
    s1=s-i-l
    d=abs(s-s1)
    if d<d2:
        d2=d
        x=i
print(int(s-l-x))

Submission status: Accepted

Solution code:
import numpy as np

N, L = [int(j) for j in input().split()]

taste = [L + i - 1 for i in range(1, N+1)]
abs_taste = [abs(i) for i in taste]
min_t_i = abs_taste.index(min(abs_taste))

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

Submission status: Accepted

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

A=[]
total=0
min=1000
min_index=0
for i in range(N):
    a=L+i
    A.append(a)
    total+=a
    if abs(a) < min:
        min_index = i
        min=abs(a)
#print(total)
#print(A)
#print(min_index)
pie=total-A[min_index]
print(pie)

Submission status: Accepted

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

a=[]
for i in range(n):
    a.append([abs(l+i),i])
a.sort(key=lambda x:x[0])
b=[]
for k in range(n):
    b.append(l+k)

print(sum(b)-(l+a[0][1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
line = input().split()
n, l = tuple([int(s) for s in line])
v = [0] * n
for i in range(n):
    v[i] = l + i
    
sum_l = sum(v)

if l >= 0:
    print(sum_l - v[0])
elif l < 0 and l+n <= 0:
    print(sum_l - v[-1])
else:
    print(sum_l)

Submission status: Accepted

Solution code:

def main():
    N, L = map(int, input().split())
    ringo = [L + i for i in range(N)]
    if 0 in ringo:
        print(sum(ringo))
    elif ringo[0] < 0:
        print(sum(ringo[:N-1]))
    else:
        print(sum(ringo[1:]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

tmp = float('inf')
for v in range(N):
    if tmp > abs(v+L):
        tmp = abs(v+L)
        eat = v
sumALL = sum([v+L for v in range(N)])

print(sumALL-eat-L)

Submission status: Accepted

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

if(l > 0):
  # 一番小さいりんごを食べる
  print(sum(range(l + 1, n + l)))
elif(n + l <= 0):
  # 一番大きいりんごを食べる
  print(sum(range(l, n + l - 1)))
else:
  # 0のりんごを食べる
  print(sum(range(l, n + l)))

Submission status: Accepted

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

sum1 = 0
absMin = 101
for i in range(N):
	taste = L + (i+1) -1
	#print(taste)
	sum1 += taste
	if abs(taste) < abs(absMin):
		absMin = taste
	
#print("min",absMin)
print(sum1-absMin)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if l<0:
    if l+n-1>0:
        print(int(l*n+(n-1)*n/2))
    else:
        print(int(l*(n-1)+(n-2)*(n-1)/2))
else:
    print(int((l+1)*(n-1)+(n-2)*(n-1)/2))

Submission status: Accepted

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

l=[L+i for i in range(N)]
l_abs=[abs(i) for i in l]

print(sum(l)-l[l_abs.index(min(l_abs))])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
ajiList = []
absList = []
for i in range(N):
    ajiList.append(i + L)
    absList.append(abs(i + L))
s = sum(ajiList)
m = min(absList)
if s > 0:
    ans = s - min(absList)
else:
    ans = s + min(absList)
print(ans)

Submission status: Accepted

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

start = li[0]
end = li[n-1]

if start >= 0:
    li[0] = 0
elif end <= 0:
    li[n-1] = 0
    
print(sum(li))

Submission status: Accepted

Solution code:
import sys

input=sys.stdin.readline()
n,l=map(int,input.split())
min_a=l
max_a=l+n-1
if min_a>0:
    min_a+=1
elif max_a<0:
    max_a-=1
print(sum(range(min_a,max_a+1,1)))

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline().split()
N, L = int(input[0]), int(input[1])
val = 0
for i in range(1,N+1):
    # print(L + i - 1)
    val +=  L + i - 1
# print(val)
if L <= 0 and (L + N - 1) >= 0:
    print(val)
elif L <= 0 and (L + N - 1) < 0:
    print(val - L - N + 1)
else:
    print(val - L)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apple = [ L + int(_) - 1 for _ in range(1, N + 1)]
sumA = sum(apple)
ans = float("INF")
for i in range(N):
    l = sum(apple[0:i])
    r = sum(apple[i + 1:N])
    ans = min(abs(sumA - (l + r)), ans)

if sumA < 0:
    print(sumA + ans)
else:
    print(sumA - ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

m = min(tasteabs)

if m in taste:
  print(sum(taste) - m)
else:
  print(sum(taste) + m)

Submission status: Accepted

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

taste = []
taste_z = []
taste_f = []
Sum = 0
for i in range(N):
  taste.append(L+i)
  if (L+i)!=0:
    taste_z.append(abs(L+i))
    taste_f.append(int((L+i)/abs(L+i)))
  else:
    taste_z.append(0)
    taste_f.append(0)

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

print(Sum-taste[taste.index(taste_f[taste_z.index(min(taste_z))]*min(taste_z))])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

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

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

	tmp = bisect_left(azi, 0)

	ans = 0
	flg = False
	for i,val in enumerate(azi):
		if i == tmp:
			flg = True
			continue
		ans += val
	
	if flg == False:
		ans -= azi[-1]
	print(ans)

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N , L = map(int, input().split())
ajisum = 0
aji = L
for x in range(N):
    ajisum += aji
    aji += 1
if L >= 0:
    ans = ajisum - L
elif aji - 1 <= 0:
    ans = ajisum - (aji - 1)
else:
    ans = ajisum
print(ans)

Submission status: Accepted

Solution code:
import sys

S = input().split()

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

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

org_taste_sum = sum(taste)
abs_min = sys.maxsize
ans = 0

for i in range(0, N):
    tmp_taste_sum = 0
    for x in taste:
        if x == taste[i]:
            continue
        else:
            tmp_taste_sum += x

    abs_val = abs(org_taste_sum - tmp_taste_sum)
    if abs_val < abs_min:
        ans = tmp_taste_sum
        abs_min = abs_val

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
m = 100000
for i in range(1, 1+n):
  a = l + i - 1
  total += a
  if abs(m) > abs(a):
    m = a

print(total-m)

Submission status: Accepted

Solution code:
# coding: utf-8
N, L = map(int, input().split())
L1 = [L+i for i in range(N)]
L2 = [abs(L1[i]) for i in range(N)]
idx = L2.index(min(L2))
min_ = L1[idx]
print(sum(L1) - min_)

Submission status: Accepted

Solution code:

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

aji = [l+i for i in range(n)]
sumaji = sum(aji)
sa = abs(sumaji - (sumaji - aji[0]))
ansind = 0
for i in range(n):
  if sa >  abs(sumaji - (sumaji - aji[i])):
    sa = abs(sumaji - (sumaji - aji[i]))
    ansind = i

print(sumaji-aji[ansind])

Submission status: Accepted

Solution code:
lis=input().split(' ')
N=int(lis[0])
L=int(lis[1])
sum=int((2*L+N-1)*N*0.5)
if(L<0 and N+L-1<0):
  print(sum-(N+L-1))
elif(L>0 and N+L-1>0):
  print(sum-L)
else:
  print(sum)

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

INF = 100000000

def main():
    N, L = map(int, input().split())
    apples = [i for i in range(L, L + N)]
    sum_ = sum(apples)
    without_self_sum = [sum_ - apples[i] for i in range(N)]
    abs_minimum = INF
    ans = 0
    for i in range(N):
        if abs(sum_ - without_self_sum[i]) < abs_minimum:
            abs_minimum = abs(sum_ - without_self_sum[i])
            ans = without_self_sum[i]
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

B()

Submission status: Accepted

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

taste = [i + l for i in range(n)]
abs_taste = [abs(i) for i in taste]
min_index = abs_taste.index(min(abs_taste))

del taste[min_index]
print(sum(taste))

Submission status: Accepted

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


def taste(i):
    return L + i - 1


all_taste = 0
for i in range(1, N + 1):
    all_taste += taste(i)
# print(all_taste)

ans = 1000000
final_taste = all_taste
for i in range(1, N + 1):
    sub_taste = 0
    for j in range(1, N + 1):
        if not i == j:
            sub_taste += taste(j)
    if abs(all_taste - sub_taste) < ans:
        ans = abs(all_taste - sub_taste)
        final_taste = sub_taste

print(final_taste)

Submission status: Accepted

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

Submission status: Accepted

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

mylist = []

negagivecheck = 0

for i in range(N):
  mylist += [i+L]
  if i+L < 0:
    negagivecheck =1
  
if negagivecheck == 0:
  print(sum(mylist[1:]))
else:
  if 0 in mylist:
    print(sum(mylist))
  else:
    print(sum(mylist[:-1]))

Submission status: Accepted

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


def solve(N: int, L: int):
    scores = [L + i   for i in range(N)]
    ans = sum(scores)
    mi = min([abs(x) for x in scores])
    if ans > 0:
        ans -= mi
    else:
        ans += mi
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

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

s = np.array(list(range(l,l+n)))
m = np.argmin(np.abs(s))
m = s[m]

print(np.sum(s)-m)

Submission status: Accepted

Solution code:
n,l=list(map(int,input().split()))
a=[0]*(n+1)
for i in range(1,n+1):
    a[i]=l+i-1
dp=[0]*(n+1)
for i in range(1,n+1):
    if a[i]<0:
        dp[i]=-1
    else:
        dp[i]=1
b=[]+a
for i in range(1,n+1):
    a[i]=abs(a[i])
a[0]=float('inf')
mini=min(a)

index=a.index(mini)
#print(index)
sum1=0
for i in range(1,n+1):
    if i==index:
        pass
    else:
        sum1+=b[i]
print(sum1)

Submission status: Accepted

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

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

if 0 in app:
    print(sum(app))
elif all(app[i] > 0 for i in range(n)):
    print(sum(app[1:]))
else:
    print(sum(app[:n-1]))

Submission status: Accepted

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

ringo = []
for i in range(1,n+1):
  ringo += [l + i - 1]
ans_list = []

sr = sum(ringo)
dic = {}
for x in ringo:
  tmp = sum(ringo) - x
  ans = abs(sum(ringo) - tmp)
  dic[ans] = tmp
x = min(dic)
print(dic[x])