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,k=map(int,input().split());a=[k+i for i in range(n)]
sumA=sum(a);min_num=float('inf');result=0
for i in a:
  if min_num > abs(sumA-(sumA-i)):
    min_num=abs(sumA-(sumA-i))
    result=sumA-i
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, L = map(int, input().split())
taste = [L + i for i in range(N)]
remove = np.argmin(np.abs(taste))
taste_sum = 0
for i in range(N):
    if i == remove:
        continue
    else:
        taste_sum += taste[i]
print(taste_sum)

Submission status: Accepted

Solution code:
n, l = (int(xi) for xi in input().split())

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

# print(a)
if 0<1-l<n+1: print(a)
if 1-l<1: print(a-(l+1-1))
if n<1-l: print(a-(l+n-1))

Submission status: Accepted

Solution code:
# abc131_b.py
# https://atcoder.jp/contests/abc131/tasks/abc131_b

# B - Bite Eating /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 200点

# 問題文
# N個のリンゴがあります。
# これらはそれぞれリンゴ 1、リンゴ 2、リンゴ 3、...、リンゴ N と呼ばれており、リンゴ i の「味」は L+i−1です。
# 「味」は負になることもありえます。
# また、1個以上のリンゴを材料として、アップルパイをつくることができます。
# その「味」は、材料となったリンゴの「味」の総和となります。
# あなたはこれらのリンゴを全て材料として、アップルパイをつくる予定でしたが、おなかがすいたので 1個だけ食べることにしました。
# 勿論、食べてしまったリンゴはアップルパイの材料にはできません。
# つくる予定だったアップルパイとできるだけ同じものをつくりたいので、N個のリンゴ全てを材料としてできるアップルパイの「味」と、
# 食べていない N−1個のリンゴを材料としてできるアップルパイの「味」の差の絶対値ができるだけ小さくなるように、
# 食べるリンゴを選ぶことにしました。
# このようにして選ばれたリンゴを食べた時、食べていない N−1個のリンゴを材料としてできるアップルパイの「味」を求めてください。
# なお、この値は一意に定まることが証明できます。

# 制約
#     2≦N≦200
#     −100≦L≦100
#     入力は全て整数である。

# 入力
# 入力は以下の形式で標準入力から与えられます。
# N L

# 出力
# 最適に食べるリンゴを選んだ時の、食べていない N−1個のリンゴを材料としてできるアップルパイの「味」を出力してください。

# 入力例 1
# 5 2

# 出力例 1
# 18

# リンゴ 1,2,3,4,5の「味」は、それぞれ 2,3,4,5,6 です。リンゴ 1 を食べるのが最適で、答えは 3+4+5+6=18となります。

# 入力例 2
# 3 -1

# 出力例 2
# 0

# リンゴ 1,2,3の「味」は、それぞれ −1,0,1 です。リンゴ 2 を食べるのが最適で、答えは (−1)+1=0となります。

# 入力例 3
# 30 -50

# 出力例 3
# -1044


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    # N = int(lines[0])
    N, L = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(6):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    mi = None
    su = 0

    for i in range(N):
        value = i + L
        if mi is None:
            mi = value
        if abs(mi) > abs(value):
            mi = value
        su += value

    return [su-mi]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['5 2']
        lines_export = [18]
    if pattern == 2:
        lines_input = ['3 -1']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['30 -50']
        lines_export = [-1044]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
p = []
q = []
for i in range(n):
  p.append(abs(l + i))
  q.append(l + i)
a = 0
for i in range(n):
  if i != p.index(min(p)):
    a += q[i]
print(a)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
b=0
ans=0
for x in range(1,N+1):
  if b==0 and abs(L+x-1)<abs(L+x):
    b=1
  else:
    ans+=L+x-1
if b==0:
  ans -= L+N-1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if L >= 1:
  eat = L
elif L+N-1 <= -1:
  eat = L+N-1
else:
  eat = 0

taste = eat*(-1)
for i in range(N):
  taste += L+i

print(taste)

