CodeEff/ECCO huggingface dataset:
# Original solution
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

if __name__ == '__main__':
    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)


# Optimized solution
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))

if __name__ == '__main__':
    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)))
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H, W = il()
    if W % 3 == 0:
        print((0))
    elif H % 3 == 0:
        print((0))
    else:
        ret = MAX
        for h in range(1, H):
            # 横, 横, 横 分割パターン
            hh = (H - h) // 2
            hmin = min(hh * W, (H - h - hh) * W, h * W)
            hmax = max(hh * W, (H - h - hh) * W, h * W)

            # 横, 縦, 縦 分割パターン
            ww = W // 2
            wmin = min((H - h) * (W - ww), (H - h) * ww, h * W)
            wmax = max((H - h) * (W - ww), (H - h) * ww, h * W)

            ret = min(ret, abs(hmax - hmin), abs(wmax - wmin))

        for w in range(1, W):
            # 縦, 縦, 縦 分割パターン
            ww = (W - w) // 2
            wmin = min(w * H, (W - w - ww) * H, ww * H)
            wmax = max(w * H, (W - w - ww) * H, ww * H)

            # 縦, 横, 横 分割パターン
            hh = H // 2
            hmin = min(w * H, hh * (W - w), (H - hh) * (W - w))
            hmax = max(w * H, hh * (W - w), (H - hh) * (W - w))

            ret = min(ret, abs(hmax - hmin), abs(wmax - wmin))

        print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
h,w=list(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)))
# Original solution
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
    print((0))
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 3):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 3):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)

# Optimized solution
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
    print((0))
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 2):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 2):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)
# Original solution
h, w = list(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)

# Optimized solution
h, w = list(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)
# Original solution
h,w = list(map(int,input().split()))
res = float('inf')

