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())
apple_list = [l + i for i in range(n)]
abs_min = min([abs(apple) for apple in apple_list])
apple_list.remove(abs_min if abs_min in apple_list else -abs_min)
print(sum(apple_list))

Submission status: Accepted

Solution code:
lst = input()
lst = lst.split()


for i in range(len(lst)):
    lst[i]= int(lst[i])
N = lst[0]
L = lst[1]
q = L
l = 0
lste = [abs(L)]
tlst = []
for i in range(2,N+1):
    t = L+i-1
    q += t
    tlst.append(t)
    t = abs(t)
    lste.append(t)


slst = sorted(lste)
l = slst[0]
if tlst.count(-l) > 0:
    print(q+l)
else:
    print(q-l)

Submission status: Accepted

Solution code:
details = input().split()
N = int(details[0])
L = int(details[1])
counter = 0
new_list = []
number = 0
checker = True
for i in range(N):
    counter += L
    new_list.append(L+i)
    if number == 0 and ((L + i) >= 0) and checker == True:
        number += L + i
        checker = False
    elif number == 0 and (i == N-1) and checker == True:
        number += L + i
        checker = False
print(sum(new_list) - number)

Submission status: Accepted

Solution code:

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

N = lst[0]
L = lst[1]

apple_flavours = []

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


abs_apple_flavours = []

for apple in apple_flavours:
    abs_apple_flavours.append(abs(apple))

min_val = min(abs_apple_flavours)

index = abs_apple_flavours.index(min_val)

total_flavour = 0

for apple in apple_flavours:
    total_flavour += apple

print(total_flavour - apple_flavours[index])

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
#L+i-1,i>=1
nin=10**6
for i in range(N):
    if abs(L+i)<nin:
        nin=abs(L+i)
        nn=L+i

ans=N*(L-1)+N*(N+1)*0.5-(nn)

print(int(ans))

Submission status: Accepted

Solution code:
n, l =list(map(int, input().split()))
arr = []
arr2 = []
for k in range(1, n+1):
  arr.append(abs(l + k - 1))
for k in range(1, n+1):
  arr2.append(l + k - 1)
arr2.pop(arr.index(min(arr)))
print(sum(arr2))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
s=0
l=[]
for i in range(N):
    s+=L+i
    l.append(abs(L+i))
l=sorted(l)
if l[0]<=L:
    s-=l[0]
else:
    s+=l[0]
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

l_list=[l+i-1 for i in range(1,n+1)]
#print(l_list)

ab_list=[abs(i) for i in l_list]
num=ab_list.index(min(ab_list))

print(sum(l_list)-l_list[num])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
aji = []
m = 100000
flg = 0
for i in range(n):
  aji.append((l+i))
  if abs(aji[i]) <= m:
    m = abs(aji[i])
    if aji[i] <= 0:
      flg = 1
    else:
      flg = 0
print(sum(aji)- m if flg==0 else sum(aji) +m)

Submission status: Accepted

Solution code:
r=input().split()
N=int(r[0])
L=int(r[1])
ans=0
ans_li=[]
for i in range(N):
    ans+=L+(i+1)-1
    ans_li.append(L+(i+1)-1)
if 0 in ans_li:
    print(ans)
elif max(ans_li)>0:
    print(ans-min(ans_li))
else:
    print(ans-max(ans_li))

Submission status: Accepted

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

li = [x+l for x in range(n)]
if 0 in li:
    print(sum(li))
elif min(li) > 0:
    print(sum(li)-min(li))
else:print(sum(li)-max(li))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
c=0
m=100000
for i in range(1,n+1):
  c+=l+i-1
  m=min(m,abs(l+i-1))
if l<0 and l-n<=0:
  print(c+m)
