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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))

n,l = m()

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

co = Max
for i in range(n):
    if abs(co) >= abs(k[i]):
        co = k[i]

print(sum(k) - co)

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

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

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

Solution (Python):
N, L = map(int, input().split())
a = [x+L for x in range(N)]
print(sum(a) - min(a, key=lambda x:abs(x)))

Solution (Python):
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n, l = input_ints()
    a = [x for x in range(l, l + n)]
    ans = sum(a)
    if a[-1] < 0:
        ans -= a[-1]
    if a[0] > 0:
        ans -= a[0]
    print(ans)

if __name__ == '__main__':
    main()

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

ref = 0
for i in range(N):
    ref += L+i
th = 2 ** 30  - 1
for i in range(N):
    tmp = 0
    for j in range(N):
        if i == j:continue
        tmp += L + j
    
    if abs(tmp - ref) < th:
        ans = tmp
        th = abs(tmp-ref)
        
print(ans)

Solution (Python):
n,l=map(int,input().split())
a=[l+i for i in range(n)]
b=[abs(l+i) for i in range(n)]
b.sort()
m=b[0]
if not m in a:m*=-1
print(sum(a)-m)

Solution (Python):










import sys
import os
from io import IOBase, BytesIO


def main():
    n, l = get_ints()
    arr = [0] * n
    for i in range(n):
        arr[i] = l + i
    arr.sort()
    
    tmp = [(abs(arr[i]), i) for i in range(n)]
    tmp.sort()
    
    ans = 0
    for i in range(1, n):
        ans += arr[tmp[i][1]]
    print(ans)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode("ascii"))
            self.read = lambda: self.buffer.read().decode("ascii")
            self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


def input(): return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Solution (Python):
n,l = map(int,input().split())
aji = [ l + i - 1 for i in range(1,n+1) ]
Aji = [ abs(l + i - 1) for i in range(1,n+1) ]
Aji.sort()
try:
    i = aji.index(Aji[0])
except:
    i = aji.index(-Aji[0])
del aji[i]
print(sum(aji))

Solution (Python):

def gcd_core(a, b):
    if b == 0:
        return a
    else:
        return gcd_core(b, a % b)


def gcd(arr):
    g = gcd_core(arr[0], arr[1])
    for i in range(2, len(arr)):
        g = gcd_core(g, arr[i])
    return g

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


abm = 100000000000000
index = 0
for i in range(n):
    if abs(apple[i]) < abm:
        index = i
        abm = abs(apple[i])



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

Solution (Python):
p=input().rstrip().split(' ')
N=int(p[0])
L=int(p[1])
l=[]
q=[]
w=[]
S=[]
D=[]
x=0;
for i in range(1,N+1):
    l.append(i)
    q.append(L+i-1)
    x=x+(L+i-1)
for i in range(0,len(q)):
    T=0;
    for j in range(0,len(q)):
        if i!=j:
            T+=q[j]
    S.append(abs(T-x))
    D.append(T)
C=min(S)
print(D[S.index(C)])

Solution (Python):

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


low = 9999
ans = 0
for i in range(n):
    taste = l+i
    low = min(taste, abs(low))
    ans += taste


print(ans - low)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N, L = map(int, input().split())

    ans = 10**4
    total = 0
    for i in range(N):
        total += L + i
        if abs(L+i) <= abs(ans):
            ans = L + i

    return total - ans


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

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

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

mi = 10*100
k = 0
for i in range(N):
    if mi > abs(a[i]):
        mi = abs(a[i])
        k = i

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

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

l = []
ll = []

for i in range(N):
    l.append(L + i)
    ll.append(abs(L + i))
    

ans = sum(l)
a = ll.index(min(ll))
print(ans - l[a])

Solution (Python):
N, L = map(int, input().split())
T = [ L + i for i in range(N)]
sumT = sum(T)

if 0 in T:
    print(sumT)
else:
    if T[0] > 0:
        print(sumT - T[0])
    else:
        print(sumT - T[-1])

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

li = [l+i for i in range(n)] 
lia = [abs(l+i) for i in range(n)]
ind = lia.index(min(lia))
print(sum(li)-li[ind])

