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:
def abc():
    n, l = map(int, input().split())
    taste = [l+i-1 for i in range(1, n+1)]
    taste.sort(key=lambda x: abs(x))
    taste.pop(0)
    print(sum(taste))


abc()

Submission status: Accepted

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

L_list = [] * N

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

tmp = float('inf')
ans = 0
for i in range(N):
    diff = sum(L_list) - L_list[i]
    if tmp > abs(sum(L_list) - diff):
        tmp = abs(sum(L_list) - diff)
        ans = diff

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
from sys import stdin
import sys
import numpy as np

n, l = stdin.readline().rstrip().split()
n, l = int(n), int(l)

#print(n, l)
array = np.arange(l, l+n)
abs_min = 300
index = 300
#ans = 300
for i in range(n):
    if abs_min > np.abs(array[i]):
        abs_min = np.abs(array[i])
        index = i

#print(array, abs_min)
ans = np.sum(array) - array[index]
print(ans)

Submission status: Accepted

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

aji_sort = sorted(aji)
min_aji = -10000
for j in range(N):
    if aji_sort[j] >= 0:
        min_aji = aji_sort[j]
        break

if min_aji == -10000:
    min_aji = aji_sort[-1]

print(sum(aji)-min_aji)

Submission status: Accepted

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

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

temp1=list(map(lambda x2:abs(x2),x))
temp2=min(temp1)

I=temp1.index(temp2)

x.remove(x[I])

print(sum(x))

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))
for i in range(n):
  if b[i]==min(b):
   d=a[i]
print(sum(a)-d)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = 0
for i in range(N):
    taste += L+i

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

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    # 1-indexed
    apples = [L+i-1 for i in range(N+1)]
    taste = 0
    eaten = False
    for a in apples[1:]:
        if (not eaten) and a >= 0:
            eaten = True
            continue
        taste += a
    if not eaten:
        taste -= a
    print(taste)


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

