Problem:


Score : 200 points

Problem Statement

You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative.

You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples used.

You planned to make an apple pie using all of the apples, but being hungry tempts you to eat one of them, which can no longer be used to make the apple pie.

You want to make an apple pie that is as similar as possible to the one that you planned to make. Thus, you will choose the apple to eat so that the flavor of the apple pie made of the remaining N-1 apples will have the smallest possible absolute difference from the flavor of the apple pie made of all the N apples.

Find the flavor of the apple pie made of the remaining N-1 apples when you choose the apple to eat as above.

We can prove that this value is uniquely determined.

Constraints

2 \leq N \leq 200

-100 \leq L \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N L

Output

Find the flavor of the apple pie made of the remaining N-1 apples when you optimally choose the apple to eat.

Sample Input 1

5 2

Sample Output 1

18

The flavors of Apple 1, 2, 3, 4, and 5 are 2, 3, 4, 5, and 6, respectively. The optimal choice is to eat Apple 1, so the answer is 3+4+5+6=18.

Sample Input 2

3 -1

Sample Output 2

0

The flavors of Apple 1, 2, and 3 are -1, 0, and 1, respectively. The optimal choice is to eat Apple 2, so the answer is (-1)+1=0.

Sample Input 3

30 -50

Sample Output 3

-1044



Sample input:
5 2


Sample output:
18

Submission status: Accepted

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

apple_1 = L
apple_2 = L+N-1

if apple_1*apple_2<=0:
    apple_min=0
elif apple_1<=0 and apple_2<=0:
    apple_min=apple_2
else:
    apple_min=apple_1

sum=0
for i in range(N):
    sum+=L+i
sum-=apple_min
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, L = (int(i) for i in input().split())
    s = 0
    li = []
    for i in range(1, N+1):
        s += L + i - 1
        li.append((abs(L + i - 1), i))
    li.sort()

    print(s - (L + li[0][1] - 1))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans -= (L + num)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc131/tasks/abc131_b

n, l = [int(x) for x in input().split()]
a = [(i, l + i) for i in range(n)]
a.sort(key=lambda x: abs(x[1]))
a.pop(0)
print(sum([x[1] for x in a]))

Submission status: Accepted

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

for i in range(n):
    abs_a.append(abs(a[i]))    

if max(a)<0:
    p=pi+min(abs_a)
else:
    p=pi-min(abs_a)
    
print(p)

Submission status: Accepted

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

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

for i in range(n):
    abs_a.append(abs(a[i]))    

if max(a)<0:
    p=pi+min(abs_a)
else:
    p=pi-min(abs_a)
    
print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, l = map(int, sys.stdin.readline().split())

def main():
    s = (l - 1) * n + (1 + n) * n // 2
    res = []
    for i in range(1, n+1):
        f = l + i - 1
        res.append((abs(f), s - f))
    
    res.sort()
    return res[0][1]

if __name__=='__main__':
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
import sys
import numpy as np 

n, l = map(int, sys.stdin.readline().split())

def main():
    f = l + np.arange(1, n+1) - 1
    s = f.sum()
    a = np.absolute(f)
    mi = np.amin(a)
    i = np.argwhere(a == mi)[0, 0]
    return s - f[i]

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
*a, = map(lambda x:L+x-1, range(1, N+1))
a.sort(key=abs)
print(sum(a)-a[0])

Submission status: Accepted

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

Submission status: Accepted

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

if L <= 0 <= L+N-1:
  a = L
  b = L+N-1
elif 0 < L:
  a = L+1
  b = L+N-1
else:
  a = L
  b = L+N-2

ans = 0
for i in range(a, b+1):
  ans += i
print(ans)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
ls=[]
s=0
for i in range(1,N+1):
  s+=L+i-1
  v=abs(L+i-1)
  ls.append(v)
  x=min(ls)
  if L+i-1>=0:
    x=x
  else:x=-x
s=s-x
print(s)

Submission status: Accepted

Solution code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-


