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):
N, L = map(int, input().split())

apple = [(abs(L+i-1), L+i-1) for i  in range(1, N+1)]
apple = sorted(apple)


ans = 0
for a in apple[1:]:
    ans += a[1]
print(ans)

Solution (Python):
inf = input().split()
N = int(inf[0])
L = int(inf[1])
ans = L*N+N*(N-1)//2
m = L*N
for i in range(N):
  if abs(L+i)<abs(m):
    m = L+i

print(ans-m)

Solution (Python):
n,k=map(int, input().split())
lin=[k+i for i in range(n)]
ablin=[abs(i) for i in lin]

print(sum(lin)-lin[ablin.index(min(ablin))])

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

n = 10**20
for a in x:
    if abs(a) < abs(n):
        n = a

print(total-n)

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

ans=0

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

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

Solution (Python):
n, l = map(int, input().split())
ans = 1000000000
r = []
for i in range(n):
    r.append(l+i)
total = sum(r)
for i in r:
    if(abs(i) < abs(ans)):
        ans = i
print(total - ans)

Solution (Python):


def solve(n, l):
	minaji = 9999999999
	res = -1
	for i in range(n):
		aji = i + l
		if abs(aji) < minaji:
			minaji = abs(aji);
			res = i
	sumaji = 0
	for i in range(n):
		aji = i + l
		if i != res:
			sumaji = sumaji + aji
	return sumaji


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

Solution (Python):

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

Vs=[0]*N
for i in range(N):
    Vs[i] = L+i

sumv = sum(Vs)

minv = 999999
v = 0
for i in range(N):
    t = sumv-Vs[i]
    d = abs(sumv-t)
    if d<minv:
        minv = d
        v = t
print(v)

Solution (Python):



def main():
    
    N, L = map(int, input().split())
    ans = 0
    min_azi = 101
    min_i = 0
    for i in range(1, N+1):
        temp = abs(L+i-1)
        
        if min_azi > temp:
            min_azi = temp
            min_i = i

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


import sys

n, l = [ int(x) for x in sys.stdin.readline().split() ]

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

if l-1<0: s-= min(1-l,n)
else: s-=1

print( s )

Solution (Python):
N, L = [int(i) for i in input().split()]
A = list(range(L, L + N))
su = sum(A)

ans = su - A[0]
mi = abs(A[0])
for a in A:
    if mi > abs(a):
        ans = su - a
        mi = abs(a)
print(ans)

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

solve()

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

sum = 0
min = 100000
min2 = 0
for i in range(0, N):
    aji = L+i
    sum += aji
    if(abs(aji) < min):
        min = abs(aji)
        min2 = aji

print(sum - min2)

Solution (Python):
n,L= map(int,input().split())
u = [i+L for i in range(n)]
a = 100000000
for i in u:
    a = min(a,abs(i))
    if a == abs(i):
        b = i
u.remove(b)
print(sum(u))

Solution (Python):
N, L = map(int, input().split())
apples = [L + i for i in range(N)]
_, idx = min([(abs(a), i) for i, a in enumerate(apples)])
print(sum([a for i, a in enumerate(apples) if i != idx]))

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


if __name__ == "__main__":
    main()

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

ans = 0
lst = []
for i in range(N):
    lst += [[abs(L + (i+1) -1), L + (i+1) -1]]
    ans += L + (i+1) -1

lst.sort()

print (ans - lst[0][1])

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

start = L
end = L + N - 1

def aji(n):
    return n * (n+1) // 2

if start * end <= 0:
    print(aji(N-1) + L * N)
elif start > 0:
    print(aji(N-1) + L * (N-1))
elif end < 0:
    print(aji(N-2) + L * (N-1))

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

Solution (Python):
n,l=map(int,input().split())
tot=l*n+n*(n-1)//2
a=float("inf")
ans=0
for i in range(n):
  if a>abs(l+i):
    a=abs(l+i)
    ans=i
print(tot-(l+ans))

Solution (Python):

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

Solution (Python):

import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,l = f()
    fsum = sum([ l+i for i in range(n)])

    minabs = min([abs(l+i) for i in range(n)])

    for i in range(n):
        if abs(l+i) == minabs:
            print(fsum - (l+i))
            return

    


solve()

Solution (Python):
N,L=map(int,input().split())
m=3000
for i in range(1,N+1):
    if abs(m)>abs(L+i-1):
        m=L+i-1
