Problem:


Score : 400 points

Problem Statement

There is a bar of chocolate with a height of H blocks and a width of W blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.

Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.
Find the minimum possible value of S_{max} - S_{min}.

Constraints

2 ≤ H, W ≤ 10^5

Input

Input is given from Standard Input in the following format:

H W

Output

Print the minimum possible value of S_{max} - S_{min}.

Sample Input 1

3 5

Sample Output 1

0

In the division below, S_{max} - S_{min} = 5 - 5 = 0.

Sample Input 2

4 5

Sample Output 2

2

In the division below, S_{max} - S_{min} = 8 - 6 = 2.

Sample Input 3

5 5

Sample Output 3

4

In the division below, S_{max} - S_{min} = 10 - 6 = 4.

Sample Input 4

100000 2

Sample Output 4

1

Sample Input 5

100000 100000

Sample Output 5

50000



Sample input:
3 5


Sample output:
0

Submission status: Wrong Answer

Solution code:
import math

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

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

if (m % 3) == 0:
    print("0")
else:
    round=lambda x:(x*2+1)//2
    y = int(round(m1 / 3))
    ans1 = abs(int((m*y) - (m1-y)*math.floor(m/2)))
    ans2 = m1
    ans3 = m1-y
    print(min(ans1, ans2, ans3))

Submission status: Wrong Answer

Solution code:
import math

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

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

if (m % 3) == 0:
    print("0")