def main():
    N, L = map(int, input().split())
    result = []
    for i in range(N):
        result.append([i + L, abs(i + L)])
    result.sort(key=lambda x: x[1])
    result.pop(0)

    print(sum([r[0] for r in result]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
#味のリスト
#l,l+1,...,l+n-1
lis=[i for i in range(l,l+n)]
if lis[-1]<0: print(sum(lis[:-1]))
elif lis[0]*lis[-1]<=0: print(sum(lis))
else: print(sum(lis[1:]))

Submission status: Accepted

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

m = max(taste)
for e in taste:
  if abs(e) < m:
    m = abs(e)
print(sum(taste) - m)

Submission status: Accepted

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

if 0 in apples:
    print(sum(apples))
elif apples[0] > 0:
    print(sum(apples)-min(apples))
else:
    print(sum(apples)-max(apples))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
ans=0
list=[i+b-1 for i in range(1,a+1)]
list.sort(key=lambda i:abs(i))
ans=sum(list[1:])
print(ans)

Submission status: Accepted

Solution code:
n, a = map(int, input().split())
ans = 0
mi = 100000000
for i in range(0, n):
    if abs(mi)>abs(a): mi=a
    ans += a
    a += 1
print(ans-mi)

Submission status: Accepted

Solution code:
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 100
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs >= abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
if len(tastes) == min_taste_index+1:
    print(sum(tastes[:min_taste_index]))
else:
    print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Submission status: Accepted

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

a = 0
d = 101
for i in range(N):
    a += L + i
    if abs(d) >= abs(L + i):
        d = L + i

print(a - d)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
p1 = [(l+i-1) for i in range(1,n+1)]
p2 = [i**2 for i in p1]
num = p2.index(min(p2))
sums = sum(p1)-p1[num]
print(sums)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
taste = 0
eat = l + n - 1
for i in range(1, n+1):
    _taste = l + i - 1
    taste += _taste
    if abs(_taste) < abs(eat):
        eat = _taste

print(taste - eat)

Submission status: Accepted

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

lis = sorted([int(x) for x in range(l,l+n)], key = abs)
print(sum(lis[1:]))

Submission status: Accepted

Solution code:
#import numpy as np
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop

"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""

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

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

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

Submission status: Accepted

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

if max(x)*min(x)<=0:
    print(sum(x))
elif min(x)>0:
    print(sum(x)-min(x))
elif max(x)<0:
    print(sum(x)-max(x))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=list(map(int,input().split()))
m=sorted(list(range(l,l+n)),key=abs)
print(sum(m[1:]))

Submission status: Accepted

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

Submission status: Accepted

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

sum_n = 0
min = 1000
ans = 0

for i in range(1, n+1):
    sum_n += L + i -1

    if(abs(L+i-1) < min):
        min = abs(L+i-1)
        ans = L+i-1
print(sum_n-ans)

Submission status: Accepted

Solution code:
a = input().split()
N, L = [int(i) for i in a]
l = []
for i in range(1,N+1):
  dif = abs(L+i-1)
  l.append(dif)
m = l.index(min(l)) + 1
sol = N*L + (N-1)*N/2 - (L+m-1)
print(int(sol))

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
taste=list(range(L,N+L))
 
taste2=[]
for i in range(N):
    taste2.append((taste[i])**2)
 
X=0
for i in range(N):
    if taste2[i]==min(taste2):
        X+=taste[i]
        
print(sum(taste)-X)

Submission status: Accepted

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

apple_sum = 0
apple_min = 1000
apple_min_index = -1

for i in range(n):
    apple_sum += i+l
    if apple_min > abs(i+l):
        apple_min = abs(i+l)
        apple_min_index = i

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
aji = np.array(list(range(1,N+1))) + L - 1

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

answer = sum(aji) - getNearestValue(aji, 0)
print(answer)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
taste = [i for i in range(l, l + n)]
SUM = sum(taste)
diff = 10 ** 3
idx = 0
for j in range(len(taste)):
    diff_n = abs(taste[j])
    if diff_n < diff:
        idx = j
        diff = diff_n
        if diff == 0:
            print(SUM)
            exit(0)
print(SUM-taste[idx])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
A=[L+i for i in range(0, N)]
m=10000
mi=0
for a in range(0,N):
    if abs(A[a])<m:
        m=abs(A[a])
        mi=a
print(sum(A)-A[mi])

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
J=[]
for i in range(N):
    J.append(L+i)
for i in J:
    if i == 0:
        J.pop(J.index(0))
        print(sum(J))
        exit(0)
J.sort()
print(sum(J[1:]) if J[0]>0 else sum(J[:-1]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
d=abs(l)
pie=(n*(n+1)//2)+(n-1)*(l-1)-1
for k in range(2,n+1):
    t_pie=((n*(n+1))//2)+n*(l-1)
    p_pie=((n*(n+1))//2)+(n-1)*(l-1)-k
    xd=abs(t_pie-p_pie)
    if xd <= d:
        d=xd
        pie=p_pie
print(pie)

Submission status: Accepted

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

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

min_t = 20000000000
total = sum(Ts)
for t in Ts:
    if abs(t) < abs(min_t):
        min_t = t
print(total-min_t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, l = [int(x) for x in input().split()]

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

tmplst = []
for x in lst:
    if x < 0:
        tmplst.append(-x)
    else:
        tmplst.append(x)
place = tmplst.index(min(tmplst))
lst.remove(lst[place])
print(sum(lst))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
t = sorted(list(range(L, L+N)), key=abs)
print(sum(t[1:]))

Submission status: Accepted

Solution code:
#131

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

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

print(sum(i + l - 1 for i in range(1, n+ 1)) - mn)

Submission status: Accepted

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

A = [L+i for i in range(N)]
d = 99999999
for i in range(N):
  if abs(A[i])<d:
    d = abs(A[i])
    ans = sum(A)-A[i]
print ans

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x = 10 ** 9
y = 0

for apple in apples:
    if abs(apple) < x:
        x = abs(apple)
        y = apple
print(sum(apples)-y)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apples = [l + i for i in range(n)]
x = 10 ** 9
y = -1
for a in apples:
    if abs(a) < x:
        x = abs(a)
        y = a
print(sum(apples)-y)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

min = 10**9
ind = -1
for i in range(1,n+1):
    diff = abs(l+i-1)
    if diff < min:
        min = diff
        ind = i

print(sum_n - (l+ind-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#128 b むずい
n,l=map(int,input().split())
aji=[i+l-1 for i in range(1,n+1)]
eat=100100
for x in aji:
    if abs(eat)>abs(x):
        eat=x
ans=sum(aji)-eat
print(ans)

Submission status: Accepted

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

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=(l-1)*(n-1)+n*(n+1)//2
if l>=1:
  print(s-1)
elif n>=1-l:
  print(s-1+l)
else:
  print(s-n)

Submission status: Accepted

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

abs_x = 1000
x = 0
total = 0
for i in range(n):
  total += l + i
  if abs_x > abs(l + i):
    x = l + i
    abs_x = abs(l + i)
print(total - x)

Submission status: Accepted

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

minNL = 101

for j in range(N):
    if listNL[j] == 0:
        minNL = 0
    elif listNL[j] > 0:
        minNL = min(minNL, listNL[j])
    else:
        minNL = (-1)*(min(abs(minNL), abs(listNL[j])))
    

print(sumNL - minNL)

Submission status: Accepted

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

list = list(range(L, L+N))
min = 1000
bite = 0
for i in list:
    if min > abs(i):
        min = abs(i)
        bite = i
            
print(sum(list) - bite)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(res))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

def LI():
  return [int(s) for s in input().split()]

N,L = LI()
ringo = np.array(list(range(1,N+1))) + L - 1

taste_all = sum(ringo)

min_index = 0
min_abs = abs(ringo[0])

for i in range(1,N):
  if min_abs > abs(ringo[i]):
    min_index = i
    min_abs = abs(ringo[i])

print(taste_all - ringo[min_index])

Submission status: Accepted

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

res = 10 ** 9
res_abs = 10 ** 9
for i in range(n):
  part_v = all_v - v[i]
  if abs(all_v - part_v) < res_abs:
    res = part_v
    res_abs = abs(all_v - part_v)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = input().split(" ")
N = int(N)
L = int(L)
trimRingoIndex = 0
trimRingoAji = 0
for value in range(N):
    aji = abs(L + value)
    if value == 0:
        trimRingoAji = aji
    else:
        if trimRingoAji > aji:
            trimRingoIndex = value
            trimRingoAji = aji

totalAji = 0
for value in range(N):
    if value != trimRingoIndex:
        totalAji += L + value

print(totalAji)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
lis=list(range(L,N+L,1))
#print(lis)
min=1000
index=0
sum=0
for i in range(len(lis)):
    if abs(lis[i])<min:
        min=abs(lis[i])
        index=i
    sum=sum+lis[i]

print(sum-lis[index])

Submission status: Accepted

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

l = list(map(lambda x:x+m, range(n)))

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
a = 0
ap = []
abp = []
while a <= n-1:
    a += 1
    ap.append(l + a - 1)
    abp.append(abs(l + a - 1))
x = abp.index(min(abp))
ap.remove(ap[x])
print(sum(ap))

Submission status: Accepted

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

    aji_list = [0]*n

    count = 0

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

    if aji_list[0] >= 0:
        for i in range(1,n):
            count += aji_list[i]
    else:
        if aji_list[n-1] >= 0:
            for i in range(n):
                count += aji_list[i]
        else:
            for i in range(n-1):
                count += aji_list[i]

    print(count)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

t = float("inf")
s = 0
for i in range(n):
    s += i + l
    if abs(t) > abs(i + l):
        t = i+l

print(s - t)

Submission status: Accepted

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

Submission status: Accepted

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

lst = list()
for i in range(0, N):
    lst.append(L + i)

base = sum(lst)
div = abs(lst[0])
res = base - lst[0]
for i in range(1, len(lst)):
    if abs(lst[i]) < div:
        div = abs(lst[i])
        res = base - lst[i]

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if l < 0 and l+n-1 > 0:
  print(result)
elif result >0 :
  print(result-l)
else:
  print(result-(l+(n-1)))

Submission status: Accepted

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

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

total = sum(aji)

if aji[0] <= 0 and 0 <= aji[-1]:
    ans = total
elif aji[-1] < 0:
    ans = total - aji[-1]
else:
    ans = total - aji[0]

print(ans)

Submission status: Accepted

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

taste=[]
buf=[]

for i in range(n):
    tmp=l-1+(i+1)
    taste.append(tmp)
    buf.append(abs(tmp))

s=sum(taste)

minindex=buf.index(min(buf))

print(s-taste[minindex])

Submission status: Accepted

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

A.remove(min(max(A), *[abs(a) for a in A]))

print(sum(A))

Submission status: Accepted

Solution code:
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, l = na()

m = 1 << 60
res = 0
for i in range(n):
    q = l + i
    m = min(m, abs(q))
    res += q

if res < 0:
    res += m
else:
    res -= m

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

    for i in range(N):
        taste.append(L+i)
    
    pie = sum(taste)
    ans = 1e10
    ans = [0]*N

    for i in range(N):
        tmp = taste[i]
        taste[i] = 0
        ans[i] = abs(pie-sum(taste))
        taste[i] = tmp
    
    print(pie-taste[ans.index(min(ans))])




if __name__=="__main__":
    main()

Submission status: Accepted

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

t = [l+i-1 for i in range(1,n+1)]
tt = [abs(i) for i in t]
t.pop(tt.index(min(tt)))
print(sum(t))

Submission status: Accepted

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

a = [0]*n
b = [0]*n

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

for i in range(n):
  b[i] = abs(a[i])

remove = a[b.index(min(b))]

print(int(sum(a)-remove))

Submission status: Accepted

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

a = [0]*n
b = [0]*n

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

for i in range(n):
  b[i] = abs(sum(a) - (sum(a) - a[i]))

remove = a[b.index(min(b))]

print(int(sum(a)-remove))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

ans = (R + L) * (R - L + 1) // 2 - eat

print(ans)

Submission status: Accepted

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

apple = []
flav = []

for i in range(1, N+1):
    apple.append(i)
    flav.append(L+i-1)

abs_flav = list(map(abs, flav))
num = abs_flav.index(min(abs_flav))

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

Submission status: Accepted

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

ai=0
if 1 <= 1-l <= n:
  ai=1-l
elif n<1-l:
  ai=n
else:
  ai=1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#python3
n,l=map(int, input().split())
print(sum(sorted([l+i for i in range(n)], key=abs)[1:]))

Submission status: Accepted

Solution code:
#python3
n,l=map(int, input().split())
a=[l+i for i in range(n)]
s=sum(a)
index=0
ab=10**9
for i in range(n):
  if ab > abs(a[i]):
    ab=abs(a[i])
    index=i

print(s-a[index])

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, L = map(int, readline().split())
F = [L + i for i in range(N)]
F.sort(key=lambda x: abs(x))

print(sum(F[1:]))

Submission status: Accepted

Solution code:
def main():
    n, l = map(int, input().split())
    m = [ i + l - 1 for i in range(1,n+1)]
    mabs = [abs(i) for i in m]

    eat = min(mabs)
    if eat in m:
        idx = m.index(eat)
    else:
        idx = m.index(-eat)
    print(sum(m)-m[idx])
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys

# import numpy as np
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, L = map(int, readline().split())
F = [L + i for i in range(N)]


tmp = 1000
ans=0
for i in itertools.combinations(F, N - 1):
    if abs(sum(F)-sum(i)) < tmp:
        tmp = abs(sum(F)-sum(i))
        ans=sum(i)

print(ans)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
tmp = 1000
ans = 0
if L > 0:
    for i in range(L+1, L+N):
       ans += i

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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

ss = np.zeros(N, dtype=int)
for k in range(1, N+1):
    ss[k-1] = s-(L+k-1)

dif = abs(ss - s)
print(*ss[np.where(dif==min(dif))])

Submission status: Accepted

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

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

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

dif = []
for kk in range(0, N):
    dif.append(abs(s-ss[kk]))

print(ss[dif.index(min(dif))])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N, L = map(int, input().split())

        pie = [L + i - 1 for i in range(1, N + 1)]
        print(sum(pie) - min(pie, key=abs))

# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Accepted

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