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())
r = l + n - 1
eat = range(l, r + 1)
print((l + r) * n // 2 - min(eat, key=abs))

Submission status: Accepted

Solution code:

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)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
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:]))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
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)

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

kei = sum(aji)/n
#print(kei)

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

i = sa.index(min(sa))

#print(i)

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

Submission status: Accepted

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

import fractions
import copy
import bisect
import math
import numpy as np
import itertools
from itertools import combinations_with_replacement
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from operator import mul
from functools import reduce
from collections import Counter
#from collections import deque

#input = stdin.readline


j=0
k=0
n=3
r=1
a=[0]
#n=int(input())
#r=int(input())
#print(M)
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    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を複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
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)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ
#intを取ると文字列分解に使える
'''
入力
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()#str style 何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"


#a,b=map(int, input().split())  #int style 複数数値入力　「A B」みたいなスペース空いた入力のとき

#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成


##############################################################################################
##############################################################################################
#under this line explains example calculation



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

#nCr combination
'''
def cmb(n,r):
    #When n < r , this function isn't valid
    r= min(n-r,r)
    #print(n,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n-r, -1))
    #flochart mul(n,n-1)=x
    #next     mul(x,n-2)........(n-r+1,n-r)
    #mul read a,b and returns a*b

    under = reduce(mul, range(1, r+1))
    #print(over, under)
    #reduce is applied mul(1,2)=2
    #next   mul(2,3)=6
    #next   mul(6,4)=4.........last(r!,r+1)=r+1!

    return over // under
    #// is integer divide
    #calc example 5C2
    #over=5*4*3
    #under=3*2*1
a = cmb(n, r)
#print(a)
'''

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



'''
#集計
#example
#a=[2,2,2,3,4,3,1,2,1,3,1,2,1,2,2,1,2,1]
#a=Counter(a)
for i in a.most_common(n):print(i)
#most_common()メソッドは、出現回数が多い要素順にCounterオブジェクトを並び替えます。
#引数にint型の数字nを設定した場合は、出現回数が高い上位ｎ個の要素を返します。
#何も設定しなければ、コンテナ型にあるすべての要素を出現回数の順番に並び替えたタプル型オブジェクトを返します。
#out put
#(2, 8)
 #(1, 6)
#(3, 3)
#(4, 1)
'''


#二部探索(binary search)
#A = [1, 2, 3, 3, 3, 4, 4, 6, 6, 6, 6]
#print(A)
#index = bisect.bisect_left(A, 5) # 7 最も左(前)の挿入箇所が返ってきている
#A.insert(index, 5)
#print(index)
#print(A)
'''
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):
        #sqrt(n)+1以上は考えて約数はないので却下
        if n % k == 0:
            return False
            #割り切れたら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)  # [1, 0, 3]

'''

def factorial(x, mod=10**9+7):
    # x!
    # 階乗
    # ex) factorial(5) = 120
    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.
    '''


########################################################################
########################################################################
#b2=a[:]  #1次元のときはコピーはこれで良い
#print(b2)

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b3=copy.deepcopy(a)  #2次元配列はこうコピーする
#print(b3)

'''
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')
# abc---xyz

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

def main():
    n=3
    steps=0
    state=0
    w=1
    j=0
    k=0
    #lenを変数に置くと事故るから注意
    #n=int(input())
    #a,b=input().split(" ")#a,bがともに文字列のとき
    n,l=map(int, input().split(" "))
    c=[0]*n
    csum=0
    d=[10000000000]*n
    for i in range(n):
        c[i]=l+i
    #print(c)
    #print(c.index(abs(min(c))))
    csum=sum(c)
    #for i in range(n):
    #    d[i]=csum-c[i]
    #print(d)
    #print(csum)
    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))
    '''
    #mapでとってもstrで変換すればappend可能
    #s=input()
    #a=[i for i in s]#int(i)にすれば数字も行ける
    #nl=list(map(int, input().split(" ")))#数字の時
    #print(a)
    #brray=[list(map(int, input().split(" ")))for i in range(N)]
    #print(brray)


    for i in range(1,n+1,2):#これで1個飛ばしループになる
     pass
     #print(i)

    l = ['aaa', 'bbb', 'ccc']
    x=l.index('aaa')#ある要素のインデックス番号を取得
    #s = ''.join(l)
    #s = " ".join(map(str,a))#スペースを空ける時はこう
    #print(s)
    # aaabbbccc

    #if state in known_states and not flag: # state => 2 steps => 5
        #こうやってある要素がリストの中にあるか探すのか
    #print(f'steps: {steps}, state: {state}')
    #こう書いてあるとデバックしやすい

    #dp= [[0]*3 for i in range(5)]#列　行
    #dp用の0の入ったやつ
    #dp= [[0]*(w+1) for i in range(n+1)]#0からwまでのw+1回計算するから
    #print(dp)＃初期条件が入る分計算回数+1列分必要(この場合は判断すべきものの数)
    DP = np.zeros(w+1, dtype=int)#これでも一次元リストが作れる
    exdp=np.zeros((3,4)) # ３×４の２次元配列を生成。2次元ならこう
    #dtypeは指定しないとfloatになる
    #for i in range(n):#ちょっとした入力に便利
    #    a, b = map(int, input().split())
        #dp[i][0] += [a]
        #これだとintとlistをつなぐことになって不適
    #    dp[i] += [a]
    #    dp[i] += [b]
        #これはうまくいく
        #やり方はいろいろあるということ
    #print(dp)


    #brray=[list(map(int, input().split(" ")))for i in range(N)
    #print(brray)



    '''
    入力
    1234
    出力
    [1, 2, 3, 4]
    '''
    pin_l=["x" for i in range(10)]#内包表記に慣れろ
    #print(pin_l)

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


    #print(ls[2:5])
    #スライスでの取得

    #print(ls[:-3])
    #一番左端から右から3番目より左まで取得

    #print(ls[:4:2])
    #スライスで1個飛ばしで取得
    #ないときは左端スタート
    #始点のインデックス番号 : 終点のインデックス番号 : スキップする数+1
    #print(ls[::2])
    '''
    lsというリストの場合に、1つ飛びの値を取得したい場合には
    ls[::2]
    のようにします。こうすると、
    ["a", "c", "d"]と出力される
    '''

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

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

max_ = l+n-1
min_ = l

# print(min_, max_)
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)
#print(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
    #print(taste_list)
    taste_list.append(rem)
    #print(all_sum, chk)
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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) )

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
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])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#b
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

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


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
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)]

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

######Combination######
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

######Factorization######
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

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

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

#############
# Main Code #
#############

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

Submission status: Accepted

Solution code:
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))#
#print(l)
#print(tot)
#lの要素の中でtotとの差が最も小さいものを出力する
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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:
    #味が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)

Submission status: Accepted

Solution code:
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()

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

# L ~ L + N - 1

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)

Submission status: Accepted

Solution code:
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])