print(N*(N+1)//2+L*N-1*N-m)

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

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

apples = []
abss = []
for i in range(0, n):
    apples.append(l + i)
    abss.append(abs(l + i))

tmp = zip(abss, apples)
tmp = sorted(tmp)
abss, apples = zip(*tmp)

after = sum(apples[1:])
print(after)

Solution (Python):

n, l = map(int, input().split())
arr = [i + l for i in range(n)]
s = sum(arr)
idx = -1
mindif = 10 ** 9
for i, a in enumerate(arr):
    if mindif > abs(a):
        mindif = abs(a)
        idx = i
print(s - arr[idx])

Solution (Python):
N , L = map(int, input().split())
sum_a = 0
min_a = 10000000

for i in range(N):
    a = L + i
    sum_a += a
    if abs(a) == min(min_a, abs(a)):
        min_a = abs(a)
        min_aa = a


print(sum_a - min_aa)

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

Solution (Python):

def solve():
    N, L = map(int, input().split())
    if L*(L+N-1) <= 0:
        return sum(L+i for i in range(N))
    elif L > 0:
        return sum(L+i for i in range(N)) - L
    else:
        return sum(L+i for i in range(N)) - ((L+N-1))

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

Solution (Python):
def getlist():
	return list(map(int, input().split()))

N, L = getlist()

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

ans = sum(a)
vv = float("inf")
v = float("inf")
for i in a:
	if abs(i) < v:
		v = abs(i)
		vv = i

print(ans - vv)

Solution (Python):
N, L = map(int, input().split())
taste = 0
for i in range(N):
  taste += L + i
ans = 0
for i in range(N):
  tmp = taste - (L + i)
  if abs(taste - tmp) < abs(taste - ans):
    ans = tmp
print(ans)

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

_, k = min((abs(L + i - 1), i) for i in range(1, N+1))
print sum(L + i - 1 for i in range(1, N+1) if i != k)

Solution (Python):
n, l = map(int, input().split())
aa = [(abs(l + i - 1), l + i - 1) for i in range(1, n + 1)]
rest = list(sorted(aa))[1:]
print(sum(map(lambda x: x[1], rest)))

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, L: int):
    ls = [L + i - 1 for i in range(1, N + 1)]
    return sum(ls) - ls[min([(abs(l), i) for i, l in enumerate(ls)])[1]]




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))  
    result = solve(N, L)
    if isinstance(result, Iterable) and not isinstance(result, str):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):


def read_input():
    n, l = map(int, input().split())

    return n, l


def submit():
    n, l = read_input()
    tastes = [l + i for i in range(n)]

    total = sum(tastes)
    left = 0
    right = total

    mindiff = abs(total) + 1
    ans = None

    for curr in tastes:
        right -= curr

        absdiff = abs(total - (left + right))
        if absdiff < mindiff:
            mindiff = absdiff
            ans = left + right

        left += curr

    print(ans)




if __name__ == '__main__':
    submit()

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

print(ans - minaji)

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

taste = [0] * N

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

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

ans = sum(taste[1:N])

print(ans)

Solution (Python):
N, L = [int(i) for i in input().split()]
taste = [L + i - 1 for i in range(1, N + 1)]
absolute = float('inf')
ans = float('inf')
total = sum(taste)
for i in range(N):
    total_b = sum(taste[:i] + taste[i + 1:])
    if abs(total - total_b) < absolute:
        ans = total_b
        absolute = abs(total - total_b)
print(ans)

Solution (Python):
N, L = map(int, input().split())
ans = 0
eat = 10 ** 9
for i in range(N):
    ans += L + i
    if abs(eat) > abs(L + i):
        eat = L + i
ans -= eat
print(ans)

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

t = [L + i - 1 for i in range(1, N + 1)]
s = sum(t)

if t[0] > 0 :
    print(s - t[0])
elif t[-1] < 0 :
    print(s - t[-1])
else :
    print(s)

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

abs_ringos=[abs(i) for i in ringos]

min_key=0
amin_ringo=99999
for i in range(len(abs_ringos)):
    if amin_ringo != min(amin_ringo,abs_ringos[i]):
        amin_ringo = abs_ringos[i]
        min_key=i

print(sum(ringos)-ringos[min_key])

Solution (Python):
N, L = map(int, input().split())
pi = []
for i in range(N):
    pi.append([L+i, abs(L+i)])
pi.sort(key=lambda x:x[1])
pi = pi[1:]
ret = 0
for p, _ in pi:
    ret += p
print(ret)

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

pos = [10000]
neg = [10000]
for a in apple:
    if a>=0:
        pos.append(a)
    else:
        neg.append(-a)
        
pos.sort()
neg.sort()

m = pos[0] if pos[0]<=neg[0] else -neg[0]

print(sum(apple) - m)

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

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

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

