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

Solution (Python):
N, L =map(int, input().split())
mini = 1000
wa = 0
for n in range(N):
  Ln = L + n
  wa = wa + Ln
  if abs(Ln) < abs(mini):
    mini = Ln
wa = wa - mini
print(wa)

Solution (Python):
def resolve():
    N, L = map(int, input().split())
    list = []
    for i in range(N):
        list.append(L+i)
    if L <= 0 and N >= (L*-1)+1:
        print(sum(list))
    elif min(list) > 0:
        print(sum(list) - min(list))
    else:
        print(sum(list) - max(list))
resolve()

Solution (Python):
N,L=map(int, input().split())
List=[]
i=1
while i<=N:
    List.append(L+i-1)
    i+=1
MIN=abs(List[0])
HIKU=List[0]
j=1
while j<N:
    if abs(List[j])<MIN:
        HIKU=List[j]
        MIN=abs(List[j])
    j+=1
del List[List.index(HIKU)]
print(sum(List))

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

amax = max(a)
amin = min(a)

if a.count(0) == 0:
    if amax > 0:
        a.pop(0)
    else:
        a.pop()
        
print(sum(a))

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

Solution (Python):

import sys
input = sys.stdin.readline
N,L = (int(x) for x in input().split())
taste =[i for i in range(L,L+N ) ]
decide =taste[0] *taste[-1]
ans =0
if 0 <= decide: 
    if taste[0] <0:
        ans =sum(taste[:-1])
    else:
        ans =sum(taste[1:])
else: 
    ans =sum(taste) 
print(ans)

Solution (Python):
N, L = map(int, input().split())
array = []
minN = 10**10
for x in range(N):
    array.append(L + x)
    if abs(L + x) < abs(minN):
        minN = L + x
array.remove(minN)
print(sum(array))

Solution (Python):
N,L = map(int,input().split())
apple = [L+i-1 for i in range(1,N+1,1)]
minapp = 10000
index = 0
for i in range(0,N,1):
    if minapp > abs(apple[i]):
        index = i
        minapp = abs(apple[i])
print(sum(apple)-apple[index])

Solution (Python):
N, L = map(int, input().split())
apple = list(range(L, L+N))

if 0 in apple:
    print(sum(apple))
elif apple[0] > 0:
    print(sum(apple)-apple[0])
elif apple[-1] < 0:
    print(sum(apple)-apple[-1])

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

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

Solution (Python):
N, L = map(int, input().split())
l = []
for i in range(N):
    l.append(L+i)
ll = min(list(map(abs, l)))

Min = L
Max = L+N-1
if (Min>0 and Max>0):
    l.remove(ll)
    print(sum(l))
elif Min < 0 and Max < 0:
    l.remove(-1*ll)
    print(sum(l))
else:
    print(sum(l))

Solution (Python):
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

INF = float("inf")












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

Solution (Python):
n,l=map(int,input().split())
a=0
b=float("inf")
for i in range(n):
  a+=i+l
  if abs(b)>abs(i+l):
    b=i+l
print(a-b)

Solution (Python):
N , L = (int(a) for a in input().split())
apple = []
for i in range (1,N+1) :
    apple.append(L + i - 1)

if L >= 0 :
    del apple[0]
elif N + L <= 1 :
    del apple[-1]
else : del apple[abs(L)]

print(sum(apple))

Solution (Python):

n, k = map(int, input().split())
a = []
b = []
c = 0
for i in range(k, n + k):
    a.append(abs(i))
    b.append(i)
if abs(min(b)) <= min(a):
    print(sum(b) - min(a))
else:
    print(sum(b) + min(a))

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

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

Solution (Python):
n,l = map(int,input().split())
lista = range(n)
listb = []
for i in range(n):
    listb.append(abs(lista[i]+l))
a = listb.index(min(listb))
listc = []
for i in range(n):
    listc.append(lista[i]+l)
listc[a] = 0
print(sum(listc))

Solution (Python):
n, l = map(int, input().split())
taste = []
abs_v = []

for i in range(n):
    taste.append(l+i)
    abs_v.append(abs(l+i))

idx = abs_v.index(min(abs_v))
del taste[idx]

print(sum(taste))

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

a = [l + i for  i in range(n)]
a.sort(key=lambda x: abs(x))
print(sum(a[1:]))