else:
  print(c-m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sumn = []
ans = 0
for i in range(n):
    t = l + i
    sumn.append(t)
sumn = sorted(sumn, key=lambda x: abs(x))
print(sum(sumn[1:]))

Submission status: Accepted

Solution code:

# ABC131
# B Bite Eating
N, L = map(int, input().split())
A = 0
a = 1000
for i in range(1,N+1):
    x = L + i - 1
    A += x
    if abs(x) < a:
        a = abs(x)
if A >= 0:
    print(A-a)
else:
    print(A+a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

taste = np.arange(1, N+1) + L -1
min_ind = np.argmin(np.abs(taste))

mask_1 = np.ones(N, dtype=bool)
mask_1[min_ind] = False

ans = np.sum(taste[mask_1])

print(ans)

Submission status: Accepted

Solution code:
n,a = map(int,input().split())
c = 0
d = 1000
for i in range(1,n+1):
    c+=a+i-1
    d = min(abs(a+i-1),d)
if a<0 and a-n <= 0:
    print(c+d)
else:
    print(c-d)

Submission status: Accepted

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def sum_applepie(list1, l):
    r = [i+l-1 for i in list1]
    return sum(r)


def main():
    n, l = Input()
    applepie = sum_applepie(list(range(1, n+1)), l)
    list2 = []
    for i in range(1, n+1):
        temp = []
        for j in range(1, n+1):
            if i == j:continue
            temp.append(j)
        k = sum_applepie(temp, l)
        list2.append((abs(applepie - k), k))
    print(sorted(list2, key=lambda x:x[0])[0][1])


main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
apple=[l+i for i in range(n)]
s=0
while True:
    if s in apple:
        apple.remove(s)
        break
    elif abs(s) in apple:
        apple.remove(abs(s))
        break
    s-=1
print(sum(apple))

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, l = MI()
    ans = 0
    temp = l
    for i in range(n):
        ans += l+i
        if abs(temp) > abs(l+i):
            temp = l+i
        
    ans -= temp
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def ApplePie():
    N, L = input().split()
    N = int(N)
    L = int(L)
    flavors = []
    for i in range(N):
        flavors.append(L+i)
    
    if 0 in flavors:
        flavors.remove(0)
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
    elif L >= 0:
        del flavors[0]
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
    else:
        del flavors[-1]
        result = 0
        for i in flavors:
            result = result + i
        print(result)
        exit()
        
ApplePie()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines
def main():
    lines = input()

    n, l = list(map(int, lines[0].split()))

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

    if l >= 0:
        print(Sum_ - l)
        return
    else:
        if n+l-1 <= 0:
            print(Sum_ - (l+n-1))
        else:
            print(Sum_)


main()

Submission status: Accepted

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

for i in range(1, n + 1):
    apples.append(l + i - 1)
    if abs(l + i - 1) < abs(min_val):
        min_val = (l + i - 1)
apples.remove(min_val)

print(sum(apples))

Submission status: Accepted

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

    total = 0
    min_taste = 10 ** 12

    for i in range(1, N + 1):
        taste = L + i - 1
        if abs(taste) < min_taste:
            min_taste = abs(taste)
            min_taste_index = i

    total = N * L + N * (N + 1) // 2 - N
    ans = total - (L + min_taste_index - 1)

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    total = 0
    min_taste = 10 ** 12

    for i in range(1, N + 1):
        taste = L + i - 1
        if abs(taste) < min_taste:
            min_taste = abs(taste)
            min_taste_index = i

    for i in range(1, N + 1):
        if i == min_taste_index:
            continue
        total += L + i - 1

    print(total)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  tmp1 = sum(stk)
  tmp = stk[i]
  stk[i] = 0
  tmp2 = sum(stk)
  stk[i] = tmp
  ans.append(abs(tmp1 - tmp2))

tmp = min(ans)

if tmp in stk:
  stk.remove(tmp)
  print(sum(stk))
else:
  stk.remove(-tmp)
  print(sum(stk))

Submission status: Accepted

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

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

ans = float("inf")
res = float("inf")

for apple in apples:
  if ans > abs(apple):
    ans = min(ans,abs(apple))
    res = apple
  
print(sum(apples) - res)

Submission status: Accepted

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

Submission status: Accepted

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

a = []
b = float('inf')
for i in range(1,n+1):
    a.append(i+l-1)
    if abs(i+l-1) < b:
        c = i+l-1
        b = abs(i+l-1)

A = sum(a)

print(A-c)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
num = 200
for i in range(1, n+1):
    if abs(num) >= abs(l+i-1):
        num = abs(l+i-1)
        x = i
cnt = 0
for j in range(1, n+1):
    cnt += j
print((l-1)*(n-1) + cnt - x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=[int(x) for x in input().split()]
a=l
pie=0
app=[]
for i in range(n):
  apple=l+i
  pie+=apple
  app.append(apple)
b=[]
for i in app:
  j=abs(i)
  b.append(j)
c=min(b)
d=b.index(c)
pie-=app[d]
print(pie)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

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

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

if 0 in A:
    print(sum(A))
else:
    AA = [abs(a) for a in A]
    b = min(AA)
    if b in A:
        print(sum(A) - b)
    else:
        print(sum(A) + b)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, l = LI()
origin = 0
m = inf
for i in range(n):
    origin += l + i
    if m > abs(l + i):
        m = min(m, abs(l + i))
        x = l + i
ans = origin - x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
min = 10**4
sum = 0
for i in range(N) :
    t = i+L
    sum += t
    if abs(t) < abs(min) :
        min  = t


print(sum - min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,l=mp()
x=0
if l>0:
    x=l
elif l+n-1<0:
    x=l+n-1
print((l-1)*n+n*(n+1)//2-x)

Submission status: Accepted

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

t=[] #各リンゴの味

for i in range(1,n+1):
  a=l+i-1
  t.append(a)

t_total=sum(t) #N個のリンゴの味の総和


t2=[] #全リンゴの味の総和から1個のリンゴを引いたもの味

for j in t:
  b=t_total-j
  t2.append(b)

ans=[]

for k in t2:
  c=t_total-k
  ans.append(abs(c))

ind=ans.index(min(ans))

print(t_total-t[ind])

Submission status: Accepted

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

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

print(sum(Ls)-min(Ls, key=abs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

eat = 0
if taste_lists[0] > 0 and taste_lists[-1] > 0:
    eat = taste_lists[0]
elif taste_lists[0] < 0 and taste_lists[-1] < 0:
    eat = taste_lists[-1]
else:
    eat = 0

taste_lists.remove(eat)
ans = 0
for i in taste_lists:
    ans += i

print(ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
mi=10000
for i in range(n):
    m=l+i
    if mi!=min(mi,abs(m)):
        j=i
        mi=min(mi,abs(m))
#print(j,mi)
ans=0
for i in range(n):
    if i!=j:
        ans+=l+i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if l+1>0 :
    mind = min(D)
elif l+n<=0:
    mind = max(D)
else:
    mind = 0


ans = sum(D)-mind
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
azi = list()
for i in range(n):
    azi.append(l+i)
kei = sum(azi)
s = list()
for i in range(n):
    s.append(kei-azi[i])

tmp = float('inf')
ans = 0
for i in range(n):
    if tmp >= abs(kei-s[i]):
        ans = s[i]
        tmp = abs(kei-s[i])
print(ans)

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
ans = 0
l = N + abs(L)
for i in range(N):
	a = L + i
	if abs(a) < abs(l):
		l = a
	ans += a

print(ans - l)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
count = L
taste = []
for i in range(N):
    taste.append(count)
    count += 1
if 0 in taste:
    taste.remove(0)
elif  N + L <= 0:
    taste.pop(-1)
else:
    taste.pop(0)
print(sum(taste))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
t = []
for i in range(n):
    t.append(l + i)
sum_t = sum(t)
abs_diff = float('inf')
idx = 0
for i in range(n):
    if abs(sum_t - (sum(t[:i]) + sum(t[i + 1:]))) <= abs_diff:
        abs_diff = abs(sum_t - (sum(t[:i]) + sum(t[i + 1:])))
        idx = i
del t[idx]
print(sum(t))

Submission status: Accepted

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

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

if 0 < l:
    c -= l
elif l <= 0 <= l + n - 1:
    pass
else:
    c -= (l+n-1)

print(c)

Submission status: Accepted

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

aji = 1000
sum = 0

for i in range(N):
    sum += L+i
    aji = min(aji, abs(L+i))
    if aji == abs(L+i):
        eat = i

print(sum - (L+eat))

Submission status: Accepted

Solution code:
def the_closest_number_to_zero(lst):
    positive_lst = []
    negative_lst = []
    zero_lst = []
    n = len(lst)

    for i in range(n):
        number = lst[i]

        if number == 0:
            zero_lst.append(number)
        elif number > 0:
            positive_lst.append(number)
        else:
            negative_lst.append(number)

    if len(zero_lst) != 0:
        the_closest_number = 0
    else:
        positive_lst = sorted(positive_lst)
        negative_lst = sorted(negative_lst)

        if len(positive_lst) == 0:
            the_closest_number = negative_lst[-1]
        elif len(negative_lst) == 0:
            the_closest_number = positive_lst[0]
        else:
            positive = positive_lst[0]
            negative = negative_lst[-1]
            if abs(positive) >= abs(negative):
                the_closest_number = negative
            else:
                the_closest_number = positive

    return the_closest_number


def main():
    n, l = map(int, input().split())
    taste_lst = []

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

    taste_total = sum(taste_lst)
    taste_bite = the_closest_number_to_zero(taste_lst)
    taste = taste_total - taste_bite

    print(taste)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

a.sort(key=lambda x: abs(x))
del a[0]

print(sum(a))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
sum_t=sum(range(l,l+n))
min_t=1000
for i in range(n):
    if min_t>=abs(l+i):
        ans=sum_t-l-i
        min_t=abs(l+i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
s = 0
min = 10**9
for i in range(N):
  s = s + i + L 
  if min > abs(i+L):
    min = abs(i+L)

if s > 0:
  print(s-min)
else:
  print(s+min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
ans = list(i+l for i in range(n))
m = 10**10
for i in ans:
    if abs(m)>abs(i):
        m = i
print(sum(ans)-m)

Submission status: Accepted

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

a.sort(key = lambda x: abs(x))
del a[0]

print(sum(a))

Submission status: Accepted

Solution code:
N,L=list(map(int,input().split()))
l=list(range(L,N+L))
l_a=[abs(i) for i in l]
print(sum(l)-min(l_a)) if min(l_a) in l else print(sum(l)+min(l_a))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
A=[]
for i in range(n):
    A.append(l+i)
B=A.copy()
for j in range(len(B)):
    B[j]=abs(B[j])
print(sum(A)-A[B.index(min(B))])

Submission status: Accepted

Solution code:
from bisect import *
N, L = map(int, input().split())
A = list(range(L,L+N))
res = sum(A)
print(res - A[min(bisect_left(A,0),len(A)-1)])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
tastes = [(i + l) for i in range(n)]
t = tastes.copy()
for j in range(n):
    t[j] = abs(t[j])
del tastes[t.index(min(t))]
print(sum(tastes))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 問題：https://atcoder.jp/contests/abc126/tasks/abc131_b

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

Submission status: Accepted

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

Submission status: Accepted

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

diff = 10 ** 9
result = 10 ** 9

for i in range(1, n+1):
  reduced = expected - (l+i-1)
  if abs(expected - reduced) < diff:
    diff = abs(expected - reduced)
    result = reduced

print(result)

Submission status: Accepted

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

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

print(sum(A)-A[B.index(min(B))])

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
s = sum([L+i-1 for i in range(1,N+1)])
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())
s = []
# リンゴの味
for i in range(1, n+1):
    s.append(l+i-1)
# リンゴの最小誤差を求める絶対値です。
a = 10**19
# リンゴの最小誤差の変数です。
h = 0
for i in range(n):
    # 最小誤差を判定します。
    if a > abs(s[i]):
        a = abs(s[i])
        h = s[i]
# 総価から最小誤差を引いた味です。
print(sum(s)-h)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = []
for i in range(1, n+1):
    s.append(l+i-1)
a = 10**19
h = 0
for i in range(n):
    # 誤差が小さい。
    if a > abs(s[i]):
        a = abs(s[i])
        h = s[i]
print(sum(s)-h)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n, l = [int(num) for num in lines.pop(0).split(" ")]
lower = l
upper = l + n - 1
sum = (lower + upper) * n // 2
if lower * upper > 0: # 同じ符号の場合
    if abs(lower) <= abs(upper):
        sum -= lower
    else:
        sum -= upper
print(sum)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
t = list(map(lambda x: l + x, range(n)))
r = sum(t)
dif = 10 ** 100
for i in range(n):
    tmp = sum(t[:i] + t[i + 1:])
    dif_t = abs(r - tmp)
    if dif_t < dif:
        ans = tmp
        dif = dif_t
print(ans)

Submission status: Accepted

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

a = []

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

print(sum(a) - min(a, key = abs))

Submission status: Accepted

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

apples = [L+i for i in range(N)]
total = sum(apples)

min_d, ans = 10**9, 0
for i in range(N):
    d = abs(apples[i])
    if d < min_d:
        min_d = d
        ans = total - apples[i]

print(ans)

Submission status: Accepted

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

for n in range(1,N+1):
  A.append(L+n-1)
  
print(sum(A)-min(A,key=abs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int, input().split())
a=[l+i for i in range(n)]
value1=1000
value=0
for i in range(n):
  if abs(a[i])<value1:
    value1=abs(a[i])
    value2=a[i]
print(sum(a)-value2)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
t=[l+i for i in range(n)]
tot = sum(t)
ans = tot - t[0]
mn = float('inf')
for i in range(n):
	tmp = tot-t[i]
	if abs(tmp-tot)<mn:
		mn = abs(tmp-tot)
		ans = tmp
		
print(ans)

Submission status: Accepted

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

taste = [L + i for i in range(N)]
taste_abs = [abs(i) for i in taste]
min_index = taste_abs.index(min(taste_abs))
eat = taste[min_index]

print(sum(taste) - eat)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]


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

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

if l < 0:
    if (-1)*l < n:
        print(sum(taste))
    else:
        del taste[-1]
        print(sum(taste))
else:
    #最初だけぬかす
    del taste[0]
    print(sum(taste))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = [l+i-1 for i in range(1, n+1)]
mn = float('inf')
idx = 0
for i in range(n):
    if mn>abs(apples[i]):
        mn = abs(apples[i])
        idx = i

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

Submission status: Accepted

Solution code:
MM = input().split()
N = int(MM[0])
L = int(MM[1])
list1 =[]
for i in range(N):
  a = L + i
  list1.append(a)

mini = 301
ans = 201
for i in range(N):
  if mini > abs(list1[i]):
    mini = abs(list1[i])
    ans = i
total = 0
for i in list1:
  total += int(i)
ans1 = total -list1[ans]
print(ans1)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
A = [l+i for i in range(n)]
num = float('inf')
for a in A:
    num = min(num, abs(a))
if num in A:
    print(sum(A) - num)
else:
    print(sum(A) - num*(-1))

Submission status: Accepted

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

total = (2*L + N - 1) * N / 2
app = [L + i -1 for i in range(1, N+1)]
app_ = [abs(n) for n in app]
idx = app_.index(min(app_))

print(int(total - app[idx]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

sum = 0
minimum = 99999
for i in range(1,N+1):
    aji = L + i - 1
    sum += aji
    if (math.fabs(minimum) > math.fabs(aji)):
        minimum = aji

print(sum - minimum)

Submission status: Accepted

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

Submission status: Accepted

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

if l - 1 + n - 1 < 0:
    print(sum(apple[:n - 1]))
elif l < 0 and  0 <= l - 1 + n - 1:
    print(sum(apple))
elif 0 <= l:
    print(sum(apple[1:]))

Submission status: Accepted

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

min_num = 10 ** 5
sum_num = sum(apple)
ans = 0
for i in range(n):
    tmp = abs(sum_num - (sum_num - apple[i]))
    if tmp < min_num:
        min_num = min(tmp, min_num)
        flag = apple[i]
        ans = sum_num - apple[i]

print(ans)

Submission status: Accepted

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

min_num = 10 ** 5
sum_num = sum(apple)
for i in range(n):
    tmp = abs(sum_num - (sum_num - apple[i]))
    if tmp < min_num:
        min_num = min(tmp, min_num)
        flag = apple[i]

if flag >= 0:
    print(sum(apple) - min_num)
else:
    print(sum(apple) + min_num)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste=[0]*N; abs_taste=[0]*N;
for i in range(N):
  taste[i]=L+i
  abs_taste[i]=abs(L+i)
for i in range(N):
  if abs_taste[i]==min(abs_taste) :
    min_i=i
    break
print(sum(taste)-taste[min_i])