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())
count = 10000
for i in range(n):
    if abs(count) > abs(l+i):
        count = l+i 

ans = (l-1) * n + n * (n+1) // 2 - count

print(ans)

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N, L = MI()
    apples = [L + i - 1 for i in range(1, N+1)]
    apple_pie = sum(apples)
    apple_pie_n = []

    for i in range(N):
        tmp = 0
        for j in range(N):
            if j != i:
                tmp += apples[j]
        apple_pie_n.append((abs(apple_pie - tmp), i))

    apple_pie_n.sort()
    print(apple_pie - apples[apple_pie_n[0][1]])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
A=[0]*201
m=100000
point=0
for i in range(1,N+1):
  A[i]=L+i-1
  if abs(L+i-1)<m:
    m=abs(L+i-1)
    p=i
print(sum(A)-A[p])

Submission status: Accepted

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

N_list = [ i for i in range(1,N+1)]

aaa_list = []

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

print(sum(aaa_list)-min(aaa_list,key=lambda x: abs(x)))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
 
ll = []
p = []
for i in range(n):
    ll.append(l + i)
    p.append(abs(l + i))
sm = 0
ind = 0
a_min = 0
a_min = min(p)
ind = p.index(a_min)
ll.pop(ind)
sm = sum(ll)

print(sm)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(l, l+n):
  ans += i

if l > 0:
  ans -= l
else:
  if (l+n-1) < 0:
    ans -= (l+n-1)


print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
flavor = []
for i in range(1, N + 1):
    flavor.append(L + i - 1)
import numpy as np
for j in flavor:
    if abs(j) == min(np.abs(flavor)):
        eat = j
print(sum(flavor) - eat)

Submission status: Accepted

Solution code:
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

NL = list(map(int,input().split()))
N = NL[0]
L = NL[1]

taste=[]

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

print(sum(taste)-getNearestValue(taste, 0))

Submission status: Accepted

Solution code:
N,L = map(int,input().split(' '))
lst = [i+L-1 for i in range(1,N+1)]
normal_ans = sum(lst)
count = 10000000
result = 0
for i in range(len(lst)):
    ans_lst =  lst.copy()
    del ans_lst[i]
    special_ans = sum(ans_lst)
    # print(special_ans,normal_ans-special_ans)
    if count >= abs(normal_ans-special_ans):
        count = abs(normal_ans-special_ans)
        result = special_ans
print(result)

Submission status: Accepted

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

sum_apple_pie = 0
min_abs_apple = float('inf')
min_num = float('inf')
for i in range(N):
    sum_apple_pie += i + L
    if abs(i + L) < min_abs_apple:
        min_abs_apple = abs(i + L)
        min_num = i + L
print(sum_apple_pie - min_num)

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())
minabs = 10000
midx = -1
for i in range(1, n + 1):
    if abs(l + i - 1) < minabs:
        midx = i
        minabs = abs(l + i - 1)
ans = 0
for i in range(1, n + 1):
    if i != midx:
        ans += l + i - 1
print(ans)

Submission status: Accepted

Solution code:
n,l = [int(i) for i in input().split(" ")]
L = [i for i in range(l,l+n)]
max = sum(L)
wei = 10000000000000
ans = 0
for i in range(n):
    tmp = 0
    for j in range(n):
        if i !=j:
            tmp+=L[j]
    if wei > abs(max - tmp):
        wei = abs(max - tmp)
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
# ABC 131: B – Bite Eating
n, l = [int(s) for s in input().split()]

flavor_apples = [l + i - 1 for i in range(1, n + 1)]
abs_flavor_apples = [abs(i) for i in flavor_apples]
flavor_apple_pie = sum(flavor_apples)

print(flavor_apple_pie - flavor_apples[abs_flavor_apples.index(min(abs_flavor_apples))])

Submission status: Accepted

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

ans = abs(max(L+N-1, L))

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