Solution (Python):
n, l = map(int, input().split())
s = sum(l + i for i in range(n))
eaten = min((l + i for i in range(n)), key=lambda x: abs(x))
print(s - eaten)

Solution (Python):
n,l= map(int,input().split())
li = []
for i in range(n):
    li.append(l)
    l += 1
ans = 0
li_min = float('inf')
for i in range(len(li)):
    li_min = min(abs(li[i]),li_min)
for i in range(len(li)):
    if li_min == abs(li[i]):
        li[i] = 0
print(sum(li))

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

x = []
y = []
for i in range(1,n+1):
  t = l + i - 1
  y.append(abs(t))
  x.append(t)
  
tmp = zip(y,x)
tmp2 = sorted(tmp)
c,ans = zip(*tmp2)
print(sum(ans[1:]))

Solution (Python):
n, l = map(int, input().split())
r = l + n - 1
eat = range(l, r + 1)
print((l + r) * n // 2 - min(eat, key=abs))

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








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

if L.count(0)>0:
    print(sum(L))
elif L[-1]<0:
    print(sum(L[:-1]))
else:
    print(sum(L[1:]))

Solution (Python):

import sys


def solve(N: int, L: int):
    ls = range(L, L + N)
    print(sum(ls) - min(ls, key=abs))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)


if __name__ == '__main__':
    main()

Solution (Python):
n, l = map(int, input().split())
ll = []

for i in range(1, n+1):
    ll.append(i + l - 1)

if ll[0]>= 0:
    ans = sum(ll) - ll[0]
elif ll[n-1]<=0:
    ans = sum(ll) - ll[n-1]
else:
    ans = sum(ll)

print(ans)

Solution (Python):



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


if __name__ == '__main__':
    main()

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

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


kei = sum(aji)/n


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


i = sa.index(min(sa))



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

Solution (Python):

import sys

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement


from operator import itemgetter
from sys import stdin

from operator import mul
from functools import reduce
from collections import Counter





j=0
k=0
n=3
r=1
a=[0]






"1行1つの整数を入力を取得し、整数と取得する"




"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

for i in number_list:
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''



"正方行列にstr型の値を入力"
'''




'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"


'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''











'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''




"aという変数に入っているものを大文字にして出力"

















'''
コンビネーションの組み合わせの中身を出力する形式
for i in itertools.combinations(brray, 2)
combinationsをpermutationsにすれば順列になる
今回なら(abc133B)
入力
1 2
5 5
-2 8
出力
[[1, 2], [5, 5], [-2, 8]]
もちろん一次元リストでも使えるし
何よりiもリストのように使えるので便利
'''


'''
def cmb(n,r):
    
    r= min(n-r,r)
    
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    
    
    

    under = reduce(mul, range(1, r+1))
    
    
    
    

    return over // under
    
    
    
    
a = cmb(n, r)

'''

'''
import itertools
from itertools import combinations_with_replacement

combinationについて
以下の違いを意識しよう
combinations() p, r 長さrのタプル列、ソートされた順で重複なし

combinations_with_replacement() p, r 長さrのタプル列、ソートされた順で重複あり


使用例 　　　　　　　　　　　                  出力　　
combinations('ABCD', 2)　　　　　　　　　　　　AB AC AD BC BD CD

combinations_with_replacement('ABCD', 2)　　 AA AB AC AD BB BC BD CC CD DD
'''



'''




for i in a.most_common(n):print(i)





 


'''









'''
bisect.bisect_left(a, x, lo=0, h=len(a))
引数
a: ソート済みリスト
x: 挿入したい値
lo: 探索範囲の下限
hi: 探索範囲の上限
(lo, hiはスライスと同様の指定方法)
bisect_leftはソートされたリストaに対して順序を保ったままxを挿入できる箇所を探索します。leftが示す通り、aにすでにxが存在している場合は、挿入箇所は既存のxよりも左側になります。また、lo, hiを指定することで探索範囲を絞り込むことも可能です。デフォルトはaの全体が探索対象です。
'''

'''
素数の判定
'''


def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        
        if n % k == 0:
            return False
            
    return True


'''
npのmaxとmaximumの違い
xs = np.array([1, -2, 3])
np.max(xs, 0)
この出力は3となります．[1, -2, 3]と0の4つの数字のうち，最も大きい値を出力します．

