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())
l = [L+i-1 for i in range(1,N+1)]
min = l[0]
for i in range(N):
    if abs(min) > abs(l[i]):
        min = l[i]
print(sum(l)-min)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [0] * N

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

tmp = taste[:]
for i in range(N):
    tmp[i] = abs(tmp[i])

ind = tmp.index(min(tmp))
print(sum(taste)-taste[ind])

Submission status: Accepted

Solution code:
def binary_search(x,li):
    low = 0
    high = len(li)-1
    mid = (low + high)//2
    while low <= high:
        if li[mid] == x:
            return True
        elif x < li[mid]:
            low = mid + 1
        else:
            high = mid - 1
        mid = (low + high)//2
    return False

n,l = map(int,input().split())
taste = [0 for i in range(n)]
check = len(taste)
for i in range(n):
    taste[i] = l + i
taste = sorted(taste)
state = 0
for i in range(n):
    if taste[i] == 0:
        state = 1
        break
    else:
        state = 0
if state == 1:
    ans = 0
    for i in range(n):
        ans+=taste[i]
    print(ans)
else:
    if taste[0]>0:
        ans = 0
        for i in range(1,len(taste)):
            ans+=taste[i]
        print(ans)
    elif taste[0]<0:
        ans = 0
        for i in range(n):
            if taste[i] > 0:
                check = i
                break
        for i in range(n):
            if i != check-1:
                ans+=taste[i]
        print(ans)

Submission status: Accepted

Solution code:
import sys
import math
import numpy as np
import bisect
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

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

Submission status: Accepted

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

apple = min(range(l,l+n),key=abs)
print(sum(range(l,l+n))-apple)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sum = 0
ans = float("inf")

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

for i in range(n):
    temp = sum
    temp -= l + (i + 1) - 1

    if abs(sum - temp) < abs(sum - ans):
        ans = temp

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left


def main():
    N, L = map(int, input().split(" "))
    taste = []
    for i in range(N):
        taste.append(L + i)
    taste.sort()
    zero = bisect_left(taste, 0)
    if zero == 0:
        eat = taste[0]
    elif zero == N:
        eat = taste[-1]
    elif abs(taste[zero]) >= abs(taste[zero - 1]):
        eat = taste[zero - 1]
    else:
        eat = taste[zero]
    print(sum(taste) - eat)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if l>=0:
    aji -= l
else:
    if abs(l)<n:
        pass
    else:
        aji-= l-1+n

print(int(aji))

Submission status: Accepted

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

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

s=sum(l)

p=10**10

ans=0
for x in l:
  if p>abs(s-(s-x)):
    p=abs(s-(s-x))
    ans=s-x

print(ans)

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
ans = (N*(N+2*L-1))//2
flag = 0
for i in range(N):
    if L+i==0:
        flag = 1
if flag == 1:
    print(ans)
elif L<0:
    print(ans-(L+N-1))
else:
    print(ans-L)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
s=[]
a=0
for i in range(n):
    a=i+l
    s.append(a)
if sum(s)<0:
    s.remove(max(s))
elif 0 in s:
    s.remove(0)
else:
    s.remove(min(s))
print(sum(s))

Submission status: Accepted

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

tastes = [L + i - 1 for i in range(1, N+1)]
# ダサい解法...
# sum_taste = sum(tastes)
#
# prev_taste_diff = 10 ** 10
#
# ans = 0
# for i in range(N):
#     s = sum(tastes[:i] + tastes[i+1:])
#     curr_taste_diff = abs(s - sum_taste)
#     if curr_taste_diff < prev_taste_diff:
#         ans = s
#     prev_taste_diff = curr_taste_diff

# エレガント?
hoge = sorted([abs(t) for t in tastes])[0]
if hoge in tastes:
    tastes.remove(hoge)
else:
    tastes.remove(-hoge)
print(sum(tastes))

Submission status: Accepted

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

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

Submission status: Accepted

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

tastes = [L + i - 1 for i in range(1, N+1)]
sum_taste = sum(tastes)

prev_taste_diff = 10 ** 10

ans = 0
for i in range(N):
    s = sum(tastes[:i] + tastes[i+1:])
    curr_taste_diff = abs(s - sum_taste)
    if curr_taste_diff < prev_taste_diff:
        ans = s
    prev_taste_diff = curr_taste_diff
print(ans)

Submission status: Accepted

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

apple = [i + l for i in range(n)]
aji = sum(apple)

if 0 in apple:
    print(aji)
