CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 1000003
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

Max = mod-1
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod
def pow_mod(x,n):
    if n==0: return 1
    if n%2:return x*pow_mod(x,n-1)%mod
    a = pow_mod(x,n//2)
    return a*a%mod

Q = int(eval(input()))
def query(x,d,n):
    if x == 0:
        return 0
    if d == 0:
        return pow_mod(x,n)
    k = (x*inv[d])%mod
    if k+n-1 >= mod:
        return 0
    ans = fac[k+n-1]*finv[k-1]%mod
    ans *= pow(d,n)
    ans %= mod
    return ans
for i in range(Q):
    x,d,n = list(map(int,input().split()))
    print((query(x,d,n)))

# Optimized solution
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 1000003
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


Max = mod
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod


Q = int(eval(input()))
def query(x,d,n):
    if x == 0:
        return 0
    if d == 0:
        return pow(x,n,mod)
    k = (x*inv[d])%mod
    if k+n-1 >= mod:
        return 0
    ans = fac[k+n-1]*finv[k-1]%mod
    ans *= pow(d,n,mod)
    ans %= mod
    return ans
for i in range(Q):
    x,d,n = list(map(int,input().split()))
    print((query(x,d,n)))
# Original solution
import sys
input = sys.stdin.readline
mod=10**6+3
n_max=mod
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
for i in range(int(eval(input()))):
  x,d,n=list(map(int,input().split()))
  print((((d**n)*F[(x*pow(d,mod-2,mod)+n-1)%mod]*FI[(x*pow(d,mod-2,mod)-1)%mod])%mod))


# Optimized solution
import sys
input = sys.stdin.readline
mod=10**6+3
n_max=mod
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
for i in range(int(eval(input()))):
  x,d,n=list(map(int,input().split()))
  if d==0:
    print((pow(x,n,mod)))
  else:
    s=(x*pow(d,mod-2,mod)-1)%mod
    if s+n>=mod:
      print((0))
    else:
      g=(x*pow(d,mod-2,mod)+n-1)%mod
      print((((pow(d,n,mod))*F[g]*FI[s])%mod))
# Original solution
h,w= list(map(int,input().split()))
ans = h*w

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

# Optimized solution
h,w = list(map(int,input().split()))
ans = float("Inf")
if h % 3 == 0 or w % 3 == 0:
    print((0))
    exit()
for i in range(1,h):
    a = (h-i)*(w//2)
    b = (h-i)*-(-w//2)
    ans = min(ans,abs(max(i*w,a,b)-min(i*w,a,b)))
for i in range(1,w):
    a = (w-i)*(h//2)
    b = (w-i)*-(-h//2)
    ans = min(ans,abs(max(i*h,a,b)-min(i*h,a,b)))
print((min(ans,h,w)))
# Original solution
import math
H, W = list(map(int, input().split()))
ans = 10**10
for h in range(1, H):
    A = h * W
    #残りを横に割る
    B = W*math.ceil((H-h)/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
    #残りを縦に割る
    B = (H-h)*math.ceil(W/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)

# 縦横入れ替え
H, W = W, H
for h in range(1, H):
    A = h * W
    #残りを横に割る
    B = W*math.ceil((H-h)/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
    #残りを縦に割る
    B = (H-h)*math.ceil(W/2)
    C = H*W - A - B
    tmp = max([A,B,C]) - min([A,B,C])
    ans = min(ans, tmp)
print(ans)

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

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


ans = H*W
# 高さを変えて調べる
for h in range(1, H+1):
    a = h*W
    #残りを高さで割る場合
    b = ((H-h)//2) * W
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = (H-h) * (W//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))



# 幅を変えて調べる
for w in range(1, W+1):
    a = H*w
    #残りを高さで割る場合
    b = (W-w) * (H//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = ((W-w)//2) * H
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))

print(ans)
# Original solution
H, W = list(map(int, input().split()))

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


ans = H*W
# 高さを変えて調べる
for h in range(1, H+1):
    a = h*W
    #残りを高さで割る場合
    b = ((H-h)//2) * W
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = (H-h) * (W//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))



# 幅を変えて調べる
for w in range(1, W+1):
    a = H*w
    #残りを高さで割る場合
    b = (W-w) * (H//2)
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))


    #残りを幅で割る場合
    b = ((W-w)//2) * H
    c = H*W - a - b
    ans = min(ans, max([a,b,c]) - min([a,b,c]))

print(ans)

# Optimized solution

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

ans = H * W

# 1つめは縦を1ずつ増やしていく場合
for h in range(1, H):
    a = h * W

    # 残りについて、縦で分割する場合
    b = ((H - h) // 2) * W
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

    # 残りについて、横で分割する場合
    b = (H - h) * (W // 2)
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

# 1つめは横を1ずつ増やしていく場合
for w in range(1, W):
    a = w * H

    # 残りについて、縦で分割する場合
    b = (W - w) * (H//2)
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

    # 残りについて、横で分割する場合
    b = ((W - w) // 2) * H
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

print(ans)
# Original solution
H, W = list(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)

# Optimized solution
H, W = list(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)
# Original solution
import math
H,W = list(map(int,input().split()))

if H%3==0 or W%3==0:
    print((0))
elif H==2 and W==2:
    print((1))
else:

    def cal(x,y):
        return max(x*y,(W-x)*y,(H-y)*W) - min(x*y,(W-x)*y,(H-y)*W)

    x1,x2 = math.floor(W/2),math.ceil(W/2)
    y1,y2 = math.floor((2*H)/3),math.ceil((2*H)/3)

    ans1 = min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    W,H = H,W
    x1,x2 = math.floor(W/2),math.ceil(W/2)
    y1,y2 = math.floor((2*H)/3),math.ceil((2*H)/3)

    ans2 = min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    if H ==2 or W == 2:
        print((min(ans1,ans2,max(H,W))))
    else:
        print((min(ans1,ans2,H,W)))

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

if H%3==0 or W%3==0:
    print((0))
elif H==2 and W==2:
    print((1))
else:
    def cal2(h,w):
        x1,x2 = math.floor(w/2),math.ceil(w/2)
        y1,y2 = math.floor((2*h)/3),math.ceil((2*h)/3)
        def cal(x,y):
            return max(x*y,(w-x)*y,(h-y)*w) - min(x*y,(w-x)*y,(h-y)*w)
        return min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    if H==2 or W ==2:
        print((min(cal2(H,W),cal2(W,H),max(H,W))))
    else:
        print((min(cal2(H,W),cal2(W,H),H,W)))
# Original solution
from math import floor,ceil
H,W = list(map(int,input().split()))
if H%3==0 or W%3==0:
    print((0))
    exit()
ans = min(H,W)
for i in range(1,W):
    M = max(i*H,floor(H/2)*(W-i),ceil(H/2)*(W-i))
    m = min(i*H,floor(H/2)*(W-i),ceil(H/2)*(W-i))
    if M-m<ans:
        ans = M-m
for i in range(1,H):
    M = max(i*W,floor(W/2)*(H-i),ceil(W/2)*(H-i))
    m = min(i*W,floor(W/2)*(H-i),ceil(W/2)*(H-i))
    if M-m<ans:
        ans = M-m
print(ans)

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

def split2(h,w):
    if h%2==0 or w%2==0:
        return h*w//2,h*w//2
    else:
        h,w = max(h,w),min(h,w)
        return h//2*w,(h+1)//2*w

ans = H*W
for i in range(1,H):
    h = H-i
    w = W
    s1 = W*i
    s2,s3 = split2(h,w)
    ans = min(max(s1,s2,s3)-min(s1,s2,s3),ans)

for i in range(1,W):
    h = H
    w = W-i
    s1 = H*i
    s2,s3 = split2(h,w)
    ans = min(max(s1,s2,s3)-min(s1,s2,s3),ans)

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

# Optimized solution
#import sys
#input = sys.stdin.readline
def main():
    H, W = list(map( int, input().split()))
    ans = min(H,W)
    if H%3 == 0 or W%3 == 0:
        ans = 0
    for i in range(1,H):
        L = [W*i]
        L.append(W//2*(H-i))
        if W%2 == 1:
            L.append((W//2+1)*(H-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    for i in range(1,W):
        L = [H*i]
        L.append(H//2*(W-i))
        if H%2 == 1:
            L.append((H//2+1)*(W-i))
        if max(L) - min(L) < ans:
            ans = max(L) - min(L)
    print(ans)
if __name__ == '__main__':
    main()
# Original solution
H, W = list(map(int, input().split()))

def get_ans(A, B):
    ans = A * B
    for A1 in range(1, A):
        A2 = (A - A1) // 2
        A3 = A - A1 - A2
        S = [A1 * B, A2 * B, A3 * B]
        ans = min(ans, max(S) - min(S))

    for A1 in range(1, A):
        B2 = B // 2
        B3 = B - B2
        S = [A1 * B, (A - A1) * B2, (A - A1) * B3]
        ans = min(ans, max(S) - min(S))

    return ans

print((min(get_ans(H, W), get_ans(W, H))))


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

def getMinDiff(A, B):
    if A % 3 == 0:
        return 0
    elif B % 2 == 0:
        return B // 2
    else:
        ans = B # 横3段に分ける場合の値

        # T字型に分ける場合
        for i in range(A % 3 + 1):
            A1 = A // 3 + i # 上半分の縦幅
            B1, B2 = B // 2, (B + 1) // 2 # 下半分の左側、右側の横幅
            Ss = [A1 * B, (A - A1) * B1, (A - A1) * B2]
            ans = min(ans, max(Ss) - min(Ss))
        return ans

print((min(getMinDiff(H, W), getMinDiff(W, H))))
# Original solution
H, W = list(map(int, input().split()))

result = []
for h in range(1, H):
    Sa = W * h

    remain = H - h
    h2 = (remain + 1) // 2
    Sb1 = W * h2
    Sc1 = W * (remain - h2)
    result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1))

    w = (W + 1) // 2
    Sb2 = w * remain
    Sc2 = (W - w) * remain
    result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2))

for w in range(1, W):
    Sa = H * w

    remain = W - w
    w3 = (remain + 1) // 2
    Sb1 = H * w3
    Sc1 = H * (remain - w3)
    result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1))

    h = (H + 1) // 2
    Sb2 = h * remain
    Sc2 = (H - h) * remain
    result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2))

print((min(result)))


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

result = []
for h in range(1, H//2+1):
    Sa = W * h

    remain = H - h
    h2 = (remain + 1) // 2
    Sb1 = W * h2
    Sc1 = W * (remain - h2)
    result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1))

    w = (W + 1) // 2
    Sb2 = w * remain
    Sc2 = (W - w) * remain
    result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2))

for w in range(1, W//2+1):
    Sa = H * w

    remain = W - w
    w3 = (remain + 1) // 2
    Sb1 = H * w3
    Sc1 = H * (remain - w3)
    result.append(max(Sa, Sb1, Sc1) - min(Sa, Sb1, Sc1))

    h = (H + 1) // 2
    Sb2 = h * remain
    Sc2 = (H - h) * remain
    result.append(max(Sa, Sb2, Sc2) - min(Sa, Sb2, Sc2))

print((min(result)))
# Original solution
H,W = list(map(int,input().split()))
#l = sorted([int(input()) for i in range(N)],reverse=True)
def three(h,w):
    ans = h*w
    for i in range(1,h):
        A = w*i
        B = w*((h-i)//2)
        C = w*((h-i+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
def onetwo(h,w):
    ans = h*w
    for i in range(1,h):
        A = w*i
        B = (h-i)*(w//2)
        C = (h-i)*((w+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
print((min(three(H,W),three(W,H),onetwo(H,W),onetwo(W,H))))

# Optimized solution
H,W = list(map(int,input().split()))
#l = sorted([int(input()) for i in range(N)],reverse=True)
def three(h,w):
    ans = h*w
    for i in range(h//3,h//3+2):
        A = w*i
        B = w*((h-i)//2)
        C = w*((h-i+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
def onetwo(h,w):
    ans = h*w
    for i in range(h//3,h//3+2):
        A = w*i
        B = (h-i)*(w//2)
        C = (h-i)*((w+1)//2)
        ans = min(ans,max(A,B,C)-min(A,B,C))
    return ans
print((min(three(H,W),three(W,H),onetwo(H,W),onetwo(W,H))))
# Original solution
def solve(h, w):
    res = float('inf')
    for hh in range(h + 1):
        s1 = hh * w
        ww = w // 2
        s2 = (h - hh) * ww
        s3 = (h - hh) * (w - ww)
        res = min(res, max(s1, s2, s3) - min(s1, s2, s3))
    return res


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

ans = H * W
if H % 3 == 0 or W % 3 == 0:
    ans = 0
else:
    ans = min(H, W)

ans = min(ans, solve(H, W))
ans = min(ans, solve(W, H))
print(ans)


# Optimized solution
def calc(h, w):
    w_1_1 = w // 3
    w_1_2 = w_1_1 + 1

    ans = inf
    for w_1 in w_1_1, w_1_2:
        s_1 = w_1 * h

        # 縦に割る
        w_2 = (w - w_1) // 2
        s_2 = w_2 * h

        w_3 = w - w_1 - w_2
        s_3 = w_3 * h

        ss = [s_1, s_2, s_3]
        # print(h, w, ss)
        ans = min(ans, max(ss) - min(ss))

        # 横に割る
        h_2 = h // 2
        s_2 = h_2 * (w - w_1)

        h_3 = h - h_2
        s_3 = h_3 * (w - w_1)

        ss = [s_1, s_2, s_3]
        # print(h, w, ss)
        ans = min(ans, max(ss) - min(ss))

    return ans


inf = float('inf')

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

a = calc(h, w)
b = calc(w, h)
print((min(a, b)))
# Original solution

def main():
    high, width = list(map(int, input().split()))
    ans = high * width

    for i in range(1, high):
        a = i * width

        b1 = (high - i) * (width // 2)
        c1 = high * width - a - b1

        b2 = ((high - i) // 2) * width
        c2 = high * width - a - b2

        kari = min(max(a, b1, c1) - min(a, b1, c1), max(a, b2, c2) - min(a, b2, c2))

        ans = min(ans, kari)

    for i in range(1, width):
        a = i * high

        b1 = (width - i) * (high // 2)
        c1 = high * width - a - b1

        b2 = ((width - i) // 2) * high
        c2 = high * width - a - b2

        kari = min(max(a, b1, c1) - min(a, b1, c1), max(a, b2, c2) - min(a, b2, c2))

        ans = min(ans, kari)


    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    high, width = list(map(int, input().split()))
    sum_s = high * width
    ans = sum_s
    for i in range(1, high):
        a = i * width
        b1 = (high - i) * (width // 2)
        b2 = ((high - i) // 2) * width
        c1 = sum_s - (a + b1)
        c2 = sum_s - (a + b2)

        ans = min(max(a, b1, c1) - min(a, b1, c1), max(a, b2, c2) - min(a, b2, c2), ans)

    for i in range(1, width):
        a = i * high
        b1 = (width - i) * (high // 2)
        b2 = ((width - i) // 2) * high
        c1 = sum_s - (a + b1)
        c2 = sum_s - (a + b2)

        ans = min(max(a, b1, c1) - min(a, b1, c1), max(a, b2, c2) - min(a, b2, c2), ans)

    print(ans)




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

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

# # どちらかの辺が3の倍数なら確実に3等分できる
# if H % 3 == 0 or W % 3 == 0:
#     print(0)
#     exit()

# T字で区切るパターンを縦横それぞれ試す
mnval = float("inf")
for i in range(1,H):
    tmpA = i * W
    tmpB = (H-i) * (W // 2)
    tmpC = (H-i) * (W // 2 + W % 2)
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

for i in range(1,W):
    tmpA = i * H
    tmpB = (W-i) * (H // 2)
    tmpC = (W-i) * (H // 2 + H % 2)
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

# 縦並び横並びパターンをそれぞれ試す
if W >= 3:
    tmpA = H * (W // 3)
    tmpB = H * (W // 3 + ((W % 3) // 2))
    tmpC = H * (W // 3 + ((W % 3) // 2 + (W % 3) % 2))
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
if H >= 3:
    tmpA = W * (H // 3)
    tmpB = W * (H // 3 + ((H % 3) // 2))
    tmpC = W * (H // 3 + ((H % 3) // 2 + (H % 3) % 2))
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

print(mnval)

# Optimized solution
# -*- coding: utf-8 -*-

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

# T字で区切るパターンを縦横それぞれ試す
mnval = float("inf")
for i in range(1,H):
    # Tの横棒に当たる方
    tmpA = i * W
    # 縦2等分
    tmpB = (H-i) * (W // 2)
    # 残り
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
for i in range(1,W):
    tmpA = i * H
    tmpB = (W-i) * (H // 2)
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

# 縦並び横並びパターンをそれぞれ試す
if W >= 3:
    # 3等分
    tmpA = H * (W // 3)
    # 3等分と、その余った部分の半分
    tmpB = H * (W // 3 + ((W % 3) // 2))
    # 残り
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
if H >= 3:
    tmpA = W * (H // 3)
    tmpB = W * (H // 3 + ((H % 3) // 2))
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

print(mnval)
# Original solution
# -*- coding: utf-8 -*-

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

# T字で区切るパターンを縦横それぞれ試す
mnval = float("inf")
for i in range(1,H):
    # Tの横棒に当たる方
    tmpA = i * W
    # 縦2等分
    tmpB = (H-i) * (W // 2)
    # 残り
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
for i in range(1,W):
    tmpA = i * H
    tmpB = (W-i) * (H // 2)
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

# 縦並び横並びパターンをそれぞれ試す
if W >= 3:
    # 3等分
    tmpA = H * (W // 3)
    # 3等分と、その余った部分の半分
    tmpB = H * (W // 3 + ((W % 3) // 2))
    # 残り
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))
if H >= 3:
    tmpA = W * (H // 3)
    tmpB = W * (H // 3 + ((H % 3) // 2))
    tmpC = H*W - tmpA - tmpB
    mnval = min(mnval, abs(max(tmpA,tmpB,tmpC) - min(tmpA,tmpB,tmpC)))

print(mnval)

# Optimized solution
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()

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

H, W = max(H, W), min(H, W)

a = H // 3
bc = H - a
ans1 = max(abs(bc*ceil(W, 2)-a*W), abs(bc*(W//2)-a*W))
a = ceil(H, 3)
bc = H - a
ans2 = max(abs(bc*ceil(W, 2)-a*W), abs(bc*(W//2)-a*W))

H, W = min(H, W), max(H, W)

a = H // 3
bc = H - a
ans3 = max(abs(bc*ceil(W, 2)-a*W), abs(bc*(W//2)-a*W))
a = ceil(H, 3)
bc = H - a
ans4 = max(abs(bc*ceil(W, 2)-a*W), abs(bc*(W//2)-a*W))

ans5 = abs(ceil(W, 3)*H-W//3*H)
ans6 = abs(ceil(H, 3)*W-H//3*W)

print((min(ans1, ans2, ans3, ans4, ans5, ans6)))
# Original solution
def calc(H, W, ans):
    w0 = W // 2
    w1 = W - w0
    for h0 in range(1, H):
        Sa = h0 * W
        h1 = H - h0
        h2 = h1 // 2
        h3 = h1 - h2
        Sb1, Sc1 = h1 * w0, h1 * w1
        Sb2, Sc2 = h2 * W, h3 * W
        m1, _, M1 = sorted([Sa, Sb1, Sc1])
        m2, _, M2 = sorted([Sa, Sb2, Sc2])
        ans = min(ans, M1 - m1, M2 - m2)
    return ans

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

# Optimized solution
h, w = list(map(int, input().split()))
if h % 3 == 0 or w % 3 == 0:
    print((0))
else:
    a = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
    b = (h - h // 3) * (w - w // 2) - h // 3 * w
    c = min(h, w)
    h, w = w, h
    d = (h // 3 + 1) * w - (h - 1 - h // 3) * (w // 2)
    e = (h - h // 3) * (w - w // 2) - h // 3 * w
    print((min(a, b, c, d, e)))
# Original solution
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)


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

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)