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: introductory

Starter code:

Solutions:
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 = 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 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)))


H,W = map(int,input().split())
ans = [H//2+W//3+1,H//3+W//2+1,H,W]

if(H%3==0 or W%3==0):
  ans+=[0]
if(H%2==0):
  ans+=[H//2]
if(W%2==0):
  ans+=[W//2]

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

h,w = map(int,input().split())
ans = 10**10

def menseki(h,w):
    nonlocal ans
    for i in range(1,h):
        # 縦1横2
        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)))
        # 縦3分割
        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)

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

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)
  



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())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    if h > w:
        h, w = w, h
    ans = h
    for w1 in range(w//3-2, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2 + 1):
            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-2, w//3+3):
        s1 = w1 * h
        w2 = w-w1
        for h1 in range(h//2 + 1):
            s2 = w2 * h1
            s3 = w2 * (h-h1)
            ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))
    print(ans)

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

def abc(x,y,z): #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): #a,b,c:abc()の戻り値
    return max(a, b, c) - min(a, b, c)

def solve(x, y): #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)

# solution
# online help taken

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)

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

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)

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

ans = 1e19
##縦方向の探索
for i in range(1,H):
    tate = W*i##上から横に切る
    ##横に切る
    if i < H-1:
        mini = W*((H-i)//2)##分割したやつ
        ##print(tate,mini,H*W-mini-tate)
        ans = min(ans,max(tate,mini,H*W-mini-tate)-min(tate,mini,H*W-mini-tate))

    ##縦に切る
    mini = (H-i)*(W//2)
    ##print(tate,mini,H*W-mini-tate)
    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)
        ##print(yoko,mini,H*W-mini-yoko)
        ans = min(ans,max(yoko,mini,H*W-mini-yoko)-min(yoko,mini,H*W-yoko-mini))
    mini = (W-i)*(H//2)
    ##print(yoko,mini,H*W-yoko-mini)
    ans = min(ans,max(yoko,mini,H*W-yoko-mini)-min(yoko,mini,H*W-yoko-mini))

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
else:
    if mini > h:
        mini = h
    elif mini > w:
        mini = w
    else:
        pass
print(mini)

h, w = list(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())
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())
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)

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

#縦に3つ分ける場合
if w % 3 == 0:
    s_tate = 0
else:
    s_tate = (int(w/3)+1) * h - int(w/3) * h

#横に3つに分ける場合
if h % 3 == 0:
    s_yoko = 0
else:
    s_yoko = (int(h/3)+1) * w - int(h/3) * w

#上側に縦に2つ、下方に1つでわける場合
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(s_tate, s_yoko, case3, case4)

print(ans)

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

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

ans = 10**12

# 1枚目を(1,2,...,H-1)*Wとする
for h in range(1, H):
    s1 = W * h
    # 残りは(H-h)*W

    # 残りを横に割る場合
    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)

# 1枚目をH*(1,2,...,W-1)とする
for w in range(1, W):
    s1 = w * H
    # 残りはH*(W-w)

    # 残りを横に割る場合
    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())
ans = [H//2+W//3+1,H//3+W//2+1,H,W]

if(H%3==0 or W%3==0):
  ans+=[0]
if(H%2==0):
  ans+=[H//2]
if(W%2==0):
  ans+=[W//2]

print(min(ans))

h,w=map(int,input().split())
pattern=[h//2+w//3+1,h//3+w//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))

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)
    # print(kouho)

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());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=map(int,input().split())
h_half=h//2
w_half=w//2
s_hw=h*w
min_x=s_hw

# H*n の範囲を探査
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)

# n*W の範囲を探査
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)

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)

#!/usr/bin/env python3
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)))

def answer(H,W,ans_kari):

    for x in range(1,W):
        y1 = H // 2
        Sa1 = H * x
        Sb1 = (W - x) * y1
        Sc1 = (W - x) * (H - y1)
        M = max(Sa1,Sb1,Sc1)
        m = min(Sa1,Sb1,Sc1)

        y2 = (W - x) // 2
        Sa2 = H * x
        Sb2 = H * y2
        Sc2 = H * (W - x - y2)
        M2 = max(Sa2,Sb2,Sc2)
        m2 = min(Sa2,Sb2,Sc2)

        if ans_kari > min(M-m,M2-m2):
            ans_kari = min(M-m,M2-m2)

    return ans_kari

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

    if answer(H,W,ans) < ans:
        ans = answer(H,W,ans)

    print(ans)

__starting_point()

H, W = map(int, input().split())
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)

import math