elif apple[0] > 0:
    print(aji - min(apple))
else:
    print(aji - max(apple))

Submission status: Accepted

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

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

    ls = [i + l for i in range(n)]
    if l >= 0:
        ls = ls[1:]
    elif n + l - 1 < 0:
        ls = ls[:-1]

    print(sum(ls))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

if l < 0:
    if l + n <= 0:
        # 絶対値最小が0以下の場合は最右を削る
        taste = sum(range(l, l+n-1))
    else:
        # 0を挟む場合はそのまま全部足す
        taste = sum(range(l, l+n))
else:
        # 絶対値最小が0以上の場合は最左を削る
        taste = sum(range(l+1, l+n))

print(taste)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min_s = 100000000000
s = 0
for i in range(1,N+1):
    t = L+i-1
    s += t

    if abs(t) <= abs(min_s):
        min_s = t

print(s-min_s)

Submission status: Accepted

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

taste = [l+i for i in range(n)]
taste_abs = [abs(i) for i in taste]
print(sum(taste) - taste[taste_abs.index(min(taste_abs))])

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
list_taste = [l + i - 1 for i in range(1,n+1)]
list_abs = [abs(j) for j in list_taste]
list_index = list_abs.index(min(list_abs))
list_taste.pop(list_index)
print(sum(list_taste))

Submission status: Accepted

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

Submission status: Accepted

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

aji = [L+i for i in range(N)]
s = sum(aji)
m = aji[0]
for i in range(N):
    if abs(m) > abs(aji[i]):
        m = aji[i]
print(s-m)

Submission status: Accepted

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

apple = []
for i in range(n):
    apple.append(l+i)

p = []
for j in range(len(apple)):
    p.append(abs(apple[j]))

m = p.index(min(p))
apple.pop(m)
print(sum(apple))

Submission status: Accepted

Solution code:
N, D = map(int, open(0).read().split())
L = D
R = D + N - 1
S = (L+R)*(R-L+1)//2

if L >= 0:
    E = L
elif R <= 0:
    E = R
else:
    E = 0

print(S - E)

Submission status: Accepted

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

ind=aji_abs.index(min(aji_abs))

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

Submission status: Accepted

Solution code:
# Bite Eating
import numpy as np

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

def taste(i, L=L):
    return L + i -1

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

# solve
diff_value = np.inf
diff_total = np.inf

for i in range(N):
    if diff_value > abs(T[i]) and diff_total > abs(sum(T) - (sum(T) - T[i])):
        diff_value = abs(T[i])
        diff_total = abs(sum(T) - (sum(T) - T[i]))
        res = sum(T) - T[i]

# output
print(res)

Submission status: Accepted

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

r = l+n-1
eat = 0
if l >= 0:
    eat = l
elif r <= 0:
    eat = r

ans = int((r + l) * n / 2 - eat)
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
num = [i for i in range(L,N+L)]
min = 10000
index = 0
for i in range(N):
    if min > abs(num[i]):
        min = abs(num[i])
        index = i

print(sum(num)-num[index])

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    apples = [i+L-1 for i in range(1, N+1)]
    app_abs = list(map(abs, apples))
    ix_min = app_abs.index(min(app_abs))

    apples.pop(ix_min)
    return sum(apples)
    
if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

if L > 0:
  j = 1
else:
  if L >= 1 - N:
    j = 1 - L
  else:
    j = N

ans = N*L + N*(N-1)//2 - (L+j-1)
print(ans)

Submission status: Accepted

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

F = [i + l for i in range(n)]
if 0 in F:
    print(sum(F))
elif min(F) > 0:
    F.pop(0)
    print(sum(F))
else:
    F.pop(-1)
    print(sum(F))

Submission status: Accepted

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

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

Submission status: Accepted

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

lst = []
tmp=1000000

for i in range(n):
	lst.append(i+l)
	
for i in lst:
	if abs(i) < abs(tmp):
		tmp = i
		
print(sum(lst)-tmp)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
x = []          
lst1 = []
lst2 = []                

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

for i in range(n-1):
    lst1.append(sum(x[:i])+sum(x[i+1:]))

lst1.append(sum(x[:n-1]))

for i in range(n):
    lst2.append(abs(sum(x)-lst1[i]))

for i in range(n):
    if lst2[i] == min(lst2):
        print(lst1[i])

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
B = []
A = []
for i in range(1, a+1):
    B.append(b+i-1)
    A.append(abs(b+i-1))

if min(A) in B:
    print(sum(B) - min(A))
