CodeEff/ECCO huggingface dataset:
# Original solution
h, w = list(map(int, input().split()))

if h%3 == 0 or w%3 == 0:
    print((0))
    exit()

#print(h, w)
min_ = float('inf')
for i in range(1, h):
    s1 = w*i
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w-w//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

    s2 = ((h-i)//2)*w
    s3 = ((h-i) - (h-i)//2)*w
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

#print('-')

for i in range(1, w):
    s1 = h*i
    s2 = (w-i)*(h//2)
    s3 = (w-i)*(h-h//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

    s2 = ((w-i)//2)*h
    s3 = ((w-i) - (w-i)//2)*h
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

print(min_)

# Optimized solution
h, w = list(map(int, input().split()))
ans = 10**18
for i in range(1, h):
    S1 = i*w
    # tate
    if h-i >= 2:
        p = (h-i)//2
        q = h-(h-i)//2-i
        S2 = p*w
        S3 = q*w
        M = max([S1, S2, S3])
        m = min([S1, S2, S3])
        ans = min(ans, M-m)
        #if i == 1:
            #print(S1, S2, S3)
    # yoko
    S2 = (h-i)*(w//2)
    S3 = (h-i)*(w-w//2)
    M = max([S1, S2, S3])
    m = min([S1, S2, S3])
    ans = min(ans, M-m)

for i in range(1, w):
    S1 = h*i
    # yoko
    if w-i >= 2:
        p = (w-i)//2
        q = w-(w-i)//2-i
        S2 = h*p
        S3 = h*q
        M = max([S1, S2, S3])
        m = min([S1, S2, S3])
        ans = min(ans, M-m)
    # tate
    S2 = (h//2)*(w-i)
    S3 = (h-h//2)*(w-i)
    M = max([S1, S2, S3])
    m = min([S1, S2, S3])
    ans = min(ans, M-m)
print(ans)
# Original solution
import sys

inf = 1<<60
ans = inf

def solve():
    H, W = list(map(int, input().split()))
    calc(H, W)
    calc(W, H)
    print(ans)

def calc(H, W):
    global ans

    for a in range(1, W):
        s0 = a * H

        s1 = H * ((W - a + 1) // 2)
        s2 = H * ((W - a) // 2)

        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))

        s1 = (W - a) * ((H + 1) // 2)
        s2 = (W - a) * (H // 2)

        ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2)) 

if __name__ == '__main__':
    solve()

# Optimized solution
import sys

inf = 1<<60
ans = inf

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

    print(ans)

def calc(H, W):
    global ans
    x = W // 3

    s0 = x * H
    s1 = H * ((W - x + 1) // 2)
    s2 = H * ((W - x) // 2)

    ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))

    s1 = (W - x) * ((H + 1) // 2)
    s2 = (W - x) * (H // 2)

    ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))

    x = (W + 2) // 3

    s0 = x * H
    s1 = H * ((W - x + 1) // 2)
    s2 = H * ((W - x) // 2)

    ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))

    s1 = (W - x) * ((H + 1) // 2)
    s2 = (W - x) * (H // 2)

    ans = min(ans, max(s0, s1, s2) - min(s0, s1, s2))

if __name__ == '__main__':
    solve()
# Original solution
H, W = list(map(int, input().split()))

if H % 3 == 0 or W % 3 == 0:
    print((0))
    exit()

ans = min(H, W)
for w1 in [W // 3, W // 3 + 1]:
    w23 = W - w1
    for h2 in [H // 2, H // 2 + 1]:
        h3 = H - h2

        S1 = w1 * H
        S2 = h2 * w23
        S3 = h3 * w23

        ans = min(ans, max(S1, S2, S3) - min(S1, S2, S3))

for h1 in [H // 3, H // 3 + 1]:
    h23 = H - h1
    for w2 in [W // 2, W // 2 + 1]:
        w3 = W - w2

        S1 = h1 * W
        S2 = w2 * h23
        S3 = w3 * h23

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

ans = min(H, W)
for A, B in ((H, W), (W, H)):
    for a in (A // 3, A // 3 + 1):
        for b in (B // 2, B // 2 + 1):
            X = a * B
            Y = (A - a) * b
            Z = (A - a) * (B - b)

            ans = min(ans, max(X, Y, Z) - min(X, Y, Z))
print(ans)
# Original solution
from math import floor, ceil
h, w = list(map(int, input().split(' ')))
result = []
if h%3 == 0 or w%3 == 0:
    print((0))
elif h<3 or w<3:
    if h<3 and w>=3:
        for i in range(1, w-1):
            x = i*h
            y = (w-i)*floor(h/2)
            z = (w-i)*ceil(h/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((w-i)/2)*h
            z = ceil((w-i)/2)*h
            result.append(max(x,y,z)-min(x,y,z))
        print((min(result)))
    elif h>=3 and w<3:
        for i in range(1, h-1):
            x = i*w
            y = (h-i)*floor(w/2)
            z = (h-i)*ceil(w/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((h-i)/2)*w
            z = ceil((h-i)/2)*w
            result.append(max(x,y,z)-min(x,y,z))
        print((min(result)))
    else:
        print((1))
else:
    for i in range(1, h-1):
        x = i*w
        y = (h-i)*floor(w/2)
        z = (h-i)*ceil(w/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((h-i)/2)*w
        z = ceil((h-i)/2)*w
        result.append(max(x,y,z)-min(x,y,z))
    for i in range(1, w-1):
        x = i*h
        y = (w-i)*floor(h/2)
        z = (w-i)*ceil(h/2)
        result.append(max(x,y,z)-min(x,y,z))
        y = floor((w-i)/2)*h
        z = ceil((w-i)/2)*h
        result.append(max(x,y,z)-min(x,y,z))
    print((min(result)))

# Optimized solution
def main():
    from math import floor, ceil
    h, w = list(map(int, input().split(' ')))
    result = []
    if h%3 == 0 or w%3 == 0:
        print((0))
    elif h<3 or w<3:
        if h<3 and w>=3:
            for i in range(1, w-1):
                x = i*h
                y = (w-i)*floor(h/2)
                z = (w-i)*ceil(h/2)
                result.append(max(x,y,z)-min(x,y,z))
                y = floor((w-i)/2)*h
                z = ceil((w-i)/2)*h
                result.append(max(x,y,z)-min(x,y,z))
            print((min(result)))
        elif h>=3 and w<3:
            for i in range(1, h-1):
                x = i*w
                y = (h-i)*floor(w/2)
                z = (h-i)*ceil(w/2)
                result.append(max(x,y,z)-min(x,y,z))
                y = floor((h-i)/2)*w
                z = ceil((h-i)/2)*w
                result.append(max(x,y,z)-min(x,y,z))
            print((min(result)))
        else:
            print((1))
    else:
        for i in range(1, h-1):
            x = i*w
            y = (h-i)*floor(w/2)
            z = (h-i)*ceil(w/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((h-i)/2)*w
            z = ceil((h-i)/2)*w
            result.append(max(x,y,z)-min(x,y,z))
        for i in range(1, w-1):
            x = i*h
            y = (w-i)*floor(h/2)
            z = (w-i)*ceil(h/2)
            result.append(max(x,y,z)-min(x,y,z))
            y = floor((w-i)/2)*h
            z = ceil((w-i)/2)*h
            result.append(max(x,y,z)-min(x,y,z))
        print((min(result)))
main()
# Original solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
if H%3==0 or W%3==0:
    answer = 0
else:
    answer = min(H, W)
# さらに小さくするには縦と横で割る
h = H // 3
area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)]
answer = min(answer, max(area)-min(area))
h += 1
area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)]
answer = min(answer, max(area)-min(area))
w = W // 3
area = [w * H, (W-w) * (H//2), (W-w) * ((H+1)//2)]
answer = min(answer, max(area)-min(area))
w += 1
area = [w * H, (W-w) * (H//2), (W-w) * ((H+1)//2)]
answer = min(answer, max(area)-min(area))
print(answer)

# 13

# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
if H%3==0 or W%3==0:
    answer = 0
else:
    answer = min(H, W)
# さらに小さくするには縦と横で割る
def cal(H, W):
    global answer
    h = H // 3
    area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)]
    answer = min(answer, max(area)-min(area))
    h += 1
    area = [h * W, (H-h) * (W//2), (H-h) * ((W+1)//2)]
    answer = min(answer, max(area)-min(area))

cal(H, W)
cal(W, H)
print(answer)
# 13
# Original solution
# -*- coding: utf-8 -*-
H,W = list(map(int, input().split()))

ret = 10**9
for h in range(1,H):
    w = W//2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

    hh = (H-h)//2
    s1 = h*W
    s2 = hh*W
    s3 = (H-h-hh)*W
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

for w in range(1,W):
    h = H//2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

    ww = (W-w)//2
    s1 = w*H
    s2 = ww*H
    s3 = (W-w-ww)*H
    ret = min(ret, max(s1,s2,s3)-min(s1,s2,s3))

print(ret)


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

if h%3==0 or w%3==0:
    print((0))
    exit()

res = min(h,w)
for hi in range(1,h):
    b1 = hi*w
    b2 = (h-hi)*(w//2)
    b3 = (h-hi)*(w//2+w%2)
    res = min(res, max(b1,b2,b3)-min(b1,b2,b3))
for wi in range(1,w):
    b1 = wi*h
    b2 = (w-wi)*(h//2)
    b3 = (w-wi)*(h//2+h%2)
    res = min(res, max(b1,b2,b3) - min(b1,b2,b3))

print(res)
# Original solution
def f(x,y):
	m=x*(x%3>0)
	for i in range(2):
		d=x//3+i;e=x-d;l=sorted([d*y,e*(y//2),e*(-~y//2)]);m=min(m,l[2]-l[0])
	return m
h,w=list(map(int,input().split()))
print((min(f(h,w),f(w,h))))

# Optimized solution
h,w=list(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))))
# Original solution
def main():
    H, W = list(map(int, input().split()))
    S = H * W
    ans = float('inf')
    for h1 in range(1,H):
        S1 = h1 * W
        # 縦に分割する場合
        h2 = (H - h1) // 2
        S2 = h2 * W
        S3 = (H - h1 - h2) * W
        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))
        # 横に分割する場合
        w2 = W // 2
        w3 = W - w2
        S2 = (H - h1) * w2
        S3 = (H - h1) * w3
        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))

    for w1 in range(1,W):
        S1 = w1 * H
        # 横に分割する場合
        w2 = (W - w1) // 2
        S2 = w2 * H
        S3 = (W - w1 - w2) * H
        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))
        # 縦に分割する場合
        h2 = H // 2
        h3 = H - h2
        S2 = (W - w1) * h2
        S3 = (W - w1) * h3
        ans = min(ans, max(S1,S2,S3) - min(S1,S2,S3))

    print(ans)


    
    

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    H, W = list(map(int, input().split()))
    ans = float('inf')
    h1, h2, h3 = 0,0,0
    w1,w2,w1 = 0,0,0
    # 横3に切る場合
    h1 = H // 3
    h2 = H // 3
    h3 = H // 3
    if H % 3 == 1:
        h3 += 1
    elif H % 3 == 2:
        h2 += 1
        h3 += 1
    S = [h1*W,h2*W,h3*W]
    ans = min(max(S)-min(S),ans)
    # 横2縦1に切る場合
    h1 = H // 2
    h2 = H // 2
    h3 = H
    if H % 2 == 1:
        h2 += 1
    for w in range(1,W):
        S = [h1*(W-w),h2*(W-w),h3*w]
        ans = min(max(S)-min(S),ans)
    # 縦3に切る場合
    w1 = W // 3
    w2 = W // 3
    w3 = W // 3
    if W % 3 == 1:
        w3 += 1
    elif W % 3 == 2:
        w2 += 1
        w3 += 1
    S = [w1*H,w2*H,w3*H]
    ans = min(max(S)-min(S),ans)

    # 縦1横2に切る場合
    w1 = W // 2
    w2 = W // 2
    w3 = W
    if W % 2 == 1:
        w2 += 1
    for h in range(1,H):
        S = [w1*(H-h),w2*(H-h),w3*h]
        ans = min(max(S)-min(S),ans)

    print(ans)

if __name__ == "__main__":
    main()
# Original solution

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

min_score = 10**27

for i in range(1,H):
    if W%2==0:
        S1 = i*W/2
        S2 = (H-i)*W
        min_score = min(abs(S1-S2),min_score)
    else:
        S1 = i*(W-1)/2
        S2 = i*(W+1)/2
        S3 = (H-i)*W
        S4 = max(S1,S2,S3)
        S5 = min(S1,S2,S3)
        min_score = min(S4-S5,min_score)

for i in range(1,W):
    if H%2==0:
        S1 = i*H/2
        S2 = (W-i)*H
        min_score = min(abs(S1-S2),min_score)
    else:
        S1 = i*(H-1)/2
        S2 = i*(H+1)/2
        S3 = (W-i)*H
        S4 = max(S1,S2,S3)
        S5 = min(S1,S2,S3)
        min_score = min(S4-S5,min_score)

s1=int(H/3)
s2=int((H-s1)/2)
s3=H-s1-s2
S1 = max(s1*W,s2*W,s3*W)
S2 = min(s1*W,s2*W,s3*W)
min_score = min(S1-S2,min_score)

s1=int(W/3)
s2=int((W-s1)/2)
s3=W-s1-s2
S1 = max(s1*H,s2*H,s3*H)
S2 = min(s1*H,s2*H,s3*H)
min_score = min(S1-S2,min_score)

print((int(min_score)))

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

min_d=10**27

if H%3==0 or W%3==0:
    print((0))
else:
    min_d=min(H,W)
    for i in range(H+1):
        a=i*W
        b=(H-i)*(W//2)
        c=(H-i)*W - b
        min_d = min(max(a,b,c)-min(a,b,c),min_d)
    for i in range(W+1):
        a=i*H
        b=(W-i)*(H//2)
        c=(W-i)*H - b
        min_d = min(max(a,b,c)-min(a,b,c),min_d)
    print(min_d)
# Original solution
h, w = list(map(int, input().split()))

# =パターン
x, y = divmod(h, 3)
if y == 0:
    x1, x2, x3 = x, x, x
elif y == 1:
    x1, x2, x3 = x+1, x, x
else:
    x1, x2, x3 = x+1, x+1, x

s1, s2, s3 = [x*w for x in (x1, x2, x3)]
ans = s1-s3

# llパターン
x, y = divmod(w, 3)
if y == 0:
    x1, x2, x3 = x, x, x
elif y == 1:
    x1, x2, x3 = x+1, x, x
else:
    x1, x2, x3 = x+1, x+1, x

s1, s2, s3 = [x*h for x in (x1, x2, x3)]
ans = min(ans, s1-s3)

# トパターン
x = -(-w//3)
s1 = x*h
y = w-x
x1, x2 = h//2, (h+1)//2
s2, s3 = x1*y, x2*y
Ss = (s1, s2, s3)
ans = min(ans, max(Ss)-min(Ss))

# トパターン
x = w//3
s1 = x*h
y = w-x
x1, x2 = h//2, (h+1)//2
s2, s3 = x1*y, x2*y
Ss = (s1, s2, s3)
ans = min(ans, max(Ss)-min(Ss))

# Tパターン
x = -(-h//3)
s1 = x*w
y = h-x
x1, x2 = w//2, (w+1)//2
s2, s3 = x1*y, x2*y
Ss = (s1, s2, s3)
ans = min(ans, max(Ss)-min(Ss))

# Tパターン
x = h//3
s1 = x*w
y = h-x
x1, x2 = w//2, (w+1)//2
s2, s3 = x1*y, x2*y
Ss = (s1, s2, s3)
ans = min(ans, max(Ss)-min(Ss))
print(ans)


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


def solve_ll(a, b):
    x, y = divmod(a, 3)
    X = [x]*3
    for i in range(y):
        X[i] += 1
    s1, s2, s3 = [x*b for x in X]
    return s1-s3


def solve_T(a, b):
    INF = 10**18
    res = INF
    for x in (b//3, -(-b//3)):
        s1 = x*a
        y = b-x
        x1, x2 = a//2, (a+1)//2
        s2, s3 = x1*y, x2*y
        Ss = (s1, s2, s3)
        res = min(res, max(Ss)-min(Ss))
    return res


ans = min(solve_T(h, w), solve_T(w, h), solve_ll(h, w), solve_ll(w, h))
print(ans)
# Original solution
h, w = list(map(int,input().split()))
m = h * w
  
def d(a,b,c):
  return max(abs(a - b), abs(b - c), abs(a - c))

def c(h,w):
  a = m
  for i in range(1, h):
    l = i * w
    y = (h - i) // 2 * w
    t = (h - i) * (w // 2)
    a = min(a, d(l, y , m - l - y), d(l, t, m - l - t))
  return a

print((min(c(h, w), c(w, h))))


# Optimized solution
h,w=list(map(int,input().split()))
m=h*w
d=lambda a,b,c:max(abs(a-b),abs(b-c),abs(a-c))
def c(h,w):
 a=m
 for i in range(1,h):
  l=i*w
  y=(h-i)//2*w
  t=(h-i)*(w//2)
  a=min(a,d(l,y,m-l-y),d(l,t,m-l-t))
 return a
print((min(c(h,w),c(w,h))))
# Original solution
# coding: utf-8
# Your code here!
h,w = [int(i) for i in input().split()]

def once(h,w):
    res = 10**9
    if h > 1:
        a,b = h//2*w, (h-h//2)*w
        res = abs(a-b)
    if w > 1:
        c,d = w//2*h, (w-w//2)*h
        if abs(c-d) < res:
            a,b = c,d
    return a,b    


def hsaki(h,w):
    res = 10**9
    for i in range(1,h):
        p1 = i*w
        p2,p3 = once(h-i,w)
        a = max(p1,p2,p3) - min(p1,p2,p3) 
        res = min(res, a)
#        print(p1,p2,p3)
    return res

#print(hsaki(h,w), hsaki(w,h))

ans = min(hsaki(h,w), hsaki(w,h))
print(ans)

# Optimized solution
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

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


def f(h,w):
    ans = h*w
    for i in range(1,h):
        v1 = i*w
        if (h-i)%2==0 or w%2 == 0:
            v2 = (h-i)*w//2
        else:
            v2 = max((h-i)//2*w,w//2*(h-i))
        v3 = (h-i)*w - v2
        
        ans = min(ans,max(v1,v2,v3)-min(v1,v2,v3))
        #print(i,h,w,v1,v2,v3,ans)
    return ans

print((min(f(h,w),f(w,h))))
# Original solution
h,w=list(map(int,input().split()))
if h*w%3:
  ans=min(h,w)
  for x in range(1,w+1):
    ans=min(ans,max(h*x,h//2*(w-x),(h-h//2)*(w-x))-min(h*x,h//2*(w-x),(h-h//2)*(w-x)))
  h,w=w,h
  for x in range(1,w+1):
    ans=min(ans,max(h*x,h//2*(w-x),(h-h//2)*(w-x))-min(h*x,h//2*(w-x),(h-h//2)*(w-x)))
  print(ans)
else:print((0))

# Optimized solution
h,w=list(map(int,input().split()))
def f(x,y):
    ret=(1 if x%3 else 0)*y
    for i in range(1,x):
        f=sorted((i*y,y//2*(x-i),(1+y)//2*(x-i)))
        ret=min(ret,f[2]-f[0])
    return ret
print((min(f(h,w),f(w,h))))
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  h,w=LI()

  if h%3==0 or w%3==0:
    return 0

  ans=inf
  for i in range(1,h):
    a=i*w
    b=(h-i)*(w//2)
    c=(h-i)*(-(-w//2))
    ans=min(ans,max([a,b,c])-min([a,b,c]))

    a=i*w
    b=(h-i)//2*w
    c=-(-(h-i)//2)*w
    ans=min(ans,max([a,b,c])-min([a,b,c]))

  for i in range(1,w):
    a=i*h
    b=(w-i)*(h//2)
    c=(w-i)*(-(-h//2))
    ans=min(ans,max([a,b,c])-min([a,b,c]))

    a=i*h
    b=(w-i)//2*h
    c=-(-(w-i)//2)*h
    ans=min(ans,max([a,b,c])-min([a,b,c]))

  return ans

# main()
print((main()))


# Optimized solution
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  h,w=LI()

  ans=inf
  for i in range(h+1):
    a=i*w
    b=(h-i+1)//2*w
    c=(h-i)//2*w
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*w
    b=(h-i)*((w+1)//2)
    c=(h-i)*(w//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  for i in range(w+1):
    a=i*h
    b=(w-i+1)//2*h
    c=(w-i)//2*h
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*h
    b=(w-i)*((h+1)//2)
    c=(w-i)*(h//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  return ans

# main()
print((main()))
# Original solution
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  h,w=LI()

  ans=inf
  for i in range(h+1):
    a=i*w
    b=(h-i+1)//2*w
    c=(h-i)//2*w
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*w
    b=(h-i)*((w+1)//2)
    c=(h-i)*(w//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  for i in range(w+1):
    a=i*h
    b=(w-i+1)//2*h
    c=(w-i)//2*h
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*h
    b=(w-i)*((h+1)//2)
    c=(w-i)*(h//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  return ans

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  h,w=LI()
  ans=[]

  h1=h//3
  h2=(h-h1)//2
  h3=h-(h1+h2)
  ans.append(max(h1,h2,h3)*w-min(h1,h2,h3)*w)

  w1=w//3
  w2=(w-w1)//2
  w3=w-(w1+w2)
  ans.append(max(w1,w2,w3)*h-min(w1,w2,w3)*h)

  mn=inf
  for i in range(1,h):
    a1=w*i
    w1=w//2
    a2=w1*(h-i)
    w2=w-w1
    a3=w2*(h-i)
    mn=min(mn,max(a1,a2,a3)-min(a1,a2,a3))
  ans.append(mn)

  mn=inf
  for i in range(1,w):
    a1=h*i
    h1=h//2
    a2=h1*(w-i)
    h2=h-h1
    a3=h2*(w-i)
    mn=min(mn,max(a1,a2,a3)-min(a1,a2,a3))
  ans.append(mn)

  return min(ans)

# main()
print((main()))
# Original solution
n,k=int(eval(input())),int(eval(input()));print((sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))])))

# Optimized solution
_,k=eval(input()),int(eval(input()));print((sum([min(i*2,(k-i)*2) for i in list(map(int,input().split()))])))
# Original solution
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
K = int(readline().rstrip())
X = list(map(int, readline().split()))

half = K / 2
ans = 0
for x in X:
    if half < x:
        ans += K - x
    else:
        ans += x

print((ans * 2))

# Optimized solution
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

N = int(readline().rstrip())
K = int(readline().rstrip())
X = list(map(int, readline().split()))

half = K / 2
ans = 0
for x in X:
    ans += min(x, K - x)
ans *= 2

print(ans)
# Original solution
n = int(eval(input()))
k = int(eval(input()))
li = list(map(int, input().split()))
total = 0

for item in li:
        total += 2* min(item , k-item)

print(total)


# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int,input().split()))
ans = 0 
for i in range(n):
    ans += min(x[i],k-x[i])*2
print(ans)
# Original solution
n=int(eval(input()))
k=int(eval(input()))
x=list(map(int,input().split()))
ans=0
for i in range(len(x)):
    c2=(k-x[i])*2
    x2=x[i]*2
    ans+=min(c2,x2)
print(ans)

# Optimized solution
n=int(eval(input()))
k=int(eval(input()))
x=list(map(int,input().split()))
a=0
for i in range(n):
    a+=min(k-x[i],x[i])
print((a*2))
# Original solution
n = int(eval(input()))
k = int(eval(input()))
x = [int(i) for i in input().split()]
ans = 0
for i in range(n):
    ans += 2 * min(x[i],k-x[i])
print(ans)

# Optimized solution
def main():
    N = int(eval(input()))
    K = int(eval(input()))
    X = [int(i) for i in input().split()]
    ans = 0
    for x in X:
        ans += 2*x if abs(x - 0) < abs(K - x) else abs(K - x) * 2
    print(ans)


if __name__ == '__main__':
    main()
# Original solution
# -*- coding: utf-8 -*-

n = int(eval(input()))
k = int(eval(input()))
x_list = list(map(int, input().split()))

count = 0
for i in range(n):
    count += min([x_list[i], k-x_list[i]])*2

print((int(count)))


# Optimized solution
N = int(eval(input()))
K = int(eval(input()))
X = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans += min([X[i], K - X[i]]) * 2

print(ans)
# Original solution
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int,input().split()))
a = 0
b = 0
c = 0

for i in range(n):
    a = x[i] * 2
    b = abs(x[i] - k) * 2
    c += min(a,b)
    
print(c)

# Optimized solution
n = int(eval(input()))
k = int(eval(input()))
x = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = x[i] * 2
    b = abs(x[i] - k) * 2
    ans += min(a,b)
print(ans)