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())
ans=[]
for i in range(1,N+1):
    ans.append(L+i-1)

List=list(map(abs,ans))

ans.pop(List.index(min(List)))

print(sum(ans))

Submission status: Accepted

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

T=[]
sum_t = 0

for n in range(N):
    taste = L + (n+1) -1
    sum_t += taste
    T.append(abs(taste))

m = T.index(min(T))

sum_t -= L + (m+1) -1
print(sum_t)

Submission status: Accepted

Solution code:
#ABC131B - Bite Eating
N, L = list(map(int,input().split()))
a = L
b = L + N-1
taste = 0
for i in range(N):
    taste += L + i
if b < 0:
    print(taste - b)
elif a <= 0 and b >= 0:
    print(taste - 0)
elif a > 0:
    print(taste-a)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

x = min(range(L,L+N),key=abs)
answer = sum(range(L,L+N)) - x
print(answer)

Submission status: Accepted

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


pie = [l + i for i in range(n)]
pie_abs = [abs(pie[j]) for j in range(n)]

pie.pop(pie_abs.index(min(pie_abs)))

print(sum(pie))

Submission status: Accepted

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

taste = 0
min = 300
for i in range(N):
	t = L+i
	taste += t
	if t*t < min*min:
		min = t
taste -= min

print(taste)

Submission status: Accepted

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

t_sum = 0
t_min = 1000
t_min_index = 1000
for i in range(1, n+1):
    if t_min != min(t_min, abs(l+i-1)):
        t_min = min(t_min, abs(l+i-1))
        t_min_index = i
    t_sum += l+i-1

t_min = l + t_min_index - 1
print(t_sum - t_min)

Submission status: Accepted

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

tot = 0
apple = []
mn, pl = 10**10, 0

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

for i in range(n):
    if abs(apple[i]) < mn:
        mn = abs(apple[i])
        pl = i

print(tot - apple[pl])

Submission status: Accepted

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

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

for j in re:
  re_abs.append(abs(j))

re.pop(re_abs.index(min(re_abs)))
print(sum(re))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=list(map(lambda x:l+x-1,list(range(1,n+1))))
a_abs=list(map(lambda x:abs(x),a))
print(sum(a)-a[a_abs.index(min(list(map(lambda x:abs(x),a))))])

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(N):
        ans += L+i
        if abs(L+i) < abs(biting_apple):
            biting_apple = L+i
    
    ans -= biting_apple

    print(ans)

solve()

Submission status: Accepted

Solution code:
def solve():
    N,L = map(int, input().split())
    a = [abs(L+i) for i in range(N)]
    b = [L+i for i in range(N)]
    [a.index(min(a))]
    print(L*N+sum(range(N))-b[a.index(min(a))])
    

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

if L >= 0:
    ans = sum_all - L
elif N <= abs(L):
    ans = sum_all - (L + N - 1)
else:
    ans = sum_all

print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
L1 = []
L2 = []
for i in range(1,a+1):
  L1.append(b+i-1)
  L2.append(abs(b+i-1))
del L1[L2.index(min(L2))]
print(sum(L1))

Submission status: Accepted

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

s = list(l+i-1 for i in range(n+1))
a = list(sum - int(abs(s[j])) for j in range(1,n+1))

if max(a) > 0:
        print(int(max(a)))
elif max(a)<0:
        print(int(sum - max(s)))
else:
        print(int(sum))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apple = [i+L for i in range(N)]
sum_apple = (sum(apple))
sa = float("inf")

for i in range(N):
    apple_pie = apple[:i] + apple[i+1:]
    count = 0
    for j in range(len(apple_pie)):
        count += apple_pie[j]
        if sa > abs(sum_apple - count):
            sa = abs(sum_apple - count)
            ans = count
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

dif=101
for i in range(len(tastes)):
    tmp=tastes[:]
    tmp.pop(i)
    if dif > abs(applepi-sum(tmp)):
        dif = abs(applepi-sum(tmp))
        apples=tmp[:]

print(applepi-(applepi-sum(apples)))

Submission status: Accepted

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

if L < 0 and N + L - 1 > 0:
    print(sum(range(L, N + L)))
else:
    if abs(L) > abs(N + L - 1):
        print(sum(range(L, N + L)) - (N + L - 1))
    else:
        print(sum(range(L, N + L)) - L)

