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()))
A = [None for _ in range(N)]
#食べるリンゴは絶対値が最も小さいリンゴであるので絶対値が最小のリンゴを求め、その味をMに記録
m = float('inf')
M = 0
for i in range(N):
  A[i] = L + i
  if m > abs(A[i]):
    m = abs(A[i])
    M = A[i] 
#結果
print(sum(A) - M)

Submission status: Accepted

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

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

Submission status: Accepted

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

sm = sum(range(L, L+N))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):
    return map(type,input().split())

#%%code

def resolve():
    N,k=pin()
    original=(range(k,k+N))
    temp=0
    min=1000000
    for o in original:
        temp=o
        if min**2>temp**2:
            min=temp
    #print(tuple(original),len(original))
    print(sum(original)-min)
#%%submit!
resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, L = map(int,input().split())
A = [L+k for k in range(N)]
t = 10**9
for e in A:
    if abs(e) < abs(t):
        t = e
print(sum(A)-t)

Submission status: Accepted

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

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

Submission status: Accepted

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

if int(a_list[n-1])<0:
    a_list.remove(a_list[n-1])

if int(a_list[0])>0:
    a_list.remove(a_list[0])

if 0 in a_list:
    a_list.remove(0)
'''
エラーコード    if int(a_list[n])<0:
               IndexError: list index out of range
if int(a_list[n-2])<0:
    a_list.remove(a_list[n-1])
'''
print(sum(a_list))

Submission status: Accepted

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

for i in range(1,N+1):
    l.append(i)
for i in range(len(l)):

    (l[i])=L+(i+1)-1

if l[0]>0 and l[len(l)-1]>0:
    l.remove(l[0])
elif l[0]<0 and l[len(l)-1]<0:
    l.remove(l[len(l)-1])
else:
    l.remove(0) 

print(sum(l))

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
al = sum(L + i for i in range(N))
ans = 0
m = None
for i in range(N):
    x = al - (L + i)
    y = abs(al - x)
    if m is None or y < m:
        m = y
        ans = x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n,l = map(int,input().split())
t = []
ans = []
w = []
diff = []

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

for i in range(n):
    ans = t.copy()
    del ans[i]
    w.append(sum(ans))
    diff.append(abs(sum(t)-sum(ans)))

num = diff.index(min(diff))

print(w[num])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())

A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""
import numpy as np

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

arr = np.arange(1, N+1)
taste = arr + L - 1
total = sum(taste)

min_sa = INF
ans = 0
for a in taste:
    ext = total - a
    sa = abs(total - ext)
    if min_sa > sa:
        ans = ext
        min_sa = sa

print(ans)


# def main():

# if __name__ == '__main__':
#     main()

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,l = map(int, input().split())
    a = []
    for i in range(n):
        a.append(l+i)
    b = 10**10
    for i in range(n):
        if b>abs(a[i]):
            b = abs(a[i])
            c = a[i]
    print(sum(a)-c)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,l = map(int, input().split())
a = 10000
b = 0
for i in range(n):
    if (abs(l+i) < a):
        a = abs(l+i)
        b = l+i
ma = l*n + (0+(n-1))*n//2    

print(ma-b)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n,l=map(int,input().split())
li=[]
for i in range(n):
  li.append(l+i)
s=sum(li)
p=np.array(li)
a=np.abs(p).tolist()
k=min(a)
b=a.index(k)
print(s-li[b])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, l = map(int, input().split())

li = list(i for i in range(1, n+1, 1))
ab = 10000
ans = 0

for i in li:
  if abs(l + i - 1) < ab:
    ab = abs(l + i - 1)
    ans = l + i - 1

su = sum(li) + n * l - n