else:
    print(sum(B) + min(A))

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
def umasa(i):
    return L+i
box = []
for i in range(N):
    box.append(umasa(i))
new = sorted(box,key=abs)
print(sum(box)-new[0])

Submission status: Accepted

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

tastes = [L + i for i in range(N)]
tastes.sort(key=abs)
ans = sum(tastes[1:])
print(ans)

Submission status: Accepted

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

all = 0
tmp = 0
for x in range(N):
	all += (x+L)
#print(all)
for i in range (1,N+1):
	tmp = all-(i+L-1)
	tmp_2 = tmp*tmp
	if i == 1:
		ans = tmp
	elif tmp == all:
		ans = tmp
		break
	else:
		if ans*ans < tmp_2:
			ans = tmp
print(ans)

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
#味はl ~ l+n-1
#全部で作った味は n*(l + (n-1)/2) 
res=n*l + n*(n-1)//2
if 0 < l:
    res-=l
elif l+n-1<0:
    res-=(l+n-1)
print(res)

Submission status: Accepted

Solution code:
(A, B), = [list(map(int, s.split())) for s in open(0)]
apples = [B + i for i in range(A)]
apples_abs = [abs(a) for a in apples]
apple_idx = apples_abs.index(min(apples_abs))
apples.pop(apple_idx)
print(sum(apples))

Submission status: Accepted

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

Submission status: Accepted

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

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

abs_taste = list(map(abs, tastes))

del tastes[abs_taste.index(min(abs_taste))]

print(sum(tastes))

Submission status: Accepted

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

ans = 0
jogai = 500
fugo = 0
for i in range(1, N+1):
    aji = L+i-1
    ans += aji
    if aji < 0:
        if -aji < jogai:
            jogai = -aji
            fugo = -1
    else:
        if aji < jogai:
            jogai = aji
            fugo = 1

print(ans-fugo*jogai)

Submission status: Accepted

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

Submission status: Accepted

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

sum=0
a=[]
for i in range(N):
     a.append(L+i)
if L<=0 and L+N-1>=0:
    for j in range(N):
        sum+=a[j]
    print(sum)
elif L>0:
    for j in range(N-1):
        sum+=a[j+1]
    print(sum)
else:
    for j in range(N-1):
        sum+=a[j]
    print(sum)

Submission status: Accepted

Solution code:
import numpy as np

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

apple = np.array([L + i - 1 for i in range(1, N + 1)])
abs_apple = np.abs(apple)
idx = abs_apple.argmin()
print(apple.sum() - apple[idx])

Submission status: Accepted

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

taste = [L+i-1 for i in range(1, N+1)]
taste_abs = [abs(L+i-1) for i in range(1, N+1)]
i = taste_abs.index(min(taste_abs))

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
sum1=0
min1=1000

for i in range(a):
    if abs(min1)>abs(b):
        min1=b
    sum1+=b
    b+=1

print(sum1-min1)

Submission status: Accepted

Solution code:
a,b =map(int, input().split())
apple=[i for i in range(b,a+b)]

if a+b-1<0:
  print(sum(apple)-a-b+1)
  
elif b>0:
  print(sum(apple)-b)
else:
  print(sum(apple))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sum = 0
for i in range(l, l + n):
    sum += i
mnabs = 10000000
mn = 10000000
for i in range(l, l + n):
    if mnabs > abs(i):
        mnabs = abs(i)
        mn = i
print(sum - mn)

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
lst=[l+i for i in range(n)]
lst2=[abs(l+i) for i in range(n)]
m=min(lst2)
ans=0
for i in lst:
    if i!=m and i!=m*-1:
        ans+=i
print(ans)

Submission status: Accepted

Solution code:
A,B = list(map(int,input().split()))
L = []
ans=0
for i in range(A):
  L.append(i+B)
L1 = sorted(L, key=lambda x: abs(x))
for i in L1[1::]:
  ans += i
print(ans)

Submission status: Accepted

Solution code:
def examA():
    S = SI()
    ans = "Good"
    for i in range(len(S)-1):
        if S[i+1]==S[i]:
            ans = "Bad"
    print(ans)
    return

def examB():
    N, L = LI()
    ans = 0
    if L>=0:
        for i in range(N - 1):
            ans += (L + i + 1)
    else:
        for i in range(N):
            ans += (L+i)
        if L+N-1<0:
            ans -=(L+N-1)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Accepted

