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:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, l = wi()
a = []
for i in range(n):
    a.append(l + i)
sumn = sum(a)
b = []
for i in range(n):
    b.append([abs(sumn - (sumn - (l + i))), sumn - (l + i)])
b.sort()
print(b[0][1])

Submission status: Accepted

Solution code:
n,l=input().split()
n=int(n)
l=int(l)
taste=[]
abs_list=[]
for i in range(n):
  taste.append(l+i)
for j in range(len(taste)):
  abs_list.append(abs(taste[j]))
taste.pop(abs_list.index(min(abs_list)))
print(sum(taste))

Submission status: Accepted

Solution code:
def main08():
    data = input().split()
    nl = []
    for i in range(2):
        nl.append(int(data[i]))
    hantei = nl[0] + nl[1]
    result = 0
    if hantei <= nl[0] and 1 <= hantei:
        for i in range(nl[0]):
            result = result + nl[1] + i
    elif nl[1] > 0:
        for i in range(nl[0]-1):
            result = result + nl[1] + i + 1
    else:
        for i in range(nl[0]-1):
            result = result + nl[1] + i
    print(result)

if __name__ == "__main__":
    main08()

Submission status: Accepted

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

taste = [(L + i) for i in range(N)]
# print(taste)
minnum = 10000
sumtaste = sum(taste)
# print(sumtaste)
for i in range(N):
    if abs(minnum) > abs(taste[i]):
        minnum = taste[i]
# print("minnum")
# print(minnum)
print(sumtaste-minnum)

Submission status: Accepted

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

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

if l > 0:
    ans = sum(apple) - apple[0]
elif (l + n - 1) >= 0:
    ans = sum(apple)
elif (l + n - 1) < 0:
    ans = sum(apple) - apple[-1]

print(ans)

Submission status: Accepted

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

if all(map(lambda x: x < 0, a)):
    ans = sum(a[:-1])
elif all(map(lambda x: x > 0, a)):
    ans = sum(a[1:])
else:
    ans = sum(a)

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N,L=map(int,input().split())
Taste=list(int(i) for i in range(L+1-1,L+N-1+1) )
MaxTaste=[sum(Taste)]*N
print(sum(Taste)-Taste[np.argmin(np.abs(np.array(Taste)))])

Submission status: Accepted

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

sum = int(N * (L + L + N - 1) / 2)

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

Submission status: Accepted

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

def main():
    N, L = (int(x) for x in input().split())

    logging.info("Hello!")

    apples = [L - 1 + i for i in range(1, N + 1)]
    apples_abs = [abs(x) for x in apples]
    
    apple_pie_answer = sum(apples) - apples[apples_abs.index(min(apples_abs))]
    
    print(apple_pie_answer)
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mina = 300
s = 0
plus = True
for  i in range(1,n+1):
    if mina > abs(i+l-1):
        mina = abs(i+l-1)
        if i+l-1 > 0:
            plus = True
        else:
            plus = False
    s += i+l-1
if plus:
    print(s-mina)
else:
    print(s+mina)

Submission status: Accepted

Solution code:
#ABC131b

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

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

if applelist[n-1]>=0:
	print(sum(applelist)-max(0,min(applelist)))
else:
	print(sum(applelist)-applelist[n-1])

Submission status: Accepted

Solution code:
N,L=list(map(int,input().split()))
taste=[]
taste1=[]
memo=[]
sum=0
for i in range(N):
    tasty=abs(L+i)
    if L+i<=0:
        memo.append(L+i)
    taste.append(tasty)
    taste1.append(L+i)
    sum+=taste1[i]
tasteab=sorted(taste)
memo=sorted(memo)
if memo!=[]:
    pie=(sum-memo[-1])
else:
    pie=(sum-tasteab[0])
print(pie)

Submission status: Accepted

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

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