Solution (Python):
N,L = map(int,input().split(" "))
A = [L+x-1 for x in range(1,N+1)]
s = sum(A)
B = [s - A[x] for x in range(N)]
print(min(B,key=lambda x:abs(s-x)))

Solution (Python):
N, L = map(int, input().split())
M = L + N - 1

if M < 0:
  print(sum(list(range(L, M))))
elif L > 0:
  print(sum(list(range(L+1, M+1))))
else:
  print(sum(list(range(L, M+1))))

Solution (Python):
n,l = map(int,input().split())
a = []
for i in range(n):
  a.append(l+i)
b = list(map(abs,a))
m = min(b)
for i in range(n):
  if abs(a[i])==m:
    del a[i]
    break
print(sum(a))

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

apple = []
for i in range(N):
    apple.append(L+i)
if apple[0] * apple[-1] < 0:
    print(sum(apple))
elif apple[0] < 0:
    print(sum(apple[:N-1]))
else:
    print(sum(apple[1:]))

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

apples = []

abs_min = 10**10
isPlus = True
for i in range(1,N+1):
    now = i+L-1
    apples.append(i+L-1)
    if abs_min > abs(now):
        abs_min = min(abs_min,abs(now))
        if now>=0:
            isPlus = True
        else:
            isPlus = False


if not isPlus:
    abs_min *= -1
    
print(sum(apples) - abs_min)

Solution (Python):
n, start = list(map(int, input().split() ))

end = start + n - 1
sumall = (start + end ) * n // 2

ans = -(10**10)
for i in range(n):
	exclude = start + i
	if abs(exclude) < abs(ans - sumall):
		ans = sumall - exclude

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

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

mi = INTMAX
hikuyatsu = 0
for i in AJI:
    if mi > abs(i):
        mi = abs(i)
        hikuyatsu = i


print(sum(AJI)-hikuyatsu)

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

value = L
sum = 0
for i in range(N):
  now = L+i
  sum = sum + now
  if abs(now) < abs(value):
    value = now

print(sum-value)

Solution (Python):

import sys


def solve(N: int, L: int):
    S = N * L + N * (N - 1) // 2
    if L <= 0 and N + L -1 >= 0:
        print(S)
    elif L > 0:
        print(S-L)
    else:
        print(S-(N + L - 1))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N,L = na()

ans = 10**9
before = 0
t =0
for i in range(N):
    before += L+i
    if ans > abs(L+i):
        ans = min(ans,abs(L+i))
        t = L+i

print(before - t)

Solution (Python):
n, l = [int(i) for i in input().split()]
num = 0
a = []
for i in range(n):
  num += i + l
  a.append(i+l)
if(l >= 0):
  ans = num - min(a)
  print(ans)
else:
  if(max(a) >= 0):
    print(num)
  else:
    ans = num - max(a)
    print(ans)

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

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

ALL_TASTE = sum(Apples)
min_diff = float('inf')
ans = 0
for apple in Apples:
    taste = ALL_TASTE - apple
    if min_diff > abs(ALL_TASTE - taste):
        min_diff = abs(ALL_TASTE - taste)
        ans = taste

print(ans)

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

Solution (Python):
N, L = map(int,input().split())
ans = N*(2*L+N-1)//2
first = L
final = L+N-1
if first * final <= 0:
  print(ans)
else:
  if abs(first) < abs(final):
    print(ans - first)
  else:
    print(ans - final)

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

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

Solution (Python):
n,l = map(int,input().split())
id = 0
ans = 0
for i in range(n):
    ans+=l+i
    if abs(l+id)>abs(l+i):
        id = i
print(ans-l-id)

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

li = []
for i in range(N):
  li.append(L+i)
  
su = sum(li)
d = 10000000000000
s = 0
for i in range(N):
  if ( abs( su - li[i] - su)<d ):
    d = abs(su - li[i] - su)
    s = su - li[i]
print ( s )

Solution (Python):
N, L = map(int, input().split())
f = 0
for i in range(N):
    f += L + i

memo = 10**9
for i in range(N):
    s = 0
    for j in range(N):
        if j != i:
            s += L + j
    if abs(f - s) < memo:
        memo = abs(f - s)
        res = s
    

