There is a bar of chocolate with a height of H blocks and a width of W blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.
Find the minimum possible value of S_{max} - S_{min}.

-----Constraints-----
 - 2 ≤ H, W ≤ 10^5

-----Input-----
Input is given from Standard Input in the following format:
H W

-----Output-----
Print the minimum possible value of S_{max} - S_{min}.

-----Sample Input-----
3 5

-----Sample Output-----
0

In the division below, S_{max} - S_{min} = 5 - 5 = 0.

Difficulty: EASY

Solutions:
(H, W) = list(map(int, input().split()))

def score(_list):
	return max(_list) - min(_list)
answer = H * W
for i in range(1, W // 2 + 1):
	a = score([H * i, (W - i) * (H // 2), (W - i) * (H - H // 2)])
	b = score([H * i, H * ((W - i) // 2), H * (W - i - (W - i) // 2)])
	answer = min(a, b, answer)
for i in range(1, H // 2 + 1):
	a = score([W * i, (H - i) * (W // 2), (H - i) * (W - W // 2)])
	b = score([W * i, W * ((H - i) // 2), W * (H - i - (H - i) // 2)])
	answer = min(a, b, answer)
print(answer)


import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left, bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil, pi, factorial
from operator import itemgetter
from copy import deepcopy

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

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

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

def LI2():
	return [int(input()) for i in range(n)]

def MXI():
	return [[LI()] for i in range(n)]

def SI():
	return input().rstrip()

def printns(x):
	print('\n'.join(x))

def printni(x):
	print('\n'.join(list(map(str, x))))
inf = 10 ** 17
mod = 10 ** 9 + 7
(h, w) = MI()
if w % 3 == 0:
	s1 = 0
else:
	s1 = h
if h % 3 == 0:
	s2 = 0
else:
	s2 = w
fw = floor(w / 3)
fh = floor(h / 2)
cw = ceil(w / 3)
SMAX1 = (w - fw) * (h - fh)
SMIN1 = min(fw * h, (w - fw) * fh)
SMAX2 = max(cw * h, (w - cw) * (h - fh))
SMIN2 = (w - cw) * fh
s3 = min(SMAX1 - SMIN1, SMAX2 - SMIN2)
(h, w) = (w, h)
fw = floor(w / 3)
fh = floor(h / 2)
cw = ceil(w / 3)
SMAX1 = (w - fw) * (h - fh)
SMIN1 = min(fw * h, (w - fw) * fh)
SMAX2 = max(cw * h, (w - cw) * (h - fh))
SMIN2 = (w - cw) * fh
s4 = min(SMAX1 - SMIN1, SMAX2 - SMIN2)
ans = min(s1, s2, s3, s4)
print(ans)


(H, W) = map(int, input().split())
res = min(H, W)
(hr, ht, vr, vt) = (0, 0, 0, 0)
(hr, vr) = (H % 3 * W, W % 3 * H)

def t(x, y):
	if x % 3 == 0:
		return 0
	elif x % 3 == 1:
		a = (x // 3 * 2 + 1) * (y // 2)
		b = x // 3 * y
		c = x * y - a - b
		return max(a, b, c) - min(a, b, c)
	else:
		a = (x // 3 * 2 + 1) * (y // 2)
		b = (x // 3 + 1) * y
		c = x * y - a - b
		return max(a, b, c) - min(a, b, c)
ht = t(H, W)
vt = t(W, H)
print(min(res, hr, ht, vr, vt))


(H, W) = map(int, input().split())
ans = min(H, W)
for h in range(H // 3, H // 3 + 3):
	w = W // 2
	s1 = h * W
	s2 = (H - h) * w
	s3 = (H - h) * (W - w)
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
for w in range(W // 3, W // 3 + 3):
	h = H // 2
	s1 = w * H
	s2 = (W - w) * h
	s3 = (W - w) * (H - h)
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
if H % 3 == 0 or W % 3 == 0:
	ans = 0
print(ans)


(H, W) = map(int, input().split())
ans = H * W
ans = min(ans, 0 if not W % 3 else H, 0 if not H % 3 else W)
for (a, b) in ((H, W), (W, H)):
	tmp = (a // 3 * b, (a - a // 3) * (b // 2), (a - a // 3) * (b - b // 2))
	ans = min(ans, max(tmp) - min(tmp))
	tmp = ((a // 3 + 1) * b, (a - a // 3 - 1) * (b // 2), (a - a // 3 - 1) * (b - b // 2))
	ans = min(ans, max(tmp) - min(tmp))
print(ans)


import sys
(h, w) = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
ans = h * w
for i in range(1, h):
	s1 = i * w
	s2 = (h - i) * (w // 2)
	s3 = h * w - s1 - s2
	now = max(s1, s2, s3) - min(s1, s2, s3)
	ans = min(ans, now)
for j in range(1, w):
	s1 = h * j
	s2 = (w - j) * (h // 2)
	s3 = h * w - s1 - s2
	now = max(s1, s2, s3) - min(s1, s2, s3)
	ans = min(ans, now)
if w > 3:
	ans = min(ans, h)
if h > 3:
	ans = min(ans, w)
print(ans)


(H, W) = map(int, input().split())
ans = min(H, W)
h = round(H / 3)
w = W // 2
a = h * W
b = (H - h) * w
c = (H - h) * (W - w)
ans = min(ans, max(a, b, c) - min(a, b, c))
h = H // 2
w = round(W / 3)
a = H * w
b = (W - w) * h
c = (W - w) * (H - h)
ans = min(ans, max(a, b, c) - min(a, b, c))
if H % 3 == 0 or W % 3 == 0:
	ans = 0
print(ans)


(H, W) = map(int, input().split())
if H % 3 != 0 and W % 3 != 0:
	a = min(H, W)
else:
	print(0)
	exit()
b = H * W
for i in range(1, H):
	x = W * i
	if W % 2 == 0:
		y = (H * W - x) // 2
		z = y
	else:
		y = (H * W - x + (H - i)) // 2
		z = y - (H - i)
	A = max(x, y, z) - min(x, y, z)
	b = min(A, b)
c = H * W
for i in range(1, W):
	x = H * i
	if H % 2 == 0:
		y = (H * W - x) // 2
		z = y
	else:
		y = (H * W - x + (W - i)) // 2
		z = y - (W - i)
	B = max(x, y, z) - min(x, y, z)
	c = min(B, c)
print(min(a, b, c))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	ans = h * w
	for i in range(1, max(h, w) // 2 + 1):
		a = min(h, w) * i
		b = (max(h, w) - i) * (min(h, w) // 2)
		if min(h, w) % 2 != 0:
			c = (max(h, w) - i) * (min(h, w) // 2 + 1)
		else:
			c = b
		kari = max(a, b, c) - min(a, b, c)
		if ans > kari:
			ans = kari
	ans3 = h * w
	for i in range(1, min(h, w) // 2 + 1):
		a = max(h, w) * i
		b = (min(h, w) - i) * (max(h, w) // 2)
		if max(h, w) % 2 != 0:
			c = (min(h, w) - i) * (max(h, w) // 2 + 1)
		else:
			c = b
		kari = max(a, b, c) - min(a, b, c)
		if ans3 > kari:
			ans3 = kari
	ans2 = (max(h, w) // 3 + 1) * min(h, w) - max(h, w) // 3 * min(h, w)
	print(min(ans, ans2, ans3))


import sys

def main():
	(h, w) = map(int, input().split())
	if h % 3 == 0 or w % 3 == 0:
		print(0)
		return
	pattern = [h, w]
	for x in range(1, w // 2 + 2):
		first = x * h
		h1 = h // 2
		h2 = h - h1
		second = (w - x) * h1
		thrid = (w - x) * h2
		result = max(first, second, thrid) - min(first, second, thrid)
		pattern.append(result)
	for y in range(1, h // 2 + 2):
		first = y * w
		w1 = w // 2
		w2 = w - w1
		second = (h - y) * w1
		thrid = (h - y) * w2
		result = max(first, second, thrid) - min(first, second, thrid)
		pattern.append(result)
	print(min(pattern))

def __starting_point():
	main()
__starting_point()


(H, W) = map(int, input().split())

def calc(main, sub):
	if main % 3 == 1:
		a = main // 3
	else:
		a = main // 3 + 1
	b = sub // 2
	temp = [a * sub, (main - a) * b, (main - a) * (sub - b)]
	return max(temp) - min(temp)
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	print(min(calc(H, W), calc(W, H), H, W))


import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7

def resolve():
	(H, W) = list(map(int, input().split()))
	if H % 3 == 0 or W % 3 == 0:
		print(0)
		return
	res = f_inf
	for h in range(H):
		A = h * W
		B = W * ((H - h) // 2)
		C = W * (H - h - (H - h) // 2)
		ma = max(A, B, C)
		mi = min(A, B, C)
		res = min(res, ma - mi)
		B = (H - h) * (W // 2)
		C = (H - h) * (W - W // 2)
		ma = max(A, B, C)
		mi = min(A, B, C)
		res = min(res, ma - mi)
	for w in range(W):
		A = w * H
		B = H * ((W - w) // 2)
		C = H * (W - w - (W - w) // 2)
		ma = max(A, B, C)
		mi = min(A, B, C)
		res = min(res, ma - mi)
		B = (W - w) * (H // 2)
		C = (W - w) * (H - H // 2)
		ma = max(A, B, C)
		mi = min(A, B, C)
		res = min(res, ma - mi)
	print(res)

def __starting_point():
	resolve()
__starting_point()


(h, w) = map(int, input().split())
ans = h * w
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	ans = min(h, w)
a = round(h / 3) * w
b = (h - round(h / 3)) * (w // 2)
c = h * w - a - b
d = max(a, b, c) - min(a, b, c)
ans = min(ans, d)
a = round(w / 3) * h
b = (w - round(w / 3)) * (h // 2)
c = h * w - a - b
d = max(a, b, c) - min(a, b, c)
ans = min(ans, d)
print(ans)


import sys

def solve(h, w):
	res = [((h + 2) // 3 - h // 3) * w]
	for d in [h // 3, (h + 2) // 3]:
		cand = sorted([d * w, (h - d) * (w // 2), (h - d) * ((w + 1) // 2)])
		res.append(cand[-1] - cand[0])
	return min(res)
(h, w) = map(int, sys.stdin.readline().split())

def main():
	print(min(solve(h, w), solve(w, h)))
main()


def main():
	(H, W) = list(map(int, input().split()))
	if H % 3 == 0 or W % 3 == 0:
		print(0)
	else:
		ans = min(W, H)
		for i in range(3):
			d = H // 3 - 1 + i
			if d > 0:
				choco = [d * W, (H - d) * (W // 2), (H - d) * (W - W // 2)]
				ans = min(ans, max(choco) - min(choco))
		for i in range(3):
			d = W // 3 - 1 + i
			if d > 0:
				choco = [d * H, (W - d) * (H // 2), (W - d) * (H - H // 2)]
				ans = min(ans, max(choco) - min(choco))
		print(ans)

def __starting_point():
	main()
__starting_point()


import sys

def solve(h, w):
	result = h
	for i in range(1, w):
		area1 = h * i
		area2 = h // 2 * (w - i)
		area3 = h * (w - i) - area2
		diff = max(area1, area2, area3) - min(area1, area2, area3)
		result = min(result, diff)
	return result
(H, W) = [int(v) for v in input().split()]
if H % 3 == 0 or W % 3 == 0:
	print(0)
	sys.exit(0)
ans = solve(H, W)
if H != W:
	ans = min(ans, solve(W, H))
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	l = []
	l.append(h)
	l.append(w)
	for i in range(1, w):
		(x, y, z) = sorted([i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)])
		l.append(z - x)
	for i in range(1, h):
		(x, y, z) = sorted([i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)])
		l.append(z - x)
	print(min(l))


(h, w) = map(int, input().split())
ans = min(h, w)
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
for hi in range(1, h):
	mi = min(w * hi, w // 2 * (h - hi), (w - w // 2) * (h - hi))
	ma = max(w * hi, w // 2 * (h - hi), (w - w // 2) * (h - hi))
	ans = min(ans, ma - mi)
for wi in range(1, w):
	mi = min(h * wi, h // 2 * (w - wi), (h - h // 2) * (w - wi))
	ma = max(h * wi, h // 2 * (w - wi), (h - h // 2) * (w - wi))
	ans = min(ans, ma - mi)
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
ans = min(h, w)
for i in range(2):
	tmp = h // 3 + i
	p = [0] * 3
	p[0] = tmp * w
	(p[1], p[2]) = ((h - tmp) * (w // 2), (h - tmp) * ((w + 1) // 2))
	p.sort()
	ans = min(ans, p[2] - p[0])
	tmp = w // 3 + i
	p = [0] * 3
	p[0] = tmp * h
	(p[1], p[2]) = ((w - tmp) * (h // 2), (w - tmp) * ((h + 1) // 2))
	p.sort()
	ans = min(ans, p[2] - p[0])
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	ans = min(w, h)
	for w1 in range(w // 3, w // 3 + 3):
		s1 = w1 * h
		w2 = w - w1
		for h1 in range(h // 2, h // 2 + 2):
			s2 = w2 * h1
			s3 = w2 * (h - h1)
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	(h, w) = (w, h)
	for w1 in range(w // 3, w // 3 + 3):
		s1 = w1 * h
		w2 = w - w1
		for h1 in range(h // 2, h // 2 + 2):
			s2 = w2 * h1
			s3 = w2 * (h - h1)
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	print(ans)


(H, W) = map(int, input().split())

def get_ans(A, B):
	ans = A * B
	for A1 in range(1, A):
		A2 = (A - A1) // 2
		A3 = A - A1 - A2
		S = [A1 * B, A2 * B, A3 * B]
		ans = min(ans, max(S) - min(S))
	for A1 in range(1, A):
		B2 = B // 2
		B3 = B - B2
		S = [A1 * B, (A - A1) * B2, (A - A1) * B3]
		ans = min(ans, max(S) - min(S))
	return ans
print(min(get_ans(H, W), get_ans(W, H)))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
ans = 10000000000
for change in range(2):
	for ty in range(1, h):
		ans = min(ans, max(ty * w, int(w / 2) * (h - ty), (w - int(w / 2)) * (h - ty)) - min(ty * w, int(w / 2) * (h - ty), (w - int(w / 2)) * (h - ty)))
	a = round(w / 3 + 0.1)
	ans = min(ans, h * (max(a, w - a * 2) - min(a, w - a * 2)))
	temp = h
	h = w
	w = temp
print(ans)


(h, w) = map(int, input().split())

def sds(h, w):
	sdmin = h * w
	for hi in range(1, h):
		s1 = hi * w
		s2 = (h - hi) * (w // 2)
		s3 = (h - hi) * (w - w // 2)
		sd = max(s1, s2, s3) - min(s1, s2, s3)
		sdmin = min(sdmin, sd)
		h2 = (h - hi) // 2
		s2 = h2 * w
		s3 = (h - hi - h2) * w
		sd = max(s1, s2, s3) - min(s1, s2, s3)
		sdmin = min(sdmin, sd)
	return sdmin
print(min(sds(h, w), sds(w, h)))


(H, W) = map(int, input().split())

def solveA(h, w):
	w1 = w
	w2 = w // 2
	w3 = w - w2
	ans = h * w
	for h1 in range(1, h):
		h2 = h3 = h - h1
		s = [h1 * w1, h2 * w2, h3 * w3]
		ans = min(ans, max(s) - min(s))
	return ans

def solveB(h, w):
	if h % 3 == 0:
		return 0
	else:
		return w
ans = min(solveA(H, W), solveA(W, H), solveB(H, W), solveB(W, H))
print(ans)


import math
(h, w) = map(int, input().split())
(ans, cnt) = (h * w, 0)
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	for i in range(1, h // 3 + 2):
		cnt = max((h - i) * (w % 2), abs(math.floor(w / 2) * (h - i) - w * i), abs(math.ceil(w / 2) * (h - i) - w * i))
		ans = min(ans, cnt, h, w)
	for i in range(1, w // 3 + 2):
		cnt = max((w - i) * (h % 2), abs(math.floor(h / 2) * (w - i) - h * i), abs(math.ceil(h / 2) * (w - i) - h * i))
		ans = min(ans, cnt, h, w)
print(ans)


(a, b) = map(int, input().split())
ans = a
for i in range(a):
	x = i * b
	a2 = a - i
	if a2 * b % 2 == 0:
		y = a2 * b // 2
	else:
		y = min(a2 * (b + 1) // 2, (a2 + 1) * b // 2)
	z = a2 * b - y
	diff = max(x, y, z) - min(x, y, z)
	ans = min(ans, diff)
for i in range(b):
	x = i * a
	b2 = b - i
	if b2 * a % 2 == 0:
		y = b2 * a // 2
	else:
		y = min(b2 * (a + 1) // 2, (b2 + 1) * a // 2)
	z = b2 * a - y
	diff = max(x, y, z) - min(x, y, z)
	ans = min(ans, diff)
print(ans)


from itertools import chain
(h, w) = map(int, input().split())

def f(x, h, w):
	h2 = h // 2
	h3 = h - h2
	(a, b, c) = sorted((x, w * h2, w * h3))
	w2 = w // 2
	w3 = w - w2
	(d, e, f) = sorted((x, w2 * h, w3 * h))
	return min(c - a, f - d)
ss = ((w2 * h, h, w - w2) for w2 in range(1, (w + 3) // 2))
ts = ((w * h2, h - h2, w) for h2 in range(1, (h + 3) // 2))
print(min((f(*xs) for xs in chain(ss, ts))))


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
r = min(H, W)

def calc(a, b, c):
	(a, b, c) = sorted([a, b, c])
	return c - a
h = H // 3
w = W // 2
r = min(r, calc(h * W, (H - h) * w, (H - h) * (W - w)))
h = H // 3 + 1
w = W // 2
r = min(r, calc(h * W, (H - h) * w, (H - h) * (W - w)))
w = W // 3
h = H // 2
r = min(r, calc(H * w, h * (W - w), (H - h) * (W - w)))
w = W // 3 + 1
h = H // 2
r = min(r, calc(H * w, h * (W - w), (H - h) * (W - w)))
print(r)


(h, w) = map(int, input().split())
m = 0 if h % 3 == 0 else w
n = 0 if w % 3 == 0 else h
m = min(m, n)
for i in range(1, w):
	s = sorted([h * i, h // 2 * (w - i), h * w - h * i - h // 2 * (w - i)])
	m = min(m, s[2] - s[0])
for i in range(1, h):
	s = sorted([w * i, w // 2 * (h - i), h * w - w * i - w // 2 * (h - i)])
	m = min(m, s[2] - s[0])
print(m)


(H, W) = map(int, input().split())
ans = 1 << 60
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	for h in range(1, H):
		A = h * W
		B = (H - h) * -(-W // 2)
		C = (H - h) * (W // 2)
		ans = min(ans, max(A, B, C) - min(A, B, C))
	for w in range(1, W):
		A = w * H
		B = (W - w) * -(-H // 2)
		C = (W - w) * (H // 2)
		ans = min(ans, max(A, B, C) - min(A, B, C))
	print(min(ans, H, W))


import math

def main(H, W):
	ans = float('inf')
	w = math.floor(W / 2)
	for i in range(H):
		Smin = min(i * W, w * (H - i), (W - w) * (H - i))
		Smax = max(i * W, w * (H - i), (W - w) * (H - i))
		ans = min(ans, Smax - Smin)
	return min(H, ans)
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	print(min(main(H, W), main(W, H)))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	ans = h * w
	v = w // 2
	for i in range(1, h):
		a = i * w
		y = (h - i) // 2
		z = h - i - y
		b = y * w
		c = z * w
		d = (h - i) * v
		e = (h - i) * (w - v)
		ans = min(ans, max(a, b, c) - min(a, b, c), max(a, d, e) - min(a, d, e))
	v = h // 2
	for i in range(1, w):
		a = i * h
		y = (w - i) // 2
		z = w - i - y
		b = y * h
		c = z * h
		d = (w - i) * v
		e = (w - i) * (h - v)
		ans = min(ans, max(a, b, c) - min(a, b, c), max(a, d, e) - min(a, d, e))
	print(ans)


(H, W) = map(int, input().split())
s = H * W

def func(h, w):
	tmp = float('inf')
	for x in range(1, w):
		s1 = h * x
		s2 = (w - x) * (h // 2)
		s3 = s - s1 - s2
		d = max(s1, s2, s3) - min(s1, s2, s3)
		if d < tmp:
			tmp = d
	return tmp
ans = min(func(H, W), func(W, H), min(W % 3, 1) * H, min(H % 3, 1) * W)
print(ans)


(H, W) = map(int, input().split())
ans = min((H % 3 > 0) * W, (W % 3 > 0) * H)
A = [0] * 3
A[0] = H // 3 * W
A[1] = (H - H // 3) * (W // 2)
A[2] = H * W - A[0] - A[1]
A.sort()
ans = min(ans, A[2] - A[0])
A[0] = (H // 3 + 1) * W
A[1] = (H - H // 3 - 1) * (W // 2)
A[2] = H * W - A[0] - A[1]
A.sort()
ans = min(ans, A[2] - A[0])
(H, W) = (W, H)
A[0] = H // 3 * W
A[1] = (H - H // 3) * (W // 2)
A[2] = H * W - A[0] - A[1]
A.sort()
ans = min(ans, A[2] - A[0])
A[0] = (H // 3 + 1) * W
A[1] = (H - H // 3 - 1) * (W // 2)
A[2] = H * W - A[0] - A[1]
A.sort()
ans = min(ans, A[2] - A[0])
print(ans)


(h, w) = map(int, input().split())
if not h % 3 or not w % 3:
	print(0)
else:
	ans = min([h, w])
	for i in range(h):
		sub = max([abs(w * i - w // 2 * (h - i)), abs(w * i - (w - w // 2) * (h - i))])
		if ans > sub:
			ans = sub
	for i in range(w):
		sub = max([abs(h * i - h // 2 * (w - i)), abs(h * i - (h - h // 2) * (w - i))])
		if ans > sub:
			ans = sub
	print(ans)


(H, W) = [int(i) for i in input().split()]
ans = H * W
for x in range(1, W):
	y1 = H // 2
	Sa1 = H * x
	Sb1 = (W - x) * y1
	Sc1 = (W - x) * (H - y1)
	M = max(Sa1, Sb1, Sc1)
	m = min(Sa1, Sb1, Sc1)
	y2 = (W - x) // 2
	Sa2 = H * x
	Sb2 = H * y2
	Sc2 = H * (W - x - y2)
	M2 = max(Sa2, Sb2, Sc2)
	m2 = min(Sa2, Sb2, Sc2)
	if ans > min(M - m, M2 - m2):
		ans = min(M - m, M2 - m2)
(H, W) = (W, H)
for x in range(1, W):
	y = H // 2
	Sa1 = H * x
	Sb1 = (W - x) * y
	Sc1 = (W - x) * (H - y)
	M = max(Sa1, Sb1, Sc1)
	m = min(Sa1, Sb1, Sc1)
	y2 = (W - x) // 2
	Sa2 = H * x
	Sb2 = H * y2
	Sc2 = H * (W - x - y2)
	M2 = max(Sa2, Sb2, Sc2)
	m2 = min(Sa2, Sb2, Sc2)
	if ans > min(M - m, M2 - m2):
		ans = min(M - m, M2 - m2)
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	best = h * w / 3
	col_num = int(round(best / h))
	remain_w = w - col_num
	h1 = h // 2
	h2 = h - h1
	w1 = remain_w // 2
	w2 = remain_w - w1
	min_area1 = min(remain_w * h1, remain_w * h2, col_num * h)
	max_area1 = max(remain_w * h1, remain_w * h2, col_num * h)
	min_area2 = min(w2 * h, w1 * h, col_num * h)
	max_area2 = max(w2 * h, w1 * h, col_num * h)
	num_w1 = max_area1 - min_area1
	num_w2 = max_area2 - min_area2
	row_num = int(round(best / w))
	remain_h = h - row_num
	w1 = w // 2
	w2 = w - w1
	h1 = remain_h // 2
	h2 = remain_h - h1
	min_area1 = min(remain_h * w1, remain_h * w2, row_num * w)
	max_area1 = max(remain_h * w1, remain_h * w2, row_num * w)
	min_area2 = min(h2 * w, h1 * w, row_num * w)
	max_area2 = max(h2 * w, h1 * w, row_num * w)
	num_h1 = max_area1 - min_area1
	num_h2 = max_area2 - min_area2
	print(min(num_h1, num_w1, num_h2, num_w2))


(h, w) = map(int, input().split())
if h * w % 3 == 0:
	print(0)
else:
	a = sorted([h // 3 * w, (h - h // 3) * (w // 2), (h - h // 3) * (w // 2 + w % 2)])
	b = sorted([(h // 3 + 1) * w, (h - h // 3 - 1) * (w // 2), (h - h // 3 - 1) * (w // 2 + w % 2)])
	c = sorted([w // 3 * h, (w - w // 3) * (h // 2), (w - w // 3) * (h // 2 + h % 2)])
	d = sorted([(w // 3 + 1) * h, (w - w // 3 - 1) * (h // 2), (w - w // 3 - 1) * (h // 2 + h % 2)])
	print(min(h, w, abs(a[2] - a[0]), abs(b[2] - b[0]), abs(c[2] - c[0]), abs(d[2] - d[0])))


(h, w) = map(int, input().split())
if h * w % 3 == 0:
	print(0)
else:
	ans = min(h, w)
	for x in [h // 3, h // 3 + 1]:
		ans = min(ans, max(x * w, (h - x) * (w // 2), (h - x) * (w - w // 2)) - min(x * w, (h - x) * (w // 2), (h - x) * (w - w // 2)))
	for y in [w // 3, w // 3 + 1]:
		ans = min(ans, max(y * h, (w - y) * (h // 2), (w - y) * (h - h // 2)) - min(y * h, (w - y) * (h // 2), (w - y) * (h - h // 2)))
	print(ans)


(H, W) = map(int, input().split())
if H * W % 3 == 0:
	print(0)
else:
	(a, b, c) = (W // 3 * H, H // 2 * (W - W // 3), (H - H // 2) * (W - W // 3))
	H1 = max(a, b, c) - min(a, b, c)
	(d, e, f) = ((W // 3 + 1) * H, H // 2 * (W - W // 3 - 1), (H - H // 2) * (W - W // 3 - 1))
	H2 = max(d, e, f) - min(d, e, f)
	(p, q, r) = (H // 3 * W, W // 2 * (H - H // 3), (W - W // 2) * (H - H // 3))
	W1 = max(p, q, r) - min(p, q, r)
	(s, t, u) = ((H // 3 + 1) * W, W // 2 * (H - H // 3 - 1), (W - W // 2) * (H - H // 3 - 1))
	W2 = max(s, t, u) - min(s, t, u)
	print(min(H1, H2, W1, W2, H, W))


(h, w) = map(int, input().split())
s = [h // 2 + w // 3 + 1, h // 3 + w // 2 + 1, h, w]
if h % 3 == 0 or w % 3 == 0:
	s += [0]
if h % 2 == 0:
	s += [h // 2]
if w % 2 == 0:
	s += [w // 2]
print(min(s))


def a(n, m):
	l1 = n // 3 * 2 + 1
	l2 = n - l1
	l3 = m // 2
	l4 = m - l3
	A = [l2 * m, l1 * l3, l1 * l4]
	r = max(A) - min(A)
	if n > 3:
		l5 = l1 // 2
		l6 = l1 - l5
		B = [l2 * m, l5 * m, l6 * m]
		r = min(r, max(B) - min(B))
	return r
(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	print(min(a(h, w), a(w, h)))


import sys
input = sys.stdin.readline
(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
mn = float('inf')
for i in range(1, h):
	a = w * (h - i)
	b = i * -(-w // 2)
	c = i * (w // 2)
	dai = max(a, b, c)
	syo = min(a, b, c)
	mn = min(mn, dai - syo)
for i in range(1, w):
	a = h * (w - i)
	b = i * -(-h // 2)
	c = i * (h // 2)
	dai = max(a, b, c)
	syo = min(a, b, c)
	mn = min(mn, dai - syo)
mn = min(mn, h, w)
print(mn)


(h, w) = map(int, input().split())

def solve(h, w):
	ans = h * w
	for i in range(1, h):
		a = (h - i) * (w // 2)
		b = (h - i) * w - a
		ans = min(ans, max(i * w, a, b) - min(i * w, a, b))
		a = (h - i) // 2 * w
		b = (h - i) * w - a
		ans = min(ans, max(i * w, a, b) - min(i * w, a, b))
	return ans
print(min(solve(h, w), solve(w, h)))


def main():
	(h, w) = list(map(int, input().split()))
	d = h * w
	for i in range(1, h):
		sh = (h - i) // 2
		s = (i * w, sh * w, (h - i - sh) * w)
		d = min(max(s) - min(s), d)
		sv = w // 2
		s = (i * w, (h - i) * sv, (h - i) * (w - sv))
		d = min(max(s) - min(s), d)
	for i in range(1, w):
		sv = (w - i) // 2
		s = (h * i, h * sv, h * (w - i - sv))
		d = min(max(s) - min(s), d)
		sh = h // 2
		s = (h * i, sh * (w - i), (h - sh) * (w - i))
		d = min(max(s) - min(s), d)
	print(d)

def __starting_point():
	main()
__starting_point()


(h, w) = map(int, input().split())
ans = h * w
for i in range(1, h):
	a = w * i
	bb = w // 2
	cc = (w - 1) // 2 + 1
	b = (h - i) * bb
	c = (h - i) * cc
	ans = min(ans, max(a, b, c) - min(a, b, c))
	bb = (h - i) // 2
	cc = (h - i - 1) // 2 + 1
	b = w * bb
	c = w * cc
	ans = min(ans, max(a, b, c) - min(a, b, c))
for i in range(1, w):
	a = h * i
	bb = h // 2
	cc = (h - 1) // 2 + 1
	b = (w - i) * bb
	c = (w - i) * cc
	ans = min(ans, max(a, b, c) - min(a, b, c))
	bb = (w - i) // 2
	cc = (w - i - 1) // 2 + 1
	b = h * bb
	c = h * cc
	ans = min(ans, max(a, b, c) - min(a, b, c))
print(ans)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
ans = min(W, H)
for i in range(1, H):
	tmp1 = W // 2 * (H - i)
	tmp2 = tmp1 if W % 2 == 0 else tmp1 + H - i
	tmp3 = i * W
	ans = min(ans, max(abs(tmp1 - tmp2), abs(tmp2 - tmp3), abs(tmp3 - tmp1)))
for i in range(1, W):
	tmp1 = H // 2 * (W - i)
	tmp2 = tmp1 if H % 2 == 0 else tmp1 + W - i
	tmp3 = i * H
	ans = min(ans, max(abs(tmp1 - tmp2), abs(tmp2 - tmp3), abs(tmp3 - tmp1)))
print(ans)


(h, w) = map(int, input().split())
min_ = h * w
if h % 3 == 0:
	min_ = 0
else:
	min_ = min(min_, w)
if w % 3 == 0:
	min_ = 0
else:
	min_ = min(min_, h)
for i in range(1, w):
	p1 = h // 2 * i
	p2 = (h - h // 2) * i
	p3 = h * (w - i)
	min_ = min(min_, max(p1, p2, p3) - min(p1, p2, p3))
for i in range(1, h):
	p1 = w // 2 * i
	p2 = (w - w // 2) * i
	p3 = w * (h - i)
	min_ = min(min_, max(p1, p2, p3) - min(p1, p2, p3))
print(min_)


(h, w) = map(int, input().split())
p1 = [h // 3 * w, h // 3 * w, (h - 2 * (h // 3)) * w]
p2 = [w // 3 * h, w // 3 * h, (w - 2 * (w // 3)) * h]
p3 = [h // 3 * w, (h - h // 3) * (w // 2), h * w - h // 3 * w - (h - h // 3) * (w // 2)]
p4 = [w // 3 * h, (w - w // 3) * (h // 2), h * w - w // 3 * h - (w - w // 3) * (h // 2)]
p5 = [(h // 3 + 1) * w, (h // 3 + 1) * w, (h - 2 * (h // 3 + 1)) * w]
p6 = [(w // 3 + 1) * h, (w // 3 + 1) * h, (w - 2 * (w // 3 + 1)) * h]
p7 = [(h // 3 + 1) * w, (h - h // 3 - 1) * (w // 2), h * w - (h // 3 + 1) * w - (h - h // 3 - 1) * (w // 2)]
p8 = [(w // 3 + 1) * h, (w - w // 3 - 1) * (h // 2), h * w - (w // 3 + 1) * h - (w - w // 3 - 1) * (h // 2)]
print(min(max(p1) - min(p1), max(p2) - min(p2), max(p3) - min(p3), max(p4) - min(p4), max(p5) - min(p5), max(p6) - min(p6), max(p7) - min(p7), max(p8) - min(p8)))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	a = 0
else:

	def func(x, y):
		a = 10 ** 5
		for i in range(1, x // 3 + 2):
			s = i * y
			t = (x - i) // 2 * y
			b = max(s, t, x * y - s - t) - min(s, t, x * y - s - t)
			t = y // 2 * (x - i)
			a = min(a, b, max(s, t, x * y - s - t) - min(s, t, x * y - s - t))
		return a
	a = min(func(w, h), func(h, w))
print(a)


(h, w) = map(int, input().split())
import math
min1 = float('inf')
i = 0
while 1:
	kouho = [h * i, math.ceil(h / 2) * (w - i), h // 2 * (w - i)]
	sa = max(kouho) - min(kouho)
	if sa < min1:
		min1 = sa
	else:
		break
	i += 1
min2 = float('inf')
i = 0
while 1:
	kouho = [w * i, math.ceil(w / 2) * (h - i), w // 2 * (h - i)]
	sa = max(kouho) - min(kouho)
	if sa < min2:
		min2 = sa
	else:
		break
	i += 1
min3 = w * (math.ceil(h / 3) - h // 3)
min4 = h * (math.ceil(w / 3) - w // 3)
print(min(min1, min2, min3, min4))


(H, W) = map(int, input().split())

def split2(h, w):
	if h % 2 == 0 or w % 2 == 0:
		return (h * w // 2, h * w // 2)
	else:
		(h, w) = (max(h, w), min(h, w))
		return (h // 2 * w, (h + 1) // 2 * w)
ans = H * W
for i in range(1, H):
	h = H - i
	w = W
	s1 = W * i
	(s2, s3) = split2(h, w)
	ans = min(max(s1, s2, s3) - min(s1, s2, s3), ans)
for i in range(1, W):
	h = H
	w = W - i
	s1 = H * i
	(s2, s3) = split2(h, w)
	ans = min(max(s1, s2, s3) - min(s1, s2, s3), ans)
print(ans)


def calc(h, w):
	ans = w
	for i in range(1, h):
		s1 = w * i
		s2 = (h - i) * (w // 2)
		s3 = (h - i) * (w - w // 2)
		s = [s1, s2, s3]
		ds = max(s) - min(s)
		ans = min([ans, ds])
	return ans
(h, w) = map(int, input().split())
if h * w % 3 == 0:
	print(0)
else:
	print(min([calc(h, w), calc(w, h)]))


(H, W) = map(int, input().split())
a = W % 3
if a == 0:
	s1 = 0
else:
	s1 = H
a = H % 3
if a == 0:
	s2 = 0
else:
	s2 = W
s3 = H * W
for i in range(1, W):
	a = max(i * H, (H - H // 2) * (W - i))
	b = min(i * H, H // 2 * (W - i))
	s3 = min(s3, a - b)
s4 = H * W
for i in range(1, H):
	a = max(i * W, (W - W // 2) * (H - i))
	b = min(i * W, W // 2 * (H - i))
	s4 = min(s4, a - b)
print(min(s1, s2, s3, s4))


def solve(h, w):
	res = float('inf')
	for hh in range(h + 1):
		s1 = hh * w
		ww = w // 2
		s2 = (h - hh) * ww
		s3 = (h - hh) * (w - ww)
		res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
	return res
(H, W) = map(int, input().split())
ans = H * W
if H % 3 == 0 or W % 3 == 0:
	ans = 0
else:
	ans = min(H, W)
ans = min(ans, solve(H, W))
ans = min(ans, solve(W, H))
print(ans)


(H, W) = map(int, input().split())

def F(H, W):
	if H % 2 == 0 or W % 2 == 0:
		return (H * W // 2, H * W // 2)
	if H > W:
		(H, W) = (W, H)
	return (H * (W - 1) // 2, H * (W + 1) // 2)
answer = H * W
for h in range(1, H):
	x = [W * h]
	x += list(F(H - h, W))
	answer = min(answer, max(x) - min(x))
for w in range(1, W):
	x = [H * w]
	x += list(F(W - w, H))
	answer = min(answer, max(x) - min(x))
print(answer)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	d = v = 10 ** 5
	for i in range(h // 4, h // 2 + 1):
		cur = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]
		d = min(max(cur) - min(cur), d)
	for j in range(w // 4, w // 2 + 1):
		cur = [j * h, (w - j) * (h // 2), (w - j) * (h - h // 2)]
		v = min(max(cur) - min(cur), v)
	print(min(h, w, d, v))


(H, W) = map(int, input().split())

def yyy(h, w):
	if h % 3 == 0:
		return 0
	else:
		return w

def yyt(h, w):
	out = h * w
	for i in range(1, w):
		temp = [(h // 2 + h % 2) * (w - i), h // 2 * (w - i), h * i]
		if out > max(temp) - min(temp):
			out = max(temp) - min(temp)
	return out

def tty(h, w):
	return yyt(w, h)

def ttt(h, w):
	return yyy(w, h)
print(min(yyy(H, W), yyt(H, W), tty(H, W), ttt(H, W)))


(H, W) = map(int, input().split())
ans = (H % 3 > 0) * W
ans = min(ans, (W % 3 > 0) * H)
for h in range(1, H):
	a = h * W
	b = (H - h) * (W // 2 + (W % 2 == 1))
	c = (H - h) * (W // 2)
	ans = min(ans, max(a, b, c) - min(a, b, c))
for w in range(1, W):
	a = H * w
	b = (W - w) * (H // 2 + (H % 2 == 1))
	c = (W - w) * (H // 2)
	ans = min(ans, max(a, b, c) - min(a, b, c))
print(ans)


def main():
	(h, w) = map(int, input().split())
	S = h * w
	if S % 3 == 0:
		return 0
	ds = [h, w]
	h1 = (h + 1) // 3
	s1 = h1 * w
	s2 = w // 2 * (h - h1)
	s3 = S - s1 - s2
	ds.append(max(s1, s2, s3) - min(s1, s2, s3))
	w1 = (w + 1) // 3
	s1 = w1 * h
	s2 = h // 2 * (w - w1)
	s3 = S - s1 - s2
	ds.append(max(s1, s2, s3) - min(s1, s2, s3))
	return min(ds)
print(main())


from math import ceil

def main():
	(H, W) = list(map(int, input().split()))
	if H * W % 3 == 0:
		print(0)
		return
	ans1 = float('inf')
	ans2 = float('inf')
	ans3 = min(H, W)
	for h in range(1, H + 1):
		if W % 2 == 0:
			ans1 = min(ans1, abs(h * (W // 2) - W * (H - h)))
		else:
			ans1 = min(ans1, max([abs(h * (W // 2) - W * (H - h)), abs(h * ((W + 1) // 2) - W * (H - h)), h]))
	for w in range(1, W + 1):
		if H % 2 == 0:
			ans2 = min(ans2, abs(w * (H // 2) - H * (W - w)))
		else:
			ans2 = min(ans2, max([abs(w * (H // 2) - H * (W - w)), abs(w * ((H + 1) // 2) - H * (W - w)), w]))
	print(min([ans1, ans2, ans3]))
	return

def __starting_point():
	main()
__starting_point()


(h, w) = list(map(int, input().split()))
a1 = min(h * (w % 3 != 0), w * (h % 3 != 0))
a2 = 10 ** 6
a3 = 10 ** 6
for i in range(1, h):
	mx = max(w * i, w // 2 * (h - i), (w + 1) // 2 * (h - i))
	mn = min(w * i, w // 2 * (h - i), (w + 1) // 2 * (h - i))
	a2 = min(a2, mx - mn)
for i in range(1, w):
	mx = max(h * i, h // 2 * (w - i), (h + 1) // 2 * (w - i))
	mn = min(h * i, h // 2 * (w - i), (h + 1) // 2 * (w - i))
	a3 = min(a3, mx - mn)
print(min(a1, a2, a3))


(h, w) = list(map(int, input().split()))
anses = []
for (x, y) in ((h, w), (w, h)):
	if x % 3 == 0:
		anses.append(0)
	else:
		anses.append(y)
	for i in range(x):
		ss = (i * y, (x - i) * (y // 2), (x - i) * (y - y // 2))
		anses.append(max(ss) - min(ss))
print(min(anses))


(H, W) = map(int, input().split())
a = 10 ** 10
S = H * W
s = [None] * 3
for i in range(W):
	s[0] = H * i
	s[1] = (W - i) // 2 * H
	s[2] = S - s[0] - s[1]
	a = min(a, max(s) - min(s))
	s[1] = H // 2 * (W - i)
	s[2] = S - s[0] - s[1]
	a = min(a, max(s) - min(s))
for i in range(H):
	s[0] = W * i
	s[1] = (H - i) // 2 * W
	s[2] = S - s[0] - s[1]
	a = min(a, max(s) - min(s))
	s[1] = W // 2 * (H - i)
	s[2] = S - s[0] - s[1]
	a = min(a, max(s) - min(s))
print(a)


import sys
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	return

def solve(p, q):
	r = int(p / 2)
	s = int(q / 3)
	(a, b, c) = (p * s, r * (q - s), (p - r) * (q - s))
	ans = max(a, b, c) - min(a, b, c)
	(a, b, c) = (p * (s + 1), r * (q - s - 1), (p - r) * (q - s - 1))
	ans = min(ans, max(a, b, c) - min(a, b, c))
	return ans
ans = min(W, H, solve(H, W), solve(W, H))
print(ans)


def cut(ch, cw):
	total = ch * cw
	if not ch % 2 or not cw % 2:
		x = ch * cw // 2
		return (x, x)
	else:
		x = max(ch * (cw // 2), cw * (ch // 2))
		return (x, total - x)
(h, w) = map(int, input().split())
ans = h * w
for i in range(2):
	yh = h // 3 + i
	s = [yh * w]
	ch = h - yh
	s += cut(ch, w)
	ans = min(ans, max(s) - min(s))
for i in range(2):
	yw = w // 3 + i
	s = [h * yw]
	cw = w - yw
	s += cut(h, cw)
	ans = min(ans, max(s) - min(s))
print(ans)


def f(a, b, c):
	return max(a, b, c) - min(a, b, c)
(h, w) = map(int, input().split())
if w % 3 == 0 or h % 3 == 0:
	print(0)
else:
	ans = min(h, w)
	for i in range(1, h):
		ans = min(ans, f(i * w, (h - i) * (w // 2), (h - i) * ((w + 1) // 2)))
	for i in range(1, w):
		ans = min(ans, f(i * h, (w - i) * (h // 2), (w - i) * ((h + 1) // 2)))
	print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
ans = min(w, h)
for x in range(1, w):
	blocks = [h * x, h // 2 * (w - x), (h - h // 2) * (w - x)]
	ans = min(ans, max(blocks) - min(blocks))
for y in range(1, h):
	blocks = [w * y, w // 2 * (h - y), (w - w // 2) * (h - y)]
	ans = min(ans, max(blocks) - min(blocks))
print(ans)


(h, w) = map(int, input().split())
ans = h * w
if h * w % 3 == 0:
	print(0)
else:
	for (x, y) in ((h, w), (w, h)):
		x1 = x // 3
		x2 = (x + 2) // 3
		y1 = y // 2
		y2 = (y + 1) // 2
		ans = min(ans, abs(y * x2 - y * x1))
		t = (y * x1, y2 * (x - x1), (y - y2) * (x - x1))
		ans = min(ans, max(t) - min(t))
		t = (y * x2, y2 * (x - x2), (y - y2) * (x - x2))
		ans = min(ans, max(t) - min(t))
	print(ans)


import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
	(H, W) = map(int, readline().rstrip().split())
	ans = H * W
	if H >= 3:
		ans = min(ans, abs(W * (H // 3) - W * (H - H // 3 * 2)))
	if W >= 3:
		ans = min(ans, abs(H * (W // 3) - H * (W - W // 3 * 2)))
	x1_cand = [i for i in range(1, W)]
	y1 = H
	for x1 in x1_cand:
		x2 = W - x1
		x3 = x2
		y2 = H // 2
		y3 = H - y2
		ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
		x2 = (W - x1) // 2
		x3 = W - x1 - x2
		ans = min(ans, max(x1 * H, x2 * H, x3 * H) - min(x1 * H, x2 * H, x3 * H))
	y1_cand = [i for i in range(1, H)]
	x1 = W
	for y1 in y1_cand:
		y2 = H - y1
		y3 = y2
		x2 = W // 2
		x3 = W - x2
		ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
		y2 = (H - y1) // 2
		y3 = H - y1 - y2
		ans = min(ans, max(W * y1, W * y2, W * y3) - min(W * y1, W * y2, W * y3))
	print(ans)

def __starting_point():
	main()
__starting_point()


(h, w) = map(int, input().split())
ans = h * w
for i in range(1, h):
	A = w * i
	if w % 2 == 0 or (h - i) % 2 == 0:
		B = (h - i) * w // 2
		C = (h - i) * w // 2
	elif h - i <= w:
		B = (h - i) * (w // 2 + 1)
		C = (h - i) * (w // 2)
	else:
		B = ((h - i) // 2 + 1) * w
		C = (h - i) // 2 * w
	ans = min(ans, max(A, max(B, C)) - min(A, min(B, C)))
for i in range(1, w):
	A = h * i
	if (w - i) % 2 == 0 or h % 2 == 0:
		B = (w - i) * h // 2
		C = (w - i) * h // 2
	elif w - i <= h:
		B = (w - i) * (h // 2 + 1)
		C = (w - i) * (h // 2)
	else:
		B = ((w - i) // 2 + 1) * h
		C = (w - i) // 2 * h
	ans = min(ans, max(A, max(B, C)) - min(A, min(B, C)))
print(ans)


import sys
input = sys.stdin.readline
(h, w) = sorted(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	c_1 = (w // 3 + 1) * h - (w - 1 - w // 3) * (h // 2)
	c_2 = (w - w // 3) * (h - h // 2) - w // 3 * h
	c_3 = h
	c_4 = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
	c_5 = (h - h // 3) * (w - w // 2) - h // 3 * w
	ans = min(c_1, c_2, c_3, c_4, c_5)
print(ans)


(h, w) = map(int, input().split())
ans = 10 ** 10
if h * w % 3 == 0:
	print(0)
	exit()
ans = min(ans, w, h)
for i in range(1, h // 2 + 1):
	a = [w * i, (h - i) * (w // 2), (h - i) * (w // 2 + w % 2)]
	a.sort()
	ans = min(ans, a[2] - a[0])
for i in range(1, w // 2 + 1):
	a = [h * i, (w - i) * (h // 2), (w - i) * (h // 2 + h % 2)]
	a.sort()
	ans = min(ans, a[2] - a[0])
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
ans = min(h, w)
for i in range(w // 3, w // 3 + 2):
	s = [h * i]
	s.append((w - i) * (h // 2))
	s.append((w - i) * (h - h // 2))
	ans = min(ans, max(s) - min(s))
(h, w) = (w, h)
for i in range(w // 3, w // 3 + 2):
	s = [h * i]
	s.append((w - i) * (h // 2))
	s.append((w - i) * (h - h // 2))
	ans = min(ans, max(s) - min(s))
print(ans)


(h, w) = map(int, input().split())
h3 = h // 3
h3a = h % 3
w3 = w // 3
w3a = w % 3
ans = min((h3 - -h3a // 2 - h3) * w, (w3 - -w3a // 2 - w3) * h)
h2 = h // 2
w2 = w // 2
h2a = h % 2
w2a = w % 2
ans = min(ans, abs(h3 * w - (w2 + w2a) * (h - h3)), abs((h3 - -h3a // 2) * w - w2 * (h - (h3 - -h3a // 2))))
ans = min(ans, abs(w3 * h - (h2 + h2a) * (w - w3)), abs((w3 - -w3a // 2) * h - h2 * (w - (w3 - -w3a // 2))))
print(ans)


import math

def calc(h, w):
	case1 = 0 if h % 3 == 0 else h
	mid = math.floor(w / 2)
	case2 = float('inf')
	for i in range(1, h):
		Smin = min(i * w, mid * (h - i), (w - mid) * (h - i))
		Smax = max(i * w, mid * (h - i), (w - mid) * (h - i))
		case2 = min(Smax - Smin, case2)
	return min(case1, case2)
(H, W) = map(int, input().split())
print(min(calc(H, W), calc(W, H)))


(h, w) = map(int, input().split())
mini = h * w
for i in range(1, h):
	if mini > max(w * (h - i), (w // 2 + w % 2) * i) - min(w * (h - i), w // 2 * i):
		mini = max(w * (h - i), (w // 2 + w % 2) * i) - min(w * (h - i), w // 2 * i)
for i in range(1, w):
	if mini > max(h * (w - i), (h // 2 + h % 2) * i) - min(h * (w - i), h // 2 * i):
		mini = max(h * (w - i), (h // 2 + h % 2) * i) - min(h * (w - i), h // 2 * i)
if h % 3 == 0 or w % 3 == 0:
	mini = 0
elif mini > h:
	mini = h
elif mini > w:
	mini = w
else:
	pass
print(mini)


(H, W) = map(int, input().split())
answer = 0
if not H % 3 == 0 and (not W % 3 == 0):
	S_1 = [H // 3 * W, (H - H // 3) * (W // 2), (H - H // 3) * (W - W // 2)]
	S_2 = [(H // 3 + 1) * W, (H - H // 3 - 1) * (W // 2), (H - H // 3 - 1) * (W - W // 2)]
	S_3 = [W // 3 * H, (W - W // 3) * (H // 2), (W - W // 3) * (H - H // 2)]
	S_4 = [(W // 3 + 1) * H, (W - W // 3 - 1) * (H // 2), (W - W // 3 - 1) * (H - H // 2)]
	answer = min(max(S_1) - min(S_1), max(S_2) - min(S_2), max(S_3) - min(S_3), max(S_4) - min(S_4), H, W)
print(answer)


(H, W) = map(int, input().split())
S = H * W
ans = S
for h in range(1, H):
	s1 = h * W
	s2 = W // 2 * (H - h)
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	s2 = (H - h) // 2 * W
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
for w in range(1, W):
	s1 = H * w
	s2 = H // 2 * (W - w)
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	s2 = (W - w) // 2 * H
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
print(ans)


import sys
readline = sys.stdin.readline
from math import floor, ceil
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def round(f, r=0):
	return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)

def main():
	(H, W) = map(int, readline().rstrip().split())
	ans = H * W
	if H >= 3:
		y1 = int(round(H / 3))
		y2 = (H - y1) // 2
		y3 = H - y1 - y2
		ans = min(ans, max(W * y1, W * y2, W * y3) - min(W * y1, W * y2, W * y3))
	if W >= 3:
		x1 = int(round(W / 3))
		x2 = (W - x1) // 2
		x3 = W - x1 - x2
		ans = min(ans, max(x1 * H, x2 * H, x3 * H) - min(x1 * H, x2 * H, x3 * H))
	x1_cand = [int(round(W / 3))]
	y1 = H
	for x1 in x1_cand:
		x2 = W - x1
		x3 = x2
		y2 = H // 2
		y3 = H - y2
		ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
	y1_cand = [int(round(H / 3))]
	x1 = W
	for y1 in y1_cand:
		y2 = H - y1
		y3 = y2
		x2 = W // 2
		x3 = W - x2
		ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
	print(ans)

def __starting_point():
	main()
__starting_point()


(H, W) = list(map(int, input().split()))
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	ans = H * W
	(H, W) = (min(H, W), max(H, W))
	for wi in range(1, W // 2 + 1):
		S1 = H * wi
		if H % 2 == 0 or (W - wi) % 2 == 0:
			S2 = H * (W - wi) // 2
			S3 = S2
		else:
			S2 = min(H, W - wi) * (max(H, W - wi) // 2)
			S3 = S2 + min(H, W - wi)
		ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
	for hi in range(1, H // 2 + 1):
		S1 = W * hi
		if W % 2 == 0 or (H - hi) % 2 == 0:
			S2 = W * (H - hi) // 2
			S3 = S2
		else:
			S2 = min(W, H - hi) * (max(W, H - hi) // 2)
			S3 = S2 + min(W, H - hi)
		ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))
	print(ans)


def separate(a, b):
	r = []
	tmp = [a // 3 * b, (a - a // 3) * (b // 2), (a - a // 3) * (b // 2 + b % 2)]
	r.append(max(tmp) - min(tmp))
	tmp = [(a // 3 + 1) * b, (a - a // 3 - 1) * (b // 2), (a - a // 3 - 1) * (b // 2 + b % 2)]
	r.append(max(tmp) - min(tmp))
	return min(r)
(H, W) = list(map(int, input().split()))
ans = 0
if H % 3 == 0 or W % 3 == 0:
	ans = 0
else:
	S = [H, W]
	S.append(separate(H, W))
	S.append(separate(W, H))
	ans = min(S)
print(ans)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()

def Tcheck(X, Y):
	res = X * Y
	for i in range(Y + 1):
		Z = [X * i, (Y - i) * (X // 2), (Y - i) * (X - X // 2)]
		res = min(res, max(Z) - min(Z))
	return res
print(min(H, W, Tcheck(H, W), Tcheck(W, H)))


(h, w) = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	num1 = max(h // 3 * w, (h - h // 3) * (w // 2), (h - h // 3) * (w - w // 2)) - min(h // 3 * w, (h - h // 3) * (w // 2), (h - h // 3) * (w - w // 2))
	num2 = max(w // 3 * h, (w - w // 3) * (h // 2), (w - w // 3) * (h - h // 2)) - min(w // 3 * h, (w - w // 3) * (h // 2), (w - w // 3) * (h - h // 2))
	num3 = max((h // 3 + 1) * w, (h - (h // 3 + 1)) * (w // 2), (h - (h // 3 + 1)) * (w - w // 2)) - min((h // 3 + 1) * w, (h - (h // 3 + 1)) * (w // 2), (h - (h // 3 + 1)) * (w - w // 2))
	num4 = max((w // 3 + 1) * h, (w - (w // 3 + 1)) * (h // 2), (w - (w // 3 + 1)) * (h - h // 2)) - min((w // 3 + 1) * h, (w - (w // 3 + 1)) * (h // 2), (w - (w // 3 + 1)) * (h - h // 2))
	print(min(num1, num2, num3, num4, h, w))


def choco(h, w):
	ans = [(h % 3 != 0) * w, (h - h // 3) * (w // 2 + (w % 2 != 0)) - min(h // 3 * w, (h - h // 3) * (w // 2)), (h // 3 + 1) * w - (h - (h // 3 + 1)) * (w // 2)]
	return min(ans)
(h, w) = [int(i) for i in input().split()]
print(min(choco(h, w), choco(w, h)))


(h, w) = list(map(int, input().split()))
tanpen = min(h, w)
chohen = max(h, w)
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:

	def findmin(h, w):
		ans = h * w
		for i in range(1, h):
			remi = h - i
			s1 = i * w
			s2 = w // 2 * remi
			s3 = (w - w // 2) * remi
			ans = min(ans, max(s1, s2, s3) - min(s1, s2))
			s2 = w * (remi // 2)
			s3 = w * (remi - remi // 2)
			ans = min(ans, max(s1, s2, s3) - min(s1, s2))
		return ans
	print(min(findmin(h, w), findmin(w, h)))


def func(H, W):
	if H % 3 == 0:
		return 0
	H_3 = int(H / 3)
	S1 = H_3 * W
	S2 = (H - H_3) * int(W / 2)
	S3 = H * W - S1 - S2
	res1 = max(S1, S2, S3) - min(S1, S2, S3)
	H_3_1 = int(H / 3) + 1
	S1 = H_3_1 * W
	S2 = (H - H_3_1) * int(W / 2)
	S3 = H * W - S1 - S2
	res2 = max(S1, S2, S3) - min(S1, S2, S3)
	return min(res1, res2)
(H, W) = list(map(int, input().split()))
print(min(func(H, W), func(W, H), H, W))


def f(x, y, z):
	return max(x, y, z) - min(x, y, z)
(h, w) = list(map(int, input().split()))
l = []
(ans1, ans2) = (h * w, h * w)
for i in range(1, h // 2 + 1):
	s1 = i * w
	s2 = w * ((h - i) // 2)
	s3 = h * w - s1 - s2
	s4 = (h - i) * (w // 2)
	s5 = h * w - s1 - s4
	ans1 = min(ans1, f(s1, s2, s3), f(s1, s4, s5))
for i in range(1, w // 2 + 1):
	s1 = i * h
	s2 = h * ((w - i) // 2)
	s3 = h * w - s1 - s2
	s4 = (w - i) * (h // 2)
	s5 = h * w - s1 - s4
	ans2 = min(ans2, f(s1, s2, s3), f(s1, s4, s5))
print(min(ans1, ans2))


def chocolate_bar():
	(h, w) = map(int, input().split())
	print(min(solve(h, w), solve(w, h)))

def solve(h, w):
	ans = h * w
	for i in range(1, h):
		sa = i * w
		sb1 = (h - i) // 2 * w
		sc1 = h * w - sa - sb1
		sb2 = (h - i) * (w // 2)
		sc2 = h * w - sa - sb2
		ans = min(ans, max(sa, sb1, sc1) - min(sa, sb1, sc1), max(sa, sb2, sc2) - min(sa, sb2, sc2))
	return ans
chocolate_bar()


(H, W) = map(int, input().split())
ans = min(((W + 2) // 3 - W // 3) * H, ((H + 2) // 3 - H // 3) * W)
S = H * W
s = [0] * 3
for w in range(1, W):
	s[0] = (H + 1) // 2 * w
	s[1] = H // 2 * w
	s[2] = S - (s[0] + s[1])
	ans = min(ans, max(s) - min(s))
for h in range(1, H):
	s[0] = (W + 1) // 2 * h
	s[1] = W // 2 * h
	s[2] = S - (s[0] + s[1])
	ans = min(ans, max(s) - min(s))
print(ans)


import sys
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	sys.exit()
kai_1 = min(H, W)

def solve_2(a, b):
	w = a // 2
	s_l = (a - w) * b
	s_s = w * b
	s_r = 0
	tmp = s_l
	for i in range(b):
		s_r += a
		s_s -= w
		s_l -= a - w
		sa = max(s_r, s_s, s_l) - min(s_r, s_s, s_l)
		if tmp > sa:
			tmp = sa
			continue
		else:
			return tmp
kai_2 = solve_2(H, W)
kai_3 = solve_2(W, H)
print(min(kai_1, kai_2, kai_3))


(H, W) = map(int, input().split())
if H % 3 * (W % 3) == 0:
	print(0)
	return
ans = H * W
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
T1 = W * ((H - 1) // 2)
S2 = (H - 1) * w2
T2 = W * (H - 1) - T1
S3 = W
h = H - 1
for i in range(H - 1):
	diff1 = max(S1, S2, S3) - min(S1, S2, S3)
	diff2 = max(T1, T2, S3) - min(T1, T2, S3)
	ans = min(ans, diff1, diff2)
	S1 -= w1
	S2 -= w2
	S3 += W
	h -= 1
	T1 = W * (h // 2)
	T2 = W * h - T1
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
T1 = H * ((W - 1) // 2)
S2 = (W - 1) * h2
T2 = H * (W - 1) - T1
S3 = H
w = W - 1
for i in range(W - 1):
	diff1 = max(S1, S2, S3) - min(S1, S2, S3)
	diff2 = max(T1, T2, S3) - min(T1, T2, S3)
	ans = min(ans, diff1, diff2)
	S1 -= h1
	S2 -= h2
	S3 += H
	w -= 1
	T1 = H * (w // 2)
	T2 = H * w - T1
print(ans)


(H, W) = map(int, input().split())
res = min(H, W)
h = round(H / 3)
w = W // 2
s1 = h * W
s2 = (H - h) * w
s3 = (H - h) * (W - w)
res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
w = round(W / 3)
h = H // 2
s1 = w * H
s2 = (W - w) * h
s3 = (W - w) * (H - h)
res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
if H % 3 == 0 or W % 3 == 0:
	res = 0
print(res)


(H, W) = map(int, input().split())

def f(H, W):
	ans = H * W
	for h1 in range(1, H // 2 + 1):
		h2 = (H - h1) // 2
		h3 = H - h1 - h2
		ans = min(ans, max(h1, h2, h3) * W - min(h1, h2, h3) * W)
		w1 = W // 2
		w2 = W - w1
		a1 = h1 * W
		a2 = (H - h1) * w1
		a3 = (H - h1) * w2
		ans = min(ans, max(a1, a2, a3) - min(a1, a2, a3))
	return ans
print(min(f(H, W), f(W, H)))


import math
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	L = [[H, W], [W, H]]
	ans = 10000000000.0
	for (H, W) in L:
		Hp = [H, math.ceil(H / 2), math.floor(H / 2)]
		for x in range(1, W):
			S = [Hp[0] * x, Hp[1] * (W - x), Hp[2] * (W - x)]
			temp = max(S) - min(S)
			if ans > temp:
				ans = temp
	ans = min([ans, W, H])
	print(ans)


def f(W, H):
	res = float('INF')
	w = W // 2
	for h in range(1, H):
		res = min(res, max(h * W, (H - h) * w, (H - h) * (W - w)) - min(h * W, (H - h) * w, (H - h) * (W - w)))
	return min(H, res)

def main():
	(H, W) = map(int, input().split())
	if H % 3 == 0 or W % 3 == 0:
		print(0)
	else:
		print(min(f(W, H), f(H, W)))
main()


(h, w) = map(int, input().split())
ans = h * w
for i in range(1, w):
	s1 = i * h
	s2 = (w - i) // 2 * h
	s3 = w * h - s1 - s2
	m1 = max(s1, s2, s3) - min(s1, s2, s3)
	s2 = h // 2 * (w - i)
	s3 = w * h - s1 - s2
	m2 = max(s1, s2, s3) - min(s1, s2, s3)
	ans = min(ans, m1, m2)
for i in range(1, h):
	s1 = i * w
	s2 = (h - i) // 2 * w
	s3 = w * h - s1 - s2
	m1 = max(s1, s2, s3) - min(s1, s2, s3)
	s2 = w // 2 * (h - i)
	s3 = w * h - s1 - s2
	m2 = max(s1, s2, s3) - min(s1, s2, s3)
	ans = min(ans, m1, m2)
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	l = (h + 1) // 3
	b = (w + 1) // 3
	ans = min(w * abs(l - (h - 2 * l)), h * abs(b - (w - 2 * b)))
	for x in range(1, w):
		half = h // 2
		rest = h - h // 2
		sub = max(x * half, x * rest, (w - x) * h) - min(x * half, x * rest, (w - x) * h)
		ans = min(ans, sub)
	for y in range(1, h):
		half = w // 2
		rest = w - w // 2
		sub = max(y * half, y * rest, (h - y) * w) - min(y * half, y * rest, (h - y) * w)
		ans = min(ans, sub)
	print(ans)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
ans = H * W
for i in range(2):
	for h in range(1, H):
		s = [h * W, W // 2 * (H - h), (W - W // 2) * (H - h)]
		s2 = [h * W, (H - h) // 2 * W, (H - h - (H - h) // 2) * W]
		ans = min(ans, min(max(s) - min(s), max(s2) - min(s2)))
	(H, W) = (W, H)
print(ans)


(H, W) = [int(i) for i in input().split()]
candidate = [H // 2 + W // 3 + 1, H // 3 + W // 2 + 1, H, W]
if H % 3 == 0 or W % 3 == 0:
	candidate.append(0)
if H % 2 == 0:
	candidate.append(H // 2)
if W % 2 == 0:
	candidate.append(W // 2)
print(min(candidate))


(H, W) = map(int, input().split())
mi = min(H, W)
if H % 3 == 0 or W % 3 == 0:
	mi = 0
for i in range(H):
	(a, b, c) = (W * i, W // 2 * (H - i), (W - W // 2) * (H - i))
	mi = min(mi, max(a, b, c) - min(a, b, c))
for i in range(W):
	(a, b, c) = (H * i, H // 2 * (W - i), (H - H // 2) * (W - i))
	mi = min(mi, max(a, b, c) - min(a, b, c))
print(mi)


(h, w) = sorted(list(map(int, input().split())))
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	c1 = (w // 3 + 1) * h - (w - 1 - w // 3) * (h // 2)
	c2 = (w - w // 3) * (h - h // 2) - w // 3 * h
	c3 = h
	c4 = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
	c5 = (h - h // 3) * (w - w // 2) - h // 3 * w
	ans = min(c1, c2, c3, c4, c5)
print(ans)


def aaa(a, b):
	return abs(a // 3 * b - (a // 3 + 1) * b)

def bbb(a, b):
	ret = 1000 * 100
	for x in range(1, a):
		xx = a - x
		i = x * b
		j = xx * (b // 2)
		k = xx * (b // 2 + b % 2)
		tmp = max(abs(i - j), abs(j - k), abs(k - i))
		ret = min(ret, tmp)
	return ret
(H, W) = list(map(int, input().split()))
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	a = aaa(H, W)
	b = aaa(W, H)
	c = bbb(H, W)
	d = bbb(W, H)
	print(min(a, b, c, d))


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

def main():
	(h, w) = map(int, input().split())
	p = [h // 2 + w // 3 + 1, h // 3 + w // 2 + 1, h, w]
	if h % 3 == 0 or w % 3 == 0:
		p += [0]
	if h % 2 == 0:
		p += [h // 2]
	if w % 2 == 0:
		p += [w // 2]
	print(min(p))
main()


(H, W) = map(int, input().split())
if H % 3 * (W % 3) == 0:
	print(0)
else:
	d1 = min(H, W)
	ah = H // 3
	h = H - ah
	d2 = abs((W + 1) // 2 * h - ah * W)
	aw = W // 3
	w = W - aw
	d3 = abs((H + 1) // 2 * w - aw * H)
	ah = (H + 2) // 3
	h = H - ah
	d4 = abs(W // 2 * h - ah * W)
	aw = (W + 2) // 3
	w = W - aw
	d5 = abs(H // 2 * w - aw * H)
	print(min(d1, d2, d3, d4, d5))


def pattern1(A, B):
	s1 = A // 3 * B
	s2 = (A - A // 3) // 2 * B
	s3 = A * B - s1 - s2
	return max([abs(s1 - s2), abs(s2 - s3), abs(s3 - s1)])

def pattern2(A, B):
	a1 = A // 2
	a2 = A - a1
	b1 = (2 * B + 1) // 3
	b2 = B - b1
	(s1, s2, s3) = (a1 * b1, a2 * b1, A * b2)
	return max([abs(s1 - s2), abs(s2 - s3), abs(s3 - s1)])

def main():
	(H, W) = list(map(int, input().split(' ')))
	ans = min([pattern1(H, W), pattern1(W, H), pattern2(H, W), pattern2(W, H)])
	print(ans)

def __starting_point():
	main()
__starting_point()


def tsep(x, y):
	m = x * y
	for i in range(1, y):
		s = [i * x, (y - i) * (x - x // 2), (y - i) * (x // 2)]
		m = min(m, max(s) - min(s))
	return m
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
print(min(W, H, tsep(H, W), tsep(W, H)))


(x, y) = map(int, input().split())
if x % 3 == 0 or y % 3 == 0:
	print(0)
	exit()
ans = []
ans.append(x)
ans.append(y)
for (x, y) in ((x, y), (y, x)):
	a1 = x // 3
	a2 = x - a1
	b1 = y // 2
	b2 = y - y // 2
	ans.append(max(a1 * y, a2 * b1, a2 * b2) - min(a1 * y, a2 * b1, a2 * b2))
	a1 = x // 3 + 1
	a2 = x - a1
	ans.append(max(a1 * y, a2 * b1, a2 * b2) - min(a1 * y, a2 * b1, a2 * b2))
print(min(ans))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
x = [h, w]
import math
for i in range(1, w):
	p = abs(h * i - (w - i) * (h // 2))
	q = abs(h * i - (w - i) * math.ceil(h / 2))
	x.append(max(p, q))
for i in range(1, h):
	p = abs(w * i - (h - i) * (w // 2))
	q = abs(w * i - (h - i) * math.ceil(w / 2))
	x.append(max(p, q))
print(min(x))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	temp = [w, h]
	if h % 2 == 0 and w % 2 == 0:
		temp.append(abs(int(w // 3 + 1) * h - int(w - w // 3 - 1) * int(h // 2)))
		temp.append(abs(int(w // 3) * h - int(w - w // 3) * int(h // 2)))
		temp.append(abs(int(h // 3 + 1) * w - int(h - h // 3 - 1) * int(w // 2)))
		temp.append(abs(int(h // 3) * w - int(h - h // 3) * int(w // 2)))
	elif h % 2 == 0:
		temp.append(max(int(h // 3 * w), int(h - h // 3) * int(w // 2), int(h - h // 3) * int(w // 2 + 1)) - min(int(h // 3 * w), int(h - h // 3) * int(w // 2), int(h - h // 3) * int(w // 2 + 1)))
		temp.append(max(int(h // 3 + 1) * w, int(h - h // 3 - 1) * int(w // 2), int(h - h // 3 - 1) * int(w // 2 + 1)) - min(int(h // 3 + 1) * w, int(h - h // 3 - 1) * int(w // 2), int(h - h // 3 - 1) * int(w // 2 + 1)))
		temp.append(abs(int(w // 3 + 1) * h - int(w - w // 3 - 1) * int(h // 2)))
		temp.append(abs(int(w // 3) * h - int(w - w // 3) * int(h // 2)))
	elif w % 2 == 0:
		temp.append(max(int(w // 3 * h), int(w - w // 3) * int(h // 2), int(w - w // 3) * int(h // 2 + 1)) - min(int(w // 3 * h), int(w - w // 3) * int(h // 2), int(w - w // 3) * int(h // 2 + 1)))
		temp.append(max(int(w // 3 + 1) * h, int(w - w // 3 - 1) * int(h // 2), int(w - w // 3 - 1) * int(h // 2 + 1)) - min(int(w // 3 + 1) * h, int(w - w // 3 - 1) * int(h // 2), int(w - w // 3 - 1) * int(h // 2 + 1)))
		temp.append(abs(int(h // 3 + 1) * w - int(h - h // 3 - 1) * int(w // 2)))
		temp.append(abs(int(h // 3) * w - int(h - h // 3) * int(w // 2)))
	else:
		temp.append(max(int(h // 3 * w), int(h - h // 3) * int(w // 2), int(h - h // 3) * int(w // 2 + 1)) - min(int(h // 3 * w), int(h - h // 3) * int(w // 2), int(h - h // 3) * int(w // 2 + 1)))
		temp.append(max(int(h // 3 + 1) * w, int(h - h // 3 - 1) * int(w // 2), int(h - h // 3 - 1) * int(w // 2 + 1)) - min(int(h // 3 + 1) * w, int(h - h // 3 - 1) * int(w // 2), int(h - h // 3 - 1) * int(w // 2 + 1)))
		temp.append(max(int(w // 3 * h), int(w - w // 3) * int(h // 2), int(w - w // 3) * int(h // 2 + 1)) - min(int(w // 3 * h), int(w - w // 3) * int(h // 2), int(w - w // 3) * int(h // 2 + 1)))
		temp.append(max(int(w // 3 + 1) * h, int(w - w // 3 - 1) * int(h // 2), int(w - w // 3 - 1) * int(h // 2 + 1)) - min(int(w // 3 + 1) * h, int(w - w // 3 - 1) * int(h // 2), int(w - w // 3 - 1) * int(h // 2 + 1)))
	print(min(temp))


(h, w) = map(int, input().split())
ans = h * w
for (x, y) in ((h, w), (w, h)):
	x1 = x // 3
	x2 = (x + 2) // 3
	y2 = (y + 1) // 2
	ans = min(ans, abs(y * x2 - y * x1))
	t = (y * x1, y2 * (x - x1), (y - y2) * (x - x1))
	ans = min(ans, max(t) - min(t))
	t = (y * x2, y2 * (x - x2), (y - y2) * (x - x2))
	ans = min(ans, max(t) - min(t))
print(ans)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	ans = min(H, W)
	for h in range(1, H):
		y = (H - h) * W
		x = h * (W // 2)
		z = h * W - x
		ans = min(ans, max(x, y, z) - min(x, y, z))
	t = H
	H = W
	W = t
	for h in range(1, H):
		y = (H - h) * W
		x = h * (W // 2)
		z = h * W - x
		ans = min(ans, max(x, y, z) - min(x, y, z))
	print(ans)


(h, w) = map(int, input().split())

def solve(h, w):
	h_3 = round(h / 3)
	top = h_3 * w
	middle = (h - h_3) // 2 * w
	bottom = (h - (h - h_3) // 2 - h_3) * w
	ans = max(top, middle, bottom) - min(top, middle, bottom)
	middle = (h - h_3) * (w // 2)
	bottom = (h - h_3) * (w - w // 2)
	return min(ans, max(top, middle, bottom) - min(top, middle, bottom))
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	print(min(solve(h, w), solve(w, h)))


from math import ceil, floor

def main():
	(h, w) = list(map(int, input().split()))
	d = h * w
	d = min((ceil(h / 3) - floor(h / 3)) * w, d)
	d = min((ceil(w / 3) - floor(w / 3)) * h, d)
	dd = h * w
	for i in range(h):
		u = i * w
		d1 = (h - i) * ceil(w / 2)
		d2 = (h - i) * floor(w / 2)
		di = max(abs(u - d1), abs(u - d2))
		if di > dd:
			break
		dd = di
	d = min(dd, d)
	dd = h * w
	for i in range(w):
		u = i * h
		d1 = (w - i) * ceil(h / 2)
		d2 = (w - i) * floor(h / 2)
		di = max(abs(u - d1), abs(u - d2))
		if di > dd:
			break
		dd = di
	d = min(dd, d)
	print(d)

def __starting_point():
	main()
__starting_point()


def solve(s1, s2, s3):
	S = [s1, s2, s3]
	return max(S) - min(S)
(H, W) = map(int, input().split())
S = H * W
for j in range(1, W):
	S1 = H * j
	i = H // 2
	S2 = (W - j) * i
	S3 = (W - j) * (H - i)
	S = min(S, solve(S1, S2, S3))
for i in range(1, H):
	S1 = W * i
	j = W // 2
	S2 = (H - i) * j
	S3 = (H - i) * (W - j)
	S = min(S, solve(S1, S2, S3))
S = min(S, H * (W % 3 > 0))
S = min(S, W * (H % 3 > 0))
print(S)


import sys
readline = sys.stdin.readline
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def round(f, r=0):
	return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)

def main():
	(H, W) = map(int, readline().rstrip().split())
	ans = H * W
	if H >= 3:
		y1 = int(round(H / 3))
		y2 = (H - y1) // 2
		y3 = H - y1 - y2
		ans = min(ans, max(W * y1, W * y2, W * y3) - min(W * y1, W * y2, W * y3))
	if W >= 3:
		x1 = int(round(W / 3))
		x2 = (W - x1) // 2
		x3 = W - x1 - x2
		ans = min(ans, max(x1 * H, x2 * H, x3 * H) - min(x1 * H, x2 * H, x3 * H))
	x1 = int(round(W / 3))
	y1 = H
	x2 = W - x1
	x3 = x2
	y2 = H // 2
	y3 = H - y2
	ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
	y1 = int(round(H / 3))
	x1 = W
	y2 = H - y1
	y3 = y2
	x2 = W // 2
	x3 = W - x2
	ans = min(ans, max(x1 * y1, x2 * y2, x3 * y3) - min(x1 * y1, x2 * y2, x3 * y3))
	print(ans)

def __starting_point():
	main()
__starting_point()


(H, W) = map(int, input().split())

def calc2(H, W):
	if H > W:
		(H, W) = (W, H)
	if H % 2 == 1 and W % 2 == 1:
		return [H * (W // 2), H * W - H * (W // 2)]
	else:
		return [H * W // 2]

def calc(H, H2, W):
	SQ = [H2 * W]
	SQ += calc2(H - H2, W)
	return max(SQ) - min(SQ)
ANS = float('inf')
ANS = min(ANS, calc(H, H // 3, W))
ANS = min(ANS, calc(H, H // 3 + 1, W))
ANS = min(ANS, calc(W, W // 3, H))
ANS = min(ANS, calc(W, W // 3 + 1, H))
print(ANS)


def parallel(h, w):
	(q, r) = divmod(h, 3)
	if r == 0:
		return 0
	else:
		return w

def t(h, w):
	ret = h * w
	q = h // 3
	c = w // 2
	for r in range(q, q + 2):
		set_ = (r * w, (h - r) * c, (h - r) * (w - c))
		ret = min(ret, max(set_) - min(set_))
	return ret

def main():
	(h, w) = map(int, input().split())
	print(min(parallel(h, w), parallel(w, h), t(h, w), t(w, h)))
main()


def abc062_c():
	(h, w) = map(int, input().split())
	if h % 3 == 0 or w % 3 == 0:
		print(0)
		return
	ans = min(h, w)
	for (x, y) in [(w, h), (h, w)]:
		for i in range(1, x):
			sa = i * y
			sb = (x - i) * (y // 2)
			sc = (x - i) * (y - y // 2)
			diff = max(sa, sb, sc) - min(sa, sb, sc)
			ans = min(diff, ans)
	print(ans)
abc062_c()


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
ans = float('inf')
for _ in range(2):
	for i in [H // 3, H // 3 + 1]:
		a = i * W
		b = (H - i) // 2 * W
		c = (H - i + 1) // 2 * W
		ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
		b = (H - i) * (W // 2)
		c = (H - i) * ((W + 1) // 2)
		ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
	(H, W) = (W, H)
print(ans)


def answer(H, W, ans_kari):
	for x in range(1, W):
		y1 = H // 2
		Sa1 = H * x
		Sb1 = (W - x) * y1
		Sc1 = (W - x) * (H - y1)
		M = max(Sa1, Sb1, Sc1)
		m = min(Sa1, Sb1, Sc1)
		y2 = (W - x) // 2
		Sa2 = H * x
		Sb2 = H * y2
		Sc2 = H * (W - x - y2)
		M2 = max(Sa2, Sb2, Sc2)
		m2 = min(Sa2, Sb2, Sc2)
		if ans_kari > min(M - m, M2 - m2):
			ans_kari = min(M - m, M2 - m2)
	return ans_kari

def __starting_point():
	(H, W) = [int(i) for i in input().split()]
	ans = H * W
	ans = answer(H, W, ans)
	(H, W) = (W, H)
	if answer(H, W, ans) < ans:
		ans = answer(H, W, ans)
	print(ans)
__starting_point()


(h, w) = map(int, input().split())

def divide(h, w):
	ans = h * w
	for w1 in range(1, w):
		s1 = h * w1
		w2 = (w - w1) // 2
		s21 = h * w2
		s31 = h * (w - w1 - w2)
		ans1 = max(s1, s21, s31) - min(s1, s21, s31)
		h2 = h // 2
		s22 = (w - w1) * h2
		s32 = (w - w1) * (h - h2)
		ans2 = max(s1, s22, s32) - min(s1, s22, s32)
		ans = min(ans, ans1, ans2)
	return ans
print(min(divide(h, w), divide(w, h)))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	ans = 10 ** 9
	for _ in range(2):
		for i in range(1, w):
			c1 = h * i
			c2 = h // 2 * (w - i)
			c3 = h * w - c1 - c2
			maxc = max(c1, c2, c3)
			minc = min(c1, c2, c3)
			if maxc - minc < ans:
				ans = maxc - minc
		(h, w) = (w, h)
	if ans > min(h, w):
		ans = min(h, w)
print(ans)


(H, W) = map(int, input().strip().split(' '))
if H % 3 * (W % 3) == 0:
	print(0)
	exit()
ans = min(H, W)
for _ in range(2):
	for h in range(1, H // 2 + 1):
		a = W * h
		b = (H - h) * (W // 2)
		c = (H - h) * (W - W // 2)
		ans = min(max(a, b, c) - min(a, b, c), ans)
	(H, W) = (W, H)
print(ans)


(H, W) = map(int, input().split())
import sys
if H * W % 3 == 0:
	print(0)
	sys.exit()
ans = min(H, W)
for i in range(1, H):
	a = i * W
	b = (H - i) * (W // 2)
	c = (H - i) * -(-W // 2)
	m = min([a, b, c])
	M = max([a, b, c])
	ans = min(ans, M - m)
for i in range(1, W):
	a = i * H
	b = (W - i) * (H // 2)
	c = (W - i) * -(-H // 2)
	m = min([a, b, c])
	M = max([a, b, c])
	ans = min(ans, M - m)
print(ans)


def main():
	(h, w) = list(map(int, input().split()))
	if h % 3 == 0 or w % 3 == 0:
		print(0)
		return
	ans = h * w
	for _ in range(2):
		i = h // 3
		j = w // 2
		x = [(i - 1, h - i + 1), (i, h - i), (i + 1, h - i - 1)]
		y = [(j - 1, w - j + 1), (j, w - j), (j + 1, w - j - 1)]
		for (u, v) in x:
			(a, b) = (v // 2, v - v // 2)
			s = [w * u, w * a, w * b]
			d = max(s) - min(s)
			ans = min(ans, d)
			for (s, t) in y:
				s = [u * w, v * s, v * t]
				d = max(s) - min(s)
				ans = min(ans, d)
		(w, h) = (h, w)
	print(ans)

def __starting_point():
	main()
__starting_point()


(H, W) = map(int, input().split())

def f(a, b):
	c = a // 3
	d = (a - c) // 2
	e = a - c - d
	return b * (e - c)

def g(a, b):
	c = a // 3
	d = b // 2
	s1 = b * c
	s2 = (a - c) * d
	s3 = (a - c) * (b - d)
	S1 = max(s1, s2, s3) - min(s1, s2, s3)
	e = a // 3 + 1
	f = b // 2
	s4 = e * b
	s5 = (a - e) * f
	s6 = (a - e) * (b - f)
	S2 = max(s4, s5, s6) - min(s4, s5, s6)
	return min(S1, S2)
print(min(f(H, W), f(W, H), g(H, W), g(W, H)))


from itertools import permutations
from math import ceil, floor
(h, w) = map(int, input().split())
res = h * w
for l in permutations((h, w), 2):
	for i in range(1, l[0]):
		s1 = i * l[1]
		for m in permutations((l[0] - i, l[1]), 2):
			s2 = floor(m[0] / 2) * m[1]
			s3 = ceil(m[0] / 2) * m[1]
			val = max(s1, s2, s3) - min(s1, s2, s3)
			if val < res:
				res = val
print(res)


(h, w) = map(int, input().split())
m = min((0 - -h // 3 - h // 3) * w, (0 - -w // 3 - w // 3) * h)
for i in range(1, h):
	(a, b, c) = sorted((i * w, -~w // 2 * (h - i), w // 2 * (h - i)))
	m = min(m, c - a)
for i in range(1, w):
	(a, b, c) = sorted((i * h, -~h // 2 * (w - i), h // 2 * (w - i)))
	m = min(m, c - a)
print(m)


(h, w) = map(int, input().split())
s = [h * w] * 4
if h == w == 2:
	print(1)
	return
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
if w > 2:
	s[0] = h
if h > 2:
	s[1] = w
if h % 2 == 0:
	s[2] = h // 2
else:
	tmp = h * w
	for i in range(w // 3, w // 3 + 2):
		s1 = i * h
		s2 = (w - i) * (h // 2)
		s3 = (w - i) * (h // 2 + 1)
		tmp = min(tmp, max(s1, s2, s3) - min(s1, s2, s3))
	s[2] = tmp
if w % 2 == 0:
	s[3] = w // 2
else:
	tmp = h * w
	for i in range(h // 3, h // 3 + 2):
		s1 = i * w
		s2 = (h - i) * (w // 2)
		s3 = (h - i) * (w // 2 + 1)
		tmp = min(tmp, max(s1, s2, s3) - min(s1, s2, s3))
	s[3] = tmp
print(min(s))


(h, w) = list(map(int, input().split()))
mi = h * w
s = h * w
for i in range(h):
	s1 = w * i
	if w % 2 == 0 or (h - i) % 2 == 0:
		s2 = (s - s1) // 2
		s3 = s2
	elif h - i < w:
		s2 = (h - i) * (w - 1) // 2
		s3 = (h - i) * (w + 1) // 2
	else:
		s2 = (h - i - 1) // 2 * w
		s3 = (h - i + 1) // 2 * w
	d = abs(min(s1, s2, s3) - max(s1, s2, s3))
	if d < mi:
		mi = d
for i in range(w):
	s1 = h * i
	if (w - i) % 2 == 0 or h % 2 == 0:
		s2 = (s - s1) // 2
		s3 = s2
	elif w - i < h:
		s2 = (w - i) * (h - 1) // 2
		s3 = (w - i) * (h + 1) // 2
	else:
		s2 = (w - i - 1) // 2 * h
		s3 = (w - i + 1) // 2 * h
	d = abs(min(s1, s2, s3) - max(s1, s2, s3))
	if d < mi:
		mi = d
print(mi)


from math import floor, ceil
(H, W) = map(int, input().split())
ans = float('inf')
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
for x in range(1, H):
	S = [W * x, (H - x) * floor(W / 2), (H - x) * ceil(W / 2)]
	ans = min(ans, max(S) - min(S))
for x in range(1, W):
	S = [H * x, (W - x) * floor(H / 2), (W - x) * ceil(H / 2)]
	ans = min(ans, max(S) - min(S))
print(min(ans, H, W))


(h, w) = list(map(int, input().split()))
ans = 10 ** 10
for i in range(h):
	x = (i + 1) * w
	mid = (h - i - 1) // 2
	y = mid * w
	z = (h - i - 1 - mid) * w
	ans = min(ans, max(x, y, z) - min(x, y, z))
	mid = w // 2
	y = (h - i - 1) * mid
	z = (h - i - 1) * (w - mid)
	ans = min(ans, max(x, y, z) - min(x, y, z))
for j in range(w):
	x = (j + 1) * h
	mid = (w - j - 1) // 2
	y = mid * h
	z = (w - j - 1 - mid) * h
	ans = min(ans, max(x, y, z) - min(x, y, z))
	mid = h // 2
	y = (w - j - 1) * mid
	z = (w - j - 1) * (h - mid)
	ans = min(ans, max(x, y, z) - min(x, y, z))
print(ans)


(H, W) = map(int, input().split())
if H % 3 * (W % 3) == 0:
	print(0)
	return
ans = min(H, W)
w1 = W // 2
w2 = W - w1
S1 = (H - 1) * w1
S2 = (H - 1) * w2
S3 = W
for i in range(H - 1):
	diff = max(S1, S2, S3) - min(S1, S2, S3)
	ans = min(ans, diff)
	S1 -= w1
	S2 -= w2
	S3 += W
h1 = H // 2
h2 = H - h1
S1 = (W - 1) * h1
S2 = (W - 1) * h2
S3 = H
for i in range(W - 1):
	diff = max(S1, S2, S3) - min(S1, S2, S3)
	ans = min(ans, diff)
	S1 -= h1
	S2 -= h2
	S3 += H
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
ans = float('inf')
if w % 2 == 0:
	ans = min(ans, (h - h // 3) * (w // 2) - h // 3 * w)
	ans = min(ans, abs((h - h // 3 - 1) * (w // 2) - (h // 3 + 1) * w))
elif h % 3 == 1:
	ans = min(ans, max(abs((h - h // 3) * (w // 2) - h // 3 * w), abs((h - h // 3) * (w // 2 + 1) - h // 3 * w), abs(h - h // 3)))
else:
	ans = min(ans, max(abs((h - h // 3 - 1) * (w // 2) - (h // 3 + 1) * w), abs((h - h // 3 - 1) * (w // 2 + 1) - (h // 3 + 1) * w), abs(h - h // 3 - 1)))
ans = min(ans, w)
a = w
w = h
h = a
if w % 2 == 0:
	ans = min(ans, (h - h // 3) * (w // 2) - h // 3 * w)
	ans = min(ans, abs((h - h // 3 - 1) * (w // 2) - (h // 3 + 1) * w))
elif h % 3 == 1:
	ans = min(ans, max(abs((h - h // 3) * (w // 2) - h // 3 * w), abs((h - h // 3) * (w // 2 + 1) - h // 3 * w), abs(h - h // 3)))
else:
	ans = min(ans, max(abs((h - h // 3 - 1) * (w // 2) - (h // 3 + 1) * w), abs((h - h // 3 - 1) * (w // 2 + 1) - (h // 3 + 1) * w), abs(h - h // 3 - 1)))
ans = min(ans, w)
print(ans)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
elif H == 2 or W == 2:
	ans0 = min(H, W)
	(H, W) = (min(H, W), max(H, W))
	w1 = W // 3
	w2 = W - w1
	s1 = 2 * w1
	s2 = w2
	ans1 = s2 - s1
	w1 = W // 3 + 1
	w2 = W - w1
	s1 = 2 * w1
	s2 = w2
	ans2 = s1 - s2
	print(min(ans0, ans1, ans2))
else:
	ans0 = min(H, W)
	h1 = H // 2
	h2 = H - h1
	w1 = W // 3
	w2 = W - w1
	s1 = w1 * H
	s2 = w2 * h1
	s3 = w2 * h2
	ans1 = max(s1, s2, s3) - min(s1, s2, s3)
	w1 = W // 3 + 1
	w2 = W - w1
	s1 = w1 * H
	s2 = w2 * h1
	s3 = w2 * h2
	ans2 = max(s1, s2, s3) - min(s1, s2, s3)
	(H, W) = (W, H)
	h1 = H // 2
	h2 = H - h1
	w1 = W // 3
	w2 = W - w1
	s1 = w1 * H
	s2 = w2 * h1
	s3 = w2 * h2
	ans3 = max(s1, s2, s3) - min(s1, s2, s3)
	w1 = W // 3 + 1
	w2 = W - w1
	s1 = w1 * H
	s2 = w2 * h1
	s3 = w2 * h2
	ans4 = max(s1, s2, s3) - min(s1, s2, s3)
	print(min(ans0, ans1, ans2, ans3, ans4))


(h, w) = map(int, input().split())
ans = h * w
for i in range(1, h // 2 + 1):
	S = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]
	ans = min(ans, max(S) - min(S))
for i in range(1, w // 2 + 1):
	S = [i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)]
	ans = min(ans, max(S) - min(S))
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	ans = min(ans, h, w)
print(ans)


(h, w) = map(int, input().split())
mind = float('inf')
for i in range(1, h):
	d = max(abs(w * i - w // 2 * (h - i)), abs(w * i + -w // 2 * (h - i)), (h - i) * bool(w % 2))
	mind = min(mind, d)
for i in range(1, w):
	d = max(abs(h * i - h // 2 * (w - i)), abs(h * i + -h // 2 * (w - i)), (w - i) * bool(h % 2))
	mind = min(mind, d)
mind = min(mind, min(h, w) * bool(max(h, w) % 3) * bool(h * w % 3))
print(mind)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()

def main(a, b):
	ans = 99999999999
	for l in range(1, a + 1):
		s1 = l * b
		s2 = (a - l) * (b // 2)
		s3 = a * b - s1 - s2
		s4 = (a - l) // 2 * b
		s5 = a * b - s1 - s4
		list1 = sorted([s1, s2, s3])
		list2 = sorted([s1, s4, s5])
		s = min(list1[-1] - list1[0], list2[-1] - list2[0])
		if ans > s:
			ans = s
	return ans
print(min(main(h, w), main(w, h)))


(H, W) = map(int, input().split())

def abc(x, y, z):
	a = z * y
	if x - z & 1 and y & 1:
		b = max(x - z, y) // 2 * min(x - z, y)
		c = x * y - a - b
	else:
		b = c = (x - z) * y // 2
	return (a, b, c)

def diffS(a, b, c):
	return max(a, b, c) - min(a, b, c)

def solve(x, y):
	z = x // 3
	return min(diffS(*abc(x, y, z)), diffS(*abc(x, y, z + 1)))
if H % 3 == 0 or W % 3 == 0:
	ans = 0
else:
	ans = min(solve(H, W), solve(W, H))
print(ans)


(h, w) = list(map(int, input().split()))
ans = 10 ** 10
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
for H in range(1, h + 1):
	a = H * w
	b = (h - H) * (w // 2)
	c = (h - H) * (w - w // 2)
	ans = min(ans, max(a, b, c) - min(a, b, c))
for W in range(1, w + 1):
	a = W * h
	b = (w - W) * (h // 2)
	c = (w - W) * (h - h // 2)
	ans = min(ans, max(a, b, c) - min(a, b, c))
if h > 3:
	ans = min(ans, w * ((h + 2) // 3) - w * (h // 3))
if w > 3:
	ans = min(ans, h * ((w + 2) // 3) - h * (w // 3))
print(ans)


def f(h, w):
	l = []
	for i in range(w):
		m = [(w - i) * h, i * (h // 2), i * (h - h // 2)]
		l.append(max(m) - min(m))
	return min(l)
(H, W) = map(int, input().split(' '))
if 0 in [H % 3, W % 3]:
	print(0)
else:
	print(min(f(H, W), f(W, H), H, W))


from math import floor, ceil
(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
ans = min(H, W)
for i in range(1, W):
	M = max(i * H, floor(H / 2) * (W - i), ceil(H / 2) * (W - i))
	m = min(i * H, floor(H / 2) * (W - i), ceil(H / 2) * (W - i))
	if M - m < ans:
		ans = M - m
for i in range(1, H):
	M = max(i * W, floor(W / 2) * (H - i), ceil(W / 2) * (H - i))
	m = min(i * W, floor(W / 2) * (H - i), ceil(W / 2) * (H - i))
	if M - m < ans:
		ans = M - m
print(ans)


import sys
(h, w) = (int(i) for i in input().split())
ans = min(h, w)
if h % 3 == 0 or w % 3 == 0:
	print(0)
	sys.exit()
for i in range(1, h + 1):
	ans = min(ans, max(w * i, (h - i) * (w // 2), (h - i) * (w - w // 2)) - min(w * i, (h - i) * (w // 2), (h - i) * (w - w // 2)))
for i in range(1, w + 1):
	ans = min(ans, max(h * i, (w - i) * (h // 2), (w - i) * (h - h // 2)) - min(h * i, (w - i) * (h // 2), (w - i) * (h - h // 2)))
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
elif h == 2 and w == 2:
	print(1)
else:
	s = [h, w]
	for i in range(max(1, h // 3 - 2), min(h // 3 + 3, h - 1)):
		s.append(max(w * i, (h - i) * (w // 2 + 1) if w % 2 == 1 else (h - i) * (w // 2)) - min(w * i, (h - i) * (w // 2)))
	for i in range(max(1, w // 3 - 2), min(w // 3 + 3, w - 1)):
		s.append(max(h * i, (w - i) * (h // 2 + 1) if h % 2 == 1 else (w - i) * (h // 2)) - min(h * i, (w - i) * (h // 2)))
	print(min(s))


(H, W) = [int(_) for _ in input().split()]
if 0 in [H % 3, W % 3]:
	print(0)
	exit()

def calc(x, y):
	res = float('inf')
	for p in [y // 3, 1 + y // 3]:
		q = x // 2
		a = sorted([x * p, q * (y - p), (x - q) * (y - p)])
		res = min(res, abs(a[2] - a[0]))
	return res
print(min(H, W, calc(H, W), calc(W, H)))


inf = float('inf')
(H, W) = map(int, input().split())
ans = min(W, H)
if H % 3 == 0 or W % 3 == 0:
	print(0)
	exit()
for i in range(1, W):
	s = [H * i, H // 2 * (W - i), (H + 1) // 2 * (W - i)]
	ans = min(ans, abs(max(s) - min(s)))
for j in range(1, H):
	s = [W * j, W // 2 * (H - j), (W + 1) // 2 * (H - j)]
	ans = min(ans, abs(max(s) - min(s)))
print(ans)


(h, w) = map(int, input().split())
if h % 3 == 0:
	m1 = 0
else:
	m1 = w
if w % 3 == 0:
	m2 = 0
else:
	m2 = h
m3 = m4 = h * w
for i in range(1, h):
	m3 = min(m3, max(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)) - min(i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)))
for i in range(1, w):
	m4 = min(m4, max(i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)) - min(i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)))
print(min(m1, m2, m3, m4))


na = lambda : list(map(int, input().split()))
(h, w) = na()
ans = 111111111111
for (a, b) in [(w, h), (h, w)]:
	for i in range(1, b):
		for (c, d) in [(a, b - i), (b - i, a)]:
			l = [i * a, c * (d // 2), c * (d - d // 2)]
			ans = min(ans, max(l) - min(l))
print(ans)


(h, w) = map(int, input().split())
stand = h * w / 3
(prevh, prevw) = (1, 1)
mini = 10 ** 18
for i in range(2, h + 1):
	if abs(stand - i * w) < abs(stand - prevh * w):
		prevh = i
if h - prevh >= 2:
	mini = min(mini, max((h - prevh) // 2 * w, prevh * w, -(-(h - prevh) // 2) * w) - min((h - prevh) // 2 * w, prevh * w, -(-(h - prevh) // 2) * w))
mini = min(mini, max(w // 2 * (h - prevh), prevh * w, -(-w // 2) * (h - prevh)) - min(w // 2 * (h - prevh), prevh * w, -(-w // 2) * (h - prevh)))
for i in range(2, w + 1):
	if abs(stand - i * h) < abs(stand - prevw * h):
		prevw = i
if w - prevw >= 2:
	mini = min(mini, max((w - prevw) // 2 * h, prevw * h, -(-(w - prevw) // 2) * h) - min((w - prevw) // 2 * h, prevw * h, -(-(w - prevw) // 2) * h))
mini = min(mini, max(h // 2 * (w - prevw), prevw * h, -(-h // 2) * (w - prevw)) - min(h // 2 * (w - prevw), prevw * h, -(-h // 2) * (w - prevw)))
print(mini)


(h, w) = map(int, input().split())
print(min(h // 2 + w // 3 + 1, h // 3 + w // 2 + 1, h * (h % 3 > 0) // (2 - h % 2), w * (w % 3 > 0) // (2 - w % 2)))


(H, W) = map(int, input().split())
ans = H * W

def ep(H, W, h):
	S1 = h * W
	S2 = (H - h) * (W // 2)
	S3 = (H - h) * (W - W // 2)
	c1 = max(S1, S2, S3) - min(S1, S2, S3)
	T1 = h * W
	T2 = (H - h) // 2 * W
	T3 = (H - h - (H - h) // 2) * W
	c2 = max(T1, T2, T3) - min(T1, T2, T3)
	return min(ans, c1, c2)
if H != 1:
	for h in range(1, H):
		ans = ep(H, W, h)
(H, W) = (W, H)
if H != 1:
	for h in range(1, H):
		ans = ep(H, W, h)
print(ans)


(h, w) = map(int, input().split())
div1 = 0
div2 = 0
if h % 3 == 0 or w % 3 == 0:
	print('0')
else:
	div1 = min(h, w)

	def div2(h, w):
		m = h * w
		for l in range(1, w):
			s = [l * h, (w - l) * (h - h // 2), (w - l) * (h // 2)]
			m = min(m, max(s) - min(s))
		return m
	div2 = min(div2(h, w), div2(w, h))
	print(min(div1, div2))


(H, W) = map(int, input().split())
ans = H * W
for h in range(1, H):
	w = W // 2
	S = (h * W, (H - h) * w, (H - h) * (W - w))
	ans = min(ans, max(S) - min(S))
	h2 = (H - h) // 2
	S = (h * W, h2 * W, (H - h - h2) * W)
	ans = min(ans, max(S) - min(S))
for w in range(1, W):
	h = H // 2
	S = (H * w, h * (W - w), (H - h) * (W - w))
	ans = min(ans, max(S) - min(S))
	w2 = (W - w) // 2
	S = (H * w, H * w2, H * (W - w - w2))
	ans = min(ans, max(S) - min(S))
print(ans)


(H, W) = map(int, input().split())
(h, w) = (H // 2, W // 3)
s = sorted([w * H, (W - w) * (H - h), (W - w) * h])
a = s[2] - s[0]
s = sorted([(w + 1) * H, (W - w - 1) * (H - h), (W - w - 1) * h])
a = min(s[2] - s[0], a)
a = min(H * (W - 3 * w), a)
a = min(H * (3 + 3 * w - W), a)
(h, w) = (H // 3, W // 2)
s = sorted([W * h, (W - w) * (H - h), w * (H - h)])
a = min(s[2] - s[0], a)
s = sorted([W * (h + 1), (W - w) * (H - h - 1), w * (H - h - 1)])
a = min(s[2] - s[0], a)
s = sorted([W * (h + 2), (W - w) * (H - h - 2), w * (H - h - 2)])
a = min(s[2] - s[0], a)
a = min((H - 3 * h) * W, a)
a = min((3 + 3 * h - H) * W, a)
print(a)


def calc(H, W, ans):
	w0 = W // 2
	w1 = W - w0
	for h0 in range(1, H):
		Sa = h0 * W
		h1 = H - h0
		h2 = h1 // 2
		h3 = h1 - h2
		(Sb1, Sc1) = (h1 * w0, h1 * w1)
		(Sb2, Sc2) = (h2 * W, h3 * W)
		(m1, _, M1) = sorted([Sa, Sb1, Sc1])
		(m2, _, M2) = sorted([Sa, Sb2, Sc2])
		ans = min(ans, M1 - m1, M2 - m2)
	return ans
(H, W) = map(int, input().split())
print(calc(W, H, calc(H, W, H * W)))


(h, w) = map(int, input().split())
candidate = [0] * 4
if h * w % 3 == 0:
	print(0)
	exit()

def solve(a, b, k):
	candidate[k] = a
	cnd = float('inf')
	for i in range(a + 1):
		c1 = b * i
		c2 = (a - i) * (b // 2)
		c3 = (a - i) * (b - b // 2)
		cnd = min(cnd, max(c1, c2, c3) - min(c1, c2, c3))
	candidate[k + 1] = cnd
solve(h, w, 0)
solve(w, h, 2)
print(min(candidate))


(h, w) = map(int, input().split())
m = s = h * w

def f(x, y):
	global m
	g = lambda : min(m, max(p, q, r) - min(p, q, r))
	for i in (x // 3, x // 3 + 1):
		p = i * y
		q = (x - i) // 2 * y
		r = s - p - q
		m = g()
		q = y // 2 * (x - i)
		r = s - p - q
		m = g()
	return m
f(h, w)
f(w, h)
print(m)


(h, w) = map(int, input().split())
h_half = h // 2
w_half = w // 2
s_hw = h * w
min_x = s_hw
for n in reversed(range(1, w_half + 2)):
	a = h * n
	b = h_half * (w - n)
	c = s_hw - (a + b)
	s1 = max(a, b, c) - min(a, b, c)
	d = (w - n) // 2 * h
	e = s_hw - (a + d)
	s2 = max(a, d, e) - min(a, d, e)
	min_x = min(min_x, s1, s2)
for n in reversed(range(1, h_half + 2)):
	a = w * n
	b = w_half * (h - n)
	c = s_hw - (a + b)
	s1 = max(a, b, c) - min(a, b, c)
	d = (h - n) // 2 * w
	e = s_hw - (a + d)
	s2 = max(a, d, e) - min(a, d, e)
	min_x = min(min_x, s1, s2)
print(min_x)


(H, W) = list(map(int, input().split()))
if H % 3 == 0 or W % 3 == 0:
	print(0)
	return
A = 0
B = 0
ans = H * W
if H % 2 == 0:
	A = H // 2
	B = H // 2
else:
	A = H // 2 + 1
	B = H - A
for i in range(1, W):
	S1 = A * i
	S2 = B * i
	S3 = (W - i) * H
	SMaxMin = max(S1, S2, S3) - min(S1, S2, S3)
	ans = min(ans, SMaxMin)
if W % 2 == 0:
	A = W // 2
	B = W // 2
else:
	A = W // 2 + 1
	B = W - A
for i in range(1, H):
	S1 = A * i
	S2 = B * i
	S3 = (H - i) * W
	SMaxMin = max(S1, S2, S3) - min(S1, S2, S3)
	ans = min(ans, SMaxMin)
if H >= 3:
	ans = min(ans, W)
if W >= 3:
	ans = min(ans, H)
print(ans)


(h, w) = list(map(int, input().split()))

def calc(a, b):
	ret = a * b
	for i in range(1, a):
		area1 = b // 2 * i
		area2 = -(-b // 2) * i
		area3 = a * b - (area1 + area2)
		ret = min(ret, max(area1, area2, area3) - min(area1, area2, area3))
	return ret
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	ans = h * w
	for i in range(1, max(h, w) - 1):
		area1 = min(h, w) * i
		area2 = min(h, w) * ((max(h, w) - i) // 2)
		area3 = min(h, w) * -(-(max(h, w) - i) // 2)
		ans = min(ans, max(area1, area2, area3) - min(area1, area2, area3))
	print(min(calc(h, w), calc(w, h), ans))


import math

def main():
	(H, W) = [int(a) for a in input().split(' ')]
	cand = []
	if W % 3 == 0 or H % 3 == 0:
		print(0)
		return 0
	cand.append(H)
	cand.append(W)
	cand += split_3(H, W)
	cand += split_3(W, H)
	print(min(cand))
	return 0

def split_3(a, b):
	a_f = math.floor(a / 3)
	a_c = math.ceil(a / 3)
	b_f = math.floor(b / 2)
	b_c = math.ceil(b / 2)
	a1 = [b * a_f, (a - a_f) * b_f, a * b - (a - a_f) * b_f - b * a_f]
	a2 = [b * a_c, (a - a_c) * b_f, a * b - (a - a_c) * b_f - b * a_c]
	a3 = [b * a_f, (a - a_f) * b_c, a * b - (a - a_f) * b_c - b * a_f]
	a4 = [b * a_c, (a - a_c) * b_c, a * b - (a - a_c) * b_c - b * a_c]
	return [max(a1) - min(a1), max(a2) - min(a2), max(a3) - min(a3), max(a4) - min(a4)]
main()


(H, W) = map(int, input().split())
if H * W % 3 == 0:
	ret = 0
else:
	ret = min(H, W)
	S = [0] * 3
	for h in range(1, H):
		S = [W // 2 * h, (W - W // 2) * h, W * (H - h)]
		ret = min(ret, max(S) - min(S))
	for w in range(1, W):
		S = [H // 2 * w, (H - H // 2) * w, H * (W - w)]
		ret = min(ret, max(S) - min(S))
print(ret)


(h, w) = map(int, input().split())
INF = 100000000
if w % 3 == 0:
	s_tate = 0
else:
	s_tate = (int(w / 3) + 1) * h - int(w / 3) * h
if h % 3 == 0:
	s_yoko = 0
else:
	s_yoko = (int(h / 3) + 1) * w - int(h / 3) * w
case3 = INF
if w % 2 == 0:
	for i in range(1, h):
		buf = abs(int(w / 2) * i - w * (h - i))
		case3 = min(buf, case3)
else:
	for i in range(1, h):
		buf1 = int(w / 2) * i
		buf2 = (int(w / 2) + 1) * i
		buf3 = w * (h - i)
		buf = [buf1, buf2, buf3]
		buf = sorted(buf)
		sa = buf[2] - buf[0]
		case3 = min(sa, case3)
case4 = INF
if h % 2 == 0:
	for i in range(1, w):
		buf = abs(int(h / 2) * i - h * (w - i))
		case4 = min(buf, case4)
else:
	for i in range(1, w):
		buf1 = int(h / 2) * i
		buf2 = (int(h / 2) + 1) * i
		buf3 = h * (w - i)
		buf = [buf1, buf2, buf3]
		buf = sorted(buf)
		sa = buf[2] - buf[0]
		case4 = min(sa, case4)
ans1 = min(s_tate, s_yoko)
ans2 = min(case3, case4)
ans = min(ans1, ans2)
print(ans)


(h, w) = map(int, input().split())
ans = float('Inf')
if h % 3 == 0 or w % 3 == 0:
	print(0)
	exit()
for i in range(1, h):
	a = (h - i) * (w // 2)
	b = (h - i) * -(-w // 2)
	ans = min(ans, abs(max(i * w, a, b) - min(i * w, a, b)))
for i in range(1, w):
	a = (w - i) * (h // 2)
	b = (w - i) * -(-h // 2)
	ans = min(ans, abs(max(i * h, a, b) - min(i * h, a, b)))
print(min(ans, h, w))


(h, w) = map(int, input().split())
ans = 10 ** 9
for i in range(1, w):
	ans = min(max(abs(i * h - h // 2 * (w - i)), abs(i * h - (h + 1) // 2 * (w - i)), ((h + 1) // 2 - h // 2) * (w - i)), ans)
for i in range(1, h):
	ans = min(max(abs(i * w - w // 2 * (h - i)), abs(i * w - (w + 1) // 2 * (h - i)), ((w + 1) // 2 - w // 2) * (h - i)), ans)
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	ans = min(ans, h, w)
print(ans)


(H, W) = map(int, input().split())
if H * W % 3 == 0:
	print(0)
	exit()
S = [H, W]
x = H // 3
a = x * W
b = (H - x) * (W // 2)
c = H * W - a - b
S.append(max([a, b, c]) - min([a, b, c]))
x += 1
a = x * W
b = (H - x) * (W // 2)
c = H * W - a - b
S.append(max([a, b, c]) - min([a, b, c]))
y = W // 3
a = y * H
b = (W - y) * (H // 2)
c = H * W - a - b
S.append(max([a, b, c]) - min([a, b, c]))
y += 1
a = y * H
b = (W - y) * (H // 2)
c = H * W - a - b
S.append(max([a, b, c]) - min([a, b, c]))
print(min(S))


(h, w) = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
	print(0)
else:
	a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
	b = (h - h // 3) * (w - w // 2) - h // 3 * w
	c = min(h, w)
	(h, w) = (w, h)
	d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
	e = (h - h // 3) * (w - w // 2) - h // 3 * w
	print(min(a, b, c, d, e))


(h, w) = list(map(int, input().split()))
ans = 10 ** 9
if h % 3 == 0 or w % 3 == 0:
	ans = 0
else:
	for width in range(1, w):
		left = width * h
		if h % 2 == 0:
			right_up = (w - width) * (h // 2)
			right_down = right_up
		else:
			right_up = (w - width) * (h // 2 + 1)
			right_down = (w - width) * (h // 2)
		ans = min(ans, max(left, right_up, right_down) - min(left, right_up, right_down))
	for height in range(1, h):
		up = w * height
		if w % 2 == 0:
			down_left = w // 2 * (h - height)
			down_right = down_left
		else:
			down_left = w // 2 * (h - height)
			down_right = (w // 2 + 1) * (h - height)
		ans = min(ans, max(up, down_left, down_right) - min(up, down_left, down_right))
	ans = min(ans, min(h, w))
print(ans)


import sys
(H, W) = map(int, sys.stdin.readline().split())

def minimize(H, W):
	if H % 3 == 0:
		return 0
	res1 = W
	h = round(H / 3)
	w = W // 2
	block = [h * W, (H - h) * w, (H - h) * (W - w)]
	block.sort()
	res2 = block[-1] - block[0]
	return min(res1, res2)

def main():
	return min(minimize(H, W), minimize(W, H))
ans = main()
print(ans)


(h, w) = map(int, input().split())
if h % 3 * (w % 3) == 0:
	print(0)
	exit()
ans = min(h, w)
a = [0, 0, 0]
for i in range(2):
	b = h // 3 + i
	a[0] = b * w
	a[1] = (h - b) * (w // 2)
	a[2] = (h - b) * (w - w // 2)
	ans = min(ans, max(a) - min(a))
for i in range(2):
	b = w // 3 + i
	a[0] = b * h
	a[1] = (w - b) * (h // 2)
	a[2] = (w - b) * (h - h // 2)
	ans = min(ans, max(a) - min(a))
print(ans)


M = min

def f(x, y):
	m = x * (x % 3 > 0)
	for i in (0, 1):
		d = x // 3 + i
		e = x - d
		l = [d * y, y // 2 * e, -~y // 2 * e]
		m = M(m, max(l) - M(l))
	return m
(h, w) = map(int, input().split())
print(M(f(h, w), f(w, h)))


(H, W) = map(int, input().split())
ans = H * W
for i in range(1, H):
	S0 = i * W
	h = (H - i) // 2
	S1 = [S0, h * W, (H - i - h) * W]
	ans = min(ans, max(S1) - min(S1))
	h = H - i
	w = W // 2
	S1 = [S0, h * w, h * (W - w)]
	ans = min(ans, max(S1) - min(S1))
for j in range(1, W):
	S0 = j * H
	w = (W - j) // 2
	S1 = [S0, H * w, H * (W - j - w)]
	ans = min(ans, max(S1) - min(S1))
	w = W - j
	h = H // 2
	S1 = [S0, h * w, (H - h) * w]
	ans = min(ans, max(S1) - min(S1))
print(ans)


(h, w) = map(int, input().split())
ans = ((h + 2) // 3 - h // 3) * w
ans = min(ans, ((w + 2) // 3 - w // 3) * h)
for i in range(1, h):
	s = [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]
	ans = min(ans, max(s) - min(s))
for i in range(1, w):
	s = [i * h, (w - i) * (h // 2), (w - i) * (h - h // 2)]
	ans = min(ans, max(s) - min(s))
print(ans)