for i in lst:
    if abs(ans) > abs(i):ans=-i

ans += sum(lst)

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(N, L):
    """Test Case
    >>> print_ans(5, 2)
    18
    >>> print_ans(3, -1)
    0
    >>> print_ans(30, -50)
    -1044
    """
    ar = np.arange(N)
    ar = ar + L
    minimum = np.argmin(np.abs(ar))
    print(np.sum(ar) - ar[minimum])



if __name__ == '__main__':
    N, L = map(int, input().rstrip().split())
    print_ans(N, L)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque, Counter
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
ans = 0

[n,l]=inpl()
applist = np.arange(1,n+1) + l - 1
applist.sort()

if 0 in applist:
    ans = applist.sum()
elif applist[0] > 0:
    ans = applist[1:].sum()
elif applist[-1] < 0:
    ans = applist[:-1].sum()
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

a_abs = list(map(abs, a))
min_index = a_abs.index(min(a_abs))

print(sum(a)-a[min_index])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


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

tmp = 10**9
for a in A:
    if tmp > abs(a):
        tmp = abs(a)
        ans = sumA - a

# print(A)
print(ans)

Submission status: Accepted

Solution code:
# 2019-11-14 20:54:46(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, l = [int(x) for x in sys.stdin.readline().split()]
    flavors = []
    for i in range(1, n+1):
        flavors.append(l + i - 1)
    # key=function  要素にfunctionを適用した戻り値でsortする
    flavors.sort(key=abs)
    print(sum(flavors[1:]))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

apple_taste = []

for i in range(N):
    taste = L + i + 1 - 1
    apple_taste.append(taste)
    
import numpy as np

abs_apple_taste = np.abs(apple_taste)
m = min(abs_apple_taste)

for j in range(N):
    if m == abs_apple_taste[j]:
        apple_taste.remove(apple_taste[j])

pie_taste = 0       

for k in range(N-1):
    pie_taste += apple_taste[k]
    
print(pie_taste)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
e = l+n-1

if (l * e) < 0:
    print(int(n/2*(l+e)))
else:
    if min(abs(l), abs(e)) == abs(l):
        print(int(n/2*(l+e)) - l)
    else:
        print(int(n/2*(l+e)) - e)

Submission status: Accepted

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

for i in range(n):
    sum2 = (sum1 - (l+i))
    li.append(sum2)

li2 = []
for i in range(n):
    li2.append(abs(sum1-li[i]))

a = li2.index(min(li2))
print(li[a])

Submission status: Accepted

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

apl = [ l+i for i in range(n) ]
tst = 100
for a in apl:
    if abs(a) < abs(tst):
        tst = a
print( sum(apl)-tst )

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

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


# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc131","b",main)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
nl=[l+i-1 for i in range(1,n+1)]
mini=10**5
for i in nl:
    mini=min(mini,abs(i))
if mini in nl:
    nl.remove(mini)
if len(nl)==n:
    nl.remove(-mini)
print(sum(nl))

Submission status: Accepted

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

sumN = (l-1) * n + sum([i for i in range(1,n+1)])

diff = 10000000000
ans = 0
for i in range(1,n+1):
    ansSum = (l-1) * (n-1) + sum([j for j in range(1,n+1) if j != i])
    if abs(sumN - ansSum) < diff:
        ans = ansSum
        diff = abs(sumN - ansSum)
print(ans)

Submission status: Accepted

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

sum = 0
rep = 0

for i in range(n):
    tmp = l + i
    sum += tmp

    if (0 <= abs(tmp) <= abs(rep)) or (i == 0):
        rep = tmp

print(sum - rep)

Submission status: Accepted

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

print(apple_sum-apple[List.index(min(List))])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

tastes = [L+i for i in range(N)]
original_sum = np.sum(tastes)
diff = float('inf')
for n in range(N):
    tmp = abs(tastes[n])
    if tmp < diff:
        diff = tmp
if original_sum < 0:
    print(original_sum+diff)