Solution code:
a = []
b = []
A,B = map(int,input().split())
for i in range(B,A+B):
  p =abs(i)
  a.append(p)
  b.append(i)
a = sorted(a)
if a[0] in b:
  b.remove(a[0])
else:
  b.remove(-a[0])
print(sum(b))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
eat = []
ans = 0
for i in range(n):
  eat.append(l + i)
good = []
for i in eat:
  good.append(abs(i))
if n + l > 0:
  print(sum(eat)-min(good))
else:
  print(sum(eat)+min(good))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
d = list(range(l, n+l))
d_eaten = min(d, key=lambda x:abs(x))
print(sum(d)-d_eaten)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ans = []
min_l = 99999
des = 9999999
for i in range(n):
    ans.append(l + i)
    if min_l > abs(l + i):
        min_l = abs(l + i)
        des = l + i
print(sum(ans) - des)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, L = map(int,input().split())

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

SUM = sum(taste)

DIF = abs(SUM - (SUM - taste[0]))
ans = SUM - taste[0]
for i in range(1,N):
    x = SUM - taste[i]
    if abs(SUM - x) < DIF:
        DIF = abs(SUM - x)
        ans = x
print(ans)

Submission status: Accepted

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


i = 1
taste = []

while i <= N:
        taste.append(L + i - 1)
        i += 1


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

Submission status: Accepted

Solution code:
(n, l) = map(int, input().split())
d = [l + i for i in range(n)]
c = [abs(i) for i in d.copy()]
nearest0 = c.index(min(c))
d.remove(d[nearest0])
ans = sum(d)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
	n,l = map(int,input().split())
	apple = list(range(1,n+1))
	taste = []
	for i in range(1,n+1):
		taste.append(l+i-1)
	# print(taste)
	taste_abs = []
	for i in range(len(taste)):
		taste_abs.append(abs(taste[i]))
	# print(taste_abs)
	if min(taste_abs) == 0:
		print(sum(taste))
	else:
		taste.remove(taste[taste_abs.index(min(taste_abs))])
		print(sum(taste))

if __name__ == '__main__':
	main()

Submission status: Accepted

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


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

min = 10000
ans = 0
for i in range(n):
    msum = 0
    for j in range(n):
        if (i != j):
            msum += j + l
    if (abs(sum - msum) < min):
        min = abs(sum-msum)
        ans = msum

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N,L=map(int,input().split())

ans=0
eat=10**18
for i in range(N):
    ans+=(i+L)
    if abs(i+L)<=abs(eat):
        eat=i+L
print(ans-eat)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = [L + i for i in range(N)]
abs_sort = [(abs(x), i) for i, x in enumerate(apples)]
abs_sort.sort()
eat = apples[abs_sort[0][1]]
print(sum(apples) - eat)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
A=list()
sa1=1000
ans=1000
for i in range(N):
    A.append(L+i)
for i in range(N):
    azi=sum(A)-A[i]
    sa2=sum(A)-azi
    if sa1>sa2:
        if sa2<0:
            sa2*=-1
        sa1=sa2
        ans=azi
print(ans)

Submission status: Accepted

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

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

temp = 500
ans = 0

for i in range(N):
    if temp >= abs(app[i]):
        temp = abs(app[i])
        ans = app[i]
