AtCoder Beginner Contest 131 - Bite Eating

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-----
5 2

-----Sample Output-----
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.

Source: atcoder | Difficulty: EASY


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


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


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


(N, L) = map(int, input().split())
x = []
for i in range(1, N + 1):
	x.append(L + i - 1)
print(sum(x) - min(x, key=abs))


(n, l) = map(int, input().split())
ls = [i + l - 1 for i in range(1, n + 1)]
ls.remove(min(ls, key=abs))
print(sum(ls))


(N, L) = map(int, input().split())
apple = sorted([L + i - 1 for i in range(1, N + 1)], key=lambda x: abs(x))
print(sum(apple[1:]))


(n, l) = map(int, input().split())
list_x = [l + x - 1 for x in range(1, n + 1)]
applepai = sum(list_x)
list_dif = []
list_sum = []
for i in range(len(list_x)):
	tmp = list_x.pop(i)
	list_dif.append(abs(applepai - sum(list_x)))
	list_sum.append(sum(list_x))
	list_x.insert(i, tmp)
indx = list_dif.index(min(list_dif))
ans = list_sum[indx]
print(ans)


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


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


(n, l) = map(int, input().split())
x = l if l >= 0 else n + l - 1 if n + l <= 0 else 0
print(n * (2 * l + n - 1) // 2 - x)


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


(n, l) = map(int, input().split())
c = 0
m = 100000
for i in range(1, n + 1):
	c += l + i - 1
	m = min(m, abs(l + i - 1))
if l < 0 and l - n <= 0:
	print(c + m)
else:
	print(c - m)


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


(N, L) = list(map(int, input().split()))
a = range(L, L + N)
(d, b) = min([(abs(x), x) for x in a])
c = sum(a)
print(c - b)


(n, l) = map(int, input().split())
(su, mi) = (0, 9999)
for i in range(1, n + 1):
	su += l + i - 1
	if abs(l + i - 1) < abs(mi):
		mi = l + i - 1
print(su - mi)


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


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


(n, l) = map(int, input().split())
apples = list(range(l, l + n))
print(sum(apples) - min(apples, key=abs))


details = input().split()
N = int(details[0])
L = int(details[1])
counter = 0
new_list = []
number = 0
checker = True
for i in range(N):
	counter += L
	new_list.append(L + i)
	if number == 0 and L + i >= 0 and (checker == True):
		number += L + i
		checker = False
	elif number == 0 and i == N - 1 and (checker == True):
		number += L + i
		checker = False
print(sum(new_list) - number)


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


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


(n, l) = map(int, input().split())
aji = []
apple = min(range(l, l + n), key=abs)
print(sum(range(l, l + n)) - apple)


(N, L) = map(int, input().split())
R = range(L, L + N)
print(sum(R) - min(R, key=abs))


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


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


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


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


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


(N, L) = map(int, input().split())
taste = sorted([i for i in range(L, L + N)], key=abs)
print(sum(taste[1:]))


(n, l) = map(int, input().split())
a = list(range(l, l + n))
a.sort(key=abs)
print(sum(a[1:]))


(n, l) = map(int, input().split())
apple = []
for i in range(1, n + 1):
	apple.append(l + i - 1)
eat = sorted(apple, key=lambda x: abs(x))
print(sum(apple) - eat[0])


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


(n, l) = map(int, input().split())
s = [0] * n
for i in range(n):
	s[i] = i + l
s.sort(key=abs)
print(sum(s[1:]))


(n, l) = list(map(int, input().split()))
arr = []
arr2 = []
for k in range(1, n + 1):
	arr.append(abs(l + k - 1))
for k in range(1, n + 1):
	arr2.append(l + k - 1)
arr2.pop(arr.index(min(arr)))
print(sum(arr2))


(n, a) = map(int, input().split())
x = [a + i - 1 + 1 for i in range(n)]
y = sorted(x, key=lambda i: abs(i))
del y[0]
print(sum(y))


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


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


(n, l) = map(int, input().split())
a = 0
for i in range(1, n + 1):
	a += l + i - 1
m = 10 ** 9
idx = 1
for i in range(1, n + 1):
	if abs(l + i - 1) < m:
		m = abs(l + i - 1)
		idx = i
print(a - (l + idx - 1))


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


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


(N, L) = map(int, input().split())
val = L * N + 0.5 * N * (N + 1) - N
if L > 0:
	val -= L
elif L + N - 1 < 0:
	val -= L + N - 1
print(int(val))


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


(a, b) = map(int, input().split())
n = list(range(b, b + a))
o = []
for i in n:
	o.append(abs(i))
del n[o.index(min(o))]
print(sum(n))


(n, l) = map(int, input().split())
taste = [l + i for i in range(n)]
eat = min(taste, key=abs)
taste.remove(eat)
print(sum(taste))


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


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


(n, l) = list(map(int, input().split()))
s = n * (l - 1) + n * (n + 1) / 2
c = abs(s)
j = 1
for i in range(n):
	t = s - (l + i)
	T = abs(s - t)
	if T < c:
		c = T
		j = i
ans = s - (l + j)
print(int(ans))


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


import sys
(n, l) = map(int, input().split())
taste_list = [l + x - 1 for x in range(1, n + 1)]
taste_sum = sum(taste_list)
diff = sys.maxsize
for i in range(n):
	if diff > abs(taste_list[i]):
		diff = abs(taste_list[i])
		num = i
print(taste_sum - taste_list[num])


(N, L) = map(int, input().split())
ll = list(range(L, N + L))
a = list(map(abs, ll))
print(sum(ll) - ll[a.index(min(a))])


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


lst = input()
lst = lst.split()
for i in range(len(lst)):
	lst[i] = int(lst[i])
N = lst[0]
L = lst[1]
q = L
l = 0
lste = [abs(L)]
tlst = []
for i in range(2, N + 1):
	t = L + i - 1
	q += t
	tlst.append(t)
	t = abs(t)
	lste.append(t)
slst = sorted(lste)
l = slst[0]
if tlst.count(-l) > 0:
	print(q + l)
else:
	print(q - l)


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


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


import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

def I():
	return int(input())

def F():
	return float(input())

def SS():
	return input()

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

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return [float(x) for x in input().split()]

def LSS():
	return input().split()

def resolve():
	(N, L) = LI()
	ans = (2 * L + N - 1) * N // 2
	if 0 <= L:
		ans -= L
	elif L + N <= 0:
		ans -= L + N - 1
	print(ans)

def __starting_point():
	resolve()
__starting_point()


(n, like) = map(int, input().split())
arr = [like + i for i in range(n)]
arr.sort(key=abs)
print(sum(arr[1:]))


def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def sum_applepie(list1, l):
	r = [i + l - 1 for i in list1]
	return sum(r)

def main():
	(n, l) = Input()
	applepie = sum_applepie(list(range(1, n + 1)), l)
	list2 = []
	for i in range(1, n + 1):
		temp = []
		for j in range(1, n + 1):
			if i == j:
				continue
			temp.append(j)
		k = sum_applepie(temp, l)
		list2.append((abs(applepie - k), k))
	print(sorted(list2, key=lambda x: x[0])[0][1])
main()


(n, l) = map(int, input().split())
s = sum(range(l, l + n))
ans = 1000
for i in range(l, l + n):
	if abs(i) <= abs(ans):
		ans = i
print(s - ans)


(N, L) = map(int, input().split())
a = list(range(L, N + L))
print(sum(a) - min(a, key=abs))


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


import sys
sys.setrecursionlimit(10 ** 9)

def int1(x):
	return int(x) - 1

def II():
	return int(input())

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

def MI1():
	return list(map(int1, input().split()))

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

def LI1():
	return list(map(int1, input().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def MS():
	return input().split()

def LS():
	return list(input())

def LLS(rows_number):
	return [LS() for _ in range(rows_number)]

def printlist(lst, k=' '):
	print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
	(N, L) = MI()
	tot = 0
	for i in range(1, N + 1):
		tot = tot + L + i - 1
	diff = INF
	ans = 0
	for i in range(1, N + 1):
		tmp = tot - L - i + 1
		if abs(tot - tmp) < diff:
			diff = abs(tot - tmp)
			ans = tmp
	print(ans)

def __starting_point():
	solve()
__starting_point()


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


(N, L) = [int(i) for i in input().split()]
tastes = [L + i for i in range(N)]
tastes.sort(key=abs)
ans = sum(tastes[1:])
print(ans)


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


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


(n, l) = map(int, input().split())
l1 = list((int(l) + i - 1 for i in range(1, n + 1)))
n1 = sum(l1)
ans = min(l1, key=abs)
print(n1 - ans)


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


(N, L) = map(int, input().split())
A = []
for n in range(1, N + 1):
	A.append(L + n - 1)
print(sum(A) - min(A, key=abs))


(n, l) = map(int, input().split())
a = 0
b = 10000
for i in range(n):
	a += l + i
	if abs(l + i) < abs(b):
		b = l + i
print(a - b)


(N, L) = map(int, input().split())
taste = [L + i for i in range(N)]
abstaste = sorted(taste, key=abs)
print(sum(taste) - abstaste[0])


(N, L) = map(int, input().split())
A = [L + i for i in range(N)]
A = sorted(A, key=lambda x: abs(x))
print(sum(A) - A[0])


(n, l) = map(int, input().split())
a = range(l, l + n)
print(sum(a) - min(a, key=abs))


def ApplePie():
	(N, L) = input().split()
	N = int(N)
	L = int(L)
	flavors = []
	for i in range(N):
		flavors.append(L + i)
	if 0 in flavors:
		flavors.remove(0)
		result = 0
		for i in flavors:
			result = result + i
		print(result)
		return
	elif L >= 0:
		del flavors[0]
		result = 0
		for i in flavors:
			result = result + i
		print(result)
		return
	else:
		del flavors[-1]
		result = 0
		for i in flavors:
			result = result + i
		print(result)
		return
ApplePie()


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


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


(n, l) = [int(k) for k in input().split(' ')]
res = sum(range(l, n + l))
if l < 0:
	res -= min(0, l + n - 1)
else:
	res -= l
print(res)


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


(N, L) = map(int, input().split())
list_ = list(range(L, L + N))
print(sum(list_) - min(list(map(abs, list_))) * (1, -1)[max(list_) < 0])


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


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


(n, l) = (int(i) for i in input().split())
d = (l - 1) * n + (n + 1) * n // 2
if l < 1:
	print(d + 1 - l - min(n, 1 - l))
else:
	print(d - l)


(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)


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


(n, l) = map(int, input().split())
apple = [l + i for i in range(n)]
s = 0
while True:
	if s in apple:
		apple.remove(s)
		break
	elif abs(s) in apple:
		apple.remove(abs(s))
		break
	s -= 1
print(sum(apple))


r = input().split()
N = int(r[0])
L = int(r[1])
ans = 0
ans_li = []
for i in range(N):
	ans += L + (i + 1) - 1
	ans_li.append(L + (i + 1) - 1)
if 0 in ans_li:
	print(ans)
elif max(ans_li) > 0:
	print(ans - min(ans_li))
else:
	print(ans - max(ans_li))


(N, L) = map(int, input().split())
s = 0
l = []
for i in range(N):
	s += L + i
	l.append(abs(L + i))
l = sorted(l)
if l[0] <= L:
	s -= l[0]
else:
	s += l[0]
print(s)


(n, l) = map(int, input().split())
apples = range(l, n + l)
print(sum(sorted(apples, key=lambda x: abs(x))[1:]))


(n, l) = list(map(int, input().split()))
apples = []
ans = 300
for i in range(1, n + 1):
	taste = i + l - 1
	apples.append(taste)
	if abs(taste) < abs(ans):
		ans = taste
apples.remove(ans)
print(sum(apples))


(n, l) = map(int, input().split())
li = []
ind = 0
for i in range(1, n + 1):
	li.append(i + l - 1)
mi = abs(li[0])
for i in li:
	if abs(i) < mi:
		mi = abs(i)
		ind = li.index(i)
print(sum(li) - li[ind])


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


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


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


(N, L) = map(int, input().split())
l = list(map(lambda x: L + x - 1, range(1, N + 1)))
print(sum(l) - min(l, key=abs))


(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])


import numpy as np
(N, L) = list(map(int, input().split()))
taste = np.arange(1, N + 1) + L - 1
min_ind = np.argmin(np.abs(taste))
mask_1 = np.ones(N, dtype=bool)
mask_1[min_ind] = False
ans = np.sum(taste[mask_1])
print(ans)


(N, L) = list(map(int, input().split()))
flavor = []
flavorabs = []
for i in range(1, N + 1):
	flavor.append(L + i - 1)
S = 0
for i in flavor:
	S += i
for i in range(N):
	flavorabs.append(abs(flavor[i]))
a = min(flavorabs)
print(S - flavor[flavorabs.index(a)])


import sys

def I():
	return int(sys.stdin.readline())

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

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

def main():
	(n, l) = MI()
	ans = 0
	temp = l
	for i in range(n):
		ans += l + i
		if abs(temp) > abs(l + i):
			temp = l + i
	ans -= temp
	print(ans)

def __starting_point():
	main()
__starting_point()


(a, b) = input().split()
a = int(a)
b = int(b)
c = a * (b + b + a - 1) / 2
if b > 0:
	print(int(c - b))
elif b + a - 1 > 0:
	print(int(c))
else:
	print(int(c - (b + a - 1)))


(N, L) = map(int, input().split())
aji1 = []
ajimin = 1000
for i in range(1, N + 1):
	aji1.append(L + i - 1)
	if abs(ajimin) >= abs(aji1[i - 1]):
		ajimin = aji1[i - 1]
print(sum(aji1) - ajimin)


(a, c) = map(int, input().split())
d = 0
m = 5000
for i in range(1, a + 1):
	d = d + c + i - 1
	if abs(m) > abs(c + i - 1):
		m = c + i - 1
print(d - m)


(n, l) = map(int, input().split())
T = [l + i for i in range(n)]
if T[-1] >= 0:
	m = min((i for i in T if i >= 0))
else:
	m = T[-1]
print(sum(T) - m)


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


(n, k) = map(int, input().split())
sum = k
tmp = k
for i in range(1, n):
	sum += k + i
	if abs(tmp) > abs(k + i):
		tmp = k + i
print(sum - tmp)


(n, l) = map(int, input().split())
lst = [l + i for i in range(n)]
m = min(lst, key=lambda x: abs(x))
print(sum(lst) - m)


(n, l) = map(int, input().split())
r = l + n - 1
s = (l + r) * n // 2
print([s - r, s, s - l][(l > 0) + (r > 0)])


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


lst = list(map(int, input().split()))
N = lst[0]
L = lst[1]
apple_flavours = []
for i in range(1, N + 1):
	apple_flavours.append(L + i - 1)
abs_apple_flavours = []
for apple in apple_flavours:
	abs_apple_flavours.append(abs(apple))
min_val = min(abs_apple_flavours)
index = abs_apple_flavours.index(min_val)
total_flavour = 0
for apple in apple_flavours:
	total_flavour += apple
print(total_flavour - apple_flavours[index])


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


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


(n, l) = map(int, input().split())
ans = 0
mv = 100000
for i in range(1, n + 1):
	tmp = l + i - 1
	ans += tmp
	if abs(mv) > abs(tmp):
		mv = tmp
print(ans - mv)


(a, b) = map(int, input().split())
x = [b + i for i in range(a)]
y = sum(x)
print(min([(abs(y - (y - i)), y - i) for i in x], key=lambda x: x[0])[1])


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


(n, l) = list(map(int, input().split()))
apple_list = [l + i for i in range(n)]
abs_min = min([abs(apple) for apple in apple_list])
apple_list.remove(abs_min if abs_min in apple_list else -abs_min)
print(sum(apple_list))


(n, l) = list(map(int, input().split()))
azi = [l + i - 1 for i in range(1, n + 1)]
diff = [0] * n
for i in range(n):
	diff[i] = abs(azi[i])
if sum(azi) < 0:
	print(sum(azi) + abs(min(diff)))
else:
	print(sum(azi) - min(diff))


(n, l) = map(int, input().split())
b = [l + i for i in range(n)]
a = list(map(abs, b))
m = a.index(min(a))
b.pop(m)
print(sum(b))


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


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


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


(n, l) = list(map(int, input().split()))
aji = [l + i for i in range(n)]
ans = None
sa = 10 ** 10
for i in range(n):
	sa_tmp = abs(aji[i])
	if sa > sa_tmp:
		sa = sa_tmp
		ans = sum(aji) - aji[i]
print(ans)


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


(n, l) = map(int, input().split())
ans = l
k = 0
sum = 0
for i in range(1, n):
	if abs(ans) > abs(l + i):
		ans = l + i
		k = i
for i in range(n):
	if i != k:
		sum += l + i
print(sum)


(N, L) = map(int, input().split())
r = [L + i - 1 for i in range(1, N + 1)]
e = min(r, key=abs)
print(sum(r) - e)


def answer(n: int, l: int) -> int:
	apples_taste = list(range(l, l + n))
	applepie_taste = sum(apples_taste) - min(apples_taste, key=abs)
	return applepie_taste

def main():
	(n, l) = list(map(int, input().split()))
	print(answer(n, l))

def __starting_point():
	main()
__starting_point()


(N, L) = list(map(int, input().split()))
azi2 = []
azi = [L + i for i in range(N)]
for i in azi:
	azi2.append(abs(i))
if 0 in azi:
	print(sum(azi))
else:
	mi = azi2.index(min(azi2))
	del azi[mi]
	print(sum(azi))


(N, L) = map(int, input().split())
Max = L + N - 1
a = int((L + Max) * N / 2)
if Max < 0:
	a = a - Max
if Max > 0:
	if L > 0:
		a = a - L
print(a)


(n, l) = map(int, input().split())
isMina = False
isPlu = False
ans = []
for i in range(1, n + 1):
	ans.append(l + i - 1)
	if l + i - 1 < 0:
		isMina = True
	elif i + i - 1 > 0:
		isPlu = True
print(sum(ans) - min(ans) if not isMina else sum(ans) - max(ans) if not isPlu else sum(ans))


(N, L) = list(map(int, input().split()))
nin = 10 ** 6
for i in range(N):
	if abs(L + i) < nin:
		nin = abs(L + i)
		nn = L + i
ans = N * (L - 1) + N * (N + 1) * 0.5 - nn
print(int(ans))


(n, l) = map(int, input().split())
L = [l + i - 1 for i in range(1, n + 1)]
Labs = list(map(abs, L))
print(sum(L) - L[Labs.index(min(Labs))])


(N, L) = list(map(int, input().split()))
A = 0
a = 1000
for i in range(1, N + 1):
	x = L + i - 1
	A += x
	if abs(x) < a:
		a = abs(x)
if A >= 0:
	print(A - a)
else:
	print(A + a)


(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)


(N, L) = map(int, input().split())
A = []
for i in range(N):
	A.append(L + i)
i = 0
ans = False
while ans == False:
	(x, y) = (abs(i), -abs(i))
	for k in A:
		if k == x or k == y:
			ans = True
			A.remove(k)
	i += 1
print(sum(A))


(n, l) = list(map(int, input().split()))
s = [i + l - 1 for i in range(1, n + 1)]
x = sum(s)
s.sort(key=lambda y: abs(y))
print(x - s[0])


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


(n, l) = map(int, input().split())
t = list(range(l, l + n))
s = [abs(_) for _ in t]
print(sum(t) - t[s.index(min(s))])


(N, L) = map(int, input().split())
tmp = [L + i - 1 for i in range(1, N + 1)]
ans = sorted(tmp, key=abs)
print(sum(ans) - ans[0])


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


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


(N, L) = map(int, input().split())
La = N * L + (N - 1) * N / 2
min_Le = La
abs_L = int(1e+100)
for i in range(N):
	Li = L + (i + 1) - 1
	if abs(La - Li - La) < abs_L:
		Le = La - Li
		abs_L = abs(Le - La)
print(int(Le))


(N, L) = map(int, input().split())
nums = list(range(1, N + 1))
tasts = [L + num - 1 for num in nums]
abs_tasts = list(map(abs, tasts))
index = abs_tasts.index(min(abs_tasts))
tasts.pop(index)
print(sum(tasts))


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


(N, L) = map(int, input().split())
s = N * (2 * L + N - 1) // 2
l = [abs(L + i) for i in range(N)]
print(s - (L + l.index(min(l))))


(a, b) = map(int, input().split())
c = [i + b for i in range(a)]
d = [abs(j + b) for j in range(a)]
print(sum(c) - c[d.index(min(d))])


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readlines

def main():
	lines = input()
	(n, l) = list(map(int, lines[0].split()))
	Sum_ = int(n * (l - 1) + n * (n + 1) / 2)
	if l >= 0:
		print(Sum_ - l)
		return
	elif n + l - 1 <= 0:
		print(Sum_ - (l + n - 1))
	else:
		print(Sum_)
main()


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


(N, L) = map(int, input().split())
total = N * (L - 1) + N * (N + 1) / 2
lowest = 10 ** 10
for i in range(1, N + 1):
	y = L + i - 1
	lowest = min(lowest, abs(y))
print(int(total) - lowest) if total >= 0 else print(int(total) + lowest)


(n, l) = list(map(int, input().split()))
S = n * l + n * (n + 1) // 2 - n
pd = S + 1
for x in range(1, n + 1):
	d = -l - x + 1
	if pd > abs(d):
		ans = S + d
	pd = d
print(ans)


(N, L) = map(int, input().split())
aji_list = [L + i - 1 for i in range(1, N + 1)]
basic = abs(sum(aji_list))
min_diff = 9999999
for i in aji_list:
	diff = abs(basic - abs(basic - abs(i)))
	min_diff = min(min_diff, diff)
for i in aji_list:
	if abs(basic - abs(basic - abs(i))) == min_diff:
		if basic == sum(aji_list):
			print(basic - abs(i))
		else:
			print(-1 * (basic - abs(i)))
		break


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


(N, L) = list(map(int, input().split()))
A = []
for i in range(N):
	x = L + i
	A.append(x)
y = sum(A)
B = sorted(A)
if L <= 0 and L + N - 1 >= 0:
	print(y)
elif L >= 0:
	y -= B[0]
	print(y)
elif L + N - 1 < 0:
	y -= B[N - 1]
	print(y)


(N, L) = map(int, input().split())
apples = list(range(L, L + N))
s = sum(apples)
print(s - sorted(apples, key=lambda x: abs(x))[0])


(N, L) = map(int, input().split())
Apple = list(range(L, L + N))
Apple.sort(key=lambda x: abs(x))
print(sum(Apple[1:]))


(N, L) = [int(i) for i in input().split()]
t = L * (N - 1) if L >= 0 else L * N if N + L > 0 else L * N - (L + N - 1)
print(N * (N - 1) // 2 + t)


(n, l) = map(int, input().split())
a = list(range(l, n + l))
m = list(map(abs, a))
print(sum(a) - a[m.index(min(m))])


(n, l) = map(int, input().split())
d = list(range(l, n + l))
d_eaten = min(d, key=lambda x: abs(x))
print(sum(d) - d_eaten)


(N, L) = list(map(int, input().split()))
stk = []
ans = []
for i in range(N):
	tmp = L + i
	stk.append(tmp)
for i in range(N):
	tmp1 = sum(stk)
	tmp = stk[i]
	stk[i] = 0
	tmp2 = sum(stk)
	stk[i] = tmp
	ans.append(abs(tmp1 - tmp2))
tmp = min(ans)
if tmp in stk:
	stk.remove(tmp)
	print(sum(stk))
else:
	stk.remove(-tmp)
	print(sum(stk))


(n, L) = map(int, input().split())
a = list(range(L, n + L))
tmp = 500
for i in a:
	if abs(tmp) > abs(i):
		tmp = i
print(sum(a) - tmp)


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


(K, L) = map(int, input().split())
apple = [i for i in range(L, L + K)]
apple.sort(key=lambda x: abs(x))
print(sum(apple[1:]))


(N, L) = map(int, input().split())
chosen = 1000
for i in range(1, N + 1):
	taste_eaten = L + i - 1
	if abs(taste_eaten) < abs(chosen):
		chosen = taste_eaten
print(int(N * L + N * (N + 1) / 2 - N - chosen))


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


(N, L) = map(int, input().split())
A = [L + i for i in range(N)]
A.remove(min(max(A), *[abs(a) for a in A]))
print(sum(A))


(N, L) = map(int, input().split())
azi = [L + i - 1 for i in range(1, N + 1)]
absmin = L ** 2
for i in range(N):
	absmin = min(absmin, abs(azi[i]))
if absmin in azi:
	print(sum(azi) - absmin)
else:
	print(sum(azi) + absmin)


(n, l) = map(int, input().split())
ans = [l + i - 1 for i in range(1, n + 1)]
mn = min(ans, key=lambda x: abs(x))
print(sum(ans) - mn)


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


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


(n, l) = map(int, input().split())
s = 0
m = 10 ** 3
for i in range(n):
	s += l + i
	if abs(m) > abs(l + i):
		m = l + i
print(s - m)


(n, l) = map(int, input().split())
li = [l + i for i in range(n)]
print(sum(li) - sorted(li, key=lambda x: abs(x))[0])


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


(n, l) = map(int, input().split())
List1 = []
List2 = []
for i in range(n):
	L = l + i
	L_abs = abs(L)
	List1.append(L)
	List2.append(L_abs)
if min(List2) in List1:
	List1.remove(min(List2))
elif -min(List2) in List1:
	List1.remove(-min(List2))
print(sum(List1))


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


(n, l) = map(int, input().split())
q = []
p = []
ans = 0
for i in range(1, n + 1):
	m = l + i - 1
	q.append(m)
	ans += m
for i in range(n):
	p.append(abs(q[i]))
print(ans - q[p.index(min(p))])


(n, l) = (int(i) for i in input().split())
r = l
s = 0
for i in range(n):
	if l + i <= 0:
		r = l + i
	s = s + l + i
print(s - r)


(N, L) = map(int, input().split())
minabs = 10 ** 9
apples = []
for i in range(N):
	t = L + i
	apples.append(t)
	if abs(t) < abs(minabs):
		minabs = t
full = sum(apples)
print(full - minabs)


(n, l) = list(map(int, input().split()))
apples = []
min_val = l
for i in range(1, n + 1):
	apples.append(l + i - 1)
	if abs(l + i - 1) < abs(min_val):
		min_val = l + i - 1
apples.remove(min_val)
print(sum(apples))


(N, L) = map(int, input().split())
apple = [L + i - 1 for i in range(1, N + 1)]
apple.remove(min(apple, key=abs))
print(sum(apple))


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


(n, l) = map(int, input().split())
a = 200
ans = 0
for i in range(l, l + n):
	ans += i
	if abs(i) < abs(a):
		a = i
print(ans - a)


(N, L) = map(int, input().split())
apple = [L + i - 1 for i in range(1, N + 1)]
apple.sort(key=abs)
print(sum(apple[1:]))


import sys
(N, L) = list(map(int, input().split()))
tastes = [L + x for x in range(N)]
if 0 in tastes:
	print(sum(tastes))
	return
if L < 0:
	absmin = max(tastes)
	print(sum(tastes) - absmin)
elif L > 0:
	absmin = min(tastes)
	print(sum(tastes) - absmin)


(n, l) = map(int, input().split())
l_list = [l + i - 1 for i in range(1, n + 1)]
ab_list = [abs(i) for i in l_list]
num = ab_list.index(min(ab_list))
print(sum(l_list) - l_list[num])


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


(N, L) = map(int, input().split())
A = list(range(L, L + N))
print(sum(A) - A[min(enumerate(A), key=lambda x: abs(x[1]))[0]])


(n, l) = list(map(int, input().split()))
aji = []
m = 100000
flg = 0
for i in range(n):
	aji.append(l + i)
	if abs(aji[i]) <= m:
		m = abs(aji[i])
		if aji[i] <= 0:
			flg = 1
		else:
			flg = 0
print(sum(aji) - m if flg == 0 else sum(aji) + m)


(N, L) = map(int, input().split())
l = [L + i for i in range(N)]
l_abs = [abs(i) for i in l]
print(sum(l) - l[l_abs.index(min(l_abs))])


(n, l) = map(int, input().split())
apple = []
diff = 1001001001
minus = False
for i in range(1, n + 1):
	apple.append(l + i - 1)
	if abs(l + i - 1) < diff:
		diff = abs(l + i - 1)
		if l + i - 1 < 0:
			minus = True
		else:
			minus = False
if minus:
	print(sum(apple) + diff)
else:
	print(sum(apple) - diff)


(N, L) = map(int, input().split(' '))
a = list(range(L, L + N))
a.sort(key=abs)
print(sum(a[1:]))


(n, a) = map(int, input().split())
c = 0
d = 1000
for i in range(1, n + 1):
	c += a + i - 1
	d = min(abs(a + i - 1), d)
if a < 0 and a - n <= 0:
	print(c + d)
else:
	print(c - d)


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


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


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


(n, l) = map(int, input().split())
apples = [i + l - 1 for i in range(1, n + 1)]
print(sum(apples) - min(((abs(x), x) for x in apples))[1])


(n, l) = map(int, input().split())
r = l + n - 1
eat = range(l, r + 1)
print((l + r) * n // 2 - min(eat, key=abs))


(N, L) = map(int, input().split())
L = [L + i - 1 for i in range(1, N + 1)]
c = sum(L)
R = [abs(i) for i in L]
print(c - L[R.index(min(R))])


(N, L) = map(int, input().split())
tastes = []
for i in range(1, N + 1):
	tastes.append(L + i - 1)
abs_tastes = list(map(abs, tastes))
min_tastes_index = abs_tastes.index(min(abs_tastes))
tastes.pop(min_tastes_index)
print(sum(tastes))


(N, L) = map(int, input().split(' '))
apple = [L + i - 1 for i in range(1, N + 1)]
abs_apple = list(map(abs, apple))
minimum_idx = abs_apple.index(min(abs_apple))
print(sum(apple) - apple[minimum_idx])


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


(n, l) = map(int, input().split())
t = []
t2 = []
for i in range(n):
	taste = l + (i + 1) - 1
	t.append(taste)
	t2.append(taste ** 2)
oa = t[t2.index(min(t2))]
ans = sum(t) - oa
print(ans)


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


(apple_num, taste) = map(int, input().split())
total = 0
table = []
total_ans = 0
manual = 100000000
ans = 0
for i in range(apple_num):
	table.append(i + 1)
for j in range(apple_num):
	table[j] = taste + j
	total += taste + j
for k in range(apple_num):
	if manual > abs(table[k]):
		manual = abs(table[k])
		ans = k
for l in range(apple_num):
	if l == ans:
		continue
	else:
		total_ans += table[l]
print(total_ans)


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