else:
    print(original_sum-diff)

Submission status: Accepted

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

tmp = 101
for i in p:
    if abs(i) < abs(tmp):
        tmp = i

print(sum(p)-tmp)

Submission status: Accepted

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

all_eat = 0
abs_min = float("inf")
for i in range(n):
    all_eat += l + i
    if abs(l + i) < abs(abs_min):
        abs_min = l + i
        
    
    
print(all_eat - abs_min)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,l=map(int,input().split())
    A=[l+i for i in range(n)]
    S=sum(A)
    a=INF
    for i in range(n):
        if(abs(a)>abs(A[i])):
            a=A[i]
    print(S-a)
resolve()

Submission status: Accepted

Solution code:
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(5, 2), 18)

    def test_2(self):
        self.assertEqual(think(3, -1), 0)

    def test_3(self):
        self.assertEqual(think(30, -50), -1044)


def solve():
    n, l = read()
    result = think(n, l)
    write(result)


def read():
    return read_int(2)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, l):
    a = [l + i - 1 for i in range(1, n + 1)]
    original_sum = sum(a)
    buf = []
    for i, e in enumerate(a):
        buf.append((abs(e), i))
    buf.sort(key=lambda x: x[0])
    return original_sum - a[buf[0][1]]


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

apple = [l+i for i in range(n)]
ans = -1
vol = apple[n-1]
for i in range(n):
  tmp = sum(apple)
  if abs(vol) > abs(apple[i]):
    vol = apple[i]
    ans = i
print(tmp - apple[ans])

Submission status: Accepted

Solution code:
import math
N,L = input().split()
N,L = int(N),int(L)
#c = math.gcd(N,L)

if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

Submission status: Accepted

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


if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

Submission status: Accepted

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


if(L>=0):
    print(int(0.5*N*(N+1)+N*L-N-(L)))
else:
    n = min([-L,N-1])
    print(int(0.5*N*(N+1)+N*L-N-(L+n)))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min_abs = float('INF')
ans = 0
for i in range(1, N + 1):
    t = L + i - 1
    if abs(t) < abs(min_abs):
        min_abs = t
    ans += t
print(ans - min_abs)

Submission status: Accepted

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

li = list()
tmp = 999
for i in range(1, n+1):
    li.append(l+i-1)
    if(abs(tmp) > abs(l+i-1)):
        tmp = l+i-1
print(sum(li)-tmp)

Submission status: Accepted

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

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

t.sort(key=lambda x:abs(x))
print(sum(t[1:]))

Submission status: Accepted

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

li = [x for x in range(l, l+n)]
t_i = 0
mi = 301
for i in range(len(li)):
  if mi >= abs(li[i]):
    mi = abs(li[i])
    t_i = i