Submission status: Accepted

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

Submission status: Accepted

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

MIN=10**9
argmin=-1
for i in range(N):
  res = abs(SUM - (SUM-score[i]))
  if res < MIN:
    MIN = res
    argmin=i

print(SUM-score[argmin])

Submission status: Accepted

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

if L>0:
    for i in range(N-1):
        ans += L+i+1
    print(ans)
    exit()

if L<=0 and N+L-1 <= 0:
    for i in range(N-1):
        ans += L+i
    print(ans)
    exit()

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

Submission status: Accepted

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

lst = []
for i in range(n):
    lst.append(l+i)
taste_total = sum(lst)
taste_pie = taste_total - min(lst, key = abs)

print(taste_pie)

Submission status: Accepted

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

ans = 0
if 0 in A:
    ans = sum(A)
else:
    if L < 0:
        ans = sum(A) - A[-1]
    else:
        ans = sum(A) - A[0]

print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
RES = 0
res = 100
mid = 0
List = []
for i in range(N):
  mid = L+i
  List.append(mid)
  if abs(mid)<abs(res):
    res = mid
for i in range(N):
  if res == List[i]:
    pass
  else:
    RES += List[i]
print(RES)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def pop_min_abs(l):
    abs_l = list(map(abs, l))
    l.pop(abs_l.index(min(abs_l)))
    return l



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

apples = [l+i-1 for i in range(1,n+1)]
print(sum(pop_min_abs(apples)))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
count = 0
lists = [l+i-1 for i in range(1,n+1)]
x = 2000
for i in range(n):
  if abs(x)>abs(lists[i]):
    x = lists[i]
lists.remove(x)
print(sum(lists))

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    tastes = []
    num = []
    perfectPie = 0
    for i in range(N):
        perfectPie += i + L
        tastes.append(i + L)
        num.append(abs(i + L))
    num.sort()
    if num[0] in tastes:
        print(perfectPie - num[0])
    else:
        print(perfectPie + num[0])
main()

Submission status: Accepted

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

ans = 0
flag = False
for i in range(N):
    if L + i == 0:
        flag = True
    ans += (L + i)
if not flag:
    if ans < 0:
        ans -= (L+N-1)
    else:
        ans -= L
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
l = range(L, N + L)
a = [sum(l[1:]), sum(l[:-1]), sum(l), sum(l)]
print(a[((0 in l) << 1) + (L < 0)])

Submission status: Accepted

Solution code:
import sys
N,L = map(int,input().split())
apple = []
diff =1000000
num = 0
for i in range(N):
  value = i + L
  apple.append(value)
  if diff > abs(value):
    diff = abs(value)
    num = i
del apple[num]
print(sum(apple))

Submission status: Accepted

Solution code:
import numpy as np

n,l = map(int,input().split())
taste = []
taste_diff = []

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

#print(taste)
s = sum(taste)

for i in range(len(taste)):
    taste_diff.append(s-taste[i])

#print(taste_diff)

def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

print(getNearestValue(taste_diff, s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
m = 0
k = float("inf")
for i in range(n):
    m += l + i
    if k > abs(l + i):
        p = l + i
        k = abs(l + i)
print(m-p)

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))
x = b.index(min(b))
print(sum(a)-a[x])

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = [L+i for i in range(N)]
total = 0
min_abs = 301

for i in range(N):
    total += A[i]
    if min_abs > abs(A[i]):
        min_abs = abs(A[i])
        idx = i

print(total - A[idx])

Submission status: Accepted

Solution code:
n, L = map(int, input().split())
l = [0] * n
for i in range(n):
  l[i] = L + i
mins = 10 ** 10
for i in l:
  if abs(mins) > abs(i):
    mins = i
print(sum(l) - mins)

Submission status: Accepted

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

Submission status: Accepted

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

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

min_diff = 10**4
min_total = -1
for i in range(N):
    diff = abs(L+i)
    if diff < min_diff:
        min_diff = diff
        min_total = total - (L+i)
