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())
m = []
for i in range(1, n+1):
    m.append(l+i-1)
su = 0
for i in m:
    su += i
e = 10**8
ans = 0
for i in range(n):
    tmp = 0
    for j in range(n):
        if i == j: continue
        tmp += m[j]
    if e > abs(su-tmp):
        e = abs(su-tmp)
        ans = tmp
print(ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
m = []
for i in range(1, n+1):
    m.append(l+i-1)
ab = 10**10
apple = 0
for i in range(n):
    if ab > abs(m[i]):
        apple = i
        ab = abs(m[i])
ans = 0
for i in range(n):
    if i == apple: continue
    ans += m[i]
print(ans)

Submission status: Accepted

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

total = L*N
for i in range(N):
    total += i
    
if L > 0:
    ans = total-L
elif L+N-1 < 0:
    ans = total-(L+N-1)
else:
    ans = total
    
print(ans)

Submission status: Accepted

Solution code:
N, L = (int(x) for x in input().split())
A = []
for i in range(N):
  A.append(L+i)
s = sum(A)
m = 1000
ans = 0
for i in range(N):
  t = A.pop(i)
  if abs(sum(A)-s) <= m:
    m = abs(sum(A)-s)
    ans = sum(A)
  A.insert(i,t)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
lst=[]
for i in range(l, n+l):
  lst.append(i)
total = sum(lst)
gap = 10000000
digit=0
for j in range(len(lst)):
  if abs(lst[j])<gap:
    gap=abs(lst[j])
    digit = j
del lst[digit]
print(sum(lst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, L = (int(x) for x in input().split())
    azi = [L + i for i in range(N)]
    ans = sum(azi)
    if 0 not in azi:
        if azi[0] > 0:
            ans -= azi[0]
        else:
            ans -= azi[N-1]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

import numpy as np

apple = np.array([l+(i+1)-1 for i in range(n)])

ringo = np.argmin(np.array(list(map(abs,apple))))

apple=np.delete(apple,ringo)

print(sum(apple))

Submission status: Accepted

Solution code:
import functools
N, L = list(map(int,input().split()))
NL = [L+i-1 for i in range(1,N+1)]
MINABS = functools.reduce(lambda x,y: x if abs(x) < abs(y) else y, NL )
print(sum(NL)-MINABS)

Submission status: Accepted

Solution code:
def solve():
    N, L = map(int, input().split())
    m = abs(L)
    for i in range(N):
        if abs(m) > abs(L+i):
            m = L+i
    print(int(N*(L+0.5*N-0.5)-m))


solve()

Submission status: Accepted

Solution code:
import numpy as np
N, L = map(int, input().split())
apple = np.array([i+L for i in range(N)])

if apple.max() <= 0:
    print(apple.sum()-apple.max())
elif apple.min() > 0:
    print(apple.sum()-apple.min())
else:
    print(apple.sum())

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
L=[i+l for i in range(n)]
s=sum(L)
absorute=1000
m=0
for i in L:
    if absorute>abs(i):
        absorute=abs(i)
        m=i
print(s-m)

Submission status: Accepted

Solution code:
n,l=map(int, input().split())
t=0
c=0
for i in range(n):
  if i==0:
    t=abs(l+(i+1)-1)
    c=i+1
  else:
    t=min(t, abs(l+(i+1)-1))
    if t==abs(l+(i+1)-1):
      c=i+1
#print(c)
g=0
for i in range(n):
  g+=(l+(i+1)-1)
#print(g)
print(g-l-c+1)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n, l = Is()
A = [l+i-1 for i in range(1, n+1)]
index = bisect_left(A, 0)
if index == n:
    m = A[-1]
else:
    m = A[index]
print(sum(A)-m)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
APsum=0
AJIList=[]
AbsList=[]

for i in range(N):
    APsum += i+L
    AJIList.append(i+L)
    AbsList.append(abs(i+L))
    
#print(AJIList)
#print(AbsList)

del AJIList[AbsList.index(min(AbsList))]

print(sum(AJIList))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans=0
min_apple = 10**10
for i in range(1,n+1):
    taste = l+i-1
    if abs(min_apple)>abs(taste):
        min_apple=taste
    ans+=taste
print(ans-min_apple)

Submission status: Accepted

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

for i in range(n):
  li1[i] = l+i
  li2[i] = abs(l+i)

li1.pop(li2.index(min(li2)))

print(sum(li1))

Submission status: Accepted

Solution code:
# ABC131B

import numpy as np
n, l = map(int, input().split())
x = l+np.arange(n)
print(sum(x) - x[np.argmin(abs(x))])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if taste[0] > 0:
    ans = sum(taste) - taste[0]
elif taste[-1] < 0:
    ans = sum(taste) - taste[-1]
else:
    ans = sum(taste)

print(ans)

Submission status: Accepted

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

aji_abs = [0]*n
for i in range(1,n+1,1):
    aji_abs[i-1]  = abs(aji[i-1])
aji.remove(aji[aji_abs.index(min(aji_abs))])
print(sum(aji))

Submission status: Accepted

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

apple = []
for i in range( N):
    apple.append(L + i)
    
min_l = apple[0]
for j in apple:
    if abs(j) < abs(min_l):
        min_l = j
print(sum(apple)-min_l)

Submission status: Accepted

Solution code:
# B - Bite Eating

N, L = map(int, input().split())
ans = 0
mn = float('inf')
for i in range(1, N + 1):
    ans += L + i - 1
    if abs(L + i - 1) < abs(mn):
        mn = L + i - 1

print(ans - mn)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, L = map(int, input().split())
    AJI = 0
    INF = float('inf')
    SA = INF
    I = 0

    for i in range(1,N+1):
        if abs(L+i-1)<SA:
            SA = abs(L+i-1)
            I = i
        AJI += L + i - 1
    print(AJI-(L+I-1))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N, L = ri_()
if L >= 0:
    eaten = 0
elif L <= -N:
    eaten = N - 1
else:
    eaten = -L
ans = N * L + N * (N - 1) // 2 - (L + eaten)
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)
sum=sum(aji)
#print(aji)
#print(sum)
p=1000
for i in range(n):
    if abs(aji[i])<=abs(aji[i-1]):
        p=aji[i]
        #print(aji[i])
print(sum-p)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Apple_List1=[]
Apple_List2=[]
for i in range(N):
    Apple_List1.append(L+i)
    Apple_List2.append(abs(L+i))

#Apple_List=abs(Apple_List)
Apple_List2.sort()

flag=0
if Apple_List2[0] in Apple_List1:
    flag=1
elif -Apple_List2[0] in Apple_List1:
    flag=-1
    
print(sum(Apple_List1)-flag*Apple_List2[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,L = map(int, input().split())
def func_abs(n):
    return abs(n)
An = [0]*N
for i in range(N):
  An[i] = L + i
print(sum(An)-min(An, key=func_abs))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
ans = 10 ** 6
k = 0
for i in range(1, n + 1):
    t = l + i - 1
    if ans > abs(t):
        ans, k = abs(t), t
print(n * l + n * (n - 1) // 2 - k)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
d = []
for i in range(1, n + 1):
    d.append(l + i - 1)
wa = sum(d)
k = []
for i in range(1, n + 1):
    t = n * l + n * (n - 1) // 2 - (l + i - 1)
    k.append(t)
for i in range(n):
    k[i] = abs(k[i] - wa)
m = k.index(min(k))
print(n * l + n * (n - 1) // 2 - (l + m))

Submission status: Accepted

Solution code:
N,L=map(int, raw_input().split())
A=[]
for i in range(1,N+1):
    A.append((abs(L+i-1),L+i-1))
A.sort()
ans=0
for i,t in enumerate(A):
    if i==0: continue
    ans+=t[1]
print ans

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
cnt = float('inf')
for i in range(n):
    if cnt > abs(l + i):
        ans, cnt = l + i, abs(l + i)
    
print(n*(l-1)+n*(n+1)//2-ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
cnt = float('inf')
for i in range(n):
    if cnt > abs(l + i):
        ans,cnt = l + i,abs(l+i)
    
print(n*(l-1)+n*(n+1)//2-ans)

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
n_l = [0]*n
flag = "ng"
for i in range(n):
    n_l[i] = l + (i+1) - 1
    if n_l[i] == 0:
        flag = "ok"
if flag == "ok":
    print(sum(n_l))
    exit()
n_l_min = min(n_l)
if n_l_min < 0 :
    print(sum(n_l)-max(n_l))
    exit()
print(sum(n_l)-n_l_min)
#print(n_l)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def resolve():
    n,l=map(int, input().split())
    ll=list(range(l,l+n))
    moto=sum(ll)
    if ll[0]>0:
        print(moto-ll[0])
    elif ll[-1]<0:
        print(moto-ll[-1])
    else:
        print(moto)
resolve()

Submission status: Accepted

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

count -= aji[0][1]
print(count)

Submission status: Accepted

Solution code:
import itertools

import math
n, l = map(int, input().split())
l_list = []
abs_list = [0]*n

for i in range(0, n):
    l_list.append(l + i)

min_tmp = 10**9
mini = 0
for i in range(0, n):
    if(abs(l_list[i]) <= min_tmp):
        min_tmp = abs(l_list[i])
        mini = l_list[i]
print(sum(l_list) - mini)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, L = map(int, readline().split())
a = []
tmp = 0
min_tmp = 100000

for i in range(n):
    a.append(i+L)

for i in range(n):
    tmp = abs(a[i])
    if tmp < min_tmp:
        min_tmp = tmp
        min_i = i

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

Submission status: Accepted

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

if 0 in t:
	print(sum(t))
else:
	if t[0] <0:
		t.pop()
		print(sum(t))

	else:
		t.pop(0)
		#print(t)
		print(sum(t))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
list = [L+i for i in range(N)]
a = float("inf")
for i in range(N):
  if abs(a) > abs(list[i]):
    a = list[i]
print(sum(list) - a)

Submission status: Accepted

Solution code:
N,L=map(int,input().split())
r=[]
i=0
s=10000
for i in range(N):
  r.append(L+i)
  a=abs(L+i)
  if s>a:
    s=a
    l=i
del r[l]
print(sum(r))

Submission status: Accepted

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

print(sum(tas) - tas[ab_tas.index(min(ab_tas))])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

a = np.array(range(0,n)) + l
b = np.abs(a)
i = np.argmin(b)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC 131 B
N,L=map(int,input().split())
apple = [i for i in range(L,L+N)]

ans = sum(apple) 
rem = sorted([abs(i) for i in (apple)])[0]
if rem in apple:
    ans -= rem
else:
    ans+=rem
print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def main():
    N, L = map(int, readline().rstrip().split())
    A = [L+i-1 for i in range(1, N+1)]
    A_abs = [abs(a) for a in A]
    mi_idx = A_abs.index(min(A_abs))
    print(sum(A) - A[mi_idx])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

n,L=MI()
l=[0]*n
for i in range(1,n+1):
    l[i-1] = L+i-1
s=sum(l)

mini=999
target=0
for i in range(n):
    if mini > abs(s-(s-l[i])):
        mini =abs(s-(s-l[i]))
        target=l[i]

print(s-target)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
pie = 0
comp = 300

for i in range(1, n+1):
    pie = pie + l + i - 1
    if abs(l + i -1) < abs(comp):
        comp = l + i -1

print(pie - comp)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    N, L = map(int, open(0).read().split())

    T = []
    T_abs = []
    for i in range(1, N + 1):
        T.append(L + i - 1)
        T_abs.append(abs(L + i - 1))
    
    Remv = T[T_abs.index(min(T_abs))]
    print(sum(T) - Remv)


main()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
motomoto=n*l-n+n*(n+1)//2
zettaisa=10**100
keep=0
for i in range(1,n+1):
  aji=motomoto-(l+i-1)
  sa=abs(motomoto-aji)
  if sa<=zettaisa:
    zettaisa=sa
    keep=aji
print(keep)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n,l=map(int,input().split())
a = np.arange(l,l+n)
d = abs(a).argmin() # argmin: ndarrayで最小値の要素のインデックスを取得
print(a.sum() - a[d])

Submission status: Accepted

Solution code:

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

N_sum=sum(aji_lis)
ap=min([abs(i) for i in aji_lis])

if N_sum >=0:
    print(N_sum-ap)
else:
    print(N_sum+ap)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sumA = 0
for i in range(N):
    sumA += (L + i)
    
cur_diff = float('inf')
ans = 0
for i in range(N):
    tmp = sumA - (L + i)
    diff = abs(sumA - tmp)
    if diff < cur_diff:
        cur_diff = diff
        ans = tmp
        
print(ans)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
# map(int, input().split())
# int(input())
# input().split()
# mojiretu = ','.join(str_list)
# sorted(input())
n, l = map(int, input().split())
minv = 300
sumv = 0
it = 0
for i in range(n):
    sumv += (l + i)
    if abs(l + i) < minv:
        it = i
        minv = abs(l + i)
print(sumv - (l + it))

Submission status: Accepted

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

Submission status: Accepted

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

s=0
for i in range(n):
  s+=l+i
cnt=0  
m=100000000
for i in range(n):
  u=m
  m=min(abs(l+i),m)
 
  if u!=m:
    cnt=i
    
    
print(s-(l+cnt))

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
t = [l+i for i in range(n)]
s = sum(t)
df = float('inf')
ans = 0
for i in range(n):
  pie = s - t[i]
  if abs(s - pie) < df:
    df = abs(s - pie)
    ans = pie
print(ans)

Submission status: Accepted

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

#ringo goto aji dasu
for i in range(N):
  a.append(L+ i+1 -1)

if max(a) < 0:
  print(sum(a)-max(a))
elif max(a) >= 0 and min(a) <= 0:
  print(sum(a))
else:
  print(sum(a)-min(a))

Submission status: Accepted

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

nums = []
total = 0
for i in range(L, L + N):
  nums.append(i)
  total += i

if max(nums) < 0:
  total -= max(nums)
elif min(nums) > 0:
  total -= min(nums)

print(total)

Submission status: Accepted

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

list=[]
for i in range(1,N+1):
  s=i+L-1
  list.append(s)
if 0 in list:
  print(sum(list))
else:
  list=sorted(list)
  if list[0]>0:
    del list[0]
    print(sum(list))
  elif list[0]<0:
    list=sorted(list,reverse=True)
    del list[0]
    print(sum(list))

Submission status: Accepted

Solution code:
# abc131_b.py
N, L = map(int,input().split())
apple = []
for i in range(N):
    apple.append(L+i)
taste = sum(apple)
diff = 10**9
ans = 0
for i,v in enumerate(apple):
    if diff > abs(taste-(taste-v)):
        diff = abs(taste-(taste-v))
        ans = taste-v
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, l = mi()
    summation = (2 * l + n - 1) * n // 2
    left = l
    right = l + n - 1
    if left <= 0 <= right:
        print(summation)
    elif 0 < left:
        print(summation - left)
    else:
        print(summation - right)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(taste)-t)

Submission status: Accepted

Solution code:
def main():
	n , l = map(int,input().split())
	arr= []
	for i in range(n):
		arr.append(l+i)
	arr.sort()
	add = sum(arr)
	mn = 10000000000000
	# print(arr)
	# print(abs(0))
	for i in range(len(arr)):
		if abs(arr[i])<abs(mn):
			mn = arr[i]
	print(add-mn)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n,l = map(int,input().split())
apple = [0]*n

for i in range(n):
  apple[i] = l+i
eat = apple[i]
for i in range(n):
  eat = min(abs(apple[i]),abs(eat))

if eat in apple:
  apple.remove(eat)
else:
  apple.remove(-1*eat)

print(sum(apple))

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,L = inputlist()
li = [0]*N
for i in range(N):
    li[i] = L+i
ans = -1
d = 10**18
s = sum(li)
for i in range(N):
    sa = s
    sa -=li[i]
    da = abs(s-sa)
    if da < d:
        ans = sa
        d = da
print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
Apple = []
compare = []
for i in range(N):
  Apple.append(L + i)
tot = sum(Apple)
for i in range(N):
  a = Apple[i]  
  Apple.remove(a)
  compare.append(abs(tot - sum(Apple)))
  Apple.insert(i,a)
Apple.remove(Apple[compare.index(min(compare))])
print(sum(Apple))

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

total = L*N
for i in range(N):
    total += i

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

Submission status: Accepted

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

d_list = [l + i - 1 for i in range(1, n + 1)]
d_sum = sum(d_list)

ans = 0
temp = abs(d_sum)
for d in d_list:
    if abs(d) < temp:
        ans = d_sum - d
        temp = abs(d)
print(ans)

Submission status: Accepted

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

d_list = [l + i - 1 for i in range(1, n + 1)]
d_sum = sum(d_list)

temp_list = sorted([(abs(d), d) for d in d_list])

ans = d_sum - temp_list[0][1]
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n, l = map(int, input().split())
t = []
for i in range(1, n+1):
    t.append(l+i-1)
fab = []
sum_t = sum(t)
tmp = 0
if n+l > 0:
    for i in range(n):
        fab.append(sum_t-t[i])
    ans = []
    for i in range(n):
        ans.append(math.fabs(sum_t-fab[i]))
    print(int(sum_t-min(ans)))

else:
    for i in range(n-1):
        tmp += t[i]
    print(tmp)

Submission status: Accepted

Solution code:
n,l = list(map(int,input().split()))
n_l = []
for i in range(n):
    n_l.append(i+l)
    
min_i = n_l[0]
for i in n_l:
    if abs(i) < abs(min_i):
        min_i = i

print(sum(n_l) - min_i)

Submission status: Accepted

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

taste_list = [L + i for i in range(N)]
taste_abs_list = [abs(n) for n in taste_list]
abs_min = min(taste_abs_list)
min_idx = taste_abs_list.index(abs_min)
total_sum = sum(taste_list)

ans = total_sum - taste_list[min_idx]
print(ans)