Submission status: Accepted

Solution code:
import numpy as np
N,L = map(int,input().split())
apple = np.array(range(N)) + 1
taste = apple + L - 1
taste_applepie = sum(taste)
if L <= 0 and abs(N) > abs(L):
    print(taste_applepie)
elif L > 0:
    print(taste_applepie - L)
else:
    print(taste_applepie - (N+L-1))

Submission status: Accepted

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

taste = []

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

Submission status: Accepted

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

taste_a = taste[absTaste.index(min(absTaste))] 
print(sum(taste) - taste_a)

Submission status: Accepted

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

# 各りんごの味の絶対値を算出し、最小の物を食べればよい
Apple_taste = [L+i for i in range(N)]
eaten_Apple = min(Apple_taste, key=abs)
Apple_taste.remove(eaten_Apple)
print(sum(Apple_taste))

Submission status: Accepted

Solution code:
import copy

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

n_L = list(range(n))
a_L = list(map(lambda x:l+x,n_L))
# out of rangeを防ぐため
a_L.append(0)

allsum = sum(a_L)

result_L = []

diff = abs(allsum-sum(a_L[1:]))

for val in range(n):
    b_L = copy.copy(a_L)
    b_L.pop(val)
    temp_sum = sum(b_L)

    if abs(allsum-temp_sum) <= diff:
        result = temp_sum
    diff = abs(allsum-temp_sum)

print(result)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
m = 100
ans = 0
for i in range(n):
    if abs(l+i) < m:
        m = abs(l+i)
        ans = i