else:
    round=lambda x:(x*2+1)//2
    y = int(round(m1 / 3))
    ans1 = abs(int((m*y) - (m1-y)*math.floor(m/2)))
    ans2 = m1
    print(min(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import math

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

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

if (m % 3) == 0:
    print("0")
else:
    round=lambda x:(x*2+1)//2
    y = round(m1 / 3)
    print(abs(int((m*y) - (m1-y)*math.floor(m/2))))

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
	print('0')
else:
	a = h
	s = []
	if a%2 == 0:
		d = a/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
			s.append(a*b)
			s.append(c*d)
		else:
			b = (w+1)/3
			c = w-b
			s.append(a*b)
			s.append(c*d)
	else:
		d = (a-1)/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
			s.append(a*b)
			s.append(c*d)
			s.append(c*(d+1))
		else:
			b = (w+1)/3
			c = w-b
			s.append(a*b)
			s.append(c*d)
			s.append(c*(d+1))
	ans1 = abs(int(max(s)-min(s)))
	x = w
	w = h
	h = x
	if h%3 == 0 or w%3 == 0:
		print('0')
	else:
		a = h
		k = []
		if a%2 == 0:
			d = a/2
			if w%3 == 1:
				b = (w-1)/3
				c = w - b
				k.append(a*b)
				k.append(c*d)
			else:
				b = (w+1)/3
				c = w-b
				k.append(a*b)
				k.append(c*d)
		else:
			d = (a-1)/2
			if w%3 == 1:
				b = (w-1)/3
				c = w - b
				k.append(a*b)
				k.append(c*d)
				k.append(c*(d+1))
			else:
				b = (w+1)/3
				c = w-b
				k.append(a*b)
				k.append(c*d)
				k.append(c*(d+1))
		ans2 = abs(int(max(k)-min(k)))
	if ans1 <= ans2:
		print(ans1)
	else:
		print(ans2)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if w < h:
	x = w
	w = h
	h = x
l = (h+w)*2
if h%3 == 0 or w%3 == 0:
	print('0')
else:
	a = h
	if a%2 == 0:
		d = a/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
		else:
			b = (w+1)/3
			c = w-b
	else:
		d = (a-1)/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
		else:
			b = (w+1)/3
			c = w-b
	print(abs(int(a*b-c*d)))

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
l = (h+w)*2
if h%3 == 0 or w%3 == 0:
	print('0')
else:
	a = h
	if a%2 == 0:
		d = a/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
		else:
			b = (w+1)/3
			c = w-b
	else:
		d = (a-1)/2
		if w%3 == 1:
			b = (w-1)/3
			c = w - b
		else:
			b = (w+1)/3
			c = w-b
		print(a,b,c,d)
	print(abs(int(a*b-c*d)))

Submission status: Wrong Answer

Solution code:
H,W=map(int, raw_input().split())
#print H,W

#tate,tate
def calc_t_t(h,w):
	if w%3==0:
		A1=h*int(w/3)
		A2=h*int(w/3)
		A3=h*w-A1-A2
	else:
		A1=h*(w/3)
		A2=h*((w-int(w/3))/2)
		A3=h*w-A1-A2
	a=[A1,A2,A3]
	#print a
	return max(a)-min(a)


#tate,yoko
def calc_t_y(h,w):
	A1=h*int(w/2)
	A2=h/2*(w-int(w/2))
	A3=h*w-A1-A2
	a=[A1,A2,A3]
	#print a
	return max(a)-min(a)

b=[]
b.append(calc_t_t(H,W))
b.append(calc_t_t(W,H))
b.append(calc_t_y(H,W))
b.append(calc_t_y(W,H))

print min(b)

Submission status: Wrong Answer

Solution code:
H,W=map(int, raw_input().split())
print H,W

#tate,tate
def calc_t_t(h,w):
	if w%3==0:
		A1=h*int(w/3)
		A2=h*int(w/3)
		A3=h*w-A1-A2
	else:
		A1=h*(w/3)
		A2=h*((w-int(w/3))/2)
		A3=h*w-A1-A2
	a=[A1,A2,A3]
	print a
	return max(a)-min(a)


#tate,yoko
def calc_t_y(h,w):
	A1=h*int(w/2)
	A2=h/2*(w-int(w/2))
	A3=h*w-A1-A2
	a=[A1,A2,A3]
	print a
	return max(a)-min(a)

b=[]
b.append(calc_t_t(H,W))
b.append(calc_t_t(W,H))
b.append(calc_t_y(H,W))
b.append(calc_t_y(W,H))

print min(b)

Submission status: Wrong Answer

Solution code:
H, W = map(int, raw_input().split())
ans = H*W 

for loop in xrange(2):
    ans = min(ans, (H - H/3)/2*W)
    for w in xrange(1, W):
        h = H/2
        mx = max(w*H, (W - w)*(H - h))
        mn = min(w*H, (W - w)*h)
        ans = min(ans, mx - mn)
    H, W = W, H

print ans

Submission status: Wrong Answer

Solution code:
H, W = map(int, raw_input().split())
ans = H*W 

for loop in xrange(2):
    ans = min(ans, ((H + 1)/3 - H/3)*W)
    for w in xrange(1, W):
        h = H/2
        mx = max(w*H, (W - w)*(H - h))
        mn = min(w*H, (W - w)*h)
        ans = min(ans, mx - mn)
    H, W = W, H

print ans

Submission status: Wrong Answer

Solution code:
H, W = map(int, raw_input().split())
ans = H*W 

for loop in xrange(2):
    ans = min(ans, (H - (H/3)*3)*W)
    for w in xrange(1, W):
        h = H/2
        mx = max(w*H, (W - w)*(H - h))
        mn = min(w*H, (W - w)*h)
        ans = min(ans, mx - mn)
    H, W = W, H

print ans

Submission status: Wrong Answer

Solution code:
H, W = map(int, raw_input().split())
ans = H*W 

# vertical
ans = min(ans, (W - W/3*3)*H)

# horizontal
ans = min(ans, (H - H/3*3)*W)

# vert -> hori
for w in xrange(1, W):
    h = H/2
    mx = max(w*H, (W - w)*(H - h))
    mn = min(w*H, (W - w)*h)
    ans = min(ans, mx - mn)

# hori -> vert
for h in xrange(1, H):
    w = W/2
    mx = max(W*h, (H - h)*(W - w))
    mn = min(W*h, (H - h)*w)
    ans = min(ans, mx - mn)

print ans

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())

ret = float('inf')
for h0 in range(1, H - 1):
    h1 = (H - h0) // 2
    h2 = H - h0 - h1
    if h1 == 0 or h2 == 0:
        continue
    S_max = max(h0 * W, h1 * W, h2 * W)
    S_min = min(h0 * W, h1 * W, h2 * W)
    ret = min(ret, S_max - S_min)

    w1 = W // 2
    w2 = W - w1
    if w1 == 0 or w2 == 0:
        continue
    S_max = max(h0 * W, (H - h0) * w1, (H - h0) * w2)
    S_min = min(h0 * W, (H - h0) * w1, (H - h0) * w2)
    ret = min(ret, S_max - S_min)

for w0 in range(1, W - 1):
    h1 = H // 2
    h2 = H - h1
    if h1 == 0 or h2 == 0:
        continue
    S_max = max(H * w0, h1 * (W - w0), h2 * (W - w0))
    S_min = min(H * w0, h1 * (W - w0), h2 * (W - w0))
    ret = min(ret, S_max - S_min)

    w1 = (W - w0) // 2
    w2 = W - w0 - w1
    if w1 == 0 or w2 == 0:
        continue
    S_max = max(H * w0, H * w1, H * w2)
    S_min = min(H * w0, H * w1, H * w2)
    ret = min(ret, S_max - S_min)

print(ret)

Submission status: Wrong Answer

Solution code:
import math
H,W = 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)

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