print(sum(app) - ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,c=map(int,input().split())
d=0
m=5000
for i in range(1,a+1):
    d=d+c+i-1
    if abs(m)>abs(c+i-1):
        m=c+i-1
print(d-m)

Submission status: Accepted

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

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

Min = 100000000
for j in apple:
    a = abs(j)
    if Min >= a:
        Min = a
        eat = j

print(sum(apple)-eat)

Submission status: Accepted

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

Min = l + 1 - 1
Max = l + n - 1

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

if (Max < 0) :
    ans -= Max

if (Min > 0):
    ans -= Min

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ringo=[0]*n
ringoz=[0]*n
min=1000000000000000
mini=0
for i in range(n):
    ringo[i]+=i+l
    if ringo[i]<0:
        ringoz[i]=-ringo[i]
    else:
        ringoz[i]=ringo[i]
    if ringoz[i]<min:
        min=ringoz[i]
        mini=i
ringo.pop(mini)

print(sum(ringo))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC-131-B
N, L = map(int, input().split())
full_apple = 0
for i in range(N):
    full_apple += (L + i)
notfull_apple = 10 ** 9

for i in range(N):
    test_apple = full_apple - (L + i)
    if abs(full_apple - notfull_apple) > abs(full_apple - test_apple):
        notfull_apple = test_apple

print(notfull_apple)

Submission status: Accepted

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

if l*(l+n-1) <0:
    print(ans)

elif l >=0:
    print(ans-l)

else:
    print(ans-(l+n-1))

Submission status: Accepted

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

Submission status: Accepted

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

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

apple = [L + i - 1 for i in range(1, N + 1)]
diff = abs(apple[0])
for i in range(1, N):
    diff = min(diff, abs(apple[i]))

print(sum(apple) - diff if sum(apple) > 0 else sum(apple) + diff)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
a = 0
for i in range(n):
    a += l + i
t = 0
u = 0
z = 999
ans = 0
for i in range(n):
    t = a - (l+i)
    u = abs(a - t)
    if z > u:
        z = u
        ans = t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

X = [L + i - 1 for i in range(1, N+1)]
if 0 in X:
    s = 0
elif abs(X[0]) < abs(X[-1]):
    s = X[0]
else:
    s = X[-1]

print(sum(X) - s)

Submission status: Accepted

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

stack=65535
sum=0

for x in range(1, N+1):
    sum+=x+L-1
    if(abs(stack)>abs(x+L-1)>=0):
        stack=x+L-1

print(sum-stack)

Submission status: Accepted

Solution code:
import bisect

n, l = map(int, input().split())
Ts = [l+i for i in range(n)]
Ts.sort()

zero = bisect.bisect_left(Ts, 0)

if n-1 >= zero:
    if abs(Ts[zero-1]) > abs(Ts[zero]):
        ans = sum(Ts) - Ts[zero]
else:
    ans = sum(Ts) - Ts[zero-1]
print(ans)

Submission status: Accepted

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

a = [0]*n

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

min = 10000
check = 0

for i in range(n):
	#3print(i)
	if min > abs(a[i]):
		#print(i)
		min = abs(a[i])
		check = a[i]

print( sum(a)-check )

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N, L = list(map(int, input().split()))
taste = np.array([L + i for i in range(N)])
total = sum(taste)
abs_ta = abs(taste)
smallest = abs_ta[0]
smallest_i = 0
for i in range(1, N):
    if abs_ta[i] < smallest:
        smallest = abs_ta[i]
        smallest_i = i
print(total - taste[smallest_i])

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
sum1 = 0
num = 1000
for i in range(n):
  a = l+(i+1)-1
  sum1 += a
  if abs(a) < num:
    num1 = a
    num = abs(a)
if num1 == num:
  print(sum1-num)
else:
  print(sum1+num)

Submission status: Accepted

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

Submission status: Accepted

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

[N, L] = [int(i) for i in input().split()]

tastes = []
for n in range(N):
    tastes.append(L + n)

minimum = tastes[0]
for t in tastes:
    if abs(t) < abs(minimum):
        minimum = t

tastes.remove(minimum)
pie_taste = sum(tastes)

print(pie_taste)

Submission status: Accepted

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

t = [L+i-1 for i in range(1, N+1)]
idx = np.abs(np.asarray(t)).argmin()

print(sum(t)-t[idx])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple = list()
for i in range(n):
    apple.append(l+i)
if l < 0:
    if l+n-1 > 0:
        apple.remove(0)
    else:
        apple.pop(-1)
elif l > 0:
    if l+n+1<0:
        apple.remove(0)
    else:
        apple.pop(0)
else:
    apple.remove(0)
print(sum(apple))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nums=list(map(int,input().split()))
N=nums[0]
L=nums[1]
taste=[L+i for i in range(N)]
abs_taste=[abs(x) for x in taste]
tabel=min(abs_taste)
if(tabel in taste):
  taste.remove(tabel)
  print(sum(taste))
else:
  taste.remove(-tabel)
  print(sum(taste))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
li=[]
absli=[]
for i in range(1,N+1):
  li.append(L+i-1)
total=sum(li)
if max(li)<0:
  print(total-max(li))
else:
  li=map(abs,li)
  print(total-min(li))

Submission status: Accepted

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

if min(abs_out) == 0:
    out = out
elif min(all_out) > 0:
    out = out - min(all_out)
elif max(all_out) < 0:
    out = out - max(all_out)

print(out)

Submission status: Accepted

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

print(ret-A[0][1])

Submission status: Accepted

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

if L >= 0:
  result = t - L
elif -N < L < 0:
  result = t
else:
  result = t - (L + N - 1)
  
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(sum(apple_taste) - apple_taste[apple_taste_abs.index(min(apple_taste_abs))])