def main():
	H, W = [int(a) for a in input().split(" ")]

	cand = []
	# case 1. w 3 split, h 3 split
	if W % 3 == 0 or H % 3 == 0:
		print((0))
		return 0
	# W % 3 !== 0 and H % 3 !== 0
	cand.append(H)
	cand.append(W)
	# case 2. w split -> h split
	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())

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 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 = [floor(W/3), ceil(W/3)]
    # 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)))

    # 横にスライス + 残りに縦にスライス
    y1_cand = [floor(H/3), ceil(H/3)]
    # 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)))

    print(ans)

def __starting_point():
    main()
__starting_point()

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

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())
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))
else:
    if (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
#print(h,w)
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))
else:
    if (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 = float("inf")
for h, w in zip([H, W], [W, H]):
    # ah の全探索
    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 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=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 = list(map(int, input().split()))

ans = float('inf')

# first cut vertical
for x in range(1, W):
  S1 = x * H
  # cut vertical
  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)
  # cut horizontal
  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)
# first cut horizontal
for y in range(1, H):
  S1 = W * y
  # cut vertical
  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)
  # cut horizontal
  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))

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

import sys
h, w = list(map(int, input().split()))
if h%3==0 or w%3==0:
    print((0))
    return
ans=h*w #inf
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)
    #print(i, now)
    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)


#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


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


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)

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


def answer(H,W,ans):

    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)

    return ans

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

    H,W = W,H

    if answer(H,W,ans) < ans:
        ans = answer(H,W,ans)

    print(ans)

__starting_point()

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

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

#!/usr/bin/env python3


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

        # Hを1:2で分割
        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))
        
        # Wを1:2で分割
        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()

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

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


def abc062_c():
    h, w = map(int, input().split())
    # 2 <= h, w のため1の場合は考えない
    # どちらかが3の倍数ならぴったり3分割できる (平行2線)
    if h % 3 == 0 or w % 3 == 0:
        print(0)
        return
    # 平行2線で割るときの差分最小は、短辺1本分
    ans = min(h, w)
    # それ以外は例2例3の割り方 (直交2線)
    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=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 = [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:
  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 = 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)


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

if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    best = (h*w)/3
    # wから割る方法
    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
    # hから割る方法
    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))

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

def hkara(h,w):
  hans = 10**9
  for i in range(1,h):
    #yoko
    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)
    #tate
    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)
    #tate
    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)))

h,w=list(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))))


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)
    # h == Tの上
    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()

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

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)

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())
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)))
#print(mini)
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)

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

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


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


# coding: utf-8
# hello worldと表示する
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
#print(SMAX1,SMIN1,SMAX2,SMIN2)
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)
#print(s1,s2,s3,s4)
ans=min(s1,s2,s3,s4)
print(ans)

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

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

def main():
    H, W = map(int, readline().rstrip().split())
    ans = H * W
    if H >= 3:
        y1 = int(round(H/3))
        y2 = (H-y1) // 2
        y3 = H - y1 - y2
        ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))
    if W >= 3:
        x1 = int(round(W/3))
        x2 = (W-x1) // 2
        x3 = W - x1 - x2
        ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))
    
    # 縦にスライス + 残りに横にスライス
    x1 = int(round(W/3))
    y1 = H
    x2 = W - x1
    x3 = x2
    y2 = H // 2
    y3 = H - y2
    ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    # 横にスライス + 残りに縦にスライス
    y1 = int(round(H/3))
    x1 = W
    y2 = H - y1
    y3 = y2
    x2 = W // 2
    x3 = W - x2
    ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    print(ans)

def __starting_point():
    main()
__starting_point()

h, w = 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)
        #print(area1, area2, area3)
        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))
        #print(area1, area2, area3)
        ans = min(ans, max(area1, area2, area3) - min(area1, area2, area3))
    print((min(calc(h, w), calc(w, h), 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)))

def __starting_point():
  main()
__starting_point()

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 = 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=list(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)))
    
# print(ans)
# print(min(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)

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

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
    else:
        if 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
    else:
        if 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)

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:
            # case1
            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:
                # case2
                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())

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)

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

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 = [floor(W/3), ceil(W/3)]
    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 = [floor(H/3), ceil(H/3)]
    y1_cand = [i for i in range(1, H)]
    x1 = W
    for y1 in y1_cand:
        y2 = H - y1
        y3 = y2
        x2 = W // 2
        x3 = W - x2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

        y2 = (H-y1) // 2
        y3 = (H-y1-y2)
        ans = min(ans, max((W*y1), (W*y2), (W*y3)) - min((W*y1), (W*y2), (W*y3)))

    print(ans)

def __starting_point():
    main()
__starting_point()

h , w = 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)


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


# coding: utf-8
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
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
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):#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=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))