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: Wrong Answer

Solution code:
N, L = (int(x) for x in input().split())
def func(i):
    return (N-1)*L + N*(N-1)//2 - (i-1)

if -L+1 <= 1:
    print(func(1))
elif 1 <= -L+1 and -L+1 <= N:
    print(0)
else:
    print(func(N))

Submission status: Wrong Answer

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

s=2*l+n-1

if l>0:
    s-=l
elif l==0:
    pass
elif l+n<=0:
    s-=l+n-1

print(s)

Submission status: Wrong Answer

Solution code:
a,b=map(int,input().split())
list=[]
List=[]
for i in range(a):
  list.append(b+i)
for j in range(a):
  List.append(abs(b+j))
LIST=sum(list)
List=min(List)
print(int(LIST)-int(List))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Submission status: Wrong Answer

Solution code:
n,l=input().split()
n=int(n)
s=f=0
l=int(l)
for i in range(n):
    a=l+i
    if(a==0):
        f=1
    else:
        s+=a
if(f==0):
    s-=(l)
print(s)

Submission status: Wrong Answer

Solution code:
a = list(map(int, input().split()))
aji=[]
kari =[]
for i in range(a[0]):
    aji.append(a[1]+i)
    kari.append(abs(a[1]+i))
m = min(kari)
sum1 = sum(aji)
print(sum1-m)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N,L = map(int,input().split())
P = [L+i-1 for i in range(1,N+1)]
if 0 in P:
    print(0)
else:
    p = list(map(abs,P))
    print(sum(P)-min(p) if min(P) == min(p) else sum(P)+min(p))

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
l = input().split()
N = int(l[0])
L = int(l[1])

T = [L + x for x in range(N)]
# print(N, L, T)
candidate = sum(T)
# print(candidate)
if L <= 0 and L + N >= 0:
    print(candidate)
elif L + N < 0:
    print(candidate - (L + N - 1))
else:
    print(candidate - (L))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if L < 0 and N + L -1 > 0:
  print(int(N * L - N + 1 / 2 * N * (N + 1)))
elif L < 0 and N + L - 1 < 0:
  print(int(N * L - N + 1 / 2 * N * (N + 1) - N - L + 1))
else:
  print(int(N * L - N + 1 / 2 * N * (N + 1) - 2))

Submission status: Wrong Answer

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