print(res)

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

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

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

print(sum(l[1:]))

Solution (Python):
import math

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

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

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

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

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

tmp = 1000
ind = 0
for i in range(N):
    if tmp > abs(A[i]):
        tmp = abs(A[i])
        ind = i
print(sum(A)-A[ind])

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

choice = abs(aji[0])
m_i = 0
for i, score in enumerate(aji):
    if choice >= abs(score):
        choice = abs(score)
        m_i = i
ans = sum(aji) - aji[m_i]
print(ans)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n, l = map(int, input().split())
    tot = n * l + (n * (n - 1) >> 1)

    res, m = 0, float('inf')
    for i in range(n):
        pie = tot - (l + i)
        if abs(pie - tot) < m:
            m = abs(pie - tot)
            res = pie

    print(res)




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):

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

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

ans = 10**6
idx = -1
for i in range(1,n+1):
    s2 = s - (l+i-1)
    if abs(s-s2)<ans:
        ans = abs(s-s2)
        idx = i

print(s-(l+idx-1))

Solution (Python):
n, L = map(int, input().split())
a = [L + i - 1 for i in range(1, n + 1)]
ans = 0
eat = float("inf")
for i in a:
    if abs(eat) > abs(i):
        eat = i
print(sum(a) - eat)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    print(sum(f) - min(f, key=lambda x: abs(0 - x)))




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
N,L = map(int,input().split())
plan = 0
for i in range(N):
        plan += L + i
diff = 10000000
ans = -1
for i in range(N):
        actual = 0
        for j in range(N):
                if i != j:
                        actual += L + j
        if abs(plan-actual) < diff:
                diff = abs(plan-actual)
                ans = actual

print(ans)

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

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

Solution (Python):
def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


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

Solution (Python):


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



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


apple = [x + L - 1 for x in range(1, N + 1)]
apple.sort(key=lambda x : abs(x))
print(sum(apple[1:]))

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

A = [L + i - 1 for i in range(1, N+1)]
A = sorted(A, key=lambda x:abs(x))[1:]

print(sum(A))

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

temp1 = [10**9] + [abs(l + i - 1) for i in range(1,n+1)]
temp2 = [10**9] + [l + i - 1 for i in range(1,n+1)]

ans = temp1.index(min(temp1))
print(sum(temp2[1:]) - temp2[ans])

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

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

a = list(range(L, L + N))
sa = sum(a)
if a[0] * a[-1] <= 0:
    print(sa)
else:
    if a[0] < 0:
        print(sa - a[-1])
    else:
        print(sa - a[0])

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

import numpy as np
taste = np.arange(n)
taste = taste + l

idx = np.argmin(np.abs(taste))

s = 0
for i in range(n):
    if i != idx:
        s += taste[i]

print(s)

Solution (Python):
N,L=map(int,input().split())
a=[L+i-1 for i in range(1,N+1)]
mina=min([abs(L+i-1) for i in range(1,N+1)])
if mina not in a:
    mina=-mina
print(sum(a)-mina)

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

taste = []

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

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

print(sum(taste[1:]))

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

  
if(hoge.count(0)==1):
  ans=0
elif(sum(hoge)>0):
  ans=min(hoge)
else:
  ans=max(hoge)

print(sum(hoge)-ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, L):
    t = [L + i-1 for i in range(1, N+1)]
    b = sys.maxsize
    for c in t:
        if abs(c) < abs(b):
            b = c
    return sum(t) - b


def main():
    N, L = read_int_n()
    print(slv(N, L))


if __name__ == '__main__':
    main()

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, L: int):
    s = N*L+N*(N+1)//2-N
    s -= min([L-1+i for i in range(1, N+1)], key=lambda x: abs(x))
    print(s)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
sys.setrecursionlimit(300000)


def solve(N: int, L: int):
    s = L * N + sum(list(range(N + 1))) - N
    mn = float('inf')
    ret = float('inf')
    for i in range(1, N + 1):
        t = L + i - 1
        tmp = abs(s - (s - t))
        if tmp < mn:
            ret = s - t
            mn = tmp
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  
    solve(N, L)