print(min_total)

Submission status: Accepted

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

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())
a = []
b = []
for i in range(n):
    a.append(l+i)
    b.append(abs(l+i))
x = b.index(min(b))
print(sum(a)-a[x])

Submission status: Accepted

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

Submission status: Accepted

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

if not ( 2 <= N <= 200 and -100 <= L <= 100 ): sys.exit()

array = [ L+x for x in range(N)]
before = 100
for I in array:
    if abs(I) <= before: before = abs(I);position = array.index(I)
print(sum(array) - array[position])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int, input().split())
L = []

for i in range(1,a+1):
    L.append(b+i-1)

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

Submission status: Accepted

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

l = [i+L for i in range(N)]
_l= [abs(x) for x in l]
l_min_id = _l.index(min(_l))
print(sum(l)-l[l_min_id])

Submission status: Accepted

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

T = [l+i for i in range(n)]
if T[-1] >= 0:
  m = min(i for i in T if i >= 0)
else:
  m = T[-1]
print(sum(T) - m)

Submission status: Accepted

Solution code:
#ABC131
N,L = map(int,input().split())
f = 0
k = 0
j = []
for i in range(1,N+1):
    f += L+i-1
for i in range(1,N+1):
    k = L+i-1
    n = f-k
    p = abs(f-n)
    j.append(p)
if f >0:
    print(int(f-min(j)))
else:
    print(int(f+min(j)))

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N, L = rl()

aji = [0]*N

minaji = float('inf')
for i in range(N):
	aji[i] = L+i
	if abs(minaji) > abs(aji[i]):
		minaji = aji[i]
print(sum(aji)-minaji)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
taste = [0]*n
for i in range(n):
    taste[i] = l+i
api = sum(taste)
eat = 0
sa = 10000
for i in range(n):
    if abs(taste[i]) < abs(sa):
        sa = taste[i]
