AtCoder Beginner Contest 062 - Chocolate Bar

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

Starter code:

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


from sys import stdin

def main():
	readline = stdin.readline
	(h, w) = map(int, readline().split())
	if h * w % 3 == 0:
		ans = 0
	else:
		ans = float('inf')
		s1 = w // 2 * h
		s2 = h * w - s1
		for i in range(1, h):
			s3 = i * w
			s1 -= w // 2
			s2 -= w - w // 2
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
		for i in range(1, h - 1):
			s3 = i * w
			s1 = (h - i) // 2 * w
			s2 = h * w - s3 - s1
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
		s1 = h // 2 * w
		s2 = h * w - s1
		for j in range(1, w):
			s3 = j * h
			s1 -= h // 2
			s2 -= h - h // 2
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
		for j in range(1, w - 1):
			s3 = j * h
			s1 = (w - j) // 2 * h
			s2 = h * w - s3 - s1
			ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	print(ans)

def __starting_point():
	main()
__starting_point()


(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 = 10 ** 10

def menseki(h, w):
	global ans
	for i in range(1, h):
		haba = w // 2
		ans = min(ans, max(i * w, haba * (h - i), (w - haba) * (h - i)) - min(i * w, haba * (h - i), (w - haba) * (h - i)))
		if i == h - 1:
			continue
		tate = (h - i) // 2
		ans = min(ans, max(w * i, tate * w, (h - i - tate) * w) - min(w * i, tate * w, (h - i - tate) * w))
menseki(h, w)
menseki(w, h)
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 re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline = sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
mod = int(10 ** 9 + 7)
inf = int(10 ** 20)

def yn(b):
	if b:
		print('yes')
	else:
		print('no')

def Yn(b):
	if b:
		print('Yes')
	else:
		print('No')

def YN(b):
	if b:
		print('YES')
	else:
		print('NO')

class union_find:

	def __init__(self, n):
		self.n = n
		self.P = [a for a in range(n)]
		self.rank = [0] * n

	def find(self, x):
		if x != self.P[x]:
			self.P[x] = self.find(self.P[x])
		return self.P[x]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def link(self, x, y):
		if self.rank[x] < self.rank[y]:
			self.P[x] = y
		elif self.rank[y] < self.rank[x]:
			self.P[y] = x
		else:
			self.P[x] = y
			self.rank[y] += 1

	def unite(self, x, y):
		self.link(self.find(x), self.find(y))

	def size(self):
		S = set()
		for a in range(self.n):
			S.add(self.find(a))
		return len(S)

def ispow(a, b):
	now = b
	while now < a:
		now *= b
	if now == a:
		return True
	else:
		return False

def getbin(num, size):
	A = [0] * size
	for a in range(size):
		if num >> size - a - 1 & 1 == 1:
			A[a] = 1
		else:
			A[a] = 0
	return A

def getfacs(n, mod_=0):
	A = [1] * (n + 1)
	for a in range(2, len(A)):
		A[a] = A[a - 1] * a
		if mod_ > 0:
			A[a] %= mod_
	return A

def comb(n, r, mod, fac):
	if n - r < 0:
		return 0
	return fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod) % mod

def nextcomb(num, size):
	x = num & -num
	y = num + x
	z = num & ~y
	z //= x
	z = z >> 1
	num = y | z
	if num >= 1 << size:
		return False
	else:
		return num

def getprimes(n, type='int'):
	if n == 0:
		if type == 'int':
			return []
		else:
			return [False]
	A = [True] * (n + 1)
	A[0] = False
	A[1] = False
	for a in range(2, n + 1):
		if A[a]:
			for b in range(a * 2, n + 1, a):
				A[b] = False
	if type == 'bool':
		return A
	B = []
	for a in range(n + 1):
		if A[a]:
			B.append(a)
	return B

def isprime(num):
	if num <= 1:
		return False
	i = 2
	while i * i <= num:
		if num % i == 0:
			return False
		i += 1
	return True

def ifelse(a, b, c):
	if a:
		return b
	else:
		return c

def join(A, c=''):
	n = len(A)
	A = list(map(str, A))
	s = ''
	for a in range(n):
		s += A[a]
		if a < n - 1:
			s += c
	return s

def factorize(n, type_='dict'):
	b = 2
	list_ = []
	while b * b <= n:
		while n % b == 0:
			n //= b
			list_.append(b)
		b += 1
	if n > 1:
		list_.append(n)
	if type_ == 'dict':
		dic = {}
		for a in list_:
			if a in dic:
				dic[a] += 1
			else:
				dic[a] = 1
		return dic
	elif type_ == 'list':
		return list_
	else:
		return None

def pm(x):
	return x // abs(x)

def inputintlist():
	return list(map(int, input().split()))
(H, W) = inputintlist()
ans = inf
for a in range(1, H):
	A = a * W
	B = (H - a) // 2 * W
	C = H * W - A - B
	ans = min(ans, max([A, B, C]) - min([A, B, C]))
	B = W // 2 * (H - a)
	C = H * W - A - B
	ans = min(ans, max([A, B, C]) - min([A, B, C]))
(H, W) = (W, H)
for a in range(1, H):
	A = a * W
	B = (H - a) // 2 * W
	C = H * W - A - B
	ans = min(ans, max([A, B, C]) - min([A, B, C]))
	B = W // 2 * (H - a)
	C = H * W - A - B
	ans = min(ans, max([A, B, C]) - min([A, B, C]))
print(ans)


(H, W) = [int(n) for n in input().split()]