wa = 0
for i in range(1,n+1):
    wa += l+i-1

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

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np
N,L = map(int,input().split())
ls = list(range(N))
ls = [i+L for i in ls]
ls = np.array(ls)
idx = np.argsort(np.abs(ls))[1:]
#print (idx)
print (sum(ls[idx]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
eat_one = 101+N
ideal_pie = 0
for i in range(N):
    taste = L+i
    ideal_pie += taste
    eat_one = taste if abs(eat_one) > abs(taste) else eat_one
print(ideal_pie - eat_one)

Submission status: Accepted

Solution code:

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

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

pi = sum(aji)
ans = 0
diff = []
for i in range(N):
  if pi - aji[i] == pi:
    print(pi)
    exit()
  diff.append(pi - aji[i])
if pi > 0:
  print(max(diff))
else:
  print(min(diff))

Submission status: Accepted

Solution code:
import numpy as np

n, l = [int(i) for i in input().split()]
tastes = []
for i in range(n):
    tastes.append(i + l)
if 0 in tastes:
    print(sum(tastes))
elif np.abs(tastes[0]) > np.abs(tastes[-1]):
    print(sum(tastes[:-1]))
elif np.abs(tastes[0]) == np.abs(tastes[-1]):
    print(sum(tastes))
else:
    print(sum(tastes[1:]))

Submission status: Accepted

Solution code:
N, L = [int(nl) for nl in input().split()]
T = []
for n in range(N):
  T.append(L + n)
T_abs = [abs(t) for t in T]
mn_T_abs = min(T_abs)
idx_mn_T_abs = T_abs.index(mn_T_abs)
T.pop(idx_mn_T_abs)
ans = sum(T)
print(ans)

Submission status: Accepted

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

aji = 0

min = 999

for i in range(N):
    tmp = L + i
    aji += tmp
    if abs(tmp) < abs(min):
        min = tmp

print(aji-min)

Submission status: Accepted

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

Submission status: Accepted

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

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

s = sum(li)

res = 1000
ans = 0

for i in li:
    t = s-i
    if res > abs(s-t):
        ans = i
        res = abs(s-t)
    
print(sum(li)-ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [(L + i) for i in range(N)]
eat = 500
ans = 0

for i in range(N):
    if abs(taste[i]) < abs(eat):
        eat = taste[i]

ans = sum(taste) - eat
print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ans=0
temp=10**9
A=sum([L+i for i in range(N)])
for i in range(N):
    B=0
    for j in range(N):
        if j!=i:
            B+=L+j
    if temp>=abs(A-B):
        ans=B
        temp=abs(A-B)
print(ans)

Submission status: Accepted

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

apples = [L+i-1 for i in range(1, N+1)]
abs_apples = [abs(L+i-1) for i in range(1, N+1)]
try:
    apples.remove(min(abs_apples))
except ValueError:
    apples.remove(-1 * min(abs_apples))

result = sum(apples)
print(result)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, L = map(int, input().split())
tastes = [None] * N
abs_tastes = [None] * N

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

print(sum(tastes) - tastes[abs_tastes.index(min(abs_tastes))])

Submission status: Accepted

Solution code:
import bisect
from operator import itemgetter
import math
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,L = IL()

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

if L < 0:
  if num > 0:
    print(ans)
  else:
    print(ans-num)
else:
  print(ans-L)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
totalTaste = 0
tastes = []
minAbs = 9999
minIdx = 9999

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

for i in range(n):
    temp = abs(tastes[i])
    if temp < minAbs:
        minAbs = temp
        minIdx = i

#print(totalTaste)
#print(tastes)
#print(totalTaste - minAbs)
print(totalTaste - tastes[minIdx])

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))
elif 0<A[0]:
  print(sum(A[1:]))
else:
  print(sum(A[:N-1]))

Submission status: Accepted

Solution code:
import numpy as np

N, L = map(int, input().split())
apples = np.array([L]*N)
apples = apples + np.arange(0, N)

if apples.min() >= 0:
    print(apples.sum()-apples.min())
elif apples.max() <= 0:
    print(apples.sum()-apples.max())
else:
    print(apples.sum())

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
m = 400
e = []
ii = -1
tmp = 400
for i in range(1,n+1):
    e.append(l + i - 1)
for i,v in enumerate(e):
    if m > abs(v):
        ii = i
        m = abs(v)
        tmp = v
print(sum(e) - tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s=l*n+((1+n)*n)//2-n
lst=[]
for i in range(n):
	lst.append(l+i)
sorted_lst=sorted(lst,key=abs)
A = s - sorted_lst[0]
print(A)

Submission status: Accepted

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

k = l + n - 1

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

if l >= 0:
    ans = sum_p - l
elif k<= 0:
    ans = sum_p - k
else:
    ans = sum_p

print(ans)

Submission status: Accepted

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007


if __name__ == "__main__":
    N, L = map(int, sys.stdin.readline().split())
    origin = 0
    for i in range(N):
        origin += (L + i)
    diffmin = mod

    comp_min = mod
    for i in range(N):
        comp = 0
        for j in range(N):
            if j == i:
                continue
            comp += (L + j)
        if abs(origin - comp) < diffmin:
            diffmin = abs(origin - comp)
            comp_min = comp
    print(comp_min)

Submission status: Accepted

Solution code:

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

abs_list = list()
sum_score = 0

for index in range(N):
    i = index + 1
    score = L + i - 1

    abs_list.append(abs(score))
    sum_score += score

low = abs_list.index(min(abs_list))

print(sum_score - (L + (low + 1) - 1))

Submission status: Accepted

Solution code:
from math import copysign
n, l = map(int, input().split())
eat=200
ans=0
for i in range(l, l+n):
  ans+=i
  eat=int(min(abs(eat), abs(i))*copysign(1,i))
ans-=eat
print(ans)

Submission status: Accepted

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

if l > 0:
    print(sum(range(l+1,l+n)))
elif l <= 0 and n > abs(l):
    ans = 0
    for i in range(l,l+n):
        ans += i
    print(ans)
else:
    #print("else")
    print(sum(range(l,l+n-1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
ringos = list(range(l,l+n))
minmin = 1000
for ringo in ringos:
    if abs(ringo)<abs(minmin):
        minmin = ringo
ringos.remove(minmin)
print(sum(ringos))

Submission status: Accepted

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

tmp = np.array([L+i for i in range(N)])
tmp2 = np.argmin(np.abs(tmp))
print(sum(tmp) - tmp[tmp2])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(l,n+l):
    m = min(abs(m),abs(i))
    if i < 0:
        m *= -1
else:
    print(sum(range(l,n+l))-m)

Submission status: Accepted

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


def main():
    n, l = map(int, input().split())
    taste = [l + i for i in range(n)]
    total = sum(taste)
    value_min = min(taste)
    value_max = max(taste)

    if value_min > 0:
        print(total - value_min)
    elif 0 in taste:
        print(total)
    elif value_max < 0:
        print(total - value_max)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,L =  list(map(int,input().split(" ")))
m = 100000
su = 0
apples = []
for i in range(N):
    apples.append(L+i)
apples.sort(key=lambda x:abs(x))

print(sum(apples[1:]))

Submission status: Accepted

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

sum = int(L*N + N*(N+1)/2 - N)
if (L <= 0) & (L + N - 1 >=0):
    print(sum)
elif L > 0:
    print(sum-L)
elif L + N - 1 < 0:
    print(sum-(L+N-1))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:

def sumof(begin, end):
    l = [i for i in range(begin, end + 1)]
    return sum(l)

N, L = [int(x) for x in input().split(' ')]
min_aji = L
max_aji = L + N - 1


if 0 <= min_aji:
    aji = sumof(min_aji + 1, max_aji)
elif 0 < max_aji:
    aji = sumof(min_aji, max_aji)
else:
    aji = sumof(min_aji, max_aji - 1)

print(aji)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
scores = [abs(L + n) for n in range(N)]
idx = scores.index(min(scores))
print(sum([L + n for n in range(N) if n != idx]))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
taste=10000
for i in range(1,n+1):
    if abs(taste)>abs(l+i-1):
        taste=l+i-1
        
print(n*l+(n*(n+1)//2)-n-taste)

Submission status: Accepted

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

for i in range(n):
    lists.append(l)
    l += 1

    c = 0
if 0 in lists:
    lists.remove(0)
    print(sum(lists))
else:
    for j in lists:
        if j > -1:
            c += 1           
    if c == len(lists):
        lists.remove(min(lists))
        print(sum(lists))
    else:
        lists.remove(max(lists))
        print(sum(lists))

Submission status: Accepted

Solution code:
from bisect import bisect

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

apple = [i for i in range(l,l+n)]
eat_idx = bisect(apple,0)
if eat_idx == n:
	eat_idx -= 1
# print(apple,eat_idx)
#- or +
if abs(apple[eat_idx]) > abs(apple[eat_idx-1]):
	eat = apple[eat_idx-1]
else:
	eat = apple[eat_idx]
print(sum(apple)-eat)

Submission status: Accepted

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

tas = []

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

tas.sort(key=lambda x:x[1])

ans = 0

for i,abs in tas[1:]:
    ans += i

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left

class Solution:
    def main(self):
        N, L = map(int, input().split())
        # print(list(range(L, L+N)))
        if L <= 0 < L+N:
            print(sum(list(range(L, L+N))))
        elif L + N <= 0:
            print(sum(list(range(L, L+N-1))))
        else:
            print(sum(list(range(L+1, L + N))))


if __name__ == '__main__':
    Solution().main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c=0
absc=10000
for i in range(1,n+1):
  if absc>abs(m+i-1):
    absc=abs(m+i-1)
    c1=m+i-1
  c+=m+i-1
print(c-c1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, itertools, collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n, l = lmi()
a = [(abs(l + i), i) for i in range(n)]
i = sorted(a)[0][1]
# print(i,a)

print(sum([l+i for i in range(n)]) - (l+i))

Submission status: Accepted

Solution code:
# coding: utf-8
n, l = map(int, input().split())
data = list(range(l, l + n))
if 0 in data:
    print(sum(data))
elif data[0] > 0:
    print(sum(data) - data[0])
else:
    print(sum(data) - data[-1])

Submission status: Accepted

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

A = [i+L for i in range(N)]
A = np.array(A)
if L >= 0:                                                                                                                                                                                                  
    print(np.sum(A[1:]))                                                                                                                                                                                    
                                                                                                                                                                                                            
elif L < 0:                                                                                                                                                                                                 
    if N + L - 1 <=0:                                                                                                                                                                                       
        print(np.sum(A[:-1]))                                                                                                                                                                               
    else:                                                                                                                                                                                                   
        print(np.sum(A[:]))

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
aji = []
min_abs = 10000
min_i = -1
for i in range(N):
    ab = abs(L+i)
    if ab<min_abs:
        min_i = i
        min_abs = ab
    aji.append(L+i)
print(sum([a for i, a in enumerate(aji) if i!=min_i]))

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

elif a[0] > 0:
    print(sum(a) - a[0])

else:
    print(sum(a) - a[-1])

Submission status: Accepted

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

cnt = 10**9
ans = 0
for i in range(n):
    a = s-ls[i]
    if abs(s-a)<cnt:
        cnt = abs(s-a)
        ans = a

print(ans)

Submission status: Accepted

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

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

b2 = sorted(b, key=abs)

print(sum(b2[1:]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  list.append(l+i)
tmp = 9999
for i in range(n):
  ans.append(sum(list)-list[i])
for i in range(n):
  if abs(sum(list) - ans[i]) < tmp:
    tmp = abs(sum(list) - ans[i])
    answer = ans[i]
print(answer)

Submission status: Accepted

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

org = 0
ab_taste = 100
for n in range(N):
    taste = L + n +1 -1
    org += taste

    if abs(ab_taste) > abs(taste):
        ab_taste = taste

ret = org - ab_taste

print(ret)

Submission status: Accepted

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

    taste = [L+i-1 for i in range(1, N+1)]
    abs_taste = [abs(x) for x in taste]
    delete_index = abs_taste.index(min(abs_taste))
    taste.pop(delete_index)
    print(sum(taste))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

dec = min(taste_abs)
idx = taste_abs.index(dec)

print(pie_all-taste[idx])

Submission status: Accepted

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

apples = []

min_apple = 99999999
min_i = -1
for i, apple in enumerate(range(l, l+n)):
    apples.append(apple)
    if min_apple > abs(apple):
        min_apple = abs(apple)
        min_i = i

res = sum(apples) - apples[min_i]
print(res)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
li1=[0]*n
li2=[0]*n
cnt=0
for i in range(n):
    li1[i]=l+i
    li2[i]=abs(li1[i])
    cnt+=li1[i]

li1.sort()
li2.sort()

c=0
for i in range(n):
    if li1[i]==li2[0]:
        c+=1

if c>=1:
    print(cnt-li2[0])
else:
    print(cnt+li2[0])

Submission status: Accepted

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

s = [L+i for i in range(N)]
l = [abs(L+i) for i in range(N)]
ind = l.index(min(l))
s.pop(ind)

print(sum(s))

Submission status: Accepted

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

s = sum(val)
small = 10000
for i in val:
    if abs(i) < small:
        small = abs(i)
        memo = i

if memo < 0:
    print(s+small)
else:
    print(s-small)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

n = i[0]
l = i[1]

aji = [] 

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

ajimap = list(map(abs, aji))

idx = ajimap.index(min(ajimap))

sum = 0

for i in range(n):
  if i != idx:
    sum += aji[i]
    
print(sum)

Submission status: Accepted

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

abs_min_taste = 9999
min_i = -1
for i in range(N):
    if abs_min_taste > abs(taste[i]):
        min_i = i
        abs_min_taste = abs(taste[i])

sum_taste = sum(taste)
ans = sum_taste - taste[min_i]
#print(N, L, taste, abs_min_taste, ans)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

if min(taste_list) > 0:
    print(sum(taste_list) - min(taste_list))
elif max(taste_list) < 0:
    print(sum(taste_list) - max(taste_list))
else:
    print(sum(taste_list))

Submission status: Accepted

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

sum_of_taste = sum(taste)

base = 10**10
answer = 0
for i in taste:
  if base > abs(i):
    base = abs(i)
    answer = sum_of_taste - i

print(answer)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
s = 0
m = abs(max(L,L+N-1))
j = 0
for i in range(N):
    s += L+i
    if m >= abs(L+i):
        m = abs(L+i)
        j = i
print(s-L-j)

Submission status: Accepted

Solution code:
import sys

fin = sys.stdin.readline
N, L = [int(elem) for elem in fin().split()]

all_sum = N * (1 + N) / 2 + L * N - N
i = min(max(1, 1 - L), N)
reduce_num = L + i - 1
print(int(all_sum - reduce_num))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,l = list(map(int,input().split()))
apple_list = [i for i in range(l,l+n)]
max_al = max(apple_list)
min_al = min(apple_list)
ret = sum(apple_list)
if 0 not in apple_list:
    if abs(max_al) >= abs(min_al):
        ret -= min_al
    else:
        ret -= max_al
print(ret)

Submission status: Accepted

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

taste = [0] * N
minimum = 10000
minAbs = 10000

for i in range(N) :
    taste[i] = L + i
    if abs(taste[i]) < minAbs :
        minimum = taste[i]
        minAbs = abs(taste[i])

print(sum(taste) - minimum)

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:
#!/usr/bin/env python3
n, l = map(int, input().split())
ans = 0
m = 10**5
for i in range(n):
    if abs(l + i) < m:
        m = abs(l + i)
        ans = l + i
print(n * l + n * (n - 1) // 2 - ans)

Submission status: Accepted

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

apples = range(l, n+l)
print(sum(sorted(apples, key=lambda x: abs(x))[1:]))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
l = []
a = abs(L)
b = a
for n in range(1, N+1):
  l.append(L+n-1)
  if abs(L+n-1) < a:
    a = abs(L+n-1)
    b = L+n-1

print(sum(l) - b)

Submission status: Accepted

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

b = np.array([l + i for i in range(n)])
a = b.sum()

idx = np.argmin(np.abs(b))

print(a - b[idx])

Submission status: Accepted

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

aaa = [l + x for x in range(n)]
sum_aaa = sum(aaa)
tmp = float("inf")
for a in aaa:
    if abs(sum_aaa - (sum_aaa - a)) < tmp:
        tmp = abs(sum_aaa - (sum_aaa - a))
        res = sum_aaa - a
print(res)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s=[]
i=0
while i!=n:
    x=[abs(l+i),l+i]
    s.append(x)
    i+=1
s.sort()
i=1
ans=0
while i!=n:
    ans+=s[i][1]
    i+=1
#print(s)
print(ans)

Submission status: Accepted

Solution code:

def input_from_console():
    n, l = map(int, input().split())
    return n, l


def solve(n, l):
    all_data = [ l + item for item in range(n)]
    new_list = sorted([abs(item) for item in all_data])
    if new_list[0] in all_data:
        result = sum(all_data) - new_list[0]
    else:
        result = sum(all_data) + new_list[0]
    return result


def main():
    n, l = input_from_console()
    print(solve(n, l))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Accepted

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

a = list(range(L+1-1, L+N-1+1))
a.sort(key=lambda x: abs(x))

print(sum(a[1:]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=(int(i) for i in input().split())
r=l
s=0
for i in range(n):
  if l+i<=0:
    r=l+i
  s=s+l+i
print(s-r)

Submission status: Accepted

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

Submission status: Accepted

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



l = []

min_a = N + abs(L) * N * N + N


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

    if abs(a) < abs(min_a):
        min_a = abs(a)
        ans_i = i



    l.append(a)


ans = sum(l) - l[ans_i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def read():
    N, L = list(map(int, input().strip().split()))
    return N, L


def solve(N, L):
    tastes = [-1] * N
    min_abs_index = 0
    for i in range(N):
        tastes[i] = L + (i+1) - 1
        if abs(tastes[i]) < abs(tastes[min_abs_index]):
            min_abs_index = i
    return sum(tastes[0:min_abs_index]) + sum(tastes[min_abs_index+1:N])


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline

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

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

a = [abs(L + i) for i in range(N)]
b = min(a)
c = a.index(b) + L

print(total - c)

Submission status: Accepted

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