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 = list(map(int,input().split()))
app_taste = list(range(L,L+N))
bite_apple=L
for i in app_taste:
    if abs(bite_apple) > abs(i):
        bite_apple = i
print(sum(app_taste) - bite_apple)

Submission status: Accepted

Solution code:
def main():
    import numpy as np
    n, l = map(int,input().split())
    inlis = []
    taishou = 10 *10000
    flag = 0

    for i in range(l, l+n):
        if taishou > np.abs(i):
            taishou = np.abs(i)
            if i < 0:
                flag = 1
        inlis.append(i)
    if flag == 0:
        print(sum(inlis) - taishou)
    else:
        print(sum(inlis) + taishou)

    
        

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
A = [L+i for i in range(N)]
#print(A)
expect = sum(A)
minimum = float('inf')
for a in A:
    tmp = expect
    minimum = min(minimum,abs(sum(A)-(tmp-a)))
    if minimum == abs(sum(A)-(tmp-a)):
        ans = tmp-a
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n, l = map(int, input().split())
a = np.arange(1, n+1) + l - 1
print(np.sum(a) - a[np.argmin(np.abs(a))])

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
taste = [l+i for i in range(n)]
taste.sort(key=lambda x: abs(x))

print(sum(taste[1:]))

Submission status: Accepted

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

del taste[ans.index(min(ans))]
print(sum(taste))

Submission status: Accepted

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

tmp = float('inf')
sum = sum(taste)
for i in range(n):
    if abs(taste[i]) < tmp:
        tmp = abs(taste[i])
        ans = sum - taste[i]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N+1):
    a = L+i-1
    ans += a
    if abs(a) < abs(min):
        min = a

ans -= min
print(ans)

Submission status: Accepted

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

ans = 0
min_abs = max(b)
min_i = 0

for i in range(N):
    ans += a[i]
    if min_abs > b[i]:
        min_abs = b[i]
        min_i = i