print(api-sa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=list(range(l,n+l))
m=list(map(abs,a))
print(sum(a)-a[m.index(min(m))])

Submission status: Accepted

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

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

tast = sum(apples)
for i in range(500):
    if i in apples:
        tast -= i
        break
    elif -i in apples:
        tast += i
        break
print(tast)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
a = [0]*N
for i in range(N):
  a[i] = L+i
all_apple_pie = sum(a)
apple_pie = [0]*N
def_apple_pie = [0]*N
for i in range(N):
  t = a[i]
  a[i] = 0
  apple_pie[i] = sum(a)
  def_apple_pie[i] = abs(all_apple_pie-apple_pie[i])
  a[i] = t
index = def_apple_pie.index(min(def_apple_pie))
print(apple_pie[index])

Submission status: Accepted

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

taste = [l + i - 1 for i in range(1, n + 1)]
taste_all = sum(taste)
if taste[n - 1] < 0:
    taste_min = taste[n - 1]
elif taste[0] > 0:
    taste_min = taste[0]
else:
    taste_min = 0
print(taste_all - taste_min)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, L = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    tot=0
    ma=100000
    for i in range(N):
        tot+=L+i
        if abs(L+i)<abs(ma):
            ma=L+i
    print(tot-ma)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

taste = [0]*N
for i in range(N):
  taste[i] = L + i

min_val = 10**3
min_idx = 0
for i in range(N):
  if min_val > abs(taste[i]):
    min_val = abs(taste[i])
    min_idx = i

ans = sum(taste)-taste[min_idx]
print(ans)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
apple=list(range(1,n+1))
aji=[l+i-1 for i in apple]
sum_num=sum(aji)
sa=10000
for i in range(len(aji)):
    if abs(aji[i])<sa:
        sa=abs(aji[i])
        ans=aji[i]
print(sum_num-ans)

Submission status: Accepted

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

Submission status: Accepted

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

if T[0] <= 0 and T[-1] >= 0:
    A = sum(T)

elif T[-1] < 0:
    A = sum(T[:-1])

else:
    A = sum(T[1:])

print(A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, l = rm()
li = np.arange(n) + l
if l > 0:
  print(sum(li[1:]))
elif l <= -n:
  print(sum(li[:-1]))
else:
  print(sum(li))

Submission status: Accepted

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

diffabs = 99999
taste = 0

for i in range(N):
    taste += L+i
    if abs(L+i)<diffabs:
        diffabs = abs(L+i)
        diff = L+i
print(taste-diff)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
 
min_abs=99999999999
min_abs_i=-1
n_aji=0
for i in range(1,n+1):
  aji=l+i-1
  aji_abs=abs(aji)
  if aji_abs < min_abs:
    min_abs = aji_abs
    aji_abs_i = i
  n_aji+=aji
 
print(n_aji-(l+aji_abs_i-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, l = map(int, input().split())
    apple = [l+i-1 for i in range(1, n+1)]
    if apple[-1] < 0:
        print(sum(apple[:-1]))
    elif apple[0] > 0:
        print(sum(apple[1:]))
    else:
        print(sum(apple[:]))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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


a = []
res = 300
for i in range(n):
  a.append(l+i)
  res = min(res, abs(l+i))
s = sum(a)
if res in a:
  print(s-res)
else:
  print(s+res)

Submission status: Accepted

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

m = 10 ** 9
pre = 0
for i in range(N):
  t = L + i
  pre += t
  
  if abs(t) < abs(m):
    m = t

print(pre - m)

Submission status: Accepted

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

all=0
now=0
for i in range(N):
    all =all +L+(i+1)-1
 
dif=all
for i in range(N):
    if abs(dif) >= abs(L+i):
        dif =L+i
 
print(all-dif)

Submission status: Accepted

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

if (l >= 0):
    ans.pop(0)
    print(sum(ans))
elif(n > abs(l)):
    ans.pop(ans.index(0))
    print(sum(ans))
else:
    ans.pop(ans.index(max(ans)))
    print(sum(ans))

Submission status: Accepted

Solution code:
import numpy as np
n,l = list(map(int, input().split())) 
t_list = np.array([l+(x+1)-1 for x in range(n)])
flags = [True]*n
idx = np.argmin(np.abs(t_list))
flags[idx] = False
print(np.sum(t_list[flags]))

Submission status: Accepted

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

if 0 in a_l:
    print(sum(a_l))
elif a_l[0] < 0 :
    print(sum(sorted(a_l, reverse=True)[1:]))
else:
    print(sum(sorted(a_l)[1:]))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=list(range(l,l+n,1))
x=sum(a)
if(0 in a):
  a.remove(0)
  print(sum(a))
elif(x<0):
  a.remove(max(a))
  print(sum(a))
elif(x>0):
  a.remove(min(a))
  print(sum(a))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
a=[]
cnt=101
index=-1
for i in range(n):
  a.append(l+i)
for i in range(n):
  if cnt>=abs(0-a[i]):
    cnt=abs(0-a[i])
    index+=1
print(sum(a)-a[index])

Submission status: Accepted

Solution code:
import math
n, l = map(int, input().split())
a_l = [l + i for i in range(n)]
 
min1 = 100
min2 = 10000
 
for j in a_l:
    if j ** 2 <= min2:
        min2 = j **2
        min1 = j
print(sum(a_l) - min1)

Submission status: Accepted

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

print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
aji = [l+i for i in range(n)]
mn= 100
for i in range(n):
    mn= min(mn,abs(aji[i]))
if mn in aji:del aji[aji.index(mn)]
else:del aji[aji.index(-mn)]
print(sum(aji))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste = [0]*N
taste_minus = [0]*N
for i in range(N):
    taste[i]=L+i
for j in range(N):
    taste_minus[j]=abs(taste[j])
    minus = min(taste_minus)
    if taste[j]<0:
        minus = -1*minus
    

print(sum(taste)-minus)

Submission status: Accepted

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

apple = [L+i for i in range(N)]
min = 500
for k in range(len(apple)):
    if abs(apple[k])<abs(min):
        min = apple[k]

apple.remove(min)
print(sum(apple))

Submission status: Accepted

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

Submission status: Accepted

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

if l > 0:
    print((n-1)*(2*l+n)//2)
elif l+n-1 < 0:
    print((n-1)*(2*l+n-2)//2)
else:
    print(n*(2*l+n-1)//2)

Submission status: Accepted

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

Submission status: Accepted

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

s1 = 0
m1 = 10**8

for i in range(n):
    if abs(m1) > abs(l):
        m1 = l
    s1 += l
    l += 1

print(s1 - m1)

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
total = 0
for i in range(1, n+1):
    total += l+i-1

m = 1000000000
ans = 0
for i in range(1, n+1):
    a = total-(l+i-1)
    # print(a)
    if abs(total-a) < m:
        m = abs(total-a)
        ans = a

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    P = 0
    for i in range(1, N+1):
        P += L + i - 1
    ans = float("inf")
    for i in range(1, N+1):
        tmp = L + i - 1
        x = P - tmp
        if abs(P - x) < abs(P - ans):
            ans = x
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A = list()
for i in range(N):
  A.append(L+i)
A.sort()
S = sum(A)
if min(A)*max(A)<=0:
  print(S)
else:
  if L>=0:
    print(S-min(A))
  else:
    print(S-max(A))

Submission status: Accepted

Solution code:
N,L = (int(x) for x in input().split())
Apple = list(L-1+x for x in range(1,N+1))
Abs = list(abs(x) for x in Apple)
Remove = Abs.index(min(Abs))
del Apple[Remove]
print(sum(Apple))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple = []
for i in range(1, n + 1):
    apple.append(i+l-1)
for i in range(400):
    if i in apple:
        apple.remove(i)
        print(sum(apple))
        break
    elif -i in apple:
        apple.remove(-i)
        print(sum(apple))
        break
    else:
        pass

Submission status: Accepted

Solution code:
def main():
    N,L = map(int, input().split())
    eat = 10**6
    apples = 0
    for i in range(N):
        apples += i+L
        eat = min(eat,abs(i+L))
    if apples < 0:
        eat *= -1

    print(apples-eat)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
if k > 0:
    print(k*(n-1)+n*(n-1)//2)
elif k > -n:
    print(k*n+n*(n-1)//2)
else:
    print(k*(n-1)+(n-1)*(n-2)//2)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
l = [x+L-1 for x in range(1, N+1)]
l_2 = list(map(abs, l))
min_index = l_2.index(min(l_2))

l[min_index] = 0
print(sum(l))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
t=[]
tmp=0
for i in range(n):
    k=i+l
    t.append(k)
    tmp+=k
if min(t)>0:
    tmp-=min(t)
if max(t)<0:
    tmp-=max(t)
print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

if L-1 >= 0:
  i = 1
elif L-1 >= -N:
  i = -(L-1)
else:
  i = N

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
li = [l+i for i in range(n)]
INF = 1001001001
mn = INF
sum = 0
for i in li:
    sum += i
    if abs(mn) > abs(i):
        mn = i
print(sum - mn)

Submission status: Accepted

Solution code:
import sys

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

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

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

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

Submission status: Accepted

Solution code:
import numpy as np
N,L  = map(int,input().split())
L_list=np.array(range(1,N+1))+L-1
if (0 in L_list):
    print(sum(L_list))
    exit()
if(N<=abs(L) and L<0):
    print(sum(L_list)-L_list[N-1])
    
    exit()
else:
    print(sum(L_list)-L_list[0])
    exit()

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
li=[]
for i in range(N):
    li.append(L+i+1-1)
A=True
li.sort()
S=sum(li)
for j in range(N-1):
    if abs(li[j])<=abs(li[j+1]):
        S-=li[j]
        A=False
        break

if A==True:
    S-=li[N-1]

print(S)

Submission status: Accepted

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

tot=N*L+(N-1)*N/2
ans=[]


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

a=ans.index(min(ans))

print(int(tot-(a+L)))