print(su - ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
apple_sum = n * (2 * l + n - 1) // 2
ate_apple = []
num = 0
for i in range(n):
    ate_apple.append(l + i)
for i in range(1, n):
    if abs(ate_apple[i - 1]) > abs(ate_apple[i]):
        num = i
print(apple_sum - ate_apple[num])

Submission status: Accepted

Solution code:



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

l = a
r = n + a -1

if r <= 0:
    eat = r
elif l >= 0:
    eat = l
else:
    eat = 0

ans = (r + l) * (r - l + 1) / 2 - eat
print(int(ans))

Submission status: Accepted

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

R = [L + i - 1 for i in range(1, N + 1)]
# print(R)

abs_R = [abs(i) for i in R]
# print(abs_R)
idx = abs_R.index(min(abs_R))
# print(idx)
ans = 0
for i, r in enumerate(R):
    if i == idx:
        continue
    ans += r
print(ans)

Submission status: Accepted

Solution code:
# ABC 131: B – Bite Eating
N, L = [int(s) for s in input().split()]
tastes = [L + i - 1 for i in range(1, N + 1)]

index = 0
taste = 500

for i in range(N):
    if abs(tastes[i]) < taste:
        index = i
        taste = abs(tastes[i])

tastes.pop(index)
print(sum(tastes))

Submission status: Accepted

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

taste = list(range(1, N+1))
for a in range(0, N):
    taste[a] = taste[a] + L - 1

abs_taste = copy.deepcopy(taste)

for a in range(0, N):
    abs_taste[a] = abs(abs_taste[a])

taste.pop(abs_taste.index(min(abs_taste)))


print(sum(taste))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()
aa = []
sum = 0

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

aa.sort(key = lambda x:x[1])

remove = L + aa[0][0] - 1

print(sum-remove)

Submission status: Accepted

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

aji = (l + l+n-1)*(n/2)

if l >= 0 :
    ans = aji - l
elif l < 0 and l+n <= 0 :
    ans = aji - (l+n-1)
else :
    ans = aji

print(int(ans))

Submission status: Accepted

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, L = il()
    R = range(L, L+N)
    mi = float('inf')
    sm = 0
    for n in R:
        mi = min(mi, abs(n))
        sm += n
    print(sm - mi if sm > 0 else sm + mi)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

min=100
sum=0
for i in range(1,N+1):
  if abs(L+i-1)<=abs(min):
    min= L+i-1
  sum += L+i-1 
  #print(i,L+i-1,sum)
sum -= min

print(sum)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n,l=map(int,input().split())
    s=n*(l-1)+n*(n+1)//2
    smin=200*200
    for i in range(1,n+1):
        ss=abs((l+i-1))
#        print(ss)
        if smin>ss:
            smin=ss
            sv=s-(l+i-1)
#            print("sv",sv,"ss",ss)
    print(sv)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
NL = [int(i)+L-1 for i in range(1,N+1)]
SNL = sum(NL)
ate = 10**18
count = 0
for i in range(N):
  ate = min(ate,abs(NL[i]))
  if ate == abs(NL[i]):
    count = i
print(SNL-NL[count])

Submission status: Accepted

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, L = map(int, readline().split())
  A = [L+i-1 for i in range(1, N+1)]
  S = sum(A)
  diff = INF
  ans = 0
  for i in range(N):
    x = S - A[i]
    d = abs(S-x)
    if d<diff:
      diff = d
      ans = x
  
  
  print(ans)
  
  
  
  
      
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def main():
    N, L = map(int, input().split())
    apple = [ L + i - 1 for i in range(1, N + 1)]
    taste = 0
    tmin = 10**9
    t = sum(apple)
    for i in range(N):
        eat = 0
        for j in range(N):
            if j != i:
                eat += apple[j]
        if abs(eat - t) < tmin:
            tmin = abs(eat - t)
            taste = eat
    print(taste)
main()

Submission status: Accepted

Solution code:
def resolve():
    n, l = map(int, input().split())
    alist =[l+i for i in range(n)]
    total = sum(alist)
    minimum = 10000
    j = 0
    for i in range(n):
        diff = abs(alist[i])
        if minimum > diff:
            minimum = diff
            j = i
    print(total-alist[j])
resolve()

Submission status: Accepted

Solution code:
n, l = map(int,input().split())
r = []
for i in range(1,n+1):
  r.append( l + i - 1 )
for i in range(400):
  for j in range(n):
    if abs(r[j]) == i:
      print(sum(r)-int(r[j]))
      exit()

Submission status: Accepted

Solution code:
n,l=map(int,input().split())
taste=[l+i-1 for i in range(1,n+1)]
b=sum(taste)
x=0
e=float('inf')
for i in taste:
    if e>abs(i):
        e=abs(i)
        x=i

print(b-x)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

ans = 10**20
Sum = 0
for i in range(n):
    s = l+i
    if ans > abs(s):
        ans = abs(s)
        arr = s
    Sum += s
    
print(Sum-arr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mn = 1000
sums = 0
for i in range(n):
    taste = l+i
    sums += taste
    
for i in range(n):
    taste = l+i
    if mn > abs(taste):
        ans = taste
        mn = abs(taste)
print(sums-ans)

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
total = [l+(i+1)-1 for i in range(n)]
m = 100000000
for i in range(n):
    if abs(total[i]) < m:
        idx = i
        m = abs(total[i])
total.pop(idx)
print(sum(total))

Submission status: Accepted

Solution code:
n,l = [int(i) for i in input().split(' ')]
a = sorted([l+i-1 for i in range(1,n+1)])
x = 0
ab = 101
for i in a:
    if abs(i) < ab:
        ab = abs(i)
        x =  sum(a) - i

print(x)

Submission status: Accepted

Solution code:
N, L = map(int, input().split())
apples = [i + L for i in range(N)]
apple_pie = sum(apples)
ans = float('inf')
for apple in apples:
    if ans > abs(apple):
        ans = abs(apple)
        val = apple
print(sum(apples) - val)

Submission status: Accepted

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

Sum = 0

for i in range(n):
    Sum += l + i

ans = 10**18

for i in range(n):
    s = l + i
    if ans > abs(-s):
        ans = min(ans, abs(Sum-Sum-s))
        t = s

if t < 0:
    print(Sum+ans)
else:
    print(Sum-ans)

Submission status: Accepted

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

# 途中で符号が変わる
tot = N * L + N * (N - 1) // 2
if (L + N - 1) * L <= 0:
    print(tot)
# ずっと負
elif L * N - 1 < 0:
    print(tot - (L + N - 1))
# ずっと正
else:
    print(tot - L)

Submission status: Accepted

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

if 0 in u:
    print(sum(u))
elif u[-1] < 0:
    print(sum(u)-u[-1])
else:
    print(sum(u)-u[0])

Submission status: Accepted

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

a = 200
I = ""
for i in range(N):
  if abs(n[i]) < a:
    a = abs(n[i])
    I = i
print(sum(n) - n[I])

Submission status: Accepted

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

a = [(int(i)) for i in range(m, m+n)]
t=100000
ne = False
for i in range(len(a)):
    if t>abs(a[i]):
        inde = i
        t=abs(a[i])
a[inde]=0
print(sum(a))

Submission status: Accepted

Solution code:
N,L=map(int, input().split())
sm=0
mn=10**10
mn2=0
for i in range(N):
    sm += L+i
    if mn > abs(L+i):
        mn = abs(L+i)
        mn2 = L+i
print(sm-mn2)

Submission status: Accepted

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

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

cur = 10**18
temp = 0
for i in range(n):
    temp = s - (l+(i+1)-1)
    if abs(temp-s) <= cur:
        ans = temp
        cur = abs(temp-s)
#print(s)
print(ans)

Submission status: Accepted

Solution code:
INF = 1001001001

def resolve():
  n, l = map(int, input().split())
  base = 0
  for i in range(1, n+1):
    base += l + i - 1

  ans = 0
  sa = INF

  for i in range(1, n+1):
    tmp = base - (l + i - 1)
    if abs(base - tmp) <= sa:
      ans = tmp
      sa = abs(base - tmp)
  print(ans)
  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
m = 10**10
j = 0
s = 0
for i in range(n):
    a = abs(l+i)
    s += l+i
    if a < m:
        m = a
        j = i
print(s-(l+j))

Submission status: Accepted

Solution code:
def main():
    N, L = (int(i) for i in input().split())
    s = sum(L + i for i in range(N))
    mi = 10**9
    ans = -1
    for i in range(N):
        eat = L + i
        if abs(eat) < mi:
            mi = abs(eat)
            ans = s - eat
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    n,l = map(int,input().split())
    mn = 10**10
    s = 0
    for i in range(n):
        s+=l+i
        if abs(mn)>abs(l+i):
            mn = l+i
    print(s-mn)
if __name__=='__main__':
    solve()

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N, L = map(int, input().split())
    sumT, minT = 0, 100000000000
    pm = 0
    for i in range(N):
        sumT += L + i
        if abs(L + i) < minT:
            minT = abs(L + i)
            if L + i < 0: pm = 1
    print(sumT - minT * (-1) ** pm)
        

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

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

apples.sort(key=lambda x: abs(x))

print(sum(apples) - apples[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
N,L=list(map(int,stdin.readline().strip().split()))
taste=L-1
apple_list=[]
min=3000
j=0
for i in range(1,N+1):
    apple_list.append(taste+i)
    if min>abs(taste+i):
        min=abs(taste+i)
        j=i-1
apple=sum(apple_list)
print(apple-(apple_list[j]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

k = (l + (l + n - 1)) * n // 2

a = float("inf")
v = 0
for i in range(l, l+n):
    if a > abs(i):
        v = i
        a = abs(i)

print(k - v)

Submission status: Accepted

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

for i in range(1, N+1):
    d=L+i-1
    if i==k:
        pass
    else:
        ans+=d
print(ans)

Submission status: Accepted

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

print(apple)

Submission status: Accepted

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

idx=taste_abs.index(min(taste_abs))
del taste[idx]
print(sum(taste))

Submission status: Accepted

Solution code:
import math
N,L = map(int,input().split())
r = []
total=0
abs_min = 100100100100
max_applepay=0
for i in range(1,N+1):
  r.append(L+i-1)
all_applepay=sum(r)
for i in range(N):
  for j in range(N):
    if j != i:
      total+=r[j]
  if abs(all_applepay-(total)) < abs_min:
    abs_min = abs(all_applepay-(total))
    max_applepay = total
  total=0
print(max_applepay)

Submission status: Accepted

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

taste = l * n + (n - 1) * n // 2

mini = 10 ** 9
for i in range(n):
    temp = l + i
    if abs(mini) > abs(temp):mini = temp
print(taste - mini)

Submission status: Accepted

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

A = [L + i for i in range(N)]
A.sort(key=lambda a: abs(a))

print(sum(A) - A[0])

Submission status: Accepted

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

    apples = range(L, L + N)

    ans = sum(apples)
    if apples[0] * apples[-1] <= 0:
        # 区間に0を含むので, それを食べればよい
        pass
    else:
        # 以後, 区間の両端の積は正なので, 区間内の符号はすべて等しい
        if apples[0] > 0:
            # すべて正なので, apples[0]が絶対値最小で最適
            ans -= apples[0]
        else:
            # すべて負なので, apples[-1]が絶対値最小で最適
            ans -= apples[-1]
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

    e = sorted((x + L for x in range(N)), key=lambda x: abs(x))
    ans = N * L + (N - 1) * N // 2 - e[0]
    print(ans)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

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

Ringo = [0]*n

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

aji = sum(Ringo)
minv = 100000000000
ans = 0
for i in range(n):
    temp_aji = 0
    if i == 0:
        for j in range(1,n):
            temp_aji += Ringo[j]
    elif i == n-1:
        for j in range(n-1):
            temp_aji += Ringo[j]
    else:
        for j in range(0,i):
            temp_aji += Ringo[j]
        for j in range(i+1,n):
            temp_aji += Ringo[j]
    if abs(aji -temp_aji)  < minv:
        minv = abs(aji - temp_aji)
        ans = temp_aji
    

print(ans)

Submission status: Accepted

Solution code:
N,L = map(int,input().split())
A = 0
cnt = 0
M = []

for i in range(1,N+1):
    A = L+i-1
    M.append(A)
    if A == 0:
        cnt += 1

B = sum(M)

if cnt == 1:
    print(B)
elif B > 0:
    print(B - min(M))
else:
    print(B - max(M))

Submission status: Accepted

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

s=sum(ap)
ans=100000
idx=0
for i,a in enumerate(ap):
  if abs(a)<=ans:
    ans=abs(a)
    idx=i

print(s-ap[idx])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

all_taste = 0
taste_list = []
minimum = L + N - 1

for i in range(1, N+1, 1):
  all_taste += L + i - 1
  taste_list.append(L + i - 1)
else:
  for i in range(N):
    if abs(taste_list[i]) < abs(minimum):
      minimum = taste_list[i]
  else:
    print(all_taste - minimum)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, l = map(int,input().split())

taste = [l + i - 1 for i in range(1, n + 1)]
taste.sort()
ans = 1000
for i in taste:
    if abs(i) < abs(ans):
        ans = i
print(sum(taste) - ans)

Submission status: Accepted

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


print(sum(l)-l[l_abs.index(min(l_abs))])

Submission status: Accepted

Solution code:
n,l  =map(int,input().split())
apples = [l+i-1 for i in range(1,n+1) ]
ideal= sum(apples)
res = 10**9
for x in apples:
    v = ideal - x
    if res > abs(v-ideal):
        res = abs(v-ideal)
        ans = v

    
    

print(ans)

Submission status: Accepted

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

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

abs_apple = 1000
total = sum(apples)
for i in apples:
    if abs(i) < abs_apple:
        abs_apple = abs(i)
        ans = total - i

print(ans)

Submission status: Accepted

Solution code:
N, L=map(int, input().split())
SUM=0
now=1000
for i in range(N):
  SUM+=L+i
  if abs(L+i)<abs(now):
    now=L+i
  #print(L+i)
  
print(SUM-now)

Submission status: Accepted

Solution code:
import numpy as np

def resolve():
  n, l = map(int, input().split())
  arr = []
  for i in range(n):
    arr.append(i + l)

  yotei = sum(arr)
  ans = abs(yotei - arr[0])
  sa = abs(yotei - (yotei - arr[0]))

  for i in range(n):
    if (sa > abs(yotei - (yotei - arr[i]))):
      sa = abs(yotei - (yotei - arr[i]))
      ans = yotei - arr[i]

  print(ans)

  return

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,l = map(int,input().split())
mn = 1000
for i in range(1,n+1):
    ans = l+i-1
    if abs(ans)<abs(mn):
        ans1 = ans
        mn = min(abs(mn),abs(ans))
ans2 = 0      
for j in range(1,n+1):
    ans2 += (l+j-1)
print(ans2-ans1)

Submission status: Accepted

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

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

Submission status: Accepted

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

eat=400
sum=0

for i in range(1,N+1):
    sum+=L+i-1
    if abs(eat)>abs(L+i-1):
        eat=L+i-1

print(sum-eat)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, l = map(int, input().split())
z = 10**8
j = 0
s = 0
for i in range(n):
    s += l+i
    if abs(l+i) < z:
        z = abs(l+i)
        j = i
print(s-(l+j))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,l = inpl()
mi = INF
a = [i+l for i in range(n)]
no = -1
for i in range(n):
    if abs(a[i]) < mi:
        no = i
        mi = abs(a[i])
# print(no)
print(sum(x for i,x in enumerate(a) if i != no))

Submission status: Accepted

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

Submission status: Accepted

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

A = [0]*N
B = [0]*N

for i in range (0, N):
	A[i] = L+i
	B[i] = abs(L+i)

min = A[B.index(min(B))]

print(sum(A)-min)

Submission status: Accepted

Solution code:
def main():
    N, L = (int(i) for i in input().split())
    s = sum(L+i-1 for i in range(1, N+1))
    mi = 10**5
    ans = -1
    for i in range(1, N+1):
        cur = L + i - 1
        eat = s - cur
        if abs(s - eat) < mi:
            mi = abs(s - eat)
            ans = eat
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import *
from heapq import *
import sys

sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
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()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
dij = [(1, 0), (-1, 0), (0, 1), (0, -1)]


def main():
    n,l=MI()
    aa=[i+l for i in range(n)]
    print(sum(aa)-min(aa,key=lambda x:abs(x)))

main()