else:
  print(int((2*L+N-1)*N/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
lis = []
for i in range(1,n+1):
    lis.append(l + i - 1)
m = 100
for i in lis:
    m = min(m,abs(i))
if not m in lis:
    lis.remove(m * (-1))
else:
    lis.remove(m)
print(sum(lis))

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
nums = list(range(l,n+l))

mi = l
ma = n+l-1

if ma < 0:
    print(sum(nums)-ma)
elif mi > 0:
    print(sum(nums)-mi)
else:
    print(sum(nums))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
aji=0
Nlist=[x for x in range(L,L+N,1)]
Nabslist=[abs(Nlist[x]) for x in range(len(Nlist))]
Nmindex=Nabslist.index(min(Nabslist))
for i in range(len(Nlist)):
    if i==Nmindex:
        continue
    aji=aji+Nlist[i]
print(aji)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
taste = [L + i - 1 for i in range(1, N+1)]
s = sum(taste)
ans = s - min(taste) if all(t >= 0 for t in taste) else s - max(taste) if all(t < 0 for t in taste) else s
print(ans)

Submission status: Accepted

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

taste = int((L+(L+N-1))*N/2)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#131　

#入力（1次元）
N, L = list(map(int, input().split()))

min = 2000000

#出力
ans = 0

#最適に食べる林檎No.を算出
for i in range(1,N+1):
    if (min > abs(L + i - 1)) :
        min = abs(L + i - 1)
        N_min = i

for j in range(1,N+1 ):
    if(j != N_min):  
        ans += L + j - 1

print(ans)

Submission status: Accepted

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

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

ab = []
for k in range(1, N+1):
    ab.append(abs(L + k - 1))

print(apple_pie - (L + ab.index(min(ab))  ))

Submission status: Accepted

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

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

origin = sum(taste)
choice = float('inf')

for t in taste:
    if abs(t) < abs(choice):
        choice = t

ans = origin - choice
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if L >= 0:
    remove = 0
elif abs(L) < N:
    remove = abs(L)
else:
    remove = N-1

print((N-1)*L+sum(range(N))-remove)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
L = a[1]
  

 
def if_test(N,L):
  taste = 0
  if L > 0:
     for i in range(N):
      taste += (L + i)
#      print("L>0"+str(taste))
       
     taste = taste - L
     print(taste)
      
  elif (L+N-1) < 0:
     for i in range(N):
      taste = taste + L + i 
#      print("<0"+str(taste))
          
     taste = taste - (L + N - 1)   
     print(taste)
        
  else:
     for i in range(N):
      taste = taste + L + i
#      print(taste)
     print(taste)
    
if_test(N,L)

Submission status: Accepted

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

abs_l = {}
taste = []
for i in range(n):
    taste.append(l+i)
taste_s = sum(taste)
for i in range(n):
    abs_l[i] = abs(taste[i])

abs_min = min(abs_l, key=abs_l.get)
print(sum(taste)-taste[abs_min])

Submission status: Accepted

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

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

abs_list = [abs(l+i) for i in range(n)]
abs_min_taste_index = abs_list.index(min(abs_list))

ans = sum - list[abs_min_taste_index]
print(ans)

Submission status: Accepted

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

list1 = []
for i in range(1, n+1):
    list1.append(l + i - 1)
if min(list1) > 0:
    print(sum(list1) - list1[0]) 
elif max(list1) < 0:
    print(sum(list1) - list1[n-1])
else:
    print(sum(list1) - list1[list1.index(0)])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import math
x =  [int(s) for s in input().split()]
aji = [x[1]+i-1 for i in range(1,x[0]+1)]

sum = 0
for i in range(0,len(aji)):
        sum += aji[i]

sum2 = 0
if(0 in aji):
    for i in range(0,len(aji)):
        sum2 += aji[i]
else:
    if(sum < 0):
        for i in range(0,len(aji)-1):
            sum2 += aji[i]
    else:
        for i in range(1,len(aji)):
            sum2 += aji[i]
print(sum2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
data = input().split()
N = int(data[0])
L = int(data[1])
taste = []
for i in range(N):
    taste.append(L + (i+1) - 1)
absTaste = []
for i in range(N):
    absTaste.append(abs(taste[i]))
index = 0
minimum = 0
for i in range(1,N):
    if absTaste[i-1] > absTaste[i]:
        index = i
        minimum = taste[i]
ans = sum(taste) - taste[index]#sumはリスト内の数値の合計を計算する関数
print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
l1 = [L+i for i in range(N)]
allsum = sum(l1)
l2 = list(map(abs,l1))
minimum = l2.index(min(l2))
print(allsum-l1[minimum])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
taste = [l + i for i in range(n)]
min_abs = None
for i in taste:
    
    if min_abs == None or abs(min_abs) > abs(i):
        min_abs = i

print(sum(taste)-min_abs)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = list(map(int, input().split()))
taste = []
a = 10000
for i in range(1, n+1):
    if(abs(l + i - 1) < abs(a)):
        a = l + i - 1
    taste.append(l + i - 1)
print(sum(taste) - a)

Submission status: Accepted

Solution code:
import numpy as np

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

N, L = list(map(int, input().split()))
apple = []

for i in range(1,N+1):
    apple.append(L + i - 1)
del apple[getNearestValue(apple, 0)]
print(sum(apple))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
eat = N - 1
for m in range(N):
    if abs(L + m) < abs(L + eat):
        eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
if L >=0:
    eat = 0
else:
    eat = N - 1
    for m in range(N):
        if abs(L + m) < abs(L + eat):
            eat = m
aj = N*(N-1)//2
pie = (N-1)*L + aj - eat
print(pie)

Submission status: Accepted

Solution code:
import numpy as np

N, L = map(int, input().split())
Nstr = []
Lstr = []
ans = 0

for i in range(N):
  Nstr.append(i)

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

Lstr.remove(Lstr[np.abs(np.asarray(Lstr) - 0).argmin()])

for i in range(len(Lstr)):
  ans += Lstr[i]

print(ans)

Submission status: Accepted

Solution code:
def main():
    n,l = map(int,input().split())
    tot = int(l*n + (n+1)*n/2 - n)
    res = tot - l
    for i in range(2,n+1):
        if abs(l+i-1) < abs(tot - res):
            res = tot - (l+i-1)
    print(res)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

a=[l+i for i in range(n)]
if a[0]>0:
    eat=a[0]
elif a[n-1]<0:
    eat=a[n-1]
else:
    eat=0
print(sum(a)-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = list(map(int,input().split()))
b = [L -1 + i for i in range(1, N+1)]
s = sum(b)

if 0 in b:
    print(s)
elif s > 0:
    print(s - min(b))
else:
    print(s - max(b))

Submission status: Accepted

Solution code:
N, L = list(map(int,input().split()))
a = L - 1
b = [a + i for i in range(1, N+1)]
s = sum(b)

if 0 in b:
    print(s)
elif s > 0:
    print(s - min(b))
else:
    print(s - max(b))

Submission status: Accepted

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

print(sum((x + L for x in range(N))) - min((x + L for x in range(N)), key = abs))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N,L = input().split()
    tastesum = 0
    tastemin = 1000000000
    N = int(N)
    L = int(L)
    for i in range(N):
        tmptaste = i + L
        if abs(tastemin) > abs(tmptaste):
            tastemin = tmptaste
        tastesum = tastesum + tmptaste
    tastesum = tastesum - tastemin
    print(tastesum)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(a):
    c.append([b + i, abs(b + i)])
c = sorted(c, key=lambda x: x[1])
d = 0
for i in range(1, a):
    d += c[i][0]
print(d)

Submission status: Accepted

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

array = []

for i in range(1, N+1):
    azi = L+i-1
    array.append(azi)

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

Submission status: Accepted

Solution code:
#!/bin/env python
#｜sum(L)-sum(L-L[i])｜ が最少となるiの時のsum(L-L[i])を求める
def main():
  n,l = map(int,input().split())
  ans = (2*l+n-1)*n//2
  if l > 0:
    ans -= l
  elif l+n-1 <0:
    ans -= (l+n-1)
  print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

total = 0
min_a = 200
min_v = 0
for i in range(N):
    a = L+i
    total += a
    if abs(a) <= min_a:
        min_a = abs(a)
        min_v = a
print(total-min_v)

Submission status: Accepted

Solution code:
import numpy as np

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

RINGO = list(np.array(list(range(1, n+1))) + l - 1)
AJI = list(map(abs, RINGO))

RINGO.pop(AJI.index(min(AJI)))
print(sum(RINGO))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min = 1000
min_ans = 1000
abs_a = 0
answer = 0
for i in range(1,N+1):
    a = i + L - 1
    answer += a
    abs_a = abs(a)
    if(min > abs_a):
        min = abs_a
        min_ans = a
print(answer - min_ans)

Submission status: Accepted

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

Submission status: Accepted

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

mi=l
ma=l+n-1

if mi <= 0 and 0 <= ma:
    print(int((mi+ma)*n/2))
elif abs(mi) < abs(ma):
    print(int((mi+ma)*n/2-mi))
else:
    print(int((mi+ma)*n/2-ma))

Submission status: Accepted

Solution code:
n, L = map(int, input().split())
N = 0
G = 999
for i in range(1, n+1):
    N += (i + L - 1)
NN = N
for i in range(1, n+1):
    DD = NN - (L + i - 1)
    if abs(NN-DD)< G :
        G = abs(NN-DD)
        ZZ = DD
print(ZZ)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

diff = 0
if l+1-1 < 0 and l+n-1 > 0:
    diff = 0
elif l+1-1 < 0:
    diff = l+n-1
else:
    diff = l+1-1

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

print(ans-diff)

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
if L < 0:
    if L+N-1 < 0:
        ans -= L+N-1

print(ans)

Submission status: Accepted

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

eat_apple = 0

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

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

print(total - (L + eat_apple - 1))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, L] = string_to_int(inputs[0])
    apples = [x + L for x in range(0, N)]
    min_i = 0
    for i in range(1, len(apples)):
        if abs(apples[min_i]) > abs(apples[i]):
            min_i = i
    apples.pop(min_i)

    return sum(apples)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

# which apple to eat
if 0 <= L:
    eat = 0
elif -(N-1) <= L:
     eat = -L
else:
    eat = N-1

# sum
print(L*(N-1) + int((N-1)*N/2) - eat)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, L = list(map(int, input().split()))
D = 99999999
I = 0
for i in range(1, N + 1):
    d = abs(L - 1 + i)
    if d < D:
        D = d
        I = i
print((N - 1) * L + (1 + N) * N // 2 - I - (N - 1))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

n, l = map(int, input().split())
apples = np.array([l + i for i in range(n)])
m = np.argmin(np.abs(apples))
print(np.sum(apples) - apples[m])

Submission status: Accepted

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

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
elif N + L > 0:
    for i in range(N):
        ans += L + i
else:
    for i in range(N-1):
        ans += L + i
print(ans)

Submission status: Accepted

Solution code:
import sys


if __name__ == '__main__':
    N, L = map(int, input().split())

    eat_apple = 0
    min_abs_apple_taste = sys.maxsize
    apples = []
    for i in range(N):
        taste = L+(i+1)-1
        apples.append(taste)
        if min_abs_apple_taste > abs(taste):
            min_abs_apple_taste = abs(taste)
            eat_apple = taste

    answer = 0
    for apple in apples:
        if apple != eat_apple:
            answer += apple
    print(answer)

Submission status: Accepted

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

apples = [L + i for i in range(N)]
if min(apples) > 0:
    diff = min(apples)
elif max(apples) < 0:
    diff = max(apples)
else:
    diff = 0
print(sum(apples) - diff)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,L = map(int,input().split())
lst = [L]
for i in range(N-1):
  lst.append(lst[-1]+1)
arr = [abs(i) for i in lst]
del lst[arr.index(min(arr))]
print(sum(lst))

Submission status: Accepted

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

# N 個のりんごがあって、それ一つ一つの味はL + i - 1 で表される（i = 1,2,...,n）
# 等差数列の和の公式を利用
total = n * (l + l + n - 1) // 2

# ひとつめのりんごの味はL, N個目のりんごの味はL+N-1
first, last = l, l + n - 1
# 1. 美味しいりんごだけで作る場合、もっともおいしくないりんごなら食べてもいい
if first >= 0:
  taste = total - first
# 2. まずいりんごが混ざっている時、美味しくないしまずくない中間のりんごを食べるべき
elif first < 0 and last >= 0: 
  taste = total - 0
# 3. まずいりんごだけで作る場合、もっともまずくないりんごを食べたほうがいい
else:
  taste = total - last  

print(taste)
# print('taste is ' + str(taste))
# print('total is ' + str(total))
# print('apple is ' + str(total - taste))

Submission status: Accepted

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

# N 個のりんごがあって、それ一つ一つの味はL + i - 1 で表される（i = 1,2,...,n）
total = n * (l + l + n - 1) // 2

# ひとつめのりんごの味はL, N個目のりんごの味はL+N-1
first, last = l, l + n - 1
# 1. 美味しいりんごだけで作る場合、もっともおいしくないりんごなら食べてもいい
if first >= 0:
  taste = total - first
# 2. まずいりんごが混ざっている時、全体が美味しければまずいものを、全体がまずければ美味しいものを食べるべき
elif first < 0 and last >= 0: 
  taste = total - 0
#  if total == 0:
#    taste = total - 0
#  elif total < 0:
#    taste = total - last
#  else:
#    taste = total - first
# 3. まずいりんごだけで作る場合、もっともまずくないりんごを食べたほうがいい
else:
  taste = total - last  

print(taste)
#print('taste is ' + str(taste))
#print('total is ' + str(total))
#print('apple is ' + str(total - taste))

Submission status: Accepted

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

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

if min(aji_abs) == 0:
    print(sum(aji))
elif max(aji) < 0:
    print(sum(aji) - max(aji))
else:
    print(sum(aji) - min(aji))

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
ringo = []
for i in range(1,N+1):
    ringo.append(L+i-1)
p = 200
p1 = 200
for i in ringo:
    p = abs(i)
    if p1 > p:
        p1 = p 
        ans = i
ringo.remove(ans)
print(sum(ringo))

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
su,mi=0,9999
for i in range(1,n+1):
    su+=(l+i-1)
    if abs(l+i-1)<abs(mi):mi=l+i-1
print(su-mi)

Submission status: Accepted

Solution code:
import math
n,l=map(int,input().split())
list0=[]
su,mi=0,9999
for i in range(1,n+1):
    list0=list0+[l+i-1]
    su+=(l+i-1)
    if abs(l+i-1)<abs(mi):mi=l+i-1
print(su-mi)

Submission status: Accepted

Solution code:
import numpy as np
x = input().split()
n = int(x[0])
l = int(x[1])

ap = np.array(range(1,n+1))
ap = ap + (l-1)
ap = np.delete(ap,abs(ap).argmin())
print(ap.sum())

Submission status: Accepted

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

work = 1e9
ans = -1
for i in range(1,N+1):
  al = N*L + N * (N-1) // 2 
  a = L + i - 1
  b = al - a
  #print(i,a,b,al)
  if abs(al - b) < work:
    work = abs(al - b)
    ans = b
    
print(ans)

Submission status: Accepted

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

list =[]
abs_list = []

for i in range(n):
  list.append(l+i)
  abs_list.append(abs(l+i))

x = min(abs_list)

for i in range(len(abs_list)):
  if abs_list[i] == x:
    x = i
    break

list.pop(x)

print(sum(list))

Submission status: Accepted

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

for i in range(N-1):
    if T[i] < T[i+1]:
        del S[i]
        break
    elif i == N-2:
        del S[N-1]

for i in range(0,N-1):
    s+=S[i]
print(s)

Submission status: Accepted

Solution code:
import numpy as np

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

t = np.zeros(2)
t[0] = L
t[1] = L+N-1
sum_all = (2*L+N-1)*N/2


if t[0]*t[1] <= 0:
	print(int(sum_all))
else:
	print(int(sum_all-t[np.argmin(np.abs(t))]))

Submission status: Accepted

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

tastes = [l+x for x in range(n)]

taste_abs_min = 300

for i in range(n):
    if abs(tastes[i]) < abs(taste_abs_min):
        taste_abs_min = tastes[i]

print(sum(tastes) - taste_abs_min)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

aji = list(map(lambda x: L + x - 1, range(1, N + 1)))

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

Submission status: Accepted

Solution code:
N,L =map(int,input().split())
inoazi=0
azi=0
min=100000
bag=[]
for i in range(1,N+1):
    azi+=L+i-1

for j in range(1,N+1):
    tab=azi-(L+j-1)
    if (min>abs(azi-tab)):
        min=abs(azi-tab)
        bag.append(j)
        
m=max(bag)
kotae=azi-(L+m-1)
print(kotae)

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
#ls = list(map(int,input().split()))
#r = int(input())
#s = input()

ans = 0
ls = []
for i in range(1,n+1):
  ls.append(l + i - 1)
ls.sort()
if ls.count(0) == 1:
  print(sum(ls))
else:
  try:
    ls.remove(min(map(abs,ls)))
  except:
  	ls.remove(-min(map(abs,ls)))
  print(sum(ls))

Submission status: Accepted

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


lis = []
for n in range(1, N+1):
    azi = L + n - 1
    lis.append(azi)

lis2 = [abs(l) for l in lis]

min = lis2.index(min(lis2))
del lis[min]

print(sum(lis))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
min_n = 300
sum_n = 0
for i in range(1, N + 1):
  sum_n += (L + i - 1)
  if min_n > abs(L + i - 1):
    min_n = abs(L + i - 1)
    eat_apple_taste = L + i - 1
print(sum_n - eat_apple_taste)

Submission status: Accepted

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

total = sum([L+i for i in range(N)])
diff = float('inf')
for i in range(N):
    a = total - (L+i)
    diff = min(abs(total - a), diff)
if total > 0:
    print(total-diff)
else:
    print(diff+total)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
list_=list(range(L,L+N))
a = 1 if max(list_) > 0 else -1
ans = min(map(abs,list_))*a
print(sum(list_)-ans)

Submission status: Accepted

Solution code:
import math

n, l = map(int, input().split())
sum = 0
small_sum = 0
small_sums = []
diffs = []

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


for i in range(1, n+1):
    small_sum = 0
    for j in range(1,n+1):
        if j==i:
            continue
        else:
            small_sum += (l+j-1)
    diffs.append(math.fabs(sum-small_sum))
    small_sums.append(small_sum)

print(small_sums[diffs.index(min(diffs))])