print(int((1+n)*(n/2) + n*(l-1) - (l+ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, l = list(map(int, input().rstrip('\n').split()))
    ls = []
    t = 0
    for i in range(n):
        ls.append([abs(l + i), l + i])
        t += (l + i)
    ls.sort()
    print(t - ls[0][1])


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ret = 0
eat = [1e9, 0]
for i in range(1, n+1):
    ret += i
    if abs(i + l - 1) < eat[0]:
        eat = [abs(i + l - 1), i + l - 1]
ret += ((l - 1) * n)
print(ret - eat[1])

Submission status: Accepted

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

Submission status: Accepted

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


def a(x):
    return abs(l + x)


c = min(list(range(n)), key=a)
j = 0
for i in range(n):
    if i != c:
        j += l + i
print(j)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
aji=[]
for i in range(n):
    aji.append(l+i)
aji_abs=[]
for i in aji:
    aji_abs.append(abs(i))
e=aji_abs.index(min(aji_abs))

print(sum(aji)-aji[e])

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(apples[1:]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n, l = map(int, input().split())
fabs_lis = []
true_lis = []
for i in range(n):
    fabs_lis.append(math.fabs(i+l))
    true_lis.append(i+l)
index = fabs_lis.index(min(fabs_lis))
print(sum(true_lis)-true_lis[index])

Submission status: Accepted

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

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

absolutes = []

for v in taste:
    if v >= 0:
        absolutes.append(v)
    else:
        absolutes.append(-v)

min = min(absolutes)
index = absolutes.index(min)
w = taste[index]
sum = sum(taste)-w

print(sum)

Submission status: Accepted

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

aji = []
aji_abs = []
total = 0
for i in range(n):
  a = l + (i + 1) - 1
  aji.append(a)
  aji_abs.append(abs(a))
  total += a

print(total - aji[aji_abs.index(min(aji_abs))])

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, L: int):
    ab = []
    sum_teste = 0
    for i in range(N):
        taste = L + i
        sum_teste += taste
        ab.append(abs(taste))
    if sum_teste > 0:
        result = sum_teste - min(ab)
    else:
        result = sum_teste + min(ab)
    print(result)
    return


# Generated by 1.1.5 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_ = (int(i) for i in input().split())
l = list(range(l_, l_+n))
if all(i > 0 for i in l):
  print(sum(l) - min(l))
elif all(i < 0 for i in l):
  print(sum(l) - max(l))
else:
  print(sum(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N, L = [int(i) for i in input().split()]
    aji = [L + i for i in range(N)]
    print(sum(aji) - min(aji, key=abs))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if L>=0:
    print(S-L)
else:
    if N>-L:
        print(S)
    else:
        print(S-(L+N-1))

Submission status: Accepted

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

a = [l + i for i in range(n)]
print(sum(a) - min(a, key=abs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L= list(map(int, input().split()))
li=[L+i for i in range(N)]
mi=100000
ma=-1000000000
for i in li:
    if i>=0:
        mi=min(mi,i)
    else:
        ma=max(ma,i)
if abs(ma)>mi:
    print(sum(li)-mi)
else:
    print(sum(li)-ma)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = []
t = 10**9
ti = 0
for i in range(N):
  if abs(L + i) < t:
    t = abs(L + i)
    ti = i
  a.append(L + i)
a[ti] = 0
print(sum(a))

Submission status: Accepted

Solution code:
n, l = [int(i) for i in input().split()]
ntaste = sum([l + i for i in range(n)])
ntastes = [ntaste - (l + i) for i in range(n)]
cand = ntastes[0]
diff = abs(ntaste - cand)
for i in range(n):
	if abs(ntaste - ntastes[i]) < diff:
		diff = abs(ntaste - ntastes[i])
		cand = ntastes[i]
print(cand)

Submission status: Accepted

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

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

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

print ans

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

lis_taste = [L + (i + 1) - 1 for i in range(N)]
lis_abs = [abs(i) for i in lis_taste]
lis_taste.pop(lis_abs.index(min(lis_abs)))
print(sum(lis_taste))

Submission status: Accepted

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

if 0 in list1:
    del list1[list1.index(0)]
elif min(list1) > 0:
    del list1[list1.index(min(list1))]
else:
    del list1[list1.index(max(list1))]
print(sum(list1))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
i = 0
line = []
while i < n:
    line.append(abs(l+i))
    i += 1
eatone = line.index(min(line))
print((n*(n-1)//2)+(n-1)*l-eatone)

Submission status: Accepted

Solution code:
def main():

    N, L = map(int, input().split())
    total = N * L + int(N * (N + 1) / 2) - N
    mylst = []
    for i in range(1, N + 1):
        taste = L + i - 1
        mylst.append(taste)
        mylst.sort()
        if taste == 0:
            print(total)
            exit()
    if mylst[0] < 0:
        mn = max(mylst)
        print(total - mn)
    else:
        mn = min(mylst)
        print(total - mn)

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

T=[]
for i in range(N):
    T.append(L+i)
    
T=np.array(T)
U=abs(T)

print(sum(T)-T[U.argmin()])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if 0 <= l:
    print((l + n - 1 + l + 2 - 1) * (n - 1) // 2)
elif 0 <= l + n - 1:
    print(sum(range(l, l + n)))
else:
    print((l + n - 2 + l) * (n - 1) // 2)

Submission status: Accepted

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

if 0 in aji_list:
    aji_list.remove(0)
elif min(aji_list) > 0:
    aji_list.remove(min(aji_list))
else:
    aji_list.remove(max(aji_list))
print(sum(aji_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
min_abs = float('inf')
Taste = []
for i in range(N):
  taste = L+(i+1)-1
  if(min_abs > taste):
     min_abs = abs(taste)
     min_abs_index = i
  Taste.append(taste)

Taste.pop(min_abs_index)
ans = sum(Taste)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

taste = [_ for _ in range(L,L+N)]
tmp = float("inf")

for t in taste:
  if abs(tmp) > abs(t):
    tmp = t

print(sum(taste) - tmp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

taste = []

for i in range(n):
    tmp = l + i
    taste.append(tmp)


taste = sorted(taste, key=abs, reverse=True)
taste.pop()

print(sum(taste))

Submission status: Accepted

Solution code:
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
  
n,l = map(int, input().split())

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

print(sum(a) - a[getNearestValue(a, 0)])

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
s=range(L,L+N)
print(sum(s)-min(s,key=abs))

Submission status: Accepted

Solution code:
import math
N, L = map(int,input().split())
min = 1000
ans = 0
A = [0] * N
for i in range(N):
    A[i] = L + (i+1) - 1
    ans += A[i]

for i in range(N):
    a = math.fabs(A[i])
    if a < min:
        min = a
        if A[i] < 0:
            judge = False
        else:
            judge = True
if judge:
    ans -= min
else:
    ans += min
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

taste = []
sum = 0

for i in range(n):
  taste.append( l + i)
  sum += l + i
  
#print("sum is",sum)
#print("tatse is", taste)

zero_near_apple = taste[0]

for i in range(0, n-1):
  if abs(taste[i]) > abs(taste[i+1]):
    zero_near_apple = taste[i+1]

#print(zero_near_apple)
print(sum - zero_near_apple)

Submission status: Accepted

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

taste = []
sum = 0

for i in range(n):
  taste.append( l + i)
  sum += l + i
  
#print("sum is",sum)
#print("tatse is", taste)

zero_apple = taste[0]

for i in range(0, n-1):
  if abs(taste[i]) > abs(taste[i+1]):
    zero_apple = taste[i+1]

#print(zero_apple)
print(sum - zero_apple)

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, L: int):

    taste = []
    taste_abs = []

    for i in range(1, N + 1):
        taste.append(L + i - 1)
        taste_abs.append(abs(L + i - 1))

    idx_delete = taste_abs.index(min(taste_abs))
    taste.pop(idx_delete)
    result = sum(taste)

    print(result)


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())
full = sum(range(1, N+1)) + N * (L - 1)
diff = 1000

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

Submission status: Accepted

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

sum = 0
min_val = 100000

for i in range(1,N+1):
  sum += L+i-1
  if abs(L+i-1) < abs(min_val):
    min_val = L+i-1
    
print(sum-min_val)

Submission status: Accepted

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

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

if A[0] > 0:
    for i in range(1,N):
        aji = aji + A[i]
elif A[N-1] < 0:
    for i in range(0,N-1):
        aji = aji + A[i]
else:
    for i in range(N):
        aji = aji + A[i]
        
print(aji)

Submission status: Accepted

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

ans = 0
s = N*L + N*(N-1)//2
dif = int(1e+9)
for i in range(N):
    tmp = 0
    for j in range(N):
        if j != i:
            tmp += L+j
    if abs(s-tmp) < dif:
        ans = tmp
        dif = abs(s-tmp)

print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
a = [0]*n
for i in range(n):
    a[i] = l + i
sum_ = sum(a)
cnt = abs(a[0])
ans = sum(a) - a[0]
for i in range(n):
    v = a[i]
    a[i] = 0
    if abs(sum_ - sum(a)) <= cnt:
        cnt = abs(sum_ - sum(a))
        ans = sum(a)
    a[i] = v
print(ans)

Submission status: Accepted

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

pie_n = (n*l) + (n*(n+1)//2) - n
taste = []
diff = []

for i in range(n):
  taste.append(pie_n - (l+i))
  diff.append(abs(l+i))
  
print(taste[diff.index(min(diff))])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,l=map(int,input().split())
a=[math.sqrt((i+l)**2) for i in range(n)]
b=[i+l for i in range(n)]
print(int(sum(b)-b[a.index(min(a))]))

Submission status: Accepted

Solution code:
nl=list(map(int,input().split()))
if nl[1]<=0<=nl[1]+nl[0]-1:
    k=(nl[1]+(nl[1]+nl[0]-1))*nl[0]/2
else:
    if abs(nl[1])<abs(nl[1]+nl[0]-1):
        k=(nl[1]+1+(nl[1]+nl[0]-1))*(nl[0]-1)/2
    else:
         k=(nl[1]+(nl[1]+nl[0]-2))*(nl[0]-1)/2
print(int(k))

Submission status: Accepted

Solution code:
from sys import stdin

n,l = [int(x) for x in stdin.readline().rstrip().split()]
li = []
abss = []
for i in range(1,n+1):
    aji = l + i - 1
    li.append(aji)
    abss.append(abs(aji))
li.pop(abss.index(min(abss)))
print(sum(li))

Submission status: Accepted

Solution code:
s=list(input().split())
n=int(s[0])
l=int(s[1])
apple=[]
total=[]
for i in range(n):
  taste=l+(i+1)-1
  if taste<0:
    apple.append(taste*-1)
  else:
    apple.append(taste)
  total.append(taste)
total.pop(apple.index(min(apple)))
print(sum(total))

Submission status: Accepted

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

kind = [i + 1 for i in range( N )]
taste = [i + L for i in range( N )]
taste_abs = [abs(i + L) for i in range( N )]

cnt =0

for i in taste:
    if i<0:
        cnt +=1
        
if cnt ==N:
    print(sum(taste) + min(taste_abs))
else:
    print(sum(taste) - min(taste_abs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste=[]
taste2=[]
tot=0
for i in range(1,N+1):
  taste.append((L+i-1))
  taste2.append(abs(L+i-1))
  tot+=L+i-1
index=taste2.index(min(taste2))
print(tot-taste[index])

Submission status: Accepted

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

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

dif = 9999
ans = 0
for i in range(n):
    pre = p[:i]
    post = p[i+1:]

    tmp = sum(pre) + sum(post)

    if abs(sum(p) - tmp) < dif:
        ans = tmp
        dif  = abs(sum(p) - tmp)

print(ans)

Submission status: Accepted

Solution code:
n=[int(i) for i in input().split()]
array=[]
abs_array=[]
for i in range(1,n[0]+1):
  array.append(n[1]+i-1)
  abs_array.append(abs(n[1]+i-1))
abs_array.sort()
if abs_array[0] in array :
  print(sum(array)-abs_array[0])
else:
  print(sum(array)+abs_array[0])

Submission status: Accepted

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

if max(aji) < 0:
    aji.remove(max(aji))
    print(sum(aji))
elif 0 in aji:
    print(sum(aji))
else:
    aji.remove(min(aji))
    print(sum(aji))

Submission status: Accepted

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

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

Submission status: Accepted

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

res = 0
if m == k:
    res = sum(t) - m
else:
    res = sum(t) + m
print(res)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
flag=0
judge=0
ans=[0]*N

for i in range(N):
    flag+=L+i

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

if (N+L)<=0:
    print(flag-(N+L)+1)
else :
    print(flag-min(ans))

Submission status: Accepted

Solution code:
#ABCB - Bite Eating
N, L = list(map(int,input().split()))
all = 0
apple = []
for i in range(N):
    apple.append(L + i)
a = min(apple)
b = max(apple)
if 0 in apple:
    print(sum(apple))
elif b < 0:
    print(sum(apple)-b)
elif a > 0:
    print(sum(apple)-a)

Submission status: Accepted

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

aji = []
min_abs = 1000000000000000
min_abs_index = 0
for i in range(1, N + 1):
    if min_abs > abs(L + i - 1):
        min_abs = abs(L + i - 1)
        min_abs_index = i - 1
    aji.append(L + i - 1)

print(sum(aji) - aji[min_abs_index])

Submission status: Accepted

Solution code:
#131b
N,L = map(int, input().split()) #2≦N≦200  , −100≦L≦100
#N 個のリンゴがあります。これらはそれぞれリンゴ 1、リンゴ 2、リンゴ 3、...、リンゴ N 
#リンゴ i の「味」は L+i−1 です。
#N 個のリンゴ全てを材料としてできるアップルパイの「味」と、
#食べていない N−1 個のリンゴを材料としてできるアップルパイの「味」の差の絶対値ができるだけ小さくなるように、
#食べるリンゴを選ぶことにしました。 →絶対値が一番少ないものを除外する
#このようにして選ばれたリンゴを食べた時、食べていない N−1 個のリンゴを材料としてできるアップルパイの「味」を求めてください。

#元のアップルパイ
taste_list = [L+(i+1)-1 for i in range(N)]

#print(min([abs(taste) for taste in taste_list]))　絶対値最小
#print([abs(taste) for taste in taste_list].index(min([abs(taste) for taste in taste_list])))　絶対値最小のインデックス
#print(taste_list[[abs(taste) for taste in taste_list].index(min([abs(taste) for taste in taste_list]))])　#絶対値最小の元の値

print(sum(taste_list)-taste_list[[abs(taste) for taste in taste_list].index(min([abs(taste) for taste in taste_list]))])

Submission status: Accepted

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

Submission status: Accepted

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

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

#絶対値が最小のList indexを抽出する

index = 0

comp = abs(list_t[0])
for n, i in enumerate(list_t):
    if comp > abs(i):
        comp = abs(i)
        index = n

print(sum(list_t[:index] + list_t[index+1:]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

apples = [i + l - 1 for i in range(1, n+1)]
all = sum(apples)
diff = 500
ans = 0

for i in range(n):
  point = sum(apples[i+1:] + apples[:-n+i])
  nextDiff= abs(point-all)
  if min(nextDiff, diff) == nextDiff:
    diff = nextDiff
    ans = point

print(ans)

Submission status: Accepted

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

lis = list(map(abs,li))
li.pop(lis.index(min(lis)))
print(sum(li))