Submission status: Wrong Answer

Solution code:
import math
H,W = 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)

    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)
        if H==2 or W ==2:
            return min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2),max(H,W))
        else:
            return min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2),H,W)

    print(min(cal2(H,W),cal2(W,H)))

Submission status: Wrong Answer

Solution code:
import math
H,W = 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)

    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)
        return min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2),H,W)

    print(min(cal2(H,W),cal2(W,H)))

Submission status: Wrong Answer

Solution code:
import math
H,W = 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)

    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)
        return min(cal(x1,y1),cal(x2,y1),cal(x1,y2),cal(x2,y2))

    print(min(cal2(H,W),cal2(W,H),W,H))

Submission status: Wrong Answer

Solution code:
import math
H,W = 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))

    print(min(ans1,ans2))

Submission status: Wrong Answer

Solution code:
import math
H,W = map(int,input().split())
if W>H:
    t = W
    W = H
    H = t
if H%3==0 or W%3==0:
    print(0)
elif H==2 :
    print(1)
else:
    x1,x2 = math.floor(W/2),math.ceil(W/2)
    y1,y2 = math.floor((2*H)/3),math.ceil((2*H)/3)

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

    print(min(calc(x1,y1),calc(x2,y1),calc(x1,y2),calc(x2,y2)))

Submission status: Wrong Answer

Solution code:
import math
H,W = map(int,input().split())
if W>H:
    t = W
    W = H
    H = t

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

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

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(x1,y1),calc(x2,y1),calc(x1,y2),calc(x2,y2)))

Submission status: Wrong Answer

Solution code:
import math
H,W = map(int,input().split())
if W>H:
    t = W
    W = H
    H = t

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

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

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(x1,y1),calc(x2,y1),calc(x1,y2),calc(x2,y2)))

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
ans = -1