def calc(H, W):
	res = 10000000000
	for h in range(1, H):
		S1 = h * W
		S2a = (H - h) * (W // 2)
		S3a = (H - h) * (W - W // 2)
		S2b = (H - h) // 2 * W
		S3b = (H - h - (H - h) // 2) * W
		dS = min(max(S1, S2a, S3a) - min(S1, S2a, S3a), max(S1, S2b, S3b) - min(S1, S2b, S3b))
		if dS < res:
			res = dS
	return res
print(min(calc(H, W), calc(W, H)))


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 = 10 ** 10
if H > 2:
	S = [H // 3, (H - H // 3) // 2, H - H // 3 - (H - H // 3) // 2]
	ans = min(ans, max(S) * W - min(S) * W)
if W > 2:
	S = [W // 3, (W - W // 3) // 2, W - W // 3 - (W - W // 3) // 2]
	ans = min(ans, max(S) * H - min(S) * H)
for w in range(1, W):
	S = [w * H, (W - w) * (H // 2), (W - w) * (H - H // 2)]
	ans = min(ans, max(S) - min(S))
for h in range(1, H):
	S = [h * W, (H - h) * (W // 2), (H - h) * (W - W // 2)]
	ans = min(ans, max(S) - min(S))
print(ans)


(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())
pattern = [H // 2 + W // 3 + 1, W // 3 + H // 2 + 1, H, W]
if H % 3 == 0 or W % 3 == 0:
	pattern += [0]
if H % 2 == 0:
	pattern += [H // 2]
if W % 2 == 0:
	pattern += [W // 2]
print(min(pattern))


def calc(w, h):
	v = float('inf')
	a = w * h
	for i in range(1, h):
		h_a = w * i
		h_b = (h - i) // 2 * w
		h_c = a - h_a - h_b
		h_max = max(h_a, h_b, h_c)
		h_min = min(h_a, h_b, h_c)
		v = min(v, h_max - h_min)
		v_b = w // 2 * (h - i)
		v_c = a - h_a - v_b
		v_max = max(h_a, v_b, v_c)
		v_min = min(h_a, v_b, v_c)
		v = min(v, v_max - v_min)
	return v

def resolve():
	(h, w) = map(int, input().split())
	print(min(calc(h, w), calc(w, h)))
resolve()


(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)
else:
	ans = float('inf')
	for i in range(1, h):
		c = max(i * (w // 2), i * (w - w // 2), (h - i) * w) - min(i * (w // 2), i * (w - w // 2), (h - i) * w)
		if ans > c:
			ans = c
	for i in range(1, w):
		d = max(i * (h // 2), i * (h - h // 2), (w - i) * h) - min(i * (h // 2), i * (h - h // 2), (w - i) * h)
		if ans > d:
			ans = d
	print(min(ans, h, w))


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


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

	def _solve(H, W):
		mean_w = W // 2
		ans = float('inf')
		for h in range(1, H):
			s1 = h * W
			mean_h = (H - h) // 2
			for i in range(0, 2):
				if i == 0:
					s2 = (H - h) * mean_w
					s3 = (H - h) * (W - mean_w)
				if i == 1:
					s2 = mean_h * W
					s3 = (H - h - mean_h) * W
				ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
		return ans
	print(min(_solve(H, W), _solve(W, H)))
if '__main__' == __name__:
	resolve()


(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) = map(int, input().split())
ans = 10 ** 9
for (p, o) in zip([h, w], [w, h]):
	for i in range(1, p // 2 + 1):
		sa = i * o
		hi = (p - i) // 2
		sb = o * hi
		sc = o * (p - i - hi)
		t = max(sa, sb, sc) - min(sa, sb, sc)
		ans = min(ans, t)
		wi = o // 2
		sb = (p - i) * wi
		sc = (p - i) * (o - wi)
		t = max(sa, sb, sc) - min(sa, sb, sc)
		ans = min(ans, t)
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())

def search(H, W):
	a = H // 2
	b = H // 2 + H % 2
	ans = float('inf')
	for w in range(1, W):
		x = a * w
		y = b * w
		z = H * (W - w)
		ans = min(ans, max(x, y, z) - min(x, y, z))
	return ans
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	ans = float('inf')
	if H > 3:
		ans = min(ans, W)
	if W > 3:
		ans = min(ans, H)
	print(min(search(H, W), search(W, H), ans))


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


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


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 = float('inf')
for _ in range(2):
	for i in range(1, H):
		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 = W // 2 * (H - i)
		c = (W + 1) // 2 * (H - i)
		ans = min(ans, abs(max(a, b, c) - min(a, b, c)))
	(H, W) = (W, H)
print(ans)


(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())
x = []
for i in range(1, w):
	x1 = [h * i, h * ((w - i) // 2), h * (w - i) - h * ((w - i) // 2)]
	x1.sort()
	x.append(x1[-1] - x1[0])
	x2 = [h * i, (w - i) * (h // 2), h * (w - i) - (w - i) * (h // 2)]
	x2.sort()
	x.append(x2[-1] - x2[0])
for i in range(1, h):
	x1 = [w * i, w * ((h - i) // 2), w * (h - i) - w * ((h - i) // 2)]
	x1.sort()
	x.append(x1[-1] - x1[0])
	x2 = [w * i, (h - i) * (w // 2), w * (h - i) - (h - i) * (w // 2)]
	x2.sort()
	x.append(x2[-1] - x2[0])
print(min(x))


(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())
ans = []
import sys

def s(a, b):
	for i in range(a):
		s = a * b
		x = i * b
		y = (a - i) // 2 * b
		z = s - x - y
		d = (a - i) * (b // 2)
		e = s - x - d
		ma = max(x, y, z)
		mi = min(x, y, z)
		mc = max(x, e, d)
		mn = min(x, e, d)
		res = min(ma - mi, mc - mn)
		ans.append(res)
	return min(ans)
f = s(h, w)
g = s(w, h)
print(min(f, g))


(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())
ans = 1e+19
for i in range(1, H):
	tate = W * i
	if i < H - 1:
		mini = W * ((H - i) // 2)
		ans = min(ans, max(tate, mini, H * W - mini - tate) - min(tate, mini, H * W - mini - tate))
	mini = (H - i) * (W // 2)
	ans = min(ans, max(tate, mini, H * W - tate - mini) - min(tate, mini, H * W - tate - mini))
for i in range(1, W):
	yoko = H * i
	if i < W - 1:
		mini = H * ((W - i) // 2)
		ans = min(ans, max(yoko, mini, H * W - mini - yoko) - min(yoko, mini, H * W - yoko - mini))
	mini = (W - i) * (H // 2)
	ans = min(ans, max(yoko, mini, H * W - yoko - mini) - min(yoko, mini, H * W - yoko - mini))
print(ans)


(W, H) = map(int, input().split())
ans = 10 ** 30
for i in range(1, W):
	a = H * i
	w = W - i
	b = max(w // 2 * H, w * (H // 2))
	c = w * H - b
	x = max(a, b, c) - min(a, b, c)
	ans = min(ans, x)
for i in range(1, H):
	a = W * i
	h = H - i
	b = max(W // 2 * h, W * (h // 2))
	c = h * W - b
	x = max(a, b, c) - min(a, b, c)
	ans = min(ans, x)
print(ans)


(h, w) = map(int, input().split())
ans = 10 ** 9
for i in range(1, h):
	x = h - i
	s0 = i * w
	s1 = x * (w // 2)
	s2 = x * (w - w // 2)
	s = max(s0, s1, s2) - min(s0, s1, s2)
	ans = min(ans, s)
	s3 = w * (x // 2)
	s4 = w * (x - x // 2)
	s = max(s0, s3, s4) - min(s0, s3, s4)
	ans = min(ans, s)
for i in range(1, w):
	x = w - i
	s0 = i * h
	s1 = x * (h // 2)
	s2 = x * (h - h // 2)
	s = max(s0, s1, s2) - min(s0, s1, s2)
	ans = min(ans, s)
	s3 = h * (x // 2)
	s4 = h * (x - x // 2)
	s = max(s0, s3, s4) - min(s0, s3, s4)
	ans = min(ans, s)
print(ans)


(h, w) = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
	print(0)
	return
ans = 10 ** 10
if h >= 3:
	ans = min(h, ans)
if w >= 3:
	ans = min(ans, w)
for i in range(1, h):
	num1 = w * i
	num2 = (h - i) * (w // 2)
	num3 = (h - i) * (w - w // 2)
	kouho = [num1, num2, num3]
	kouho.sort()
	ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
	num1 = h * i
	num2 = (w - i) * (h // 2)
	num3 = (w - i) * (h - h // 2)
	kouho = [num1, num2, num3]
	kouho.sort()
	ans = min(ans, kouho[-1] - kouho[0])
print(ans)


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


(H, W) = map(int, input().split())
h = min(H, W)
w = max(H, W)
s = h * w
res = 10 ** 10
for i in range(1, w):
	a = h * i
	b = (w - i) // 2 * h
	c = s - a - b
	res = min(max(a, b, c) - min(a, b, c), res)
	b = (w - i) * (h // 2)
	c = s - a - b
	res = min(max(a, b, c) - min(a, b, c), res)
for i in range(1, h):
	a = w * i
	b = (h - i) // 2 * w
	c = s - a - b
	res = min(max(a, b, c) - min(a, b, c), res)
	b = (h - i) * (w // 2)
	c = s - a - b
	res = min(max(a, b, c) - min(a, b, c), res)
print(res)


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())
s = float('inf')
for i in range(1, h):
	a1 = min(i * w, w * ((h - i) // 2))
	b1 = max(i * w, w * (h - i - (h - i) // 2))
	d1 = b1 - a1
	a2 = min(i * w, (h - i) * (w // 2))
	b2 = max(i * w, (h - i) * (w - w // 2))
	d2 = b2 - a1
	s = min(s, d1, d2)
for j in range(1, w):
	a1 = min(j * h, h * ((w - j) // 2))
	b1 = max(j * h, h * (w - j - (w - j) // 2))
	d1 = b1 - a1
	a2 = min(j * h, (w - j) * (h // 2))
	b2 = max(j * h, (w - j) * (h - h // 2))
	d2 = b2 - a2
	s = min(s, d1, d2)
print(s)


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


(H, W) = map(int, input().split())
S = []

def Scal(H, W):
	for i in range(1, H // 2 + 1):
		S1 = W * i
		S2 = W * ((H - i) // 2)
		S3 = H * W - S1 - S2
		s1 = [S1, S2, S3]
		S.append(s1)
		S2 = W // 2 * (H - i)
		S3 = H * W - S1 - S2
		s2 = [S1, S2, S3]
		S.append(s2)
Scal(H, W)
Scal(W, H)
Sdif = []
for i in range(len(S)):
	Sdif.append(max(S[i]) - min(S[i]))
print(min(Sdif))


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())
ans = 10 ** 12
for h in range(1, H):
	s1 = W * h
	h2 = (H - h) // 2
	h3 = H - h - h2
	s2 = W * h2
	s3 = W * h3
	max_s = max(s1, s2, s3)
	min_s = min(s1, s2, s3)
	ans = min(ans, max_s - min_s)
	w2 = W // 2
	w3 = W - w2
	s2 = (H - h) * w2
	s3 = (H - h) * w3
	max_s = max(s1, s2, s3)
	min_s = min(s1, s2, s3)
	ans = min(ans, max_s - min_s)
for w in range(1, W):
	s1 = w * H
	h2 = H // 2
	h3 = H - h2
	s2 = (W - w) * h2
	s3 = (W - w) * h3
	max_s = max(s1, s2, s3)
	min_s = min(s1, s2, s3)
	ans = min(ans, max_s - min_s)
	w2 = (W - w) // 2
	w3 = W - w - w2
	s2 = H * w2
	s3 = H * w3
	max_s = max(s1, s2, s3)
	min_s = min(s1, s2, s3)
	ans = min(ans, max_s - min_s)
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)


(H, W) = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
elif H == W:
	if H % 2 == 0:
		print(H // 2)
	else:
		print(H - (2 * H // 6 - H // 6))
elif H % 2 == 0 and W % 2 == 0:
	print(min(H // 2, W // 2))
elif H % 2 == 0:
	print(min(H // 2, H, W))
elif W % 2 == 0:
	print(min(W // 2, H, W))
else:
	print(min(H, W))


(h, w) = map(int, input().split())
r = 1000000000.0
f = lambda x: max(x) - min(x)
for _ in 'aa':
	for i in range(1, h):
		r = min(min(r, f([j if j else -1000000000.0 for j in [i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w]])), f([j if j else -1000000000.0 for j in [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)]]))
	(h, w) = (w, h)
print(r)


(H, W) = map(int, input().split())
M = 10 ** 10
if H == 2 and W == 2:
	M = 1
if H > 2:
	HH = H // 3
	S1 = HH * W
	HH = H - H // 3
	HHH = HH // 2
	S2 = HHH * W
	HHH = HH - HH // 2
	S3 = HHH * W
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
	HH = H // 3
	S1 = HH * W
	WW = W // 2
	S2 = (H - HH) * WW
	WW = W - W // 2
	S3 = (H - HH) * WW
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
	HH = H // 3 + 1
	S1 = HH * W
	WW = W // 2
	S2 = (H - HH) * WW
	WW = W - W // 2
	S3 = (H - HH) * WW
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
if W > 2:
	WW = W // 3
	S1 = WW * H
	WW = W - W // 3
	WWW = WW // 2
	S2 = WWW * H
	WWW = WW - WW // 2
	S3 = WWW * H
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
	WW = W // 3
	S1 = WW * H
	HH = H // 2
	S2 = (W - WW) * HH
	HH = H - H // 2
	S3 = (W - WW) * HH
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
	WW = W // 3 + 1
	S1 = WW * H
	HH = H // 2
	S2 = (W - WW) * HH
	HH = H - H // 2
	S3 = (W - WW) * HH
	m = max(S1, S2, S3) - min(S1, S2, S3)
	M = min(M, m)
print(M)


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


class V:

	def __init__(self, f, v=None):
		self.f = f
		self.v = v

	def __str__(self):
		return str(self.v)

	def __call__(self, n):
		if n is None:
			return self.v
		if self.v is None:
			self.v = n
			return self.v
		self.v = self.f(self.v, n)
(h, w) = map(int, input().split())

def minmax(*args):
	return max(args) - min(args)

def sep(m, n):
	a = b = c = 0
	nn = n // 2
	ans = V(min, float('inf'))
	for i in range(1, m):
		a = i * n
		mm = (m - i) // 2
		(b, c) = ((m - i) * nn, (m - i) * (n - nn))
		ans(minmax(a, b, c))
		(b, c) = (mm * n, (m - i - mm) * n)
		ans(minmax(a, b, c))
	return ans.v
print(min(sep(h, w), sep(w, h)))


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


(h, w) = map(int, input().split())
e = 50000
for (a, b) in [(w, h), (h, w)]:
	for i in range(b):
		for (c, d) in [(a, b - i), (b - i, a)]:
			l = [i * a, c * (d // 2), c * (d - d // 2)]
			e = min(e, max(l) - min(l))
print(e)


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


(hight, width) = map(int, input().split())
ans = 10 ** 18

def F(H, W):
	global ans
	for h in range(1, H):
		sa = h * W
		h2 = (H - h) // 2
		sb = h2 * W
		sc = (H - h - h2) * W
		ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))
		w = W // 2
		sb = (H - h) * w
		sc = (H - h) * (W - w)
		ans = min(ans, max(sa, sb, sc) - min(sa, sb, sc))
F(hight, width)
F(width, hight)
print(ans)


(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) = list(map(int, input().split(' ')))
ans = []
for h in range(1, H):
	r1 = h * W
	h = H - h
	r2a = h // 2 * W
	r3a = -1 * (-h // 2) * W
	r2b = W // 2 * h
	r3b = -1 * (-W // 2) * h
	ans.append(max(r1, r2a, r3a) - min(r1, r2a, r3a))
	ans.append(max(r1, r2b, r3b) - min(r1, r2b, r3b))
for w in range(1, W):
	r1 = H * w
	w = W - w
	r2a = H // 2 * w
	r3a = -1 * (-H // 2) * w
	r2b = w // 2 * H
	r3b = -1 * (-w // 2) * H
	ans.append(max(r1, r2a, r3a) - min(r1, r2a, r3a))
	ans.append(max(r1, r2b, r3b) - min(r1, r2b, r3b))
print(min(ans))


def answer(H, W, ans):
	global ans_list
	for x in range(1, W):
		y1 = H // 2
		S1 = [H * x, (W - x) * y1, (W - x) * (H - y1)]
		ans_list.append(max(S1) - min(S1))
		y2 = (W - x) // 2
		S2 = [H * x, H * y2, H * (W - x - y2)]
		ans_list.append(max(S2) - min(S2))
(H, W) = [int(i) for i in input().split()]
ans_list = []
answer(H, W, ans_list)
answer(W, H, ans_list)
print(min(ans_list))


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


print((lambda a: min([min([float('inf') if a[1] <= 1 else (lambda b: b[2] - b[0])(sorted([i * a[0], (a[1] - i) * (a[0] // 2), (a[1] - i) * (a[0] // 2 + a[0] % 2)])) for i in range(1, a[1])])] + [min([float('inf') if a[0] <= 1 else (lambda b: b[2] - b[0])(sorted([i * a[1], (a[0] - i) * (a[1] // 2), (a[0] - i) * (a[1] // 2 + a[1] % 2)])) for i in range(1, a[0])])] + [a[1] if a[0] % 3 else 0] + [a[0] if a[1] % 3 else 0]))(list(map(int, input().split()))))


(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())
ans = 10 ** 10
for _ in range(2):
	for h in range(1, H):
		a = h * W
		b = (H - h) // 2 * W
		c = (H - h - (H - h) // 2) * W
		d = max(a, b, c) - min(a, b, c)
		ans = min(ans, d)
		b = (H - h) * (W // 2)
		c = (H - h) * (W - W // 2)
		d = max(a, b, c) - min(a, b, c)
		ans = min(ans, d)
	(H, W) = (W, H)
print(ans)


(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) = map(int, input().split())
ans = float('inf')
for h in range(1, H):
	S = [h * W]
	w = W // 2
	S += [(H - h) * w]
	S += [(H - h) * (W - w)]
	ans = min(ans, max(S) - min(S))
for h in range(1, H):
	S = [h * W]
	hb = (H - h) // 2
	S += [hb * W]
	S += [(H - h - hb) * W]
	ans = min(ans, max(S) - min(S))
for w in range(1, W):
	S = [H * w]
	h = H // 2
	S += [h * (W - w)]
	S += [(H - h) * (W - w)]
	ans = min(ans, max(S) - min(S))
for w in range(1, W):
	S = [w * H]
	wb = (W - w) // 2
	S += [wb * H]
	S += [(W - w - wb) * H]
	ans = min(ans, max(S) - min(S))
print(ans)


(h, w) = map(int, input().split())
print(min(min((min(max((i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w)) - min((i * w, (h - i) // 2 * w, (h - i - (h - i) // 2) * w)), max((i * w, w // 2 * (h - i), (h - i) * (w - w // 2))) - min((i * w, w // 2 * (h - i), (h - i) * (w - w // 2)))) for i in range(h))), min((min(max((h * i, (w - i) // 2 * h, h * (w - i - (w - i) // 2))) - min((h * i, (w - i) // 2 * h, h * (w - i - (w - i) // 2))), max((h * i, h // 2 * (w - i), (h - h // 2) * (w - i))) - min((h * i, h // 2 * (w - i), (h - h // 2) * (w - i)))) for i in range(w)))))


(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())
ans = 10 ** 9
(w1, w2) = (w // 2, w - w // 2)
for i in range(1, h):
	s = (i * w, w1 * (h - i), w2 * (h - i))
	ans = min(ans, max(s) - min(s))
(h1, h2) = (h // 2, h - h // 2)
for i in range(1, w):
	s = (i * h, h1 * (w - i), h2 * (w - i))
	ans = min(ans, max(s) - min(s))
if h % 3 == 0 or w % 3 == 0:
	ans = 0
if w > 2:
	ans = min(ans, w)
if h > 2:
	ans = min(ans, h)
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) = map(int, input().split())
candicate = []
for y in range(1, H):
	candicate.append(max(y * W, W * ((H - y + 1) // 2)) - min(y * W, W * ((H - y) // 2)))
	candicate.append(max(y * W, (H - y) * ((W + 1) // 2)) - min(y * W, (H - y) * (W // 2)))
for x in range(1, W):
	candicate.append(max(x * H, H * ((W - x + 1) // 2)) - min(x * H, H * ((W - x) // 2)))
	candicate.append(max(x * H, (W - x) * ((H + 1) // 2)) - min(x * H, (W - x) * (H // 2)))
print(min(candicate))


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


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

def case1(h, w):
	MIN = float('inf')
	for i in range(1, h):
		sa = i * w
		sb = (h - i) * (w // 2)
		sc = (h - i) * (w - w // 2)
		if max([sa, sb, sc]) - min([sa, sb, sc]) < MIN:
			MIN = max([sa, sb, sc]) - min([sa, sb, sc])
	return MIN

def case2(h, w):
	MIN = float('inf')
	for i in range(1, h):
		sa = i * w
		sb = (h - i) // 2 * w
		sc = (h - i - (h - i) // 2) * w
		if max([sa, sb, sc]) - min([sa, sb, sc]) < MIN:
			MIN = max([sa, sb, sc]) - min([sa, sb, sc])
	return MIN
print(min([case1(H, W), case1(W, H), case2(H, W), case2(W, H)]))


import math
(h, w) = map(int, input().split())
R = []

def func(h, w):
	for i in range(1, h + 1):
		s1 = i * w
		s2 = (h - i) * math.ceil(w / 2)
		s3 = (h - i) * (w // 2)
		R.append(max(s1, s2, s3) - min(s1, s2, s3))
		s2 = math.ceil((h - i) / 2) * w
		s3 = (h - i) // 2 * w
		R.append(max(s1, s2, s3) - min(s1, s2, s3))
	return min(R)
print(min(func(h, w), func(w, h)))


(H, W) = map(int, input().split())
ans = float('inf')
for (h, w) in zip([H, W], [W, H]):
	for ah in range(1, h):
		Sa = ah * w
		bw = (w - 1) // 2 + 1
		Sb = (h - ah) * bw
		Sc = (h - ah) * (w - bw)
		ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
		if h - ah > 1:
			bh = (h - ah - 1) // 2 + 1
			Sb = bh * w
			Sc = (h - ah - bh) * w
			ans = min(ans, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
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)


def calc(i, w, h):
	fixed = w * h
	a = w * i
	v_b = (h - i) // 2 * w
	v_c = fixed - a - v_b
	v_d = max(a, v_b, v_c) - min(a, v_b, v_c)
	h_b = w // 2 * (h - i)
	h_c = fixed - a - h_b
	h_d = max(a, h_b, h_c) - min(a, h_b, h_c)
	return min(v_d, h_d)

def resolve():
	(h, w) = map(int, input().split())
	ans = float('inf')
	for i in range(1, h):
		ans = min(ans, calc(i, w, h))
	for i in range(1, w):
		ans = min(ans, calc(i, h, w))
	print(ans)
resolve()


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


(a, b) = map(int, input().split())
m = 10000000000.0
for i in range(1, a):
	l = [i * b, (a - i) * (b // 2), (a - i) * (b - b // 2)]
	if sum(l) == a * b:
		m = min(m, max(l) - min(l))
	o = [i * b, b * (a - i) // 2, b * (a - i - (a - i) // 2)]
	if sum(o) == a * b:
		m = min(m, max(o) - min(o))
for i in range(1, b):
	l = [i * a, (b - i) * (a // 2), (b - i) * (a - a // 2)]
	if sum(l) == a * b:
		m = min(m, max(l) - min(l))
	o = [i * a, a * (b - i) // 2, a * (b - i - (b - i) // 2)]
	if sum(o) == a * b:
		m = min(m, max(o) - min(o))
print(m)


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

def calc(h, w):
	minv = 2 ** 32
	for i in range(1, h):
		s1 = i * w
		s2 = (h - i) // 2 * w
		s3 = (h - i - (h - i) // 2) * w
		lmin = max(s1, s2, s3) - min(s1, s2, s3)
		minv = min(minv, lmin)
		s2v = (h - i) * (w // 2)
		s3v = (h - i) * (w - w // 2)
		minv = min(minv, max(s1, s2v, s3v) - min(s1, s2v, s3v))
	return minv
m = min(calc(H, W), calc(W, H))
print(m)


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


(h, w) = map(int, input().split())
ans = 10 ** 5
for _ in range(2):
	for i in range(1, h):
		th = (h - i) // 2
		m1 = max(i * w, th * w, (h - i - th) * w) - min(i * w, th * w, (h - i - th) * w)
		tw = w // 2
		m2 = max(i * w, (h - i) * tw, (h - i) * (w - tw)) - min(i * w, (h - i) * tw, (h - i) * (w - tw))
		ans = min(ans, m1, m2)
	(h, w) = (w, h)
print(ans)


from math import ceil, floor
(W, H) = map(int, input().split())

def S(H, W):
	res = []
	for i in range(1, H):
		S1 = i * W
		S2 = (H - i) * ceil(W / 2)
		S3 = (H - i) * floor(W / 2)
		S4 = W * ceil((H - i) / 2)
		S5 = W * floor((H - i) / 2)
		res.append(max(S1, S2, S3) - min(S1, S2, S3))
		res.append(max(S1, S4, S5) - min(S1, S4, S5))
	return min(res)
print(min(S(H, W), S(W, H)))


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


(H, W) = list(map(int, input().split()))
ans = float('inf')
for x in range(1, W):
	S1 = x * H
	w2 = (W - x) // 2
	w3 = W - x - w2
	S2 = w2 * H
	S3 = w3 * H
	S_max = max(S1, S3)
	S_min = min(S1, S2)
	ans = min(ans, S_max - S_min)
	h2 = H // 2
	h3 = H - h2
	S2 = (W - x) * h2
	S3 = (W - x) * h3
	S_max = max(S1, S3)
	S_min = min(S1, S2)
	ans = min(ans, S_max - S_min)
for y in range(1, H):
	S1 = W * y
	w2 = W // 2
	w3 = W - w2
	S2 = w2 * (H - y)
	S3 = w3 * (H - y)
	S_max = max(S1, S3)
	S_min = min(S1, S2)
	ans = min(ans, S_max - S_min)
	h2 = (H - y) // 2
	h3 = H - y - h2
	S2 = W * h2
	S3 = W * h3
	S_max = max(S1, S3)
	S_min = min(S1, S2)
	ans = min(ans, S_max - S_min)
print(int(ans))


(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())
S = H * W
ans = 0
if H * W % 3 != 0:
	ans = 10 ** 11
	for (a, b) in zip((H, W), (W, H)):
		for i in range(1, a):
			S1 = i * b
			S2 = (a - i) * (b // 2)
			S3 = S - S1 - S2
			S4 = (a - i) // 2 * b
			S5 = S - S1 - S4
			ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3), max(S1, S4, S5) - min(S1, S4, S5))
print(ans)


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


import sys
input = sys.stdin.readline
(H, W) = list(map(int, input().split()))
S = H * W
s1 = 0
ans = 10 ** 10
for i in range(1, H):
	s1 += W
	s2 = (H - i) * (W // 2)
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	s2 = (H - i) // 2 * W
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
s1 = 0
for i in range(1, W):
	s1 += H
	s2 = (W - i) * (H // 2)
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
	s2 = (W - i) // 2 * H
	s3 = S - s1 - s2
	ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
print(ans)


(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) = (int(T) for T in input().split())
minSH = H * W
minSW = H * W
for TH in range(1, H):
	BlockA = TH * W
	if TH <= H - 2:
		BlockB1 = (H - TH) // 2 * W
		BlockC1 = H * W - (BlockA + BlockB1)
		BigSCa1 = max(BlockA, BlockB1, BlockC1)
		SmlSCa1 = min(BlockA, BlockB1, BlockC1)
		DifSCa1 = BigSCa1 - SmlSCa1
	else:
		DifSCa1 = H * W
	if W >= 2:
		BlockB2 = (H - TH) * (W // 2)
		BlockC2 = H * W - (BlockA + BlockB2)
		BigSCa2 = max(BlockA, BlockB2, BlockC2)
		SmlSCa2 = min(BlockA, BlockB2, BlockC2)
		DifSCa2 = BigSCa2 - SmlSCa2
	else:
		DifSCa2 = H * W
	if min(DifSCa1, DifSCa2) < minSH:
		minSH = min(DifSCa1, DifSCa2)
for TW in range(1, W):
	BlockA = H * TW
	if TW <= W - 2:
		BlockB1 = H * ((W - TW) // 2)
		BlockC1 = H * W - (BlockA + BlockB1)
		BigSCa1 = max(BlockA, BlockB1, BlockC1)
		SmlSCa1 = min(BlockA, BlockB1, BlockC1)
		DifSCa1 = BigSCa1 - SmlSCa1
	else:
		DifSCa1 = H * W
	if H >= 2:
		BlockB2 = H // 2 * (W - TW)
		BlockC2 = H * W - (BlockA + BlockB2)
		BigSCa2 = max(BlockA, BlockB2, BlockC2)
		SmlSCa2 = min(BlockA, BlockB2, BlockC2)
		DifSCa2 = BigSCa2 - SmlSCa2
	else:
		DifSCa2 = H * W
	if min(DifSCa1, DifSCa2) < minSW:
		minSW = min(DifSCa1, DifSCa2)
print(min(minSH, minSW))


(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()))
inf = float('inf')
ans = inf
for i in range(1, h):
	a = i * w
	rest = h * w - a
	b = w // 2 * (h - i)
	c = rest - b
	max_s = max(a, b, c)
	min_s = min(a, b, c)
	ans = min(ans, max_s - min_s)
for j in range(1, w):
	A = j * h
	Rest = h * w - A
	B = h // 2 * (w - j)
	C = Rest - B
	Max_s = max(A, B, C)
	Min_s = min(A, B, C)
	ans = min(ans, Max_s - Min_s)
if w >= 3:
	if w % 3 == 0:
		ans = 0
	else:
		ans = min(ans, h)
if h >= 3:
	if h % 3 == 0:
		ans = 0
	else:
		ans = min(ans, w)
print(ans)


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


(x, y) = map(int, input().split(' '))

def a(H, W):
	m = float('inf')

	def b(HH, WW):
		ww = WW // 2
		return [HH * ww, HH * (WW - ww)]
	h = 1
	while h < H:
		Sa = h * W
		(Sb, Sc) = b(H - h, W)
		a = sorted([Sa, Sb, Sc])
		m = min(a[2] - a[0], m)
		(Sb, Sc) = b(W, H - h)
		a = sorted([Sa, Sb, Sc])
		m = min(a[2] - a[0], m)
		h += 1
	return m
print(min(a(x, y), a(y, x)))


(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())
ans = 1000000000
if max(h, w) >= 3:
	if h >= w:
		ans = w * min(1, h % 3)
	else:
		ans = h * min(1, w % 3)
if h % 3 == 0:
	ans = 0
if w % 3 == 0:
	ans = 0
for i in range(1, h):
	ans_ = max(i * w, (h - i) * (w + w % 2) // 2) - min(i * w, (h - i) * (w - w % 2) // 2)
	ans = min(ans, ans_)
for i in range(1, w):
	ans_ = max(i * h, (w - i) * (h + h % 2) // 2) - min(i * h, (w - i) * (h - h % 2) // 2)
	ans = min(ans, ans_)
print(ans)


def min_value(w, h):
	ans = float('inf')
	for i in range(1, h):
		a = w * i
		v_t = (h - i) // 2 * w
		v_b = (h - i) * w - v_t
		v_re = max(a, v_t, v_b) - min(a, v_t, v_b)
		h_l = (h - i) * (w // 2)
		h_r = (h - i) * w - h_l
		h_re = max(a, h_l, h_r) - min(a, h_l, h_r)
		ans = min(ans, v_re, h_re)
	return ans

def resolve():
	(h, w) = map(int, input().split())
	a = min_value(w, h)
	b = min_value(h, w)
	print(min(a, b))
resolve()


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

def calc(H, W, ans):
	for i in range(1, H):
		Sa = i * W
		h = (H - i) // 2
		Sb = h * W
		Sc = (H - i - h) * W
		d1 = max(Sa, Sb, Sc) - min(Sa, Sb, Sc)
		w = W // 2
		Sb = (H - i) * w
		Sc = (H - i) * (W - w)
		d2 = max(Sa, Sb, Sc) - min(Sa, Sb, Sc)
		if ans > min(d1, d2):
			ans = min(d1, d2)
	return ans
ans = 1000000
ans = calc(H, W, ans)
ans = calc(W, H, ans)
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())
f = lambda x: max(x) - min(x)
g = lambda h, w: min([min(f([i, (h - i) // 2, h - i - (h - i) // 2]) * w, f([i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)])) for i in range(1, h)])
print(min(g(h, w), g(w, h)))


ma = lambda : map(int, input().split())
lma = lambda : list(map(int, input().split()))
tma = lambda : tuple(map(int, input().split()))
ni = lambda : int(input())
yn = lambda fl: print('Yes') if fl else print('No')
import collections
import math
import itertools
import heapq as hq
(H, W) = ma()

def f(H, W):
	ret = 10 ** 10 + 5
	for h in range(1, H):
		s1 = h * W
		(s2, s3) = ((H - h) // 2 * W, (H - h + 1) // 2 * W)
		ret = min(ret, max(s1, s2, s3) - min(s1, s2, s3))
		(s2, s3) = (W // 2 * (H - h), (W + 1) // 2 * (H - h))
		ret = min(ret, max(s1, s2, s3) - min(s1, s2, s3))
	return ret
print(min(f(H, W), f(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)


def readInts():
	return list(map(int, input().split()))
mod = 10 ** 9 + 7

def main():
	(H, W) = readInts()
	LIST = [H // 2 + W // 3 + 1, W // 3 + H // 2 + 1, H, W]
	if H % 3 == 0 or W % 3 == 0:
		LIST += [0]
	if H % 2 == 0:
		LIST += [H // 2]
	if W % 2 == 0:
		LIST += [W // 2]
	print(min(LIST))

def __starting_point():
	main()
__starting_point()


(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())
ans = h * w
if h % 3 == 0 or h % 3 == 0:
	print(0)
	exit()
for i in range(1, w):
	(H1, H2) = (h // 2, -(-h // 2))
	check = max(h * i, H2 * (w - i), H1 * (w - i))
	check2 = min(h * i, H1 * (w - i), H2 * (w - i))
	ans = min(ans, abs(check - check2))
for i in range(1, h):
	(w1, w2) = (w // 2, -(-w // 2))
	check = max(w * i, w1 * (h - i), w2 * (h - i))
	check2 = min(w * i, w1 * (h - i), w2 * (h - i))
	ans = min(ans, abs(check - check2))
print(min(ans, h, w))


(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 = float('inf')
for h in range(1, H):
	Sa = h * W
	w = W // 2
	Sb = (H - h) * w
	Sc = (H - h) * (W - w)
	ans = min(ans, max([Sa, Sb, Sc]) - min([Sa, Sb, Sc]))
for h in range(1, H):
	Sa = h * W
	hb = (H - h) // 2
	Sb = hb * W
	Sc = (H - h - hb) * W
	ans = min(ans, max([Sa, Sb, Sc]) - min([Sa, Sb, Sc]))
for w in range(1, W):
	Sa = H * w
	h = H // 2
	Sb = h * (W - w)
	Sc = (H - h) * (W - w)
	ans = min(ans, max([Sa, Sb, Sc]) - min([Sa, Sb, Sc]))
for w in range(1, W):
	Sa = w * H
	wb = (W - w) // 2
	Sb = wb * H
	Sc = (W - w - wb) * H
	ans = min(ans, max([Sa, Sb, Sc]) - min([Sa, Sb, Sc]))
print(ans)


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


from sys import stdin
(H, W) = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 10000000000.0
for _ in range(2):
	for i in range(1, H):
		a = i * W
		b = W // 2 * (H - i)
		c = (W + 1) // 2 * (H - i)
		ans = min(ans, abs(max([a, b, c]) - min([a, b, c])))
		b = (H - i) // 2 * W
		c = (H - i + 1) // 2 * W
		ans = min(ans, abs(max([a, b, c]) - min([a, b, c])))
	(H, W) = (W, H)
print(ans)


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

def choco(H, W):
	ans = float('inf')
	(a, b, c) = (0, 0, 0)
	for i in range(1, H):
		a = i * W
		for j in range(2):
			if j == 0:
				b = (H - i) // 2 * W
				c = H * W - a - b
			else:
				b = (H - i) * (W // 2)
				c = H * W - a - b
			ans = min(ans, max(a, b, c) - min(a, b, c))
	return ans
print(min(choco(h, w), choco(w, h)))


(h, w) = map(int, input().split())
if h == 2 and w == 2:
	print(1)
	return
ans = 10 ** 10
if h >= 3:
	if h % 3 == 0:
		a = 0
	else:
		a = w
	if a < ans:
		ans = a
if w >= 3:
	if w % 3 == 0:
		a = 0
	else:
		a = h
	if a < ans:
		ans = a
if h > 1:
	b = h // 3
	x1 = w * b
	x2 = (h - b) * (w // 2)
	x3 = h * w - x1 - x2
	a = max(x1, x2, x3) - min(x1, x2, x3)
	if a < ans:
		ans = a
	x1 = w * (b + 1)
	x2 = (h - b - 1) * (w // 2)
	x3 = h * w - x1 - x2
	a = max(x1, x2, x3) - min(x1, x2, x3)
	if a < ans:
		ans = a
	b = w // 3
	x1 = h * b
	x2 = (w - b) * (h // 2)
	x3 = h * w - x1 - x2
	a = max(x1, x2, x3) - min(x1, x2, x3)
	if a < ans:
		ans = a
	x1 = h * (b + 1)
	x2 = (w - b - 1) * (h // 2)
	x3 = h * w - x1 - x2
	a = max(x1, x2, x3) - min(x1, x2, x3)
	if a < ans:
		ans = a
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)


import math
(H, W) = map(int, input().split())
d = ([H, W], [W, H])
ans = 10 ** 15
for (x, y) in d:
	for i in range(1, x):
		A = (x - i) * y
		B = i * y
		if i % 2 == 0 or y % 2 == 0:
			ans = min(ans, max(A, B // 2) - min(A, B // 2))
		else:
			e = ([y, i], [i, y])
			for (c, d) in e:
				C = math.floor(c / 2) * d
				D = math.ceil(c / 2) * d
				ans = min(ans, max(A, C, D) - min(A, C, D))
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)


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

def defs(h, w):
	ans = 10 ** 12
	for i in range(1, h):
		sa = i * w
		h2 = h - i
		for j in range(2):
			if j == 0:
				sb = h2 * (w // 2)
				sc = h2 * (w - w // 2)
			else:
				sb = h2 // 2 * w
				sc = (h - i - h2 // 2) * w
			s_max = max(sa, sb, sc)
			s_min = min(sa, sb, sc)
			ans = min(ans, s_max - s_min)
	return ans
print(min(defs(h, w), defs(w, h)))


(H, W) = map(int, input().split())
dif = 10 ** 10
if H % 3 == 0 or W % 3 == 0:
	print(0)
	return
for i in range(H):
	a = i * W
	h = (H - i) // 2
	abc = [a, h * W, (H - i - h) * W]
	if not 0 in abc:
		dif = min(dif, max(abc) - min(abc))
	h = H - i
	w = W // 2
	abc = [a, h * w, h * (W - w)]
	if not 0 in abc:
		dif = min(dif, max(abc) - min(abc))
for i in range(W):
	a = H * i
	w = (W - i) // 2
	abc = [a, H * w, H * (W - i - w)]
	if not 0 in abc:
		dif = min(dif, max(abc) - min(abc))
	w = W - i
	h = H // 2
	abc = [a, h * w, (H - h) * w]
	if not 0 in abc:
		dif = min(dif, max(abc) - min(abc))
print(dif)


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) = map(int, input().split())
S = h * w
ans = h * w
for (a, b) in [(h, S // (3 * h)), (h, S // (3 * h) + 1), (S // (3 * w), w), (S // (3 * w) + 1, w)]:
	s_list = [a * b]
	hr = h - a * (a < h)
	wr = w - b * (b < w)
	if hr * wr % 2 == 0:
		s_list += [hr * wr // 2]
	else:
		s_list += [min(hr, wr) * (max(hr, wr) // 2), min(hr, wr) * (max(hr, wr) // 2 + 1)]
	ans = min(ans, max(s_list) - min(s_list))
print(ans)


(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 collections
(h, w) = map(int, input().split())

def hkara(h, w):
	hans = 10 ** 9
	for i in range(1, h):
		fst = w * i
		snd = w // 2 * (h - i)
		trd = (w - w // 2) * (h - i)
		mx = max(max(fst, snd), trd)
		mn = min(min(fst, snd), trd)
		hans = min(mx - mn, hans)
		tfst = w * i
		tsnd = (h - i) // 2 * w
		ttrd = (h - (h - i) // 2 - i) * w
		tmx = max(max(tfst, tsnd), ttrd)
		tmn = min(min(tfst, tsnd), ttrd)
		hans = min(tmx - tmn, hans)
	return hans

def wkara(h, w):
	wans = 10 ** 9
	for i in range(1, w):
		fst = h * i
		snd = h // 2 * (w - i)
		trd = (h - h // 2) * (w - i)
		mx = max(max(fst, snd), trd)
		mn = min(min(fst, snd), trd)
		wans = min(mx - mn, wans)
		tfst = h * i
		tsnd = (w - i) // 2 * h
		ttrd = (w - (w - i) // 2 - i) * h
		tmx = max(max(tfst, tsnd), ttrd)
		tmn = min(min(tfst, tsnd), ttrd)
		wans = min(tmx - tmn, wans)
	return wans
print(min(hkara(h, w), wkara(h, w)))


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)


def divide_into_three(X, Y):
	minimum = float('inf')
	for x in range(1, X):
		b1 = x * Y
		if not all((X - x & 1, Y & 1)):
			b2 = b3 = (X - x) * Y >> 1
		else:
			(s, l) = sorted((X - x, Y))
			b2 = s * (l >> 1)
			b3 = s * l - b2
		diff = max((b1, b2, b3)) - min((b1, b2, b3))
		minimum = min(minimum, diff)
	return minimum
(H, W) = map(int, input().split())
print(min(divide_into_three(H, W), divide_into_three(W, H)))


def main():
	(H, W) = (int(_) for _ in input().split())
	INF = 10 ** 11

	def calc(h, w):
		w1 = w // 2
		w2 = w - w1
		ret = INF
		for hh in range(1, h):
			ret = min(ret, max(w * hh, (h - hh) * w1, (h - hh) * w2) - min(w * hh, (h - hh) * w1, (h - hh) * w2))
		for hh in range(1, h):
			h1 = (h - hh) // 2
			h2 = h - hh - h1
			ret = min(ret, max(w * hh, w * h1, w * h2) - min(w * hh, w * h1, w * h2))
		return ret
	m1 = calc(H, W)
	m2 = calc(W, H)
	print(min(m1, m2))
	return

def __starting_point():
	main()
__starting_point()


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


(h, w) = map(int, input().split())
tmps = 0
ans = 10 ** 18
for i in range(1, h):
	k = (h - i) // 2
	t = [i * w, k * w, (h - i - k) * w]
	tmp = max(t) - min(t)
	ans = min(tmp, ans)
	k = w // 2
	t = [i * w, (h - i) * k, (h - i) * (w - k)]
	tmp = max(t) - min(t)
	ans = min(tmp, ans)
for i in range(1, w):
	k = (w - i) // 2
	t = [i * h, k * h, (w - i - k) * h]
	tmp = max(t) - min(t)
	ans = min(tmp, ans)
	k = h // 2
	t = [i * h, (w - i) * k, (w - i) * (h - k)]
	tmp = max(t) - min(t)
	ans = min(tmp, ans)
print(ans)