f = [(L + i) for i in range(N)]
print(sum(f) - min([abs(i) for i in f]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

ans = 9999999999

for a in A:
  if abs(a) < abs(ans):
    ans = a
    
print(sum(A) - a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,l=[int(i) for i in input().split()]
app=[0]*(n)
for i in range(n):
    app[i]=l+i
m=1000000000000000000
num=0
for i,j in enumerate(app):
    if m>j and j>=0:
        m=i
        num=i
if m==1000000000000000000:
    m,num=max(app),app.index(max(app))
print(sum(app[0:num]+app[num+1:]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))

n, l = getList()

if l >= 0:
    ans = sum([l + i for i in range(1,n)])

elif l >= -(n+1):
    ans = sum([l+i for i in range(n)])

else:
    ans = sum([l+i for i in range(n-1)])

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, L = i2nn()
    a = L
    b = L + N - 1
    if a <= 0 and b >= 0:
        print(0)
    else:
        c = abs(a)
        d = abs(b)
        n = 0
        if c < d:
            for i in range(a+1, b+1):
                n += i
        else:
            for i in range(a, b):
                n += i
        print(n)

main()

Submission status: Wrong Answer

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

ans = 9999999999

for a in A:
  if abs(a) < ans:
    ans = a
    
print(sum(A) - a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, l = map(int, input().split())
aji = []
for i in range(1, n+1):
    aji.append(l + i - 1)
aji.sort(reverse = True)
aji.pop()
print(sum(aji))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

S = []
for i in range(1, N):
    S.append(L+i)
print(sum(S))

Submission status: Wrong Answer

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

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

s = sum(aji)
ans = 1000000000
for i in range(n):
    sd = s - aji[i]
    b = abs(s-sd)
    ans = min(ans, b)

print(ans)

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

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

alist = []
i = 1

while i < n+1:
  x = l + i - 1
  alist.append(x)
  i =+ 1
  
  

k = 0
m = 0
while k < n-1:
  if abs(alist[k]) >= abs(alist[k+1]):
    m = k+1
  
  k =+ 1
  
  
print(sum(alist) - alist[m])

Submission status: Time Limit Exceeded

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

alist = []
i = 1

while i <= n:
  x = l + i - 1
  alist.append(x)
  i =+ 1
  
  
j = 0
abslist = []
while j < n:
  abslist[j] = abs(alist[j])
  j =+ 1

  

k = 0
m = 0
while k < n-1:
  if abslist[k] >= abslist[k+1]:
    m = k+1
  
  k =+ 1
  
  
print(sum(alist) - alist[m])

Submission status: Accepted

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

mi = abs(li[0])
for i in li:
    if abs(i) < mi:
        mi = abs(i)
        ind = li.index(i)

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

Submission status: Accepted

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

ringo = []
for i in range(l,l+n):
    ringo.append(i)
ringo.sort(key=int)
if 0 in ringo:
    print(sum(ringo))
else:
    if ringo[0] > 0:
        ringo.pop(0)
    else:
        ringo.pop(-1)
    print(sum(ringo))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
t = []
t2 = []
for i in range(n):
    taste = l+(i+1)-1
    t.append(taste)
    t2.append(taste**2)
oa = t[t2.index(min(t2))]
ans = sum(t) - oa
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N, L = MI()
    tot = 0
    for i in range(1, N+1):
        tot = tot + L + i - 1
    diff = INF
    ans = 0
    for i in range(1, N+1):
        tmp = tot - L - i + 1
        if abs(tot - tmp) < diff:
            diff = abs(tot - tmp)
            ans = tmp
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
list_x=[l+x-1 for x in range(1,n+1)]
applepai=sum(list_x)
list_dif=[]
list_sum=[]
for i in range(len(list_x)):
    tmp=list_x.pop(i)
    list_dif.append(abs(applepai-sum(list_x)))
    list_sum.append(sum(list_x))
    list_x.insert(i,tmp)
indx=list_dif.index(min(list_dif))
ans=list_sum[indx]
print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
all = sum([L+i-1 for i in range(1, N+1)])
anss = []
for j in range(1, N+1):
    tmp = sum([L+i-1 for i in range(1, N+1) if i != j])
    anss.append((abs(all-tmp), tmp))
anss.sort()
print(anss[0][1])

Submission status: Accepted

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

Submission status: Accepted

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

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

abs_apple = list(map(abs, apple))

minimum_idx = abs_apple.index(min(abs_apple))

print(sum(apple) - apple[minimum_idx])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
chosen = 1000
for i in range(1, N+1):
  taste_eaten = L + i - 1
  if abs(taste_eaten) < abs(chosen):
    chosen = taste_eaten
print(int(N*L + N*(N+1)/2 - N - chosen))

Submission status: Accepted

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

print(ans - q[p.index(min(p))])

Submission status: Accepted

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

Submission status: Accepted

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

m=10**9
idx=1
for i in range(1,n+1):
  if abs(l+i-1)<m:
    m=abs(l+i-1)
    idx=i
        
print(a-(l+idx-1))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
isMina = False
isPlu = False
ans = []
for i in range(1,n+1):
  ans.append(l+i-1)
  if l+i-1 < 0:
    isMina = True
  elif i+i-1 > 0:
    isPlu = True
print(sum(ans)-min(ans) if not isMina else sum(ans)-max(ans) if not isPlu else sum(ans))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
ans = l 
k = 0
sum = 0
for i in range(1,n):
    if abs(ans) > abs(l + i):
        ans = l + i
        k = i
for i in range(n):
    if i != k:
        sum += l + i
print(sum)

Submission status: Accepted

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

for i in range(n):
    L = l + i
    L_abs = abs(L)
    List1.append(L)
    List2.append(L_abs)

if min(List2) in List1:
    List1.remove(min(List2))
elif -min(List2) in List1:
    List1.remove(-min(List2))

print(sum(List1))

Submission status: Accepted

Solution code:
#ABC131 B

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

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:
n, l = map(int, input().split())
if l >= 0:
    print((n - 1) * l + (n * (n + 1)) // 2 - (n - 1) - 1)
else:
    if n >= -l + 1:
        print(n * l + (n * (n + 1)) // 2 - n)
    else:
        print((n - 1) * l + (n * (n + 1)) // 2 - (n - 1) - n)

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

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

eat = sorted(apple, key=lambda x: abs(x))
print(sum(apple)-eat[0])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
azi = [l+i-1 for i in range(1, n+1)]
diff = [0]*n
for i in range(n):
    diff[i] = abs(azi[i])

if sum(azi) < 0:
    print(sum(azi) + abs(min(diff)))
else:  
    print(sum(azi) - min(diff))

Submission status: Accepted

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

apple = []
diff = 1001001001
minus = False
for i in range(1, n+1):
    apple.append(l+i-1)
    if abs(l+i-1) < diff:
        diff = abs(l+i-1)
        if l+i-1 < 0:
            minus = True
        else:
            minus = False

if minus:
    print(sum(apple) + diff)
else:
    print(sum(apple) - diff)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, L = mapint()
apples = [L+i for i in range(N)]
pos_apples = [abs(a) for a in apples]
apples.pop(pos_apples.index(min(pos_apples)))
print(sum(apples))

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
a = N*L+(N*(N-1))//2
d = 1000
ans = -1000
for i in range(L,L+N):
    b = a-i
    if abs(a-b)<d:
        d = abs(a-b)
        ans = b
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
S = n*l + (n * (n + 1)) // 2 - n
pd = S + 1
for x in range(1, n + 1):
    d = - l - x + 1
    if pd > abs(d):
        ans = S + d
    pd = d

print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1, N+1):
    ans += L+i-1
    

if L+N-1 < 0:
    ans -= (L+N-1)
elif L <= 0 <= L+N-1:
    ans = ans
else:
    ans -= L
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
# 味：L + i - 1
aji_list = [L+i-1 for i in range(1, N+1)]

basic = abs(sum(aji_list))
min_diff = 9999999 
for i in aji_list:
    diff = abs(basic - abs(basic - abs(i)))
    min_diff = min(min_diff, diff)

for i in aji_list:
    if abs(basic - abs(basic - abs(i))) == min_diff:
        if basic == sum(aji_list):
            print(basic - abs(i))
        else:
            print(-1*(basic - abs(i)))
        break

Submission status: Accepted

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

for i in flavor:
    S += i

for i in range(N):
    flavorabs.append(abs(flavor[i]))

a = min(flavorabs)
print(S - flavor[flavorabs.index(a)])

Submission status: Accepted

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

aji = [l+i for i in range(n)]
ans = None
sa=10**10
for i in range(n):
    sa_tmp=abs(aji[i])
    if sa>sa_tmp:
        sa=sa_tmp
        ans=sum(aji)-aji[i]
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
if M >= 0:
    a_list = [i for i in range(M+1,M+N)]
elif N + M > 0:
    a_list = [i for i in range(M,M+N)]
else:
    a_list = [i for i in range(M,M+N-1)]
print(sum(a_list))

Submission status: Accepted

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

apples = []
ans = 300
for i in range(1, n + 1):
    taste = i + l - 1
    apples.append(taste)
    if abs(taste) < abs(ans):
        ans = taste

apples.remove(ans)
print(sum(apples))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
A = []
for i in range(N):
  A.append(L+i)
i = 0
ans = False
while ans == False:
    x, y = abs(i), -abs(i)
    for k in A:
      if k == x or k == y:
        ans = True
        A.remove(k)
    i += 1
print(sum(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, L = LI()

    ans = (2 * L + N - 1) * N // 2
    if 0 <= L:
        ans -= L
    elif L + N <= 0:
        ans -= L + N - 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

if A[0] < 0:
    if A[-1] < 0:
        print(sum(A) - max(A))
    else:
        print(sum(A))
else:
    print(sum(A) - min(A))

Submission status: Accepted

Solution code:
# import math
# import statistics
# import itertools
# a=int(input())
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(int(i))
N,L= map(int,input().split())
# f = list(map(int,input().split()))
# g = [input().split for _ in range(a)]
# h = []
# for i in range(a):
#     h.append(list(map(int,input().split())))
# a = [[0] for _ in range(H)]#nizigen

azi2=[]
azi=[L+i for i in range(N)]
for i in azi:
    azi2.append(abs(i))
if 0 in azi:
    print(sum(azi))
else:
    mi=azi2.index(min(azi2))
    del azi[mi]
    print(sum(azi))

Submission status: Accepted

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

total = N * (L - 1) + N * (N + 1) / 2
lowest = 10 ** 10
for i in range(1, N + 1):
    y = L + i - 1
    lowest = min(lowest, abs(y))
print(int(total) - lowest) if total >= 0 else print(int(total) + lowest)

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

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
def f(i):
	return L+i-1
def eat(bad):
	return sum([f(i) for i in range(1,N+1) if i!=bad])
best = 10**18
best_val = -1
for i in range(1,N+1):
	x = abs(eat(i)-eat(-1))
	if x < best:
		best = x
		best_val = eat(i)
print(best_val)

Submission status: Accepted

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

taste=[l+i-1 for i in range(1,n+1)]
dif=10**10
for i in taste:
    if dif>abs(i):
        ans=sum(taste)-i
        dif=abs(i)
print(ans)

Submission status: Accepted

Solution code:
#nはりんごの数　りんごiの味はl＋i-1

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

each_taste = []
for x in range(1,n+1):
  each_taste.append(l+x-1)
  
if min(each_taste) >= 0:
  print(sum(each_taste[1:]))
  
elif max(each_taste) >= 0:
  print(sum(each_taste))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
 
# 元々の味（等差数列の和の公式より）
s = N*(2*L+N-1) // 2
# 味の絶対値が最小になるリンゴの味を求める
if L+N-1 < 0: eat = L+N-1
elif L > 0: eat = L
else: eat = 0

# 食べる（最適なリンゴ）以外の味の和
print(s - eat)

Submission status: Accepted

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

# 元々の味（等差数列の和の公式より）
s = N*(2*L+N-1) // 2
# 味の差の絶対値=リンゴiの味の絶対値
l = [abs(L+i) for i in range(N)]
 
# 味の絶対値が最小になるリンゴのindexを求め、sからその味を引けばよい
print(s - (L+l.index(min(l))))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
 
s = N*(2*L+N-1) // 2
l = [abs(L+i) for i in range(N)]

print(s - (L+l.index(min(l))))

Submission status: Accepted

Solution code:
apple_num, taste = map(int, input().split())
total = 0
table = []
total_ans = 0
manual = 100000000
ans = 0
for i in range(apple_num):
    table.append(i+1)

for j in range(apple_num):
    table[j] = taste + j
    total += taste + j

for k in range(apple_num):
    if manual > abs(table[k]):
        manual = abs(table[k])
        ans = k
for l in range(apple_num):
    if l == ans:
        continue
    else:
        total_ans += table[l]
print(total_ans)

Submission status: Accepted

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

y = sum(A)
B = sorted(A)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = n*(l-1) + n*(n+1)/2
c = abs(s)
j = 1
for i in range(n):
  t = s - (l+i)
  T = abs(s-t)
  if T < c:
    c = T
    j = i
ans = s -(l+j)
print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

elif l < 0 and -l < n:
    a = (l+n + l -1)*n/2
    print(int(a))
elif l < 0 and -l >=n:
    a = (l+ n + l -2)*(n-1)/2
    print(int(a))

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 131
# B - Bite Eating

N,L=map(int,input().split())
minabs=10**9
apples=[]
for i in range (N):
    t=L+i
    apples.append(t)
    if abs(t)<abs(minabs):
        minabs=t

full=sum(apples)

print(full-minabs)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
l = []
idx = (10**6, -1)

for i in range(1, N + 1):
    l.append(L + i - 1)
    if abs(L + i - 1) < idx[0]:
        idx = (abs(L + i - 1), i)
ans = 0
for i in range(1, N + 1):
    if i != idx[1]:
        ans += l[i - 1]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
A = []
for i in range(1,n+1):
    A.append((abs(l+i-1),l+i-1))
A.sort()
# print(A)
ans = 0
for i in range(1,len(A)):
    ans += A[i][1]
print(ans)

Submission status: Accepted

Solution code:
import sys
N, L = map(int, input().split())
tastes = [ L+x for x in range(N) ] 

if 0 in tastes:
    print(sum(tastes))
    sys.exit(0)
    

if L<0:
    absmin = max(tastes)
    print(sum(tastes)-absmin)
elif L>0:
    absmin = min(tastes)
    print(sum(tastes)-absmin)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
c = 0
if L >= 0:
    skip = 0
else:
    if N - (-L) > 0:
        skip = L*-1
    else:
        skip = N-1
for i in range(N):
    if i == skip:
        continue
    c += L+i
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
l1=list(int(l)+i-1 for i in range(1,n+1))
n1=sum(l1)
ans=min(l1,key=abs)

print(n1-(ans))