if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, L = MAP()
    aji = 0
    minv = inf
    minv_ = 0
    for i in range(N):
        aji += L + i
        if abs(L + i) < minv:
            minv = abs(L + i)
            minv_ = L + i
    print(aji - minv_)

if __name__ == '__main__':
    main()

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, L = nl()

min_aji = 1000
min_aji_real = 1000
total = 0
for i in range(N):
    total += L + i
    if abs(L + i) < min_aji:
        min_aji = abs(L + i)
        min_aji_real = L + i

print(total - min_aji_real)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,L = inpl()
ans = 0
MIN = INF
for i in range(N):
    x = L + i
    ans += x

if L >= 0:
    print(ans-L)
else:
    if abs(L) < N:
        print(ans)
    else:
        print(ans-x)

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N, L = map(int, input().split())
    apples = [L + i for i in range(N)]
    total = sum(apples)

    rm = 0
    if apples[0] >= 0:
        rm = apples[0]
    else:
        for i in range(N):
            rm = apples[i]
            if rm == 0:
                break
    total -= rm
    print(total)


if __name__ == '__main__':
    main()

Solution (Python):
N,L = (int(x) for x in input().split())

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

print(sum(range(L, L+N))-eat)

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

diff = 10**9
min_idx = -1
for i in range(N):
    _diff = abs(L + i)
    if _diff < diff:
        diff = _diff
        min_idx = i

ans = sum([L+i for i in range(N)]) - (L+min_idx)
print(ans)

Solution (Python):
N,L = list(map(int, input().split()))
S = L*N + N*(N-1)//2

if L+N-1 < 0:
  print(S - (L+N-1))
elif 0 < L:
  print(S-L)
else:
  print(S)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()

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


for i in apple:
	if i == 0:
		print(sum(apple))
		break
else:  
	if max(apple) > 0:
		print(sum(apple)-min(apple))
	else:
		print(sum(apple)-max(apple))

Solution (Python):
n, l = map(int, input().split())
s = sum(l + i for i in range(n))
res = min((abs(l + i), i) for i in range(n))
print(s - l - res[1])

Solution (Python):
N, L = map(int, input().split())
rng = []
for i in range(N):
    rng.append(L + i)
minimini = 1000000000000
mini = 100000000000
for i in rng:
    if minimini > abs(i):
        mini = i
        minimini = abs(i)

print(sum(rng) - mini)

Solution (Python):



(N,M) = (int(i) for i in input().split(" "))

K = N*(N-1)/2
K += M*N
K = int(K)
if M <=0 and N+M-1>=0:
	print(K)
elif M > 0:
	print(K-M)
else:
	print(K-N-M+1)

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


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


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,l = get_nums_l()

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

Solution (Python):
import numpy as np
N, L =  list(map(int, input().split()))
r = np.arange(L, N + L)
print(np.sum(r) - r[np.argmin(np.abs(r))])

Solution (Python):
import numpy as np

def main():
    N, L = map(int, input().split())
    aji = [L+i-1 for i in range(1, N+1)]
    absaji = list(map(abs, aji))

    i = np.argmin(absaji)

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


if __name__ == '__main__':
    main()

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

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

if tastes[0] * tastes[-1] <= 0:
    print(sum(tastes))
else:
    if min(tastes) < 0:
        print(sum(tastes) - tastes[-1])
    else:
        print(sum(tastes) - tastes[0])

Solution (Python):
def main():
    N, L = map(int, input().split())
    T = list(range(L, L+N))
    m = float("inf")
    x = float("inf")
    for t in T:
        if abs(t) < m:
            m = abs(t)
            x = t
    print(sum(T) - x)


if __name__ == "__main__":
    main()

Solution (Python):
n,L=map(int,input().split())
l=[]
l2=[]
for i in range(n):
  l.append(L+i)
  l2.append(abs(L+i))
x=l2.index(min(l2))
print(sum(l)-l[x])

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

if L <= 0 and L+N > 0:
    d = 0
else:
    d = min((abs(L),L), (abs(L+N-1),L+N-1))[1]

print(sum(range(L,L+N)) - d)

Solution (Python):

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

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

answer = sum(A[1:])
print(answer)