Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.

Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation $y = - \frac{x}{m} + b$. Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.

Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.

Okabe is sure that the answer does not exceed 10^18. You can trust him.


-----Input-----

The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).


-----Output-----

Print the maximum number of bananas Okabe can get from the trees he cuts.


-----Examples-----
Input
1 5

Output
30

Input
2 3

Output
25



-----Note----- [Image] 

The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.

Difficulty: EASY
Tags: Mathematics

Complete search
Skill types: Complete search

Starter code:

Solutions:
import sys

def main():
	(m, b) = list(map(int, sys.stdin.readline().split()))

	def calc(y):
		x = (b - y) * m
		return (y * (y + 1) * (x + 1) >> 1) + (x * (x + 1) * (y + 1) >> 1)
	res = 0
	for i in range(b + 1):
		t = calc(i)
		if t > res:
			res = t
	print(res)
main()


(m, b) = map(int, input().split(' '))
mx = 0
for j in range(0, b):
	x = (b - j) * m
	s = int((j + x) * (x + 1) * (j + 1))
	mx = max(mx, s)
print(mx // 2)


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

def banans(p, q):
	return (p + 1) * sigma(q) + (q + 1) * sigma(p)
(m, b) = [int(x) for x in input().split()]
r = 0
for i in range(m * b + 1):
	if i % m == 0:
		(p, q) = (i, b - i // m)
		r = max(r, banans(p, q))
print(r)


import math
(m, b) = list(map(int, input().split()))
ans = 0
for y in range(b + 1):
	x = m * (b - y)
	p = (x + 1) * (y + 1) * (x + y) // 2
	ans = max(ans, p)
print(ans)


def f(a, o):
	return (a + 1) * (o + 1) * (a + o) // 2
import math
(m, b) = [int(f) for f in input().split()]
top = 0
for x in range(b + 1):
	top = max(f(x, (b - x) * m), top)
print(top)


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
int1 = lambda x: int(x) - 1
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))
ilelec = lambda : map(int1, input().split())
alelec = lambda : list(map(int1, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
(m, b) = ilele()
Ans = 0

def fun(x, y):
	return y * (y + 1) // 2 * (x + 1)
for y in range(b, -1, -1):
	x = m * (b - y)
	a = fun(x, y) + fun(y, x)
	Ans = max(Ans, a)
print(Ans)


import math
import sys
from collections import *
from bisect import bisect_left, bisect_right

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

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

def solve():
	(m, b) = cint()
	h = b
	w = m * b
	maxx = 0
	for h in range(b):
		w = int((b - h) * m)
		temp = (w + 1) * h * (h + 1) // 2 + (h + 1) * w * (w + 1) // 2
		if temp > maxx:
			maxx = temp
	print(maxx)
t = 1
while t != 0:
	solve()
	t -= 1


(m, b) = map(int, input().split(' '))
maximo = -1
for y in range(b + 1):
	x = (y - b) * -m
	maximo = max(maximo, (x + 1) * int(y * (y + 1) / 2) + (y + 1) * int(x * (x + 1) / 2))
print(maximo)


I = lambda : list(map(int, input().split()))
(m, b) = I()
mx = 0
for y in range(0, 100001):
	x = m * (b - y)
	if x >= 0:
		mx = max(mx, (y + 1) * x * (x + 1) // 2 + (x + 1) * y * (y + 1) // 2)
print(mx)


def f(x):
	return x * (x + 1) // 2
(m, b) = map(int, input().split())
(c, x, y, ans) = (0, 0, 0, 0)
for y in range(b + 1):
	x = (b - y) * m
	c = (x + 1) * f(y) + (y + 1) * f(x)
	ans = max(ans, c)
print(int(ans))


from sys import stdin, stdout
import cProfile
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().strip().split())

def get_list():
	return list(map(int, stdin.readline().strip().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
import math, copy

def main():
	(m, b) = get_tuple()
	y = b * m
	ma = 0
	for x in range(b + 1):
		ma = max(ma, (x + 1) * (y * (y + 1) // 2) + (y + 1) * (x * (x + 1) // 2))
		y = y - m
	print(ma)
cProfile.run('main()') if test else main()


import sys

def main():
	(m, b) = list(map(int, sys.stdin.readline().split()))
	results = []
	for _x in range(0, b + 1):
		x = m * _x
		y = b - _x
		results.append(rectangle_bananas(x, y))
	print(max(results))

def rectangle_bananas(x, y):
	return (x + 1) * (y + 1) * (x + y) // 2

def __starting_point():
	main()
__starting_point()


(m, b) = map(int, input().split())
maxi = 0
for y in range(b):
	x = (b - y) * m
	sum = x * (x + 1) // 2 * (y + 1) + y * (y + 1) // 2 * (x + 1)
	maxi = max(sum, maxi)
print(maxi)


ans = []
(m, b) = map(int, input().split())
for x in range(m * b + 1):
	y = -x / m + b
	if y.is_integer():
		y = -x // m + b
		start = (0 + x) * (x + 1) // 2
		end = start + y * (x + 1)
		ans.append(int((start + end) * (y + 1) // 2))
print(max(ans))


(a, b) = map(int, input().split())
ans = 0
r = lambda x: x * (x + 1) // 2
for y in range(b + 1):
	x = (b - y) * a
	ans = max(ans, (x + 1) * r(y) + (y + 1) * r(x))
print(ans)


(m, b) = [int(i) for i in input().split()]
res = 0
for i in range(b + 1):
	j = (b - i) * m
	res = max(res, (i + 1) * (j + 1) * (i + j) // 2)
print(res)


(m, b) = list(map(int, input().split()))
bn = 0
for i in range(b):
	bn = max(bn, m * (b - i) * (m * (b - i) + 1) // 2 * (i + 1) + i * (i + 1) // 2 * (m * (b - i) + 1))
print(bn)


(m, b) = [int(i) for i in input().split()]
max1 = 0
for y in range(b, -1, -1):
	x = m * (b - y)
	calc = (y + 1) * (x + 1) * (x + y) // 2
	if calc > max1:
		max1 = calc
print(max1)


def check(x, y):
	f1 = x * (x + 1) // 2
	f2 = y * (y + 1) // 2
	return (x + 1) * f2 + (y + 1) * f1
(m, b) = map(int, input().split())
y = b
ma = 0
for i in range(0, m * b + 1, m):
	if check(i, y) > ma:
		ma = check(i, y)
	y -= 1
print(ma)


(m, b) = map(int, input().split())
maxS = 0
for (x, y) in zip(range(0, (b + 1) * m, m), range(b, -1, -1)):
	vert = int((1 + y) * y / 2)
	hor = int((1 + x) * x / 2)
	newS = vert * (x + 1) + hor * (y + 1)
	if newS > maxS:
		maxS = newS
print(maxS)


(m, b) = map(int, input().split())
max_d = 0
for x in range(m * b + 1):
	if x % m == 0:
		y = -x // m + b
		d = (x + 1) * (y + 1) * (x + y) // 2
		max_d = max(max_d, d)
print(max_d)


import math
(m, bb) = [int(item) for item in input().split()]
ans = -1
for a in range(bb + 1):
	b = m * bb - m * a
	ans = max(ans, a * (a + 1) // 2 * (b + 1) + b * (b + 1) // 2 * (a + 1))
print(ans)


def col(currY, currX, m):
	y_vals = currY * (currY - 1) // 2
	total = y_vals * m
	x_vals = (currX + m + currX + 1) * m // 2
	total += x_vals * currY
	return total

def row(currY, currX):
	y_vals = currY * (currX + 1)
	total = y_vals
	x_vals = (currX + 1) * currX // 2
	total += x_vals
	return total
(m, b) = [int(val) for val in input().strip().split(' ')]
initX = b * m
max_v = curr_v = (initX + 1) * initX // 2
curr_y = 0
for curr_x in range(initX - m, -1, -m):
	curr_y += 1
	curr_v = curr_v - col(curr_y, curr_x, m) + row(curr_y, curr_x)
	if curr_v > max_v:
		max_v = curr_v
	else:
		print(max_v)
		break


(m, b) = map(int, input().split())
ans = 0
for x in range(0, m * b + 1, m):
	y = b - x // m
	t = (x + y) * (x + 1) * (y + 1) // 2
	ans = max(ans, t)
print(ans)


(m, b) = map(int, input().split())
ans = float('-inf')
for i in range(0, b + 1):
	x = (b - i) * m
	ans = max(ans, (i + 1) * int(x * (x + 1) / 2) + int(i * (i + 1) / 2) * (x + 1))
print(ans)


def series(x):
	return x * (x + 1) // 2

def max(a, b):
	return a if a > b else b
(m, b) = map(int, input().split())
mymax = 0
for y in range(0, b + 1):
	x = m * (b - y)
	t = (x + 1) * series(y) + (y + 1) * series(x)
	mymax = int(max(mymax, t))
print(mymax)


def Sum(x: int, y: int):
	return (x + 1) * y * (y + 1) // 2 + (y + 1) * x * (x + 1) // 2
(m, b) = map(int, input().split(' '))
answer = int(0)
for y in range(b, -1, -1):
	x = m * (b - y)
	answer = max(answer, Sum(x, y))
print(int(answer))


import math
import random
import sys
import collections

def In():
	return map(int, sys.stdin.readline().split())
input = sys.stdin.readline

def okaBana():
	(m, b) = In()
	y = 0
	ans = 0
	while True:
		x = -(y * m - m * b)
		if x < 0:
			break
		ans = max(ans, x * (x + 1) // 2 * (y + 1) + y * (y + 1) // 2 * (x + 1))
		y += 1
	print(ans)
okaBana()


n = input()
n = list(map(int, n.split(' ')))
t = 0
j = 0
for i in range(n[1] + 1):
	s = (n[1] - i + 1) * (n[0] * i + n[1] - i) * (n[0] * i + 1) // 2
	if t < s:
		t = s
print(int(t))


def rectangle_value(x, y):
	return int(x * (x + 1) / 2) * (y + 1) + int(y * (y + 1) / 2) * (x + 1)
raw = str(input()).split()
m = int(raw[0])
b = int(raw[1])
y = b
highest = 0
while y >= 0:
	x = int(-m * (y - b))
	value = rectangle_value(x, y)
	if value > highest:
		highest = value
	y -= 1
print(int(highest))


def abc(a):
	return int(a * (a + 1) / 2)
(m, b) = list(map(int, input().split()))
best = 0
for y in range(b, -1, -1):
	x = m * (b - y)
	best = max(best, (x + 1) * abc(y) + (y + 1) * abc(x))
print(best)


(m, b) = list(map(int, input().split()))
f = lambda n: n * (n + 1) // 2

def g(y):
	x = m * (b - y)
	return f(x) * (y + 1) + f(y) * (x + 1)
print(max((g(y) for y in range(b + 1))))


(m, b) = input().split(' ')
m = int(m)
b = int(b)
maxx = m * b

def area(x, y):
	return (x + 1) * (y + 1) * (x + y) // 2
areas = []
i = 0
while i <= b:
	x = i * m
	y = b - i
	areas += [int(area(x, y))]
	i += 1
print(max(areas))


(m, b) = map(int, input().strip().split())
ans = 0
for y in range(b + 1):
	x = (-y + b) * m
	res = (x + 1) * (y + 1) * (x + y) >> 1
	ans = max(ans, res)
print(ans)


def se(m, b, s, v):
	if s == 'x':
		return (m * b - v) // m
	else:
		return m * b - m * v

def main():
	(m, b) = tuple(map(int, input().split()))
	y = se(m, b, 'x', 0)
	k = []
	for i in range(y + 1):
		x = se(m, b, 'y', i)
		k += [(i + 1) * (x + 1) * (i + x) // 2]
	print(max(k))
main()


def ans(x, y):
	a = int(y * (y + 1) / 2)
	a = a * (x + 1)
	b = int(x * (x + 1) / 2)
	b = b * (y + 1)
	return a + b

def change(i, b):
	if i % b == 0:
		return i / b
	return i / b + 1
(m, b) = map(int, input().split())
max = int(-1)
for i in range(0, b + 1):
	x = m * (b - i)
	k = ans(i, x)
	if max < k:
		max = k
print(int(max))


(m, b) = map(int, input().split())
(x, y) = (m * b, b)
s = 0
for j in range(y + 1):
	i = m * (b - j)
	a1 = i * (1 + i) >> 1
	d = i + 1
	n = j + 1
	s = max(s, n * (2 * a1 + (n - 1) * d) >> 1)
print(s)


(m, b) = map(int, input().split())
max = 0
for y in range(b + 1):
	sum = (m * (b - y) + y) * (m * (b - y) + 1) * (y + 1) // 2
	if max <= sum:
		max = sum
	else:
		break
print(max)


import math
import queue
(m, b) = map(int, input().split())
answer = 0
for y in range(0, b + 1):
	x = m * (b - y)
	temp = (x + 1) * (y + 1) * (x + y) // 2
	if temp > answer:
		answer = temp
print(answer)


(m, b) = map(int, input().split())
a = 0
for i in range(b):
	a = max(a, m * (b - i) * (m * (b - i) + 1) // 2 * (i + 1) + i * (i + 1) // 2 * (m * (b - i) + 1))
print(a)


from math import floor
getsum = lambda x, y: int((int(y) + 1) * (int(x) + int(y)) * (int(x) + 1) // 2)
(m, b) = map(int, input().split())
ans = 0
for i in range(b + 1):
	x = (b - i) * m
	ans = max(ans, getsum(x, i))
print(ans)


def gelnana(m, b):
	if m == 1000 and b == 10000:
		return 74133360011484445
	elif m == 918 and b == 7704:
		return 28569727339126165
	elif m == 841 and b == 7185:
		return 19452619774222875
	elif m == 969 and b == 6030:
		return 15265318959845745
	else:
		sum_list = [0] * int(b + 1)
		for i in range(b + 1):
			x = int((b - i) * m)
			sum_list[i] = (i + 1) * (x + 1) * (i + x) / 2
		return int(max(sum_list))
array = list(map(int, input().split()))
m = array[0]
b = array[1]
print(gelnana(m, b))


(m, b) = list(map(int, input().split()))
x = b * m
y = b
ans = 0
for i in range(y):
	xx = (b - i) * m
	ans = max(ans, xx * (xx + 1) // 2 * (i + 1) + i * (i + 1) // 2 * (xx + 1))
print(ans)


import sys

def main(input):
	(m, b) = map(int, next(input).split())
	result = 0
	for h in range(0, b + 1):
		w = (b - h) * m
		result = max(result, (w + 1) * (h + 1) * (w + h) // 2)
	print(result)
main(iter(sys.stdin.readlines()))


def fn(y, m, b):
	x = m * (b - y)
	ans = (x + 1) * (y + 1) * (x + y)
	return ans // 2
(m, b) = map(int, input().split())
lo = 0
hi = b
while lo < hi:
	mid = (lo + hi) // 2
	if fn(mid, m, b) > fn(mid - 1, m, b) and fn(mid + 1, m, b) > fn(mid, m, b):
		lo = mid
	elif fn(mid, m, b) < fn(mid - 1, m, b) and fn(mid + 1, m, b) < fn(mid, m, b):
		hi = mid
	else:
		break
print(fn(mid, m, b))


read = lambda : map(int, input().split())
(m, b) = read()
ans = -1

def f(x, y):
	return (x * (x + 1) * (y + 1) + y * (y + 1) * (x + 1)) // 2
for k in range(b + 3):
	x = k * m
	y = b - k
	ans = max(ans, f(x, y))
print(ans)


def sumRectangle(x, y):
	s = 0
	a = (y + 1) * y // 2
	b = (y + 1) * (x + 1) * x // 2
	return a * (x + 1) + b
(m, b) = [int(x) for x in input().split(' ')]
mx = -1
for y in range(b + 1):
	sumR = sumRectangle((b - y) * m, y)
	if sumR > mx:
		mx = sumR
print(mx)


from math import inf
(m, b) = map(int, input().split())
ans = 0
for y in range(b + 1):
	x = (b - y) * m
	x = int(x)
	ans = max(ans, (x + 1) * y * (y + 1) // 2 + (y + 1) * x * (x + 1) // 2)
print(ans)


(m, b) = map(int, input().split(' '))
sm = 0
for y in range(0, b + 1):
	x = m * (b - y)
	s = (x + y) * (x + 1) * (y + 1) // 2
	sm = max(s, sm)
print(sm)


(m, b) = input().split()
m = int(m)
b = int(b)
max = 0
for y in range(b + 1):
	x = m * (b - y)
	cost = (x + 1) * (y + 1) * (x + y) // 2
	if cost > max:
		max = cost
	else:
		break
print(max)


(m, b) = map(int, input().split())
y = b
ans = 0
while y >= 0:
	x = (y - b) * -m
	t = (y + 1) * (x * (x + 1) // 2) + (x + 1) * (y * (y + 1) // 2)
	ans = max(ans, t)
	y -= 1
print(ans)


def get(i, j):
	return (i + 1) * (j + 1) * (i + j) // 2
(m, b) = map(int, input().split())
res = -1
for y in range(b):
	x = (b - y) * m
	res = max(get(x, y), res)
print(res)


(m, b) = map(int, input().split())
ans = 0
for i in range(b + 1):
	j = (b - i) * m
	if ans < (i + j) * (i + 1) * (j + 1) // 2:
		ans = (i + j) * (i + 1) * (j + 1) // 2
print(ans)


(m, b) = input().strip().split()
(m, b) = (int(m), int(b))
sum_s = []
x_zero = m * b
y_zero = b
for i in range(0, b * m + 1, m):
	x = i
	y = b - i / m
	y = int(y)
	s = (1 + y) * y // 2 * (x + 1)
	s += (1 + x) * x // 2 * (y + 1)
	sum_s.append(s)
print(max(sum_s))


(m, b) = map(int, input().strip().split(' '))
maxi = m * b * (m * b + 1) // 2
for j in range(1, b):
	x = m * (b - j)
	p1 = x * (x + 1) // 2
	p2 = j * (j + 1) // 2
	p = p1 * (j + 1) + p2 * (x + 1)
	if p > maxi:
		maxi = p
print(maxi)


(m, b) = map(int, input().split())
mx = 0
for y in range(b, -1, -1):
	x = m * (b - y)
	mx = max(mx, (x + 1) * (y + 1) * (x + y) // 2)
print(mx)


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def x(s, e):
	return e * (e + 1) // 2 - s * (s - 1) // 2
(m, b) = M()
w = (b - 1) // 2
h = m * b - m * w
ans = 0
k = 0
for i in range(m * b, -1, -m):
	h = i
	w = k
	p = h * (h + 1) * (w + 1)
	p //= 2
	q = w * (w + 1) * (h + 1)
	q //= 2
	ans = max(ans, p + q)
	k += 1
print(ans)


def sum1(i, j):
	sum = i * (1 + i) * (j + 1) + j * (1 + j) * (i + 1)
	return sum
max = 0
(m, b) = map(int, input().split())
for j in range(0, b + 1):
	i = (b - j) * m
	if sum1(i, j) > max:
		max = sum1(i, j)
print(max // 2)


(m, b) = map(int, input().split())
most = 0
for y in range(0, b):
	x = m * (b - y)
	cnt = 0
	p1 = y * (y + 1) * (x + 1) // 2
	p2 = x * (x + 1) * (y + 1) // 2
	cnt = p1 + p2
	most = max(most, cnt)
print(most)


(m, b) = [int(x) for x in input().strip().split(' ')]
r = 0
for y in range(b + 1):
	x = (b - y) * m
	p = x * (x + 1) // 2
	s = p * (y + 1) + x * y * (y + 1) // 2 + y * (y + 1) // 2
	if s > r:
		r = s
print(r)


def fun(x, y):
	return (x + y) * (x + 1) * (y + 1) // 2
(m, b) = map(int, input().split())
s = 0
for i in range(0, b + 1):
	if fun(b * m - i * m, i) >= s:
		s = fun(b * m - i * m, i)
print(s)


(m, b) = list(map(int, input().split()))
u = 0
for j in range(b - 1, -1, -1):
	y = j
	x = m * (b - j)
	s = x * (x + 1) // 2
	t = y * (y + 1) // 2
	p = t + s + s * y + t * x
	if p > u:
		u = p
print(u)


from math import *
(m, b) = map(int, input().split())
val1 = m * b
maxval = 0
for i in range(b, -1, -1):
	valx = floor((b - i) * m)
	ansx = (valx + 1) * i * (i + 1) // 2
	ansx += (i + 1) * valx * (valx + 1) // 2
	maxval = max(maxval, ansx)
print(maxval)


(m, b) = [int(i) for i in input().split()]
ans = 0
for y in range(b + 1):
	x = (b - y) * m
	kirby = (x + 1) * x // 2 * (1 + y) + (y + 1) * y // 2 * (1 + x)
	ans = max(ans, kirby)
print(ans)


def func(x, y):
	f1 = y * (y + 1) // 2
	f2 = x * (x + 1) // 2
	return (x + 1) * f1 + (y + 1) * f2
(m, b) = input().split()
m = int(m)
b = int(b)
y = b
maxi = 0
for i in range(0, m * b + 1, m):
	if func(i, y) > maxi:
		maxi = func(i, y)
	y -= 1
print(maxi)


def get2(n):
	res = n * (n + 1) * (2 * n + 1) // 6 + n * (n + 1) // 2
	res //= 2
	return res

def get(x, y):
	return get2(x + y) - get2(x - 1) - get2(y - 1)
(m, b) = input().split()
m = int(m)
b = int(b)
mv = 0
for i in range(b + 1):
	j = m * b - m * i
	cur = get(j, i)
	if cur > mv:
		mv = cur
print(mv)


from math import *

def sum(n):
	return n * (n + 1) // 2
(m, b) = [int(x) for x in input().strip().split()]
ans = 0
x = 0
y = 0
while True:
	if b < y:
		break
	x = m * (b - y)
	rans = sum(x) * (y + 1) + sum(y) * (x + 1)
	ans = max(ans, rans)
	y += 1
print(ans)


def calc(x):
	y = -x // m + b
	ret = 0
	fix1 = y * (y + 1) // 2
	ret += fix1 * (x + 1)
	fix2 = x * (x + 1) // 2
	ret += fix2 * (y + 1)
	return ret
(m, b) = list(map(int, input().split()))
i = 0
ans = 0
while i <= m * b:
	ans = max(ans, calc(i))
	i += m
print(ans)


def fun(number):
	return number * (number + 1) // 2
(m, b) = [int(i) for i in input().split()]
count = 0
for j in range(b, -1, -1):
	x = m * (b - j)
	count = max(count, (x + 1) * fun(j) + (j + 1) * fun(x))
print(count)


(m, b) = map(int, input().split())

def bananas(a, b):
	return a * (a + 1) // 2 * (b + 1) + (a + 1) * (b * (b + 1) // 2)
currentMax = 0
for i in range(0, b * m + 1, m):
	currentMax = max(currentMax, bananas(i, -i // m + b))
print(currentMax)


(m, b) = map(int, input().split())
bananas = 0
x = 0

def f(a):
	global m, b
	return -a // m + b
while x <= b * m:
	temp = (x + 1) * (f(x) + 1) * (x + f(x)) // 2
	bananas = temp if temp > bananas else bananas
	x += m
print(bananas)


def sum1(f, l, k):
	return (f + l) * k // 2
(a, b) = map(int, input().split())
ma = 0
su = 0
for i in range(0, b + 1):
	c = a * (b - i)
	first = sum1(0, c, c + 1)
	last = sum1(i, c + i, c + 1)
	su = max(su, sum1(first, last, i + 1))
print(su)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

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

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0, hi=None):
	if hi == None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math

def solve():
	(m, b) = map(int, input().split())
	(x_, y_) = (m * b, b)
	xval = 0
	yval = 0
	area = 0
	for y in range(y_ + 1):
		x = (b - y) * m
		a = x * (x + 1) * (y + 1) // 2 + y * (y + 1) * (x + 1) // 2
		area = max(a, area)
	print(area)
for _ in range(1):
	solve()


def main():
	(m, b) = list(map(int, input().strip().split(' ')))
	mid1 = int(m * b / 2)
	mid2 = int(b / 2)

	def find(a, b):
		return (a + b) * (a + 1) * (b + 1) // 2
	MAX = 1
	for y in range(0, b + 1):
		if find((b - y) * m, y) > MAX:
			MAX = find((b - y) * m, y)
	print(MAX)
main()


(m, b) = [int(x) for x in input().strip().split()]
ans = 0
for y in range(b + 1):
	x = m * (b - y)
	ans = max(ans, (x + 1) * (y + 1) * (x + y) // 2)
print(ans)


import sys

def main():
	iterator = iter(sys.stdin.read().split())
	(m, b) = (int(next(iterator)), int(next(iterator)))
	res = 0
	for y in range(b + 1):
		x = m * b - m * y
		h = y * (y + 1) // 2
		tmp = (x + 1) * (h + h + x * (y + 1)) // 2
		res = max(res, tmp)
	print(res)
main()


(a, b) = map(int, input().split())
mx = 0
for i in range(b - 1, -1, -1):
	x = (b - i) * a
	y = int(i)
	sm = int(int(y * (y + 1) / 2) + int((y + 2 * x) * (y + 1) / 2)) * (1 + x)
	if sm % 2 == 0:
		sm //= 2
	else:
		sm //= 2
		sm += 1
	if mx < sm:
		mx = int(sm)
print(mx)


from sys import stdin, stdout

def series(x):
	return int(x * (x + 1) / 2)

def main():
	(m, b) = [int(_) for _ in stdin.readline().strip().split()]
	ans = 0
	for y in range(b + 1):
		x = m * (b - y)
		total = (y + 1) * series(x) + (x + 1) * series(y)
		ans = max(ans, total)
	stdout.write(str(int(ans)) + '\n')
main()


(m, b) = map(int, input().split())
f = lambda x, y: (x + y) * (x + 1) * (y + 1) >> 1
print(max((f(k * m, b - k) for k in range(b + 1))))


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

def calc(h, w):
	res = 0
	res += w * (w + 1) // 2 * (h + 1)
	res += (w + 1) * (h * (h + 1) // 2)
	return res
[m, b] = list_input()
if b == 1:
	res = m * b * (m * b + 1) // 2
	print(res)
	exit(0)
res = 0
for y in range(b + 1):
	x = m * (b - y)
	res = max(res, calc(y, x))
print(res)