smallest_abs = 100000000000
elem = 0
for i in range(1, N + 1):
    if abs(L - 1 + i) < smallest_abs:
        smallest_abs = abs(L - 1 + i)
        elem = L - 1 + i

print(all_flavor - elem)

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

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())


N, L = mi()
tastes = [L+i for i in range(N)]
absmintaste = 10**9
for t in tastes:
  if abs(absmintaste) > abs(t):
    absmintaste = t

print(sum(tastes)-absmintaste)

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

Solution (Python):
n,l=map(int,input().split())
a=[]
for i in range(1,n+1):
    a.append(l+i-1) 
a.sort()
for i in range(n):
    if a[i]>=0:
        m=a[i] 
        break 
    else:
        m=a[n-1]
ans=sum(a)-m 
print(ans)

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

Solution (Python):
n,l=map(int,input().split())
taste=[l+i for i in range(n)]
absTaste=[abs(l+i) for i in range(n)]
eat=min(enumerate(absTaste),key=lambda x:x[1])[0]

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

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

N, L = map(int, input().split())
taste = [0]*N
taste2 = [0]*N

for i in range(N):
    taste[i] = L + (i+1) - 1
    taste2[i] = abs(L + (i+1) - 1)
eat = min(taste2)
taste.pop(taste2.index(eat))
print(sum(taste))

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

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

ans=sum(Good)

x=100000
for i in range(len(Good)):
    if abs(Good[i])<abs(x):
        x=Good[i]

print(ans-x)

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

Solution (Python):
N,L=(int(x) for x in input().split())
aji=[]
aji_abs=[]
for n in range(N):
    a=L+n
    aji.append(a)
    aji_abs.append(abs(a))
ba=aji_abs.index(min(aji_abs))
wa=0
for n in range(N):
    wa=wa+aji[n]
print(wa-aji[ba])

Solution (Python):


import sys
import math

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

taste = []
for i in range(n):
    taste.append(i + l)
s = sum(taste)
m = 100000000
for i in range(n):
    tmp = 0
    for j in range(n):
        if i != j:
            tmp += taste[j]
    if abs(s - tmp) < m:
        m = abs(s - tmp)
        t = tmp

print(t)

Solution (Python):
n,l=map(int,input().split())
f=[i for i in range(l,l+n)]
sf=sum(f)
s=f[0]
for i in f:
    if abs(i)<abs(s):
        s=i
print(sf-s)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)



def solve():
    n, l = map(int, input().split())

    absmn = 10**9
    mn = None
    sm = 0
    for i in range(n):
        index = i + 1
        aji = l + index - 1
        if absmn > abs(aji):
            absmn = abs(aji)
            mn = aji
        sm += aji
    dprint(sm, absmn)
    print(sm - mn)

solve()

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

print(ans-mo)

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

Solution (Python):
n, l = map(int, raw_input().split())
a, b = l, l + n - 1
s = (a + b) * n / 2


if a <= 0 and b >= 0:
    print s
elif l > 0:
    print s - a
else:
    print s - b

Solution (Python):
N,L = map(int,input().split())
T = []
for i in range(N):
  T.append(L+i)
if max(T) >= 0 and min(T) <= 0:
  print(sum(T))
else:
  if max(T) < 0:
    print(sum(T)-max(T))
  else:
    print(sum(T)-min(T))

Solution (Python):

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

S = 0
ss = L
for i in range(N):
    S += i + L
    if abs(i+L) < abs(ss):
        ss = i + L
        
print(S - ss)

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

answer=0
mi=10**9
for i in range(N):
  flabor=L+i
  if abs(flabor)<abs(mi):
    mi=flabor
  answer+=flabor
print(answer-mi)

Solution (Python):
N, L = map(int, input().split())
min_abs = 1000
for i in range(N):
    if abs(min_abs) > abs(L + i):
        min_abs = L + i
ans = 0

for i in range(N):
    if min_abs == L + i:
        continue
    ans += L + i
print(ans)

Solution (Python):

import sys


def solve(N: int, L: int):
    T = [L+i for i in range(N)]

    min_abs = float("inf")
    st = float("inf")
    for t in T:
        if min_abs > abs(t):
            min_abs = abs(t)
            st = t

    print(sum(T) - st)
    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.dont_write_bytecode = True
stdin = sys.stdin
input = stdin.readline
sys.setrecursionlimit(10000000)






import math, itertools, operator
from math import *
from math import factorial as fact
from operator import itemgetter, attrgetter
from itertools import permutations, combinations
from functools import reduce, lru_cache


from fractions import gcd
from fractions import Fraction as Frac

inf = float('inf')

def lcm(a, b):
    return a * b // gcd(a,b)

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(func = input, sep = None, conv = int):
    return list(map(conv, func().split(sep = sep)))