# H
for i in range(1,h):
    s_h = [i * w]
    s_w = [i * w]
    # のこりは(h-i)*w
    # H
    s_h.append(((h-i)//2) * w)
    s_h.append(((h-i)-(h-i)//2) * w)
    if 0 in ((h-i)//2,((h-i)-(h-i)//2),w):
        s_h.append(float('inf'))
    #print((h-i)//2,w)
    #print(((h-i)-(h-i)//2) , w)
    #print(s_h)
    # W
    s_w.append((h-i) * (w//2))
    s_w.append((h-i) * (w - w//2))
    if 0 in ((h-i),w//2,(w-(w//2))):
        s_w.append(float('inf'))
    #print((h-i) , w//2)
    #print((h-i) , (w - w//2))
    #print(s_w)
    res_h = max(s_h) - min(s_h)
    res_w = max(s_w) - min(s_w)
    res = min(res,res_h)
    res = min(res,res_w)

# W
for i in range(1,w):
    s_h = [h * i]
    s_w = [h * i]
    # のこりはh*(w-i)
    # H
    s_h.append((h//2) * (w-i))
    s_h.append((h - (h//2)) * (w-i))
    if 0 in ((h//2),(w-i),(h-(h//2))):
        s_h.append(float('inf'))
    # W
    s_w.append(h * ((w-i)//2))
    s_w.append(h * ((w-i) - (w-i)//2))
    if 0 in (h,((w-i)//2),((w-i)-(w-i)//2)):
        s_w.append(float('inf'))
    res_h = max(s_h) - min(s_h)
    res_w = max(s_w) - min(s_w)
    res = min(res,res_h)
    res = min(res,res_w)

print(res)


# Optimized solution
h,w=list(map(int,input().split()))
r=1e9
f=lambda x:max(x)-min(x)
for _ in 'aa':
    for i in range(1,h):
        p=[j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]
        q=[j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]
        r=min(min(r,f(p)),f(q))
    h,w=w,h
print(r)
# Original solution
h,w=list(map(int,input().split()))
r=1e9
f=lambda x:max(x)-min(x)
for _ in 'aa':
    for i in range(1,h):
        p=[j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]
        q=[j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]
        r=min(min(r,f(p)),f(q))
    h,w=w,h
print(r)

# Optimized solution
h,w=list(map(int,input().split()))
r=1e9
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 -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]])),f([j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]))
    h,w=w,h
print(r)
# Original solution
h,w=list(map(int,input().split()))
r=1e9
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 -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]])),f([j if j else -1e9for j in[i*w,(h-i)*(w//2),(h-i)*(w-w//2)]]))
    h,w=w,h
print(r)

# Optimized solution
h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]),f([j if j else -1e9for j in[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))))
# Original solution
h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([j if j else -1e9for j in[i*w,((h-i)//2)*w,((h-i)-(h-i)//2)*w]]),f([j if j else -1e9for j in[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))))

# Optimized solution
h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([i*w,((h-i)//2)*w,((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))))
# Original solution
h,w=list(map(int,input().split()));f=lambda x:max(x)-min(x);g=lambda h,w:min([min(f([i*w,((h-i)//2)*w,((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))))

# Optimized solution
h,w=list(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))))
# Original solution
h,w=list(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))))

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

res = 10**1000

for _ in range(2):
    a,b = h // 3 + 1, h // 3 + 1
    c = h - a - b
    if c < 0:
        h,w = w,h
        continue
    mx = max(a,b,c)
    mn = min(a,b,c)
    res = min(res, mx*w-mn*w)
    h,w = w,h

for _ in range(2):
    a,b = h // 3, h // 3
    c = h - a - b
    mx = max(a,b,c)
    mn = min(a,b,c)
    res = min(res, mx*w-mn*w)
    h,w = w,h

for _ in range(2):
    for i in range(1,h):
        l = [i * w]
        j = h - i
        a = w // 2
        l.append(a * j)
        l.append((w - a) * j)
        res = min(res, max(l) - min(l))
    h,w = w,h

print(res)
# Original solution
H, W = list(map(int, input().split()))
if (H%3) * (W%3) == 0:
  print((0))
  quit()

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)

# Optimized solution
H, W = list(map(int, input().split()))
if (H%3) * (W%3) == 0:
  print((0))
  quit()

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)
# Original solution
def func(H,W):
    area = H * W

    half_H = int(H/2)
    half_W = int(W/2)  
    
    res = 10000000
    
    # よこ
    # T
    for x in range(1,W):
        S1 = H * x
        S2_T = (W - x) * half_H
        S3_T = area - S1 - S2_T
        
        S2_2 = H * int((W - x)/2)
        S3_2 = area - S1 - S2_2
        
        tmpres_T = max(S1, S2_T, S3_T) - min(S1, S2_T, S3_T)
        tmpres_2 = max(S1, S2_2, S3_2) - min(S1, S2_2, S3_2)
        
        if tmpres_T < res:
            res = tmpres_T
        if tmpres_2 < res:
            res = tmpres_2
    # たて
    # T
    for y in range(1,H):
        S1 = W * y
        S2_T = (H - y) * half_W
        S3_T = area - S1 - S2_T
        
        S2_2 = W * int((H - y)/2)
        S3_2 = area - S1 - S2_2
        
        tmpres_T = max(S1, S2_T, S3_T) - min(S1, S2_T, S3_T)
        tmpres_2 = max(S1, S2_2, S3_2) - min(S1, S2_2, S3_2)
        
        if tmpres_T < res:
            res = tmpres_T
        if tmpres_2 < res:
            res = tmpres_2
    
    return res

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

# Optimized solution
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)))
# Original solution
def c_ChocolateBar(H, W):
    ans = float('inf')
    # for文の順は解説における矩形の分け方の図の左からの順と一致
    for h in range(1, H):
        S_A = h * W
        hh = (H - h) // 2
        S_B = hh * W
        S_C = (H - h - hh) * W
        ans = min(ans, max([S_A, S_B, S_C]) - min([S_A, S_B, S_C]))
    for h in range(1, H):
        S_A = h * W
        w = W // 2
        S_B = (H - h) * w
        S_C = (H - h) * (W - w)
        ans = min(ans, max([S_A, S_B, S_C]) - min([S_A, S_B, S_C]))
    for w in range(1, W):
        S_A = H * w
        ww = (W - w) // 2
        S_B = H * ww
        S_C = H * (W - w - ww)
        ans = min(ans, max([S_A, S_B, S_C]) - min([S_A, S_B, S_C]))
    for w in range(1, W):
        S_A = H * w
        h = H // 2
        S_B = h * (W - w)
        S_C = (H - h) * (W - w)
        ans = min(ans, max([S_A, S_B, S_C]) - min([S_A, S_B, S_C]))
    return ans
H,W = [int(i) for i in input().split()]
print((c_ChocolateBar(H, W)))

# Optimized solution
def c_chocolate_bar(H, W):
    # 変数a, b, cはeditorialの図のA, B, Cに対応する
    ans = float('inf')
    for _ in range(2):
        for i in range(1, H):
            a = i * W  # 領域Aの面積

            # 横に2つ切り込みを入れる(図の左から1番目の分け方)
            b = ((H - i) // 2) * W
            c = ((H - i + 1) // 2) * W
            ans = min(ans, abs(max(a, b, c) - min(a, b, c)))

            # 横縦に1つずつ切り込みを入れる(図の左から2番目の分け方)
            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  # H,Wを入れ替えて同じことをする(図の左から3, 4番目の分け方)
    return ans

H, W = [int(i) for i in input().split()]
print((c_chocolate_bar(H, W)))
# Original solution
import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    H, W = list(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)

if __name__ == '__main__':
    main()

# Optimized solution
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 = list(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)

if __name__ == '__main__':
    main()
# Original solution
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 = list(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)

if __name__ == '__main__':
    main()

# Optimized solution
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 = list(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)

if __name__ == '__main__':
    main()
# Original solution
h,w=list(map(int,input().split()))
if h%3==0 or w%3==0:
    print((0))
else:
    x=[]
    for i in range(1,w):
        sub=[]
        sub.append([h*i,h*((w-i)//2),h*(w-i)-h*((w-i)//2)])
        sub.append([h*i,h*((w-i)//2+1),h*(w-i)-h*((w-i)//2+1)])
        sub.append([h*i,(w-i)*(h//2),h*(w-i)-(w-i)*(h//2)])
        sub.append([h*i,(w-i)*(h//2+1),h*(w-i)-(w-i)*(h//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    for i in range(1,h):
        sub=[]
        sub.append([w*i,w*((h-i)//2),w*(h-i)-w*((h-i)//2)])
        sub.append([w*i,w*((h-i)//2+1),w*(h-i)-w*((h-i)//2+1)])
        sub.append([w*i,(h-i)*(w//2),w*(h-i)-(h-i)*(w//2)])
        sub.append([w*i,(h-i)*(w//2+1),w*(h-i)-(h-i)*(w//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    print((min(x)))


# Optimized solution
h,w=list(map(int,input().split()))
if h%3==0 or w%3==0:
    print((0))
else:
    x=[]
    for i in range(1,w):
        sub=[]
        sub.append([h*i,h*((w-i)//2),h*(w-i)-h*((w-i)//2)])
        #sub.append([h*i,h*((w-i)//2+1),h*(w-i)-h*((w-i)//2+1)])
        sub.append([h*i,(w-i)*(h//2),h*(w-i)-(w-i)*(h//2)])
        #sub.append([h*i,(w-i)*(h//2+1),h*(w-i)-(w-i)*(h//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    for i in range(1,h):
        sub=[]
        sub.append([w*i,w*((h-i)//2),w*(h-i)-w*((h-i)//2)])
        #sub.append([w*i,w*((h-i)//2+1),w*(h-i)-w*((h-i)//2+1)])
        sub.append([w*i,(h-i)*(w//2),w*(h-i)-(h-i)*(w//2)])
        #sub.append([w*i,(h-i)*(w//2+1),w*(h-i)-(h-i)*(w//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    print((min(x)))
# Original solution
h,w=list(map(int,input().split()))
if h%3==0 or w%3==0:
    print((0))
else:
    x=[]
    for i in range(1,w):
        sub=[]
        sub.append([h*i,h*((w-i)//2),h*(w-i)-h*((w-i)//2)])
        #sub.append([h*i,h*((w-i)//2+1),h*(w-i)-h*((w-i)//2+1)])
        sub.append([h*i,(w-i)*(h//2),h*(w-i)-(w-i)*(h//2)])
        #sub.append([h*i,(w-i)*(h//2+1),h*(w-i)-(w-i)*(h//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    for i in range(1,h):
        sub=[]
        sub.append([w*i,w*((h-i)//2),w*(h-i)-w*((h-i)//2)])
        #sub.append([w*i,w*((h-i)//2+1),w*(h-i)-w*((h-i)//2+1)])
        sub.append([w*i,(h-i)*(w//2),w*(h-i)-(h-i)*(w//2)])
        #sub.append([w*i,(h-i)*(w//2+1),w*(h-i)-(h-i)*(w//2+1)])
        for j in sub:
            x.append(max(j)-min(j))
    print((min(x)))


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