一方で，[max(1, 0), max(-2, 0), max(3, 0)]を出力したい時があります．
その時は，numpyのmaximum関数を用います．

xs = np.array([1, -2, 3])
np.maximum(xs, 0)  

'''

def factorial(x, mod=10**9+7):
    
    
    
    tmp = 1
    for i in range(1, x+1):
        tmp = (tmp * i) % mod
    return tmp
    '''
    Basically, when you do a**d % n, you actually have to calculate a**d, which could be quite large.
    But there are ways of computing a**d % n without having to compute a**d itself, and that is what pow does.
    '''











'''
ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digits = '0123456789'
hexdigits = '0123456789abcdefABCDEF'
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv...\xaf\xb0...
lowercase = 'abcdefghijklmnopqrstuvwxyz'
octdigits = '01234567'
printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU...
punctuation = '!"
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
whitespace = '\t\n\x0b\x0c\r '
'''
'''
引数endに任意の文字列を指定すると、その文字列が改行の代わりに最後に挿入される。例えば連続するprint()の出力を改行なしで単純に連結したい場合は空文字列''を指定すればよい。

print('abc', end='---')
print('xyz')


print('abc', end='')
print('xyz')

source: print_basic.py
なお、デフォルトで改行されるのは引数endのデフォルト値が改行文字'\n'に設定されているから。
'''

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    
    
    
    n,l=map(int, input().split(" "))
    c=[0]*n
    csum=0
    d=[10000000000]*n
    for i in range(n):
        c[i]=l+i
    
    
    csum=sum(c)
    
    
    
    
    if min(c)>=0:
        print(csum-min(c))
    elif min(c)<0 and max(c)>=0:
            print(csum)
    elif max(c)<0:
        print(csum-max(c))
    '''
    if l<=0 and n>=abs(l):
     print(csum)
    elif l>0:
     print(csum-min(c))
    elif l<=0 and n<abs(l) :
     print(csum-max(c))
    '''
    
    
    
    
    
    
    


    for i in range(1,n+1,2):
     pass
     

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')
    
    
    
    

    
        
    
    

    
    
    
    
    DP = np.zeros(w+1, dtype=int)
    exdp=np.zeros((3,4)) 
    
    
    
        
        
    
    
        
        
    


    
    



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]
    

    ls = ["a", "b", "c", "d", "e"]


    
    

    
    

    
    
    
    
    
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

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

Solution (Python):
N, L = map(int, input().split(' '))
total = 0
eat = float('inf')
for i in range(N):
  total += L + i
for i in range(N):
  if abs(L + i) < eat:
    eat = abs(L + i)
    ans = L + i
print(total - ans)

Solution (Python):
N, L = map(int, input().split(' '))
total = 0
eat = float('inf')
for i in range(N):
  total += L + i
for i in range(N):
  if abs(L + i) < eat:
    eat = abs(L + i)
    ans = L + i
print(total - ans)

Solution (Python):
n,l = map(int,input().split())
taste_all = 0
taste_remain = 0
taste_ans = 0
taste_select = 1000000

for i in range(n):
    taste_all += l + i

for i in range(n):
    for j in range(n):
        if i != j:
            taste_remain += l + j
    temp = abs(taste_remain-taste_all)
    if temp < taste_select:
        taste_ans = taste_remain
        taste_select = temp
    taste_remain = 0

print(taste_ans)

Solution (Python):
import copy

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

s = [x + l for x in range(n)]
num = sum(s)
b = abs(num - (num - s[0]))
test = num - s[0]

for i in range(1, n):
  a = copy.copy(s)
  a.remove(s[i])
  if(i != 0):
    if(min(b, abs(num - sum(a))) != b):
      test = sum(a)
      b = abs(num - sum(a))
  
print(test)

Solution (Python):
n, l = map(int, input().split())
ll = []

for i in range(1, n+1):
    ll.append(i + l - 1)

if ll[0]>= 0:
    ans = sum(ll) - ll[0]
elif ll[n-1]<=0:
    ans = sum(ll) - ll[n-1]
else:
    ans = sum(ll)

print(ans)

Solution (Python):
n, l = map(int, input().split())
ll = []

for i in range(1, n+1):
    ll.append(i + l - 1)

if ll[0]>= 0:
    ans = sum(ll) - ll[0]
elif ll[n-1]<=0:
    ans = sum(ll) - ll[n-1]
else:
    if n != 3:
        for i in range(1, n-1):
            if abs(ll[i-1]) >  abs(ll[i]) and abs(ll[i]) < abs(ll[i+1]):
                ans = sum(ll) - ll[i]
    else:
        ans = sum(ll) - ll[1]

print(ans)

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

Solution (Python):


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

max_ = l+n-1
min_ = l


if max_ >= 0 and min_ <= 0:
    print((max_+min_)*(max_-min_+1)//2)
elif max_ <= 0:
    max_ -= 1
    print((max_+min_)*(max_-min_+1)//2)
else:
    min_ += 1
    print((max_+min_)*(max_-min_+1)//2)

Solution (Python):
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    n,l = map(int, input().split())
    min_abs = 100
    ans = []
    for i in range(l,(l+n)):
        ans.append(i)
        if abs(i) < min_abs:
            min_abs = abs(i)
    
    for j,v in enumerate(ans):
        if min_abs == abs(v):
            ans.pop(j)
            break
    print(sum(ans))

if __name__ == "__main__":
    main()

Solution (Python):
n , l = map(int, input().split())
L = []

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

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

Solution (Python):
n, l = map(int, input().split())
taste_list = []
abs_list = []
for i in range(n):
    taste = l + i
    taste_list.append(taste)
    abs_taste = abs(taste)
    abs_list.append(abs_taste)
abs_min = min(abs_list)
min_index = abs_list.index(abs_min)
taste_list.remove(taste_list[min_index])
print(sum(taste_list))

Solution (Python):
n, l = map(int, input().split())
taste_list = []
for i in range(n):
    taste = l + i
    taste_list.append(taste)
all_sum = sum(taste_list)

div_chk = 10000000000
for j in range(n):
    rem = taste_list[0]
    taste_list.remove(rem)
    chk = sum(taste_list)
    div = abs(all_sum - chk)
    if abs(div) < abs(div_chk):
        div_chk = abs(div)
        ans = chk
    else:
        pass
    
    taste_list.append(rem)
    
print(ans)

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

ans=0

m=10000

for i in range(n):
  ans += l
  if abs(l)<abs(m):
    m=l
  l += 1
  
print(ans-m)

Solution (Python):
N, L = map(int, input().split())
total = 0

if L>=0:
    for i in range(1,N,1):
        total = total + L  + i
else:
    if -L<N:
        for i in range(N):
            total = total + L + i
    else:
        for i in range(N-1):
            total = total + L + i

print(total)

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

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

min_idx = -1
mins = None
for idx, n in enumerate(ns):
    if mins is None:
        mins = abs(n)
        min_idx = 0
    else:
        if mins > abs(n):
            min_idx = idx
            mins = abs(n)

ns.pop(min_idx)
print(sum(ns))

Solution (Python):
N, L = map(int, input().split())
taste = [L+i-1 for i in range(1, N+1)]
min_num = [abs(i) for i in taste]
min_num = sum(min_num)
result = 0
for i in taste:
  num = abs(sum(taste) - (sum(taste) - i))
  if min_num > num:
    min_num = num
    result = sum(taste) - i
print(result)

Solution (Python):
N,L = map(int,input().split())
E = []
a=0
for i in range(1,N+1):
  E.append(L+i-1)
  a += L+i-1
if E[0]<=0 and E[N-1]>=0:
  print(a)
else:
  if E[0]>0:
    print(a-E[0])
  else:
    print(a - E[N-1])

Solution (Python):
n, l = map(int, input().split())
tastes = [i + l for i in range(n)]
abs_tastes = [abs(taste) for taste in tastes]
ind = abs_tastes.index(sorted(abs_tastes)[0])
print(sum(tastes) - tastes[ind])

Solution (Python):

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


T = [L + i - 1 for i in range(1, N + 1)]
abs_T = [abs(t) for t in T]
min_abs = min(abs_T)
min_idx = abs_T.index(min_abs)
Pt = sum(T) - T[min_idx]

print(Pt)

Solution (Python):
n, l = map(int, input().split())
taste = []
for i in range(1, n + 1):
    taste.append(l + i - 1)
m = 1000
for i in range(n):
    if abs(taste[i]) < m:
        m = abs(taste[i])
        eat = taste[i]
print(sum(taste) - eat)

Solution (Python):
x = list(map(int, input().split()))
count = 0
l = []
for i in range(1, x[0]+1):
  tmp = x[1] + i - 1
  l.append(tmp)
if (0 in l) == True:
  for i in l:
    count += i
else:
  if l[0] > 0:
    for i in l[1:]:
      count += i
  else:
    for i in l[:-1]:
      count += i
print(count)

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

print(b)

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

Solution (Python):
n,l=map(int,input().split())
aji=list(range(l,l+n))
ans=0
sa=abs(sum(aji))

for i in range(n):
  pie=sum(aji)-aji[i]
  if sa>abs(sum(aji)-pie):
    sa=abs(sum(aji)-pie)
    ans=pie

print(ans)

Solution (Python):
def resolve():
    N, L = map(int, input().split())
    tastes = [i + L - 1 for i in range(1, N + 1)]

    tastes.sort(key=lambda x: abs(x))

    print(sum(tastes[1:]))


resolve()

Solution (Python):
N,L=map(int,input().split())
mem=sum(range(L,L+N))
m=mem
ans=0
for i in range(N):
    tmp=(sum(range(L,L+N))-(L+i))
    if abs(mem-tmp) < abs(m):
        m=mem-tmp
        ans=tmp
print(ans)

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

Solution (Python):
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)




input_list = lambda : list(map(int,input().split()))


n,l=input_list()

r=l+n-1

ans=0

bite=0
if r<0:
    bite=r

if l>0:
    bite=l

for i in range(l,r+1):
    if i==bite:
        continue
    ans+=i

print(ans)

Solution (Python):
n,l = list(map(int,input().split()))
n_l = []
for i in range(n):
    n_l.append(i+l)
    
min_i = 100000
for i in n_l:
    if abs(i) < abs(min_i):
        min_i = i

print(sum(n_l) - min_i)

Solution (Python):
N, L = map(int, input().split())
original_taste = int(N*(L-1) + N*(N+1)*0.5)
difference = float("inf")

for i in range(N):
    if abs(L+i) < difference:
        difference = abs(L+i)
        apple_chosen = i

print(original_taste - (L+apple_chosen))

Solution (Python):
import itertools
import math
import fractions
import functools
import copy

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

minimum = min(aji)
maximum = max(aji)

if minimum <= 0 and maximum >= 0:
    print(sum(aji))
    quit()
if minimum <= 0 and maximum <= 0:
    print(sum(aji)-maximum)
    quit()
if minimum >= 0 and maximum >= 0:
    print(sum(aji)-minimum)

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

Solution (Python):
n,l = map(int,input().split())
p = [l+i for i in range(n)]
ans1 = 0
q = 10**9
y = 0
for i in range(n):
    ans1 += p[i]
for i in range(n):
    if q>p[i] :
        y = i
    q = min(q,abs(p[i]))
print(ans1-p[y])

Solution (Python):
n,l=map(int,input().split())
a=[0]*n
b=[0]*n
for ii in range(n):
  a[ii]=l+ii
  b[ii]=abs(a[ii])
import numpy as np
x=np.argsort(b)
a[x[0]]=0
print(sum(a))

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

if 0 in A:
    print(sum(A))
else:
    B = [abs(n) for n in A]
    m = min(B)
    if m in A:
        print(sum(A)-m)
    else:
        print(sum(A)+m)

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

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

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

apples = []

should_eat_score = float("inf")

for i in range(N):
    apples.append(L+i)
    if abs(should_eat_score) > abs(L+i):
        should_eat_score = L+i

apples.remove(should_eat_score)

print(sum(apples))

Solution (Python):

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

t=[l+i for i in range(n)]

ans=min(t)
for i in t:
    if abs(i)<abs(ans):
        ans=i
t.remove(ans)
print(sum(t))

Solution (Python):
import numpy as np

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

A = np.arange(N)+L

if A[0] <= 0 and A[N-1] >= 0:
    print(np.sum(A))
elif A[0] < 0 and A[N-1] < 0:
    print(np.sum(A)-A[N-1])
else:
    print(np.sum(A)-A[0])

Solution (Python):
import sys
input = sys.stdin.readline
N, L = map(int,input().split())
A = [0] * N
B = [0] * N
for i in range(N):
  A[i] = L + i

ans = 0
diff = 10 ** 10
for j in range(N):
  B[j] = sum(A) - A[j]
  diff = min(diff, abs(sum(A)-B[j]))

if sum(A) >= 0:
  print(sum(A)-diff)
else:
  print(sum(A)+diff)

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

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

apple_tastes = list()

for num in range(n):
    apple_taste = l + num
    apple_tastes.append(apple_taste)

max_taste = max(apple_tastes)
min_taste = min(apple_tastes)

if max_taste > 0 and min_taste < 0:
    apple_tastes.remove(0)
elif max_taste > 0 and min_taste > 0:
    apple_tastes.remove(min_taste)
elif max_taste < 0 and min_taste < 0:
    apple_tastes.remove(max_taste)
    
ans = sum(apple_tastes)
print(ans)

Solution (Python):

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

Solution (Python):
n,l=map(int,input().split())
ls=[]
for i in range(1,n+1):
  ls.append(abs(l-1+i))
mi=ls.index(min(ls))
print(n*(l-1)+sum(range(1,n+1))-l-mi)

Solution (Python):






import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)


def bit_count(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count





N,L = inputIL()

l = [i for i in range(L,L+N)]
a = [abs(i) for i in l]
p = a.index(min(a))

print(sum(l)-l[p])

Solution (Python):
N,L=map(int,input().split())
tot=0
for i in range(1,N+1):
    tot+=(L+i-1)
l=[]
for i in range(N):
    l.append(tot-(L+(i+1)-1))



for i in range(len(l)):
    if i==0:
        ans=l[i]
        dif=abs(l[i]-tot)
    else:
        if dif>abs(l[i]-tot):
            dif=abs(l[i]-tot)
            ans=l[i]
print(ans)

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

ans = sum(L + i for i in range(N))
if L < 0 and abs(L) >= N:
    ans -= (N + L - 1)
elif L > 0:
    ans -= L
print(ans)

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


f_ringo = 0

l_ringo = 0

num = 0

if L >= 0:
    
    f_ringo = L + 2 - 1
    l_ringo = L + N - 1
    num = N - 1

        
elif L < 0 and N+L > 0:
    
    f_ringo = L + 1 - 1
    l_ringo = L + N - 1
    num = N


elif L < 0 and N+L <= 0:
    
    f_ringo = L + 1 - 1
    l_ringo = L + N-1 - 1
    num = N - 1

total = ((f_ringo+l_ringo) * int(num/2))
if num%2 == 1:
    ringocenter = f_ringo + int(num/2)
    total += ringocenter

print(total)

Solution (Python):
def bite_eating(n, l):

    count = 0
    ans = 10**5
    ansmin = 0

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

    return count - ansmin
def main():
    n, l = map(int, input().split())
    print(bite_eating(n, l))

if __name__ == '__main__':
    main()

Solution (Python):
n,l=map(int,input().split())
f=1
as_=[]
m=float('inf')
for i in range(n):
    a=l+i
    as_.append(a)
    m=min(m,abs(a))
    if a<0:
        f=-1
    else:
        f=1
print(sum(as_)-f*m)

Solution (Python):
N,L = map(int,input().split())
l1 = []
l2 = []
for i in range(1,N+1):
    a = L+i-1
    l1.append(a)
    l2.append(abs(a))

for j in range(N):
    if abs(l1[j]) == min(l2):
        del l1[j]
        break
print(sum(l1))

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

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



y = 1000000000000
xx = None
for x in range(l, l + n):
    if y > abs(x):
        y = abs(x)
        xx = x

ans = 0
for x in range(l, l + n):
    if x == xx:
        continue
    ans += x
print(ans)

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

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

Solution (Python):
n, l = map(int, input().split())
m = []
for i in range(1, n+1):
    m.append(l+i-1)
su = 0
for i in m:
    su += i
e = 10**8
ans = 0
for i in range(n):
    tmp = 0
    for j in range(n):
        if i == j: continue
        tmp += m[j]
    if e > abs(su-tmp):
        e = abs(su-tmp)
        ans = tmp
print(ans)