def main():
    N, L = list(map(int, input().split()))
    aji = [None for i in range(N)]
    for i in range(N):
        aji[i] = L + i
    mi = inf
    for i in range(N):
        if abs(aji[i]) < mi:
            mi = abs(aji[i])
            mi_real = aji[i]
    print(sum(aji) - mi_real)


if __name__ == '__main__':
    main()

Solution (Python):
def inpl(): return list(map(int, input().split()))
N, L = inpl()
S = [L+i for i in range(N)]

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

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

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

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

Solution (Python):
a,b=map(int, input().split())
arr=[]
de=9999999999999999999
denum=0
for i in range(a):
    arr.append(i+b)
    if abs(i+b)<de:
        de=abs(i+b)
        denum=i


del arr[denum]
print(sum(arr))

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

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

print(ans)

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


mn = 10**9
for i in range(N):
  if mn > abs(a[i]):
    mn = abs(a[i])
    agmn = i

sm = 0
for i in range(N):
  if i!=agmn:
    sm += a[i]


print(sm)

Solution (Python):
N, L = map(int, input().split())
taste = [0] * N

for i in range(N):
	taste[i] = (abs(L + i), L + i)
	
taste.sort()
ans = 0

for i in range(1, N):
	ans += taste[i][1]
	
print(ans)

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

j = min(
    range(1, N + 1),
    key=lambda i: abs(L + i - 1)
)
ans = sum(L + i - 1 for i in range(1, N + 1)) - (L + j - 1)

print(ans)

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

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


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


ans = taste
if 0 in apple_list:
    ans = taste
elif taste < 0:
    ans = taste - apple_list[-1]
else:
    ans = taste - apple_list[0]

print(ans)

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

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

min_idx = 0
min_abs = abs(dat[0])
for i in range(n):
    if abs(dat[i])<min_abs:
        min_abs = abs(dat[i])
        min_idx = i

print(sum(dat) - dat[min_idx])

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

n, k = [int(i) for i in input().split()]
a = []
for i in range(n):
    a.append(k+i)
temp = float('inf')
for apple in a:
    if abs(temp) > abs(apple):
        temp = apple
print(sum(a)-temp)

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

ans = 0
margin = float("inf")
for i in range(1, N + 1):

    tar = 0
    for j in range(1, N + 1):
        tar += L + j - 1

    res = 0
    for j in range(1, N + 1):
        if j == i:
            continue
        else:
            res += L + j - 1

    if abs(tar - res) < margin:
        ans = res
        margin = abs(tar - res)


print(ans)

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

a = [0] * n

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

total = sum(a)

ap = 100 * 2000

tmp = 0
for i in range(n):
    tmp = total - a[i]
    if abs(total - tmp) < ap:
        ap = abs(total - tmp)
        ans = tmp

print(ans)

Solution (Python):
N,L=map(int,input().split())
apple=[]
total=0
min_effect=0
for i in range(0,N):
    apple.append(L+i)
    total+=(L+i)
if(apple[0]*apple[N-1]<=0):
    min_effect=0
elif(apple[N-1]<0):
    min_effect=apple[N-1]
elif(apple[0]>0):
    min_effect=apple[0]
print(total-min_effect)

Solution (Python):

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

Solution (Python):
def main():
	import sys
	input = sys.stdin.readline
	N, L = map(int, input().split())
	sum = L * N + N * (N - 1) / 2
	if L >= 0:
		eat = L
	elif L + N - 1 >= 0:
		eat = 0
	else:
		eat = L + N -1
	print(int(sum - eat))

if __name__ == '__main__':
    main()

Solution (Python):
N, L = map(int, input().split())
a = []
no = L
for i in range(N):
  a.append(L+i)
  if abs(no) > abs(L+i):
    no = L+i
print(sum(a)-no)

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

Solution (Python):
N, L = map(int, input().split())
A = list(range(L, L + N, 1))
org = sum(A)
if A[0] <= 0 <= A[-1]:
  print(org)
elif A[0] <= 0:
  print(org - A[-1])
else:
  print(org - A[0])

Solution (Python):

import sys






from copy import deepcopy
















input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())



def iterate_tokens():
    for line in sys.stdin:
        for word in line.split():
            yield word


if __name__ == '__main__':

    tokens = iterate_tokens()
    N = int(next(tokens))  
    L = int(next(tokens))  

    
    A = [L + i - 1 for i in range(1, N + 1)]
    subA = deepcopy(A)
    sum_A = sum(A)
    
    A = list(map(abs, A))
    A.sort()
    if A[0] in subA:
        print(sum_A - A[0])
    else:
        print(sum_A + A[0])

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