n_sum = sum(li)
print(n_sum-li[t_i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
import copy
j_sum = 0
absum = 0
j_sum_max = 0
ab = 0
for i in range(1, N+1):
    ab += L+i-1
for i in range(1, N+1):
    for j in range(1, N+1):
        if j != i:
            j_sum += L+j-1
    if i == 1:
        absum = abs(ab-j_sum)
        j_sum_max = copy.copy(j_sum)
        j_sum = 0
    else:
        if absum > abs(ab-j_sum):
            absum = abs(ab-j_sum)
            j_sum_max = copy.copy(j_sum)
            j_sum = 0
print(j_sum_max)

Submission status: Accepted

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

Submission status: Accepted

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

ls.remove(min(ls, key=abs))
print(sum(ls))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
# 等差数列の和の公式
# S = 1/2n(2a + (n-1)d)
a = l
if l >= 0:
    total = 1/2 * n * (2 * a + (n - 1) * 1) - l
elif l < 0 and abs(n) > abs(l):
    total = 1/2 * n * (2 * a + (n - 1) * 1)
elif l < 0:
    total = 1/2 * n * (2 * a + (n - 1) * 1) - (l + n - 1)
print(int(total))

Submission status: Accepted

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

eaten = 'None'
if l >= 0:
  eaten = 0
elif (l+n-1) < 0:
  eaten = n-1

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

print(total)

Submission status: Accepted

Solution code:
n,l =map(int, input().strip().split())
a=-1000000009
b=1000000009
ans=0
for i in range(0,n):
  ans+=l+i
  if(l+i<0):
    a=max(a,l+i)
  elif l+i>=0:
    b=min(b,l+i)
  #print(i,a,b,l+i)
#print(ans)   
if(a==-1000000009):
  print(ans-b)
elif(b==1000000009):
  print(ans-a)
else:
  if(min(a*-1 , b))*-1 ==a:
  	print(ans-a)
  else:
  	print(ans-b)

Submission status: Accepted

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

answer = sum(list[1:])
print(answer)

Submission status: Accepted

Solution code:
n,l=map(int,input().split(" "))
a=[]
for i in range(1,n+1):
    a.append(i+l-1)
b=list(map(lambda x:abs(x),a))
c=b.index(min(b))
a.pop(c)
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())
ans=(((2*l)+n-1)*n)/2

if l>=0:
  ans-=l
elif l<0 and (l+n-1)>=0:
  ans+=0
else:
  ans-=(l+n-1)
  
print(int(ans) )

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
a = sum(L + i for i in range(N))
min_ = None
for i in range(N):
    b = sum(L + j for j in range(N) if i != j)
    if min_ is None or abs(a - b) < abs(a - min_):
        min_ = b
print(min_)

Submission status: Accepted

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

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

    bbb = [abs(j) for j in aaa]

    print(sum(aaa)-aaa[bbb.index(min(bbb))])
    
resolve()

Submission status: Accepted

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

oishisa = [0] * n
min = l

for i in range(0, n):
    oishisa[i] = l + i
    if abs(oishisa[i]) < abs(min):
        min = oishisa[i]

sum = sum(oishisa) - min
print(sum)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L + i for i in range(N)]
d = 10000
min_i = -1
for i in range(N):
    if abs(A[i]) < d:
        min_i = i
        d = abs(A[i])

del A[min_i]

print(sum(A))

Submission status: Accepted

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

mngap=[1,abs(l+1-1)]
for i in range(2,n+1):
  if mngap[1]>abs(l+i-1):
    mngap=[i,abs(l+i-1)]

total=0
for i in range(1,n+1):
  total+=l+i-1
print(total-(l+mngap[0]-1))

Submission status: Accepted

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

pie=0
deli=[]
for i in range(1,n+1):
  pie+=l+i-1
  deli.append(l+i-1)
ans={}
ans2=[]
for j in range(1,n+1):
  deli2=copy.copy(deli)
  deli2.remove(l+j-1)
  ans[abs(sum(deli2)-pie)]=sum(deli2)
  ans2.append(abs(sum(deli2)-pie))
print(ans[min(ans2)])

Submission status: Accepted

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

apple = [i + L for i in range(N)]
ab = [abs(i + L) for i in range(N)]

print(sum(apple) - apple[ab.index(min(ab))])

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
t=[l+i for i in range(n)]
t1=[abs(item) for item in t]
eat=min(t1)

def check_eat(L,X):
  for i in range(n):
    if abs(L[i])==X:
      break
  return i

print(sum(t)-t[check_eat(t,eat)])

Submission status: Accepted

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

mn = [float('inf'), -1]
for i in range(N):
	cur = L + i
	mn = min(mn, [abs(cur), cur])
print(azi - mn[1])

Submission status: Accepted

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

mn = float('inf')
for i in range(N):
	cur = L + i
	if mn > abs(cur):
		mn = abs(cur)
		ans = azi - cur

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    N,L= map(int, input().split())
    ringos = []
    for i in range(N):
        ringos.append(L + i)
    
    full_ringo_pie = sum(ringos)
    min_taste_ringo = 101
    for ringo in ringos:
        if abs(min_taste_ringo) > abs(ringo):
            min_taste_ringo = ringo
    
    print(full_ringo_pie - min_taste_ringo)
        



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