ans -= a[min_i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
v=[L+i for i in range(N)]
s=sum(v)
ans=10**9
for i in range(N):
    if abs(s-(s-v[i]))<abs(s-ans):
        ans=s-v[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 131 B

n, l = map(int, input().split())
cmin = float('inf')
sum = 0

for i in range(1, n+1):
    f = l + i - 1
    sum += f
    if cmin >= 0:
        cmin = min(cmin, f)
    else:
        cmin = max(cmin, f)

print(sum - cmin)

Submission status: Accepted

Solution code:
A,B=map(int,input().split())
tot=A*(A+2*B-1)//2
X=B
Y=A+B-1
if abs(X)<abs(Y):
  Z=X
else:
  Z=Y
if X<=0 and Y>=0:
  print(tot)
else:
  print(tot-Z)

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int,input().split())
AL = []
ans = 0

for i in range(1, N+1):
    Ap = L + i - 1
    AL.append(Ap)
tmp = sorted(np.abs(AL))[0] 

for i in range(1, N+1):
    App = L + i - 1
    if abs(App) != tmp:
        ans += App

print(ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
liste =[int(x+l) for x in range(n)]
liste2 = [abs(x) for x in liste]
roger = liste2.index(min(liste2))
liste.pop(roger)
print(sum(liste))

Submission status: Accepted

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

curr_min = float('inf')
curr_sum = 0
for i in range(1, N + 1):
    curr_flavour = L + i - 1
    curr_sum += curr_flavour
    if curr_min >= 0:
        curr_min = min(curr_min, curr_flavour)
    else:
        curr_min = max(curr_min, curr_flavour)
print(curr_sum - curr_min)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
arr = input().split()

n = int(arr[0])
l = int(arr[1])
s = 0
arr2 = []
for i in range(0,n):
  s += l + i
  arr2.append(l + i)
  
minimum = l + n - 1

for i in range(0, n):
  minimum = min(minimum, abs(arr2[i]))
  
print(s-minimum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import datetime
from math import fabs
def main():
    inp,var = map(int, input().split())
    var3 = [var+i-1 for i in range(1,inp+1)]
    var2 = min(var3, key=abs)
    x=sum(var3)-var2
    return x
print(main())

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
n=list(range(b,b+a))
o=[]
for i in n:
    o.append(abs(i))

del n[o.index(min(o))]

print(sum(n))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, L = map(int, readline().split())
    
    full = N * L + N * (N-1) // 2
    min_error = INF
    for i in range(N):
        tmp = (N-1) * L + sum(j for j in range(N) if j != i)
        if min_error > abs(full-tmp):
            min_error = abs(full-tmp)
            ans = tmp
            
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
total=a*(a+2*b-1)//2
x=b
y=a+b-1
if abs(x)<abs(y):
  z=x
else:
  z=y
if x<=0 and y>=0:
  print(total)
else:
  print(total-z)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = [int(z) for z in input().split()]
a = [0]*n
m = 10000000000
index = 0
for i in range(n):
      a[i] = l+i
      if (abs(a[i])<m):
            index = i
            m = abs(a[i])
print(sum(a)-a[index])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

taste = np.array(taste)

if 0 in taste:
  print(taste.sum())
else:
  if sum(taste) >= 0:
    print(sum(taste) - np.abs(taste).min())
  else:
    print(sum(taste) + np.abs(taste).min())

Submission status: Accepted

Solution code:
import sys
a=sys.stdin.readline()
res = [int(i) for i in a.split(" ")] 
N,L = [res[i] for i in (0,1)]
flavour1=0
if (N>=2 and N<=200) and (L>=-100 and L<=100) and type(N)==int and type(L)==int:
    a1=[x for x in range(1,N+1)]
    b=[(L+i-1) for i in a1]
    for i in a1:
        flavour1+=b[i-1]
    c=[abs(x) for x in b]
    d=min(c)
    e=c.index(d)
    print((flavour1)-(b[e]))
else:
    print("Error")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

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

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

Submission status: Accepted

Solution code:
def solve():
    n, l = map(int, input().split())
    t = [l+i for i in range(n)]
    mint = 100
    index = 0
    for i, v in enumerate(t):
        if mint > abs(v):
            mint = min(mint, abs(v))
            index = i
    t.pop(index)
    print(sum(t))




if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
Aji=[0]*N
Sum=0
AjiMin=10**9
EatApple=0
for i in range(N):
  if i==0:
    Aji[i]=L
  else:
    Aji[i]=Aji[i-1]+1
  Sum+=Aji[i]
  AbsVal=abs(Aji[i])
  if AbsVal<AjiMin:
    AjiMin=AbsVal
    EatApple=Aji[i]
print(Sum-EatApple)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
Aji=[0]*N
Sum=0
AjiMin=10**9
EatApple=0
for i in range(N):
  if i==0:
    Aji[i]=L
  else:
    Aji[i]=Aji[i-1]+1
  Sum+=Aji[i]
  AbsVal=abs(Aji[i])
  if AbsVal<AjiMin:
    AjiMin=AbsVal
    EatApple=Aji[i]
print(Sum-EatApple)

Submission status: Accepted

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

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

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

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

l2.pop(l2.index(l2[l.index(min(l))]))
ans = sum(l2)    

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

min1 = 100
min2 = 10000

for j in a_l:
    if j ** 2 <= min2:
        min2 = j **2
        min1 = j
print(sum(a_l) - min1)

Submission status: Accepted

Solution code:
def main():
	N, L = map(int, input().split())
	apple = [L+i-1 for i in range(1, N+1)]
	original = sum(apple)

	mindiff = float('inf')
	for j in range(N):
		applepai = sum(apple[:j] + apple[j+1:])
		diff = abs(original - applepai)

		if diff < mindiff:
			mindiff = diff
			ans = applepai
	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
ans=float('inf')
for i in range(1,n+1):
  ans=min(ans,abs(l+i-1))
  
#print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    s.append(l+i)
for i in range(n):
    t.append(abs(s[i]))
    
x=t.index(min(t))

print(sum(s)-s[x])

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, N + 1):
    if apple_min > abs(L + i - 1):
        apple_min = abs(L + i - 1)
        ans = L + i - 1 
    apple_sum += L + i - 1
    
print(apple_sum - ans)

Submission status: Accepted

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

ans = 0

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

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

else:
    for i in range(n-1):
        ans += l+i+1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

minn = float('INF')
savei = None
for i in range(n):
    num = abs(apple[i])
    if(minn > num):
        minn = num
        savei = i

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

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(list(range(L,L+N-1))))
else:
    print(sum(list(range(L,L+N))))

Submission status: Accepted

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

l = 0
m = 10000
for i in range(1,N+1):
  l += L+i-1
  m = min(m,abs(L+i-1))
if L+N-1 >= 0:
  l -= m
else:
  l += m
print(l)

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(N):
    if abs(A[i]) == min(P):
        print(sum(A) - A[i])
        break

Submission status: Accepted

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

a = []
min_aji = float("inf")

for i in range(n):
    a.append(l + i)
    if abs(min_aji) > abs(l + i):
        min_aji = l + i

a.remove(min_aji)
print(sum(a))

Submission status: Accepted

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

a = []
min_aji = l

for i in range(n):
    a.append(l + i)
    if abs(min_aji) > abs(l + i):
        min_aji = l + i

a.remove(min_aji)
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n,l = map(int,input().split())
    a = [l+i-1 for i in range(1, n+1)]
    b = [abs(i) for i in a]
    m = min(b)
    i = b.index(m)
    del a[i]
    print(sum(a))
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, l = map(int, input().split())
    a_score = list()
    
    for i in range(n):
        # りんごiはl+i-1。indexがずれるので-1しない
        a_score.append(l+i)
    a_sum = sum(a_score)
    if 0 in a_score:
        print(a_sum - 0)
    elif min(a_score) < 0:
        print(a_sum - max(a_score))
    else:
        print(a_sum - min(a_score))
        
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    min_abs = 1e10
    s = 0
    for i in range(N):
        if abs(L + i) < min_abs:
            min_abs = abs(L+i)

    for i in range(N):
        if abs(L+i) != min_abs:
            s += L+i
    print(s)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
N,L=map(int,input().split())
taste=np.zeros(N)
for i in range(N):
  taste[i]=L+i
tot=sum(taste)
min_taste=abs(taste[0])
min_i=0
for i in range(N):
  if min_taste>abs(taste[i]):
    min_taste=abs(taste[i])
    min_i=i
print(int(tot-taste[min_i]))

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()
INF = 10 ** 9 + 7


def solve():

    N, L = map(int, input().split())
    flaver = [0 for _ in range(N)]

    m = INF
    pm = True
    for i in range(1, N + 1):
        n = i + L - 1
        flaver[i - 1] = n
        if abs(n) < m:
            m = abs(n)
            pm = True if n >= 0 else False

    ans = sum(flaver)
    if pm:
        ans -= m
    else:
        ans += m
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
taste=range(l,l+n)
print(sum(taste)-min(taste,key=abs))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy

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

apps = [(l + i -1) for i in range(1, n + 1)]
# print(apps)
# print(sum(apps))
apps_abs = list(numpy.abs(apps))
# print(apps_abs)
# print(apps_abs.index(min(apps_abs)))
apps.pop(apps_abs.index(min(apps_abs)))
# print(apps)
print(sum(apps))

Submission status: Accepted

Solution code:

def main():
    n, l = list(map(int, input().split()))
    lis = [i+l for i in range(n)]
    ans = sum(lis)
    if 0 in lis:
        pass
    elif lis[0] < 0:
        ans -= lis[-1]
    else:
        ans -= lis[0]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

tmp = 10**12
for taste in tastes:
    s = sum([x for x in tastes if x != taste])
    if abs(sum(tastes)-s) <= tmp:
        tmp = abs(sum(tastes)-s)
        ans = s

print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = list(range(l, l + n))
if n + l <= 0:
    print(sum(a) + min(map(abs, a)))
else:
    print(sum(a) - min(map(abs, a)))

Submission status: Accepted

Solution code:
n,L = map(int,input().split())
a = []
m = float("Inf")
x = 0
for i in range(n):
    a.append(i+L)
    if abs(i+L) < m:
        m = abs(i+L)
        x = i+L
print(sum(a)-x)

Submission status: Accepted

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

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

if 0 in taste:
    select = 0
else:
    select_with_ind = min(enumerate(taste), key = lambda x: abs(x[1]))
    select = select_with_ind[1]
    
print(sum(taste) - select)

Submission status: Accepted

Solution code:
n,l = map(int, raw_input().split(' '))
m = (+float('inf'), -1)
cumul = 0
for a in range(1, n + 1):
  	cumul += l + a -1 
	m = min(m, (abs(l + a - 1), a))
print cumul - (l + m[1] - 1)

Submission status: Accepted

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

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

m=[l+i for i in range(n)]
ans=sum(m)-m[mi]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def actual(n, l):
    apples = [l + i - 1 for i in range(1, n + 1)]
    yotei = sum(apples)

    if 0 in apples:
        return yotei

    if apples[0] >= 0:
        return yotei - apples[0]

    if apples[-1] <= 0:
        return yotei - apples[-1]

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

Submission status: Accepted

Solution code:
N,X=map(int,input().split())
S=[]
eat=1000000
eatpos=0
for i in range(N):
    S.append(X+i)
    if abs(S[i])<eat:
        eat=abs(S[i])
        eatpos=i

goukei=0
for i in range(N):
    if i!=eatpos:
        goukei+=S[i]
print(goukei)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
sum,flag,mini = 0,0,10000
for i in range(1,n+1):
    hoge = l+i-1
    sum += hoge
    if abs(mini) >= abs(hoge):
        mini = hoge
    if (hoge == 0):
        flag = 1
if flag == 1:
    print(sum)
else:
    print(sum-mini)

Submission status: Accepted

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

Submission status: Accepted

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

r = [l+i for i in range(n)]
min_r = 1000000000
for i in r:
    if min_r > abs(i):
        min_r = abs(i)
        ans = i
print(sum(r)-ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def ip():return int(input())
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
from bisect import bisect_right


def main():
    input = stdin.buffer.readline
    n, l = map(int, input().split())
    arr = []
    for i in range(n):
        arr.append(l + i)
    arr.sort()
    print(sum(arr) - arr[min(bisect_right(arr, -1), n - 1)])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

lis = []

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

lis = sorted(lis)


if 0 in lis:
    lis.remove(0)
elif lis[0] >= 0:
    lis.remove(min(lis))
else:
    lis.remove(max(lis))
    
print(sum(lis))

Submission status: Accepted

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

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

if 0 in a :
  print(sum(a))
else :
  if a[0] > 0 :
    print(sum(a[1:]))
  else :
    print(sum(a[:-1]))

Submission status: Accepted

Solution code:
N, L =map(int, input().split())
mini = 1000
wa = 0
for n in range(N):
  Ln = L + n
  wa = wa + Ln
  if abs(Ln) < abs(mini):
    mini = Ln
wa = wa - mini
print(wa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
List=[]
i=1
while i<=N:
    List.append(L+i-1)
    i+=1
MIN=abs(List[0])
HIKU=List[0]
j=1
while j<N:
    if abs(List[j])<MIN:
        HIKU=List[j]
        MIN=abs(List[j])
    j+=1
del List[List.index(HIKU)]
print(sum(List))

Submission status: Accepted

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

amax = max(a)
amin = min(a)

if a.count(0) == 0:
    if amax > 0:
        a.pop(0)
    else:
        a.pop()
        
print(sum(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 初期入力
import sys
input = sys.stdin.readline
N,L = (int(x) for x in input().split())
taste =[i for i in range(L,L+N ) ]
decide =taste[0] *taste[-1]
ans =0
if 0 <= decide: #味が、全て正or全て負
    if taste[0] <0:
        ans =sum(taste[:-1])
    else:
        ans =sum(taste[1:])
else: #味が0をまたぐ時は０を引く⇒合計は変わらない
    ans =sum(taste) 
print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
array = []
minN = 10**10
for x in range(N):
    array.append(L + x)
    if abs(L + x) < abs(minN):
        minN = L + x
array.remove(minN)
print(sum(array))

Submission status: Accepted

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

Submission status: Accepted

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

if 0 in apple:
    print(sum(apple))
elif apple[0] > 0:
    print(sum(apple)-apple[0])
elif apple[-1] < 0:
    print(sum(apple)-apple[-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
l = []
for i in range(N):
    l.append(L+i)
ll = min(list(map(abs, l)))

Min = L
Max = L+N-1
if (Min>0 and Max>0):
    l.remove(ll)
    print(sum(l))
elif Min < 0 and Max < 0:
    l.remove(-1*ll)
    print(sum(l))
else:
    print(sum(l))

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())[:-1]
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N , L = (int(a) for a in input().split())
apple = []
for i in range (1,N+1) :
    apple.append(L + i - 1)

if L >= 0 :
    del apple[0]
elif N + L <= 1 :
    del apple[-1]
else : del apple[abs(L)]

print(sum(apple))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, k = map(int, input().split())
a = []
b = []
c = 0
for i in range(k, n + k):
    a.append(abs(i))
    b.append(i)
if abs(min(b)) <= min(a):
    print(sum(b) - min(a))
else:
    print(sum(b) + min(a))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    taste.append(l+i)
    abs_v.append(abs(l+i))

idx = abs_v.index(min(abs_v))
del taste[idx]

print(sum(taste))

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))
print(sum(a[1:]))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
s = sum(l + i for i in range(n))
eaten = min((l + i for i in range(n)), key=lambda x: abs(x))
print(s - eaten)

Submission status: Accepted

Solution code:
n,l= map(int,input().split())
li = []
for i in range(n):
    li.append(l)
    l += 1
ans = 0
li_min = float('inf')
for i in range(len(li)):
    li_min = min(abs(li[i]),li_min)
for i in range(len(li)):
    if li_min == abs(li[i]):
        li[i] = 0
print(sum(li))

Submission status: Accepted

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

x = []
y = []
for i in range(1,n+1):
  t = l + i - 1
  y.append(abs(t))
  x.append(t)
  
tmp = zip(y,x)
tmp2 = sorted(tmp)
c,ans = zip(*tmp2)
print(sum(ans[1:]))