Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import math
h,w = map(int, raw_input().split())

area = [0,0,0]
ans = 999999999999
if(h%3 == 0 or w%3 == 0):
    ans = 0
for i in range(1,h/2+1):
    area[0] = i*w
    for j in range(w/2-int(math.sqrt(w/2)),w/2+1):
        area[1] = j*(h-i)
        area[2] = (w-j)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
    
for i in range(1,w/2+1):
    area[0] = i*h
    for j in range(h/2-int(math.sqrt(h/2)),h/2+1):
        area[1] = (j)*(w-i)
        area[2] = (h-j)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)
    

Fixed submission:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())
 
area = [0,0,0]
ans = 10**15
if(h%3 == 0 or w%3 == 0):
    ans = 0
else:
    for i in range(1,h/2+1):
        area[0] = i*w
        tmp = w/2
        area[1] = tmp*(h-i)
        area[2] = (w-tmp)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (h-i)/2
        area[1] = tmp*w
        area[2] = (h-i-tmp)*w
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        
    for i in range(1,w/2+1):
        area[0] = i*h
        tmp = h/2
        area[1] = tmp*(w-i)
        area[2] = (h-tmp)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (w-i)/2
        area[1] = tmp*h
        area[2] = (w-i-tmp)*h
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())

area = [0,0,0]
ans = 999999999999
if(h%3 == 0 or w%3 == 0):
    print('0')
    exit(1)
for i in range(1,h/2+1):
    area[0] = i*w
    area[1] = (w/2)*(h-i)
    area[2] = (w-w/2)*(h-i)
    S = max(area)-min(area)
    if(S<ans):
        ans = S
    
for i in range(1,w/2+1):
    area[0] = i*h
    area[1] = (h/2)*(w-i)
    area[2] = (h-h/2)*(w-i)
    S = max(area)-min(area)
    if(S<ans):
        ans = S
print(ans)
    

Fixed submission:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())
 
area = [0,0,0]
ans = 10**15
if(h%3 == 0 or w%3 == 0):
    ans = 0
else:
    for i in range(1,h/2+1):
        area[0] = i*w
        tmp = w/2
        area[1] = tmp*(h-i)
        area[2] = (w-tmp)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (h-i)/2
        area[1] = tmp*w
        area[2] = (h-i-tmp)*w
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        
    for i in range(1,w/2+1):
        area[0] = i*h
        tmp = h/2
        area[1] = tmp*(w-i)
        area[2] = (h-tmp)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (w-i)/2
        area[1] = tmp*h
        area[2] = (w-i-tmp)*h
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())

a,b,c = 0,0,0
diff =[0,0,0]   
ans = 999999999999
if(h%3 == 0 or w%3 == 0):
    print('0')
    exit(1)
for i in range(1,h/2+1):
    a = i*w
    b = (w/2)*(h-i)
    c = (w-w/2)*(h-i)
    diff = abs(a-b),abs(a-c),abs(b-c)
    S = max(diff)-min(diff)
    if(S<ans):
        ans = S
    
    
for i in range(1,w/2+1):
    a = i*h
    b = (h/2)*(w-i)
    c = (h-h/2)*(w-i)
    diff = abs(a-b),abs(a-c),abs(b-c)
    S = max(diff)-min(diff)
    if(S<ans):
        ans = S
print(ans)
    

Fixed submission:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())
 
area = [0,0,0]
ans = 10**15
if(h%3 == 0 or w%3 == 0):
    ans = 0
else:
    for i in range(1,h/2+1):
        area[0] = i*w
        tmp = w/2
        area[1] = tmp*(h-i)
        area[2] = (w-tmp)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (h-i)/2
        area[1] = tmp*w
        area[2] = (h-i-tmp)*w
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        
    for i in range(1,w/2+1):
        area[0] = i*h
        tmp = h/2
        area[1] = tmp*(w-i)
        area[2] = (h-tmp)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        tmp = (w-i)/2
        area[1] = tmp*h
        area[2] = (w-i-tmp)*h
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)