tast = [L+i for i in range(N)]
tast_abs = [t if t>0 else -t for t in tast]
tast_min_idx = sorted(range(len(tast_abs)), key = lambda x : tast_abs[x])
tast_min = tast[tast_min_idx[0]]

tast_sum = sum(tast) - tast_min

print(tast_sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

a = sum(aji)

ans = 0
diff = 10**9
for i in range(N):
    s = sum(aji) - aji[i]
    t = abs(a - s)
    if t < diff:
      diff = t
      ans = s

print(ans)

Submission status: Accepted

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

List = [0]*N
c = 10**6
for i in range(N):
    List[i] = L+i
    c = min(c, abs(L+i))
    
for i in range(N):
    if List[i] == c or List[i] == -c:
        List[i] = 0
        break
        
print(sum(List))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
apple_taste=[0]*N
eat_apple=0
for i in range(0,N):
    apple_taste[i]+=L+i
    if abs(apple_taste[eat_apple])>abs(apple_taste[i]):
        eat_apple=i

print(sum(apple_taste)-apple_taste[eat_apple])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ans = 0
eat = 1+l-1

for i in range(1, n+1):
  apple_taste = i+l-1
  ans += apple_taste
  if abs(eat) > abs(apple_taste):
    eat = apple_taste

print(ans-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = { l+i for i in range(n) }
if 0 in a:
  print(sum(a))
else:
  if min(a) > 0:
    print(sum(a)-min(a))
  else:
    print(sum(a)-max(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,l = [int(x) for x in input().split()]
    array = [int(x) for x in range(l,l+n)]

    array_abs = [abs(x) for x in array]
    minimum_val = min(array_abs)
    min_index = array_abs.index(minimum_val)

    array[min_index] = 0
    ans = sum(array)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
import math
T = []
for i in range(N):
  T.append(L+i)
cnt = 0
mcnt = sum(T)
k = 1000000
for i in range(0,N):
  if abs(T[i])<k:
    mcnt = sum(T)-T[i]
    cnt = i+1
    k=abs(T[i])
print(mcnt)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
d=list(range(1,N+1))
s=[]
a=1000
b=0

for i in range(N):
  s.append(L+i)
for j in range(N):
  if a > abs(s[j]):
    a=abs(s[j])
    b=s[j]
print(sum(s)-b)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
Sum = 0
S = 500
ans = 0
for i in range(1,N+1):
  Sum += L + i - 1
  if abs(L + i - 1) < abs(S):
    S = L + i - 1
print(Sum - S)

Submission status: Accepted

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

Aji = [L+i-1 for i in range(1,N+1)]
EAT = abs(Aji[0])

for i in range(N):
    if abs(EAT) > abs(Aji[i]):
        EAT = Aji[i]
        
ans = sum(Aji) - EAT

print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
sumi = (N * L + ((N-1) * N)//2)
mini = 10**10
ans = sumi
for idx in range(N):
	if(mini > abs(L+idx)):
		mini = abs(L+idx)
		ans = sumi - (L+idx)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

taste = []
j = 500
k = 0
adr = 0
for i in range(l,n+l,1):
    taste.append(i)
    j = min(j,abs(i))
    if j == abs(i):
        adr = k
    k += 1

res = sum(taste) - taste[adr]
print(res)

Submission status: Accepted

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

m = 10 ** 4
c = m
ans = 0

for i in range(L, N+L):
    if m > abs(i):
        m = abs(i)
        c = i

    ans += i


print(ans - c)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
x = [0 for i in range(a)]
for i in range(a):
  x[i] = b + i
x.sort(key=lambda t:abs(t))
print(sum(x[1:]))

Submission status: Accepted

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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