Solution (Python):
def main():
  n, l = map(int, input().split())
  total = sum([l + i for i in range(n)])
  mina = pow(10, 9)
  for i in range(n):
    _l = l + i
    if abs(_l) < abs(mina):
      mina = _l
  print(total - mina)


if __name__ == '__main__':
  main()

Solution (Python):
import numpy as np
n, l = input().split()
n = int(n)
l = int(l)

taste = np.array([l + i for i in range(n)], dtype=np.int)
taste_abs = np.abs(taste)
i = np.argmin(taste_abs)

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

print(s)

Solution (Python):
def main():
    n,l = map(int,input().split())
    min_diff = float('inf')
    pies = []
    for i in range(1,n+1):
        pies.append(l+i-1)

    total = sum(pies)
    ans = 0

    for i in range(n):
        new = total
        new -= pies[i]
        if abs(new-total) < min_diff:
            min_diff = abs(new-total)
            ans = new

    print(ans)


main()

Solution (Python):
def main():
  n, l = map(int, input().split())
  u = l + n - 1
  v = (l + u) * n // 2

  if u * l <= 0:
    print(v)
  elif u > 0:
    print(v - l)
  else:
    print(v - u)


if __name__ == '__main__':
  main()

Solution (Python):
import sys
sys.setrecursionlimit(100000)

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

n,l=intinput()
li=[l+i for i in range(n)]
k=sum(li)
ans=float("inf")
for i in range(len(li)):
    v=sum(li[:i]+li[i+1:])
    if abs(ans-k) > abs(v-k):
        ans=v
print(ans)

Solution (Python):



N, L = map(int, raw_input().split())
A = range(L, L + N)
print sum(A) - min([i for i in A], key=abs)

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

T=sum(t)
S=[]
for i in range(n):
    k=t[:i]+t[i+1:]

    S.append([abs(T-sum(k)),sum(k)])
S.sort(key=lambda x:x[0])

print(S[0][1])

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
from collections import defaultdict

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

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


absmin = 1000
ans_minus = 0
ans = 0
for i in range(N):
    if abs(L+i)<absmin:
        absmin = abs(L+i)
        ans_minus = L+i
    ans += L+i

print(ans-ans_minus)

Solution (Python):
import sys


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

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

for i in range(N):
    if L + i == 0:
        ans = i
        break
else:
    if L + N - 2 < 0: ans = N - 1
    else: ans = 0

print(Lsum - (L + ans))

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

mn = l
mx = l+n-1
s = sum(range(mn, mx+1))
if l >= 0:
    s -= mn
elif mx < 0:
    s -= mx

print(s)

Solution (Python):
N, L = [int(c) for c in input().split()]
S = L * N + (N-1)*N // 2

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

Solution (Python):
def InputToInt():
    A = input().split()
    for i in range(len(A)):
        A[i] = int(A[i])
    return A
    
if __name__ == '__main__':
    N, L = InputToInt()
    if L > 0:
        print(sum(range(L+1,N+L)))
    elif N+L-1>0:
        print(sum(range(L,N+L)))
    else:
        print(sum(range(L,N+L-1)))

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right





def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")



N, L = l_inpl()
aji = []

for i in range(N):
    aji.append(L+i)

r = INF
for a in aji:
    if abs(r) > abs(a):
        r = a

print(sum(aji)-r)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

from functools import lru_cache

def main(): 
    N, L = LI()
    

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

    li.sort()
    li.pop(0)

    sum_ = 0
    for i in li:
        sum_ += i[1]

    print(sum_)


main()

Solution (Python):
N,L = map(int,input().split())
apple = [i+L for i in range(N)]
apple_abs = [abs(i) for i in apple]
del apple[apple_abs.index(min(apple_abs))]
print(sum(apple))

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

Solution (Python):
n, l = map(int, input().split())
taste = [i for i in range(l,l+n)]
abs_taste = [abs(t) for t in taste]
min_taste = min(abs_taste)
if min_taste == 0:
	print(sum(taste))
elif min_taste in taste:
	print(sum(taste) - min_taste)
else:
	print(sum(taste) + min_taste)

Solution (Python):

 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
import time
import sys
from pprint import pprint
import itertools

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


min_abs = 1000
eat_d = None
sum = 0
for i in range(N):
    d = L + i
    sum += d
    if min_abs > d:
        min_abs = abs(d)
        eat_d = d
print(sum - eat_d)

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

min_a = 10**10
for i in range(n):
    if abs(a[i]) < abs(min_a):
        min_a = a[i]

print(sum(a) - min_a)