if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    if a < b:
        (a, b) = (b, a)

    box = [0]*3

    if a % 3 == 1:
        tmp1 = a // 3
    elif a % 3 == 2:
        tmp1 = a // 3 + 1
    
    box[0] = tmp1 * b

    a -= tmp1
    
    if a < b:
        (a, b) = (b, a)


    if a % 2 == 0 or b % 2 == 0:
        (box[1], box[2]) = ((a*b) // 2, (a*b) // 2)
    else:
        box[1] = (a // 2 + a % 2) * b
        box[2] = (a // 2) * b

    ans = max(box) - min(box)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
ans = -1

if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    if a < b:
        (a, b) = (b, a)
    if a % 3 != 1 and b % 3 == 1:
        (a, b) = (b, a)

    box = [0]*3

    if a % 3 == 1:
        tmp1 = a // 3
    elif a % 3 == 2:
        tmp1 = a // 3 + 1
    
    box[0] = tmp1 * b

    a -= tmp1
    
    if a < b:
        (a, b) = (b, a)


    if a % 2 == 0 or b % 2 == 0:
        (box[1], box[2]) = ((a*b) // 2, (a*b) // 2)
    else:
        box[1] = (a // 2 + a % 2) * b
        box[2] = (a // 2) * b

    ans = max(box) - min(box)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
ans = -1
if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    if a < b:
        (a, b) = (b, a)

    box = [0]*3

    if a % 3 == 1:
        tmp1 = a // 3
    elif a % 3 == 2:
        tmp1 = a // 3 + 1
    
    box[0] = tmp1 * b

    a -= tmp1
    
    if a < b:
        (a, b) = (b, a)


    if a % 2 == 0 or b % 2 == 0:
        (box[1], box[2]) = ((a*b) // 2, (a*b) // 2)
    else:
        box[1] = (a // 2 + a % 2) * b
        box[2] = (a // 2) * b

    ans = max(box) - min(box)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
ans = -1
if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    if a < b:
        (a, b) = (b, a)
    if a % 3 != 2 and b % 3 == 2:
        (a, b) = (b, a)

    box = [0]*3

    if a % 3 == 1:
        tmp1 = a // 3
    elif a % 3 == 2:
        tmp1 = a // 3 + 1
    
    box[0] = tmp1 * b

    a -= tmp1
    
    if a < b:
        (a, b) = (b, a)


    if a % 2 == 0 or b % 2 == 0:
        (box[1], box[2]) = ((a*b) // 2, (a*b) // 2)
    else:
        box[1] = (a // 2 + a % 2) * b
        box[2] = (a // 2) * b

    ans = max(box) - min(box)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b = map(int, input().split())
ans = -1
if a % 3 == 0 or b % 3 == 0:
    ans = 0
else:
    if a < b:
        (a, b) = (b, a)

    box = [0]*3
    tmp1 = a // 3 + 1
    box[0] = tmp1 * b

    a -= tmp1
    
    if a < b:
        (a, b) = (b, a)

    if a % 2 == 0 or b % 2 == 0:
        (box[1], box[2]) = ((a*b) // 2, (a*b) // 2)
    else:
        box[1] = (a // 2 + a % 2) * b
        box[2] = (a // 2) * b

    ans = max(box) - min(box)

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())

def get_ans(A, B):
    if A % 3 == 0:
        return 0
    elif B % 2 == 0:
        return B // 2
    else:
        ans = A * B
        for a in range(A % 3 + 1):
            A1 = A // 3 + a
            S = [A1 * B, (A - A1) * (B // 2), (A - A1) * (B // 2 + 1)]
            ans = min(ans, max(S) - min(S))
        return ans

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

Submission status: Wrong Answer

Solution code:
H, W = [int(i) for i in input().split()]
s = [0] * 3
ans = H * W
for h in range(H // 2 + 1, 0, -1):
    s[0] = W * h
    s[1] = (H - h) * (W//2)
    s[2] = H * W - s[0] - s[1]
    if max(s) - min(s) < ans:
        ans = max(s) - min(s)
    if ans == 0:
        print(ans)
        exit()

for w in range(W // 2 + 1, 0, -1):
    s[0] = H * w
    s[1] = (W - w) * (H//2)
    s[2] = H * W - s[0] - s[1]
    if max(s) - min(s) < ans:
        ans = max(s) - min(s)
    if ans == 0:
        print(ans)
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = [int(i) for i in input().split()]
s = [0] * 3
ans = H * W
for h in range(H // 2 + 1, 0, -1):
    s[0] = W * h
    s[1] = (H - h) * (W//2)
    s[2] = H * W - s[0] - s[1]
    if max(s) - min(s) < ans:
        ans = max(s) - min(s)
    if ans == 0:
        print(ans)
        exit()

for w in range(W // 2 + 1, 0, -1):
    s[0] = H * w
    s[1] = (W - w) * (h//2)
    s[2] = H * W - s[0] - s[1]
    if max(s) - min(s) < ans:
        ans = max(s) - min(s)
    if ans == 0:
        print(ans)
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().split()]
small=min(h,w)
big=max(h,w)
if h%3==0 or w%3==0:
    s=0
elif h==1 or w==1:
    s=1
else:
    s=float("inf")
    s_hen=small//2
    for i in  range(1,big):
        p1=i*small
        p2=(big-i)*s_hen
        p3=(big-i)*(small-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
    s_hen=big//2
    for i in range(1,small):
        p1=i*big
        p2=(small-i)*s_hen
        p3=(small-i)*(big-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
print(s)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().split()]
small=min(h,w)
big=max(h,w)
if h%3==0 or w%3==0:
    s=0
elif h==1 or w==1:
    s=1
else:
    s=float("inf")
    s_hen=small//2
    for i in  range(1,big):
        p1=i*small
        p2=(big-i)*s_hen
        p3=(big-i)*(small-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
print(s)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().split()]
small=min(h,w)
big=max(h,w)
if h%3==0 or w%3==0:
    s=0
elif h==1 or w==1:
    s=1
else:
    s=float("inf")
    s_hen=small//2
    for i in  range(1,big+1):
        p1=i*small
        p2=(big-i)*s_hen
        p3=(big-i)*(small-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
print(s)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().split()]
small=min(h,w)
big=max(h,w)
if h%3==0 or w%3==0:
    s=0
elif h==1 or w==1:
    print(big%3)
else:
    s=float("inf")
    s_hen=small//2
    for i in  range(1,big+1):
        p1=i*small
        p2=(big-i)*s_hen
        p3=(big-i)*(small-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
print(s)

Submission status: Wrong Answer

Solution code:
h,w=[int(x) for x in input().split()]
small=min(h,w)
big=max(h,w)
if h%3==0 or w%3==0:
    s=0
else:
    s=float("inf")
    s_hen=small//2
    for i in  range(1,big+1):
        p1=i*small
        p2=(big-i)*s_hen
        p3=(big-i)*(small-s_hen)
        s=min(s,max(p1,p2,p3)-min(p1,p2,p3))
print(s)

Submission status: Wrong Answer

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

def min_s_diff(x, y):
    if x % 3 == 0:
        return 0
    if x % 3 == 1:
        a = x // 3
        b = y // 2
        s1 = a * y
        s2 = (x - a) * b
        s3 = x * y - s1 - s2
        return max(s1, s2, s3) - min(s1, s2, s3)
    if x % 3 == 2:
        a = x // 3 + 1
        b = y // 2
        s1 = a * y
        s2 = (x - a) * b
        s3 = x * y - s1 -s2
        return max(s1, s2, s3) - min(s1, s2, s3)

print(min(min_s_diff(H, W), min_s_diff(W, H)))

Submission status: Wrong Answer

Solution code:
choco=[int(i) for i in input().split()]
size_list01=[[a1*choco[0], (choco[1]-a1)*a0, (choco[1]-a1)*(choco[0]-a0)] for a1 in range(1, choco[1]) for a0 in range(1, choco[0])]
size_list1=[[a1,choco[1]-a1*2] for a1 in range(choco[1]) if (choco[1]-a1*2)>0]
size_list0=[[a0,choco[0]-a0*2] for a0 in range(choco[0]) if (choco[0]-a0*2)>0]
diff01=[max(i)-min(i) for i in size_list01]
diff0=[max(i)-min(i) for i in size_list0]
diff1=[max(i)-min(i) for i in size_list1]

print(
    min(
    min(diff01),min(diff1)*choco[0],min(diff0)*choco[1]
    )
)

Submission status: Wrong Answer

Solution code:
choco=[int(i) for i in input().split()]
size_list01=[[a1*choco[0], (choco[1]-a1)*a0, (choco[1]-a1)*(choco[0]-a0)] for a1 in range(choco[1]) for a0 in range(choco[0])]
size_list1=[[a10,a11,choco[1]-a10-a11] for a11 in range(choco[1]) for a10 in range(choco[1]-a11)]
size_list0=[[a00,a01,choco[0]-a00-a01] for a01 in range(choco[0]) for a00 in range(choco[0]-a01)]
diff01=[max(i)-min(i) for i in size_list01]
diff0=[max(i)-min(i) for i in size_list0]
diff1=[max(i)-min(i) for i in size_list1]

print(min(min(diff01),min(diff0),min(diff1)))

Submission status: Wrong Answer

Solution code:
choco=[int(i) for i in input().split()]
size_list=[[a1*choco[0], (choco[1]-a1)*a0, (choco[1]-a1)*(choco[0]-a0)] for a1 in range(choco[1]) for a0 in range(choco[0])]
diff=[max(i)-min(i) for i in size_list]
print(min(diff))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
hold = H * W

if H % 3 == 0 or W % 3 == 0:
    hold = 0
else:
    for h in range(H):
        if W % 2 == 0:
            Sa = h * W
            Sb = (H - h) * (W / 2)
            Sc = (H - h) * (W - (W / 2))
            hold = min(hold, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
        else:
            Sa = h * W
            Sb = (H - h) * (( (W + 1) / 2) )
            Sc = (H - h) * (( (W - 1) / 2) )
            hold = min(hold, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))

    for w in range(W):
        if H % 2 == 0:
            Sa = H * w
            Sb = (W - w) * (H / 2)
            Sc = (W - w) * (H / 2)
            hold = min(hold, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))
        else:
            Sa = H * w
            Sb = (W - w) * ((H + 1) / 2)
            Sc = (W - w) * ((H - 1) /2)
            hold = min(hold, max(Sa, Sb, Sc) - min(Sa, Sb, Sc))


print(int(hold))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
hr,ht,vr,vt = 0,0,0,0
hr,vr = H%3*W,W%3*H
def t(x,y):
    if x%3==0:
        return 0
    elif x%3==1:
        a = ((x//3)*2+1)*(y//2)
        b = x//3*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
    else:
        a = ((x//3)*2+1)*(y//2)
        b = (x//3+1)*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
ht = t(H,W)
vt = t(W,H)
print(min(hr,ht,vr,vt))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
hr,ht,vr,vt = 0,0,0,0
hr,vr = H%3*W,W%3*H
def t(x,y):
    if x%3==0:
        return 0
    elif x%3==1:
        a = ((x//3)*2+1)*(y//2)
        b = x//3*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
    else:
        a = ((x//3)*2+1)*(y//2)
        b = (x//3+1)*y
        c = x*y-a-b
        return max(a,b,c)-min(a,b,c)
ht = t(H,W)
vt = t(W,H)
print(hr,ht,vr,vt)

Submission status: Wrong Answer

Solution code:
H , W = map(int , input().split())
h_ans = 100000
w_ans = 100000

for h in range(1,H):
    Sa = h * W
    Sb = (H - h) * (W // 2)
    Sc = (H - h) * (W - ( W //2 ))
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < h_ans:
        h_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
        
for h in range(1,H):
    Sa = h * W
    Sb = (H - h)//2 * W
    Sc = (H - (h + (H-h)//2)) * W
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < h_ans:
        h_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
for w in range(1,W):
    Sa = H * w
    Sb = (H // 2) * (W - w)
    Sc = (H - (H //2)) * (W - w)
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < w_ans:
        w_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
for w in range(1,W):
    Sa = H * w
    Sb = H * (W -w)//2
    Sc = H * (W - (w + (W -w)//2) ) 
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < w_ans:
        w_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
        
print((min(h_ans,w_ans)))

Submission status: Wrong Answer

Solution code:
H , W = map(int , input().split())
h_ans = 100000
w_ans = 100000

for h in range(1,H):
    Sa = h * W
    Sb = (H - h) * (W // 2)
    Sc = (H - h) * (W - ( W //2 ))
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < h_ans:
        h_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
    
for w in range(1,W):
    Sa = H * w
    Sb = (H // 2) * (W - w)
    Sc = (H - (H //2)) * (W - w)
    if max(Sa,Sb,Sc) - min(Sa,Sb,Sc) < w_ans:
        w_ans = max(Sa,Sb,Sc) - min(Sa,Sb,Sc)
        
print((min(h_ans,w_ans)))

Submission status: Wrong Answer

Solution code:
#ABC062C
import sys

h,w=map(int,raw_input().split())
if h%3==0 or w%3==0:
 print 0
 sys.exit()
res=[]
#case1
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case2
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case3
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
w,h=h,w
#case4
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case5
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case6
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
print min(res)

Submission status: Wrong Answer

Solution code:
#ABC062C

h,w=map(int,raw_input().split())
res=[]
#case1
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case2
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case3
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
w,h=h,w
#case4
s1=(h/3)*w
s2=(h-h/3)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case5
s1=((h/3)+1)*w
s2=(h-h/3-1)*(w/2)
s3=h*w-s1-s2
s=[s1,s2,s3]
res.append(max(s)-min(s))
#case6
s1=s2=(h/3)*w
s3=h*w-2*s1
s=[s1,s2,s3]
res.append(max(s)-min(s))
print min(res)

Submission status: Wrong Answer

Solution code:
(h, w) = map(int, input().split(" "))

ans=[]
### case1  000
ans.append(0 if h%3==0 else w)
###case 2 tate 000
ans.append(0 if w%3==0 else h)

def getmin(h, w):
    area=9999999999999
    for i in range(h//3-3, h//3+2):
        for j in range(w//2 -3, w//2 +3):
            areas=[ i * w, j * (h-i), (w-j)*(h-i)]
            area = max(areas)-min(areas) if area > max(areas)-min(areas) else area
    return area

ans.append(getmin(h, w))
ans.append(getmin(w, h))

print(ans)
print(min(ans))

Submission status: Wrong Answer

Solution code:
(h, w) = map(int, input().split(" "))

ans=[]
### case1  000
ans.append(0 if h%3==0 else w)
###case 2 tate 000
ans.append(0 if w%3==0 else h)

def getmin(h, w):
    area=9999999999999
    for i in range(1, h):
        for j in range(1, w):
            areas=[ i * w, j * (h-i), (w-j)*(h-i)]
            area = min(areas) if area > min(areas) else area
    return area

ans.append(getmin(h, w))
ans.append(getmin(w, h))

print(min(ans))

Submission status: Wrong Answer

Solution code:
(h, w) = map(int, input().split(" "))

ans=[]
### case1  000
ans.append(h)
###case 2 tate 000
ans.append(w)

if h%3 == 0 or w %3 == 0:
    print(0)
else:
    ###case3
    w_1 = w // 3
    w_2 = w_1 + 1
    h_1 = h%2
    h_2 = h - h_1
    areas1=[w_1 * h, (w-w_1)*h_1, (w-w_1)*h_2]
    areas2=[w_2 * h, (w-w_2)*h_1, (w-w_2)*h_2]
    areas1.sort()
    areas2.sort()
    deltas=[areas1[2]-areas1[0], areas2[2]-areas2[0]]
    deltas.sort()
    ans.append(deltas[0])

    ###case4
    w_1 = h // 3
    w_2 = h_1 + 1
    h_1 = w%2
    h_2 = w - w_1
    areas1=[w_1 * h, (w-w_1)*h_1, (w-w_1)*h_2]
    areas2=[w_2 * h, (w-w_2)*h_1, (w-w_2)*h_2]
    areas1.sort()
    areas2.sort()
    deltas=[areas1[2]-areas1[0], areas2[2]-areas2[0]]
    deltas.sort()
    ans.append(deltas[0])

    ans.sort()
    print(ans[0])

Submission status: Wrong Answer

Solution code:
# Chocolate Bar
h,w = map(int,input().split())

if ( h>w ):
    h,w = w,h
a = None
if ( h%3==0 or w%3==0 ):
    a = 0
else:
    if ( w%3==1 ):
        a = min([h, 2*(w-1)/3])
    else:
        a = min([h, 2*(w+1)/3])
        
print(int(a))

Submission status: Wrong Answer

Solution code:
# Chocolate Bar
h,w = map(int,input().split())

if ( h>w ):
    h,w = w,h
a = None
if ( h%3==0 or w%3==0 ):
    a = 0
else:
    if ( w%3==1 ):
        a = min([h, (w-1)/3])
    else:
        a = min([h, 2*(w+1)/3])
        
print(int(a))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np

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

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

m = 10000000000000000000000000
for _ in range(2):
    for i in range(1, h+1):
        v = np.array([i*w, w//2*(h-i), (w-w//2)*(h-i)])
        tmp = max(v) - min(v)
        if tmp < m:
            m = tmp
    h, w = w, h

print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np

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

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

m = 10000000000000000000000000
for _ in range(2):
    for i in range(1, h+1):
        v = np.array([i*w, w//2*(h-i), (w+1)//2*(h-i)])
        tmp = max(v) - min(v)
        if tmp < m:
            m = tmp
    h, w = w, h

print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np

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

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

m = 10000000000000000000000000
for i in range(1, h+1):
    v = np.array([i*w, w//2*(h-i), (w+1)//2*(h-i)])
    tmp = max(v) - min(v)
    if tmp < m:
        m = tmp

print(m)

Submission status: Wrong Answer

Solution code:
import math
h,w = [int(i) for i in input().split()]

setOfS = [{"smin": 0, "smax": 0},
          {"smin": 0, "smax": 0},
          {"smin": 0, "smax": 0},
          {"smin": 0, "smax": 0}]

#for i in setOfS:
#    print("smin=%d, smax=%d" % (i["smin"], i["smax"]))

setOfS[0]["smin"] = math.floor(h/3)*w
if h % 3 == 0:
    setOfS[0]["smax"] = setOfS[0]["smin"]
else:
    setOfS[0]["smax"] = (math.floor(h/3)+1)*w


setOfS[1]["smax"] = max((math.floor(w/2) + w%2) * (math.floor(h/2) + h%2), w*math.floor(h/2))
setOfS[1]["smin"] = w*(math.floor(h/2) + h%2) - (math.floor(w/2) + w%2) * (math.floor(h/2) + h%2)


setOfS[2]["smin"] = math.floor(w/3)*h
if w % 3 == 0:
    setOfS[2]["smax"] = setOfS[2]["smin"]
else:
    setOfS[2]["smax"] = (math.floor(w/3)+1)*h

setOfS[3]["smax"] = max((math.floor(h/2) + h%2) * (math.floor(w/2) + w%2), h*math.floor(w/2))
setOfS[3]["smin"] = h*(math.floor(w/2) + w%2) - (math.floor(h/2) + h%2) * (math.floor(w/2) + w%2)

ans = min([cand["smax"] - cand["smin"] for cand in setOfS])
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
l =[]
if H%3==0 or W%3==0:
    print(0)
else:
  for i in range(1,H):
          a1 = W//2*(H-i)
          b1 = (W+1)//2*(H-i)
          c1 = W*i
          mx1= max(a1,b1,c1)
          mn1= min(a1,b1,c1)
          d1 = mx1-mn1
          l.append(d1)
  for j in range(1,W):
          a2 = H//2*(W-j)
          b2 = (H+1)//2*(W-j)
          c2 = H*j
          mx2 = max(a2,b2,c2)
          mn2 = min(a2,b2,c2)
          d2 = mx2-mn2
          l.append(d2)
  print(min(l))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())


def Choco(H,W,ans):
    if H%3==0 or W%3==0:
        print("0")
        exit()
    else:
        for i in range(H):
            if i==0:
                pass
            else:
                a=W*i
                if (H-i)%2==0:
                    b=(H-i)*W/2
                    dif=abs(a-b)
                else:
                    w1=W//2
                    b=(H-i)*w1
                    c=(H-i)*(W-w1)
                    M=max(a,b,c)
                    m=min(a,b,c)
                    dif=M-m
                ans=min(dif,ans)
    return ans

ans=float("inf")
ans=Choco(H,W,ans)
ans=Choco(W,H,ans)

print(ans)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())


def Choco(H,W,ans):
    if H%3==0 or W%3==0:
        print("0")
        exit()
    else:
        for i in range(H):
            if i==0:
                pass
            else:
                a=W*i
                if (H-i)%2==0:
                    b=(H-i)*W/2
                    dif=abs(a-b)
                else:
                    w1=W//2
                    b=(H-i)*w1
                    c=(H-i)*(W-w1)
                    M=max(a,b,c)
                    m=min(a,b,c)
                    dif=M-m
                ans=min(dif,ans)
    return ans

ans=10**10
ans=Choco(H,W,ans)
ans=Choco(W,H,ans)

print(ans)