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))))
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))))
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 -1e9
                    for j in [i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w]
                ]
            ),
            f(
                [
                    j if j else -1e9
                    for 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))))

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

-            f( -                [ -                    j if j else -1e9 -                    for j in [i * w, ((h - i) // 2) * w, ((h - i) - (h - i) // 2) * w] -                ] -            ), -            f( -                [ -                    j if j else -1e9 -                    for j in [i * w, (h - i) * (w // 2), (h - i) * (w - w // 2)] -                ] -            ), +            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)]),