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:
H, W = map(int, input().split())

if (H * W) % 3 == 0:
    ans = 0
else:
    ans = H*W
    for _ in range(2):
        for h in range(H//3,H//3 + 2):
            for w in range(W//2, W//2 + 2):
                M = max(h * W, (H-h)*w, (H-h)*(W-w))
                m = min(h * W, (H-h)*w, (H-h)*(W-w))
                if m != 0:
                    ans = min(ans, M-m)

        H, W = W, H

print(ans)

Submission status: Wrong Answer

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

if (H * W) % 3 == 0:
    ans = 0
else:
    ans = H*W
    for _ in range(2):
        for h in range(H//3,H//3 + 2):
            for w in range(W//2, W//2 + 2):
                M = max(h * W, (H-h)*w, (H-h)*(W-w))
                m = min(h * W, (H-h)*w, (H-h)*(W-w))
                ans = min(ans, M-m)

        H, W = W, H

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
Smin = 10**5 * 10**5
for i in range(1, H):
    S1 = i * W
    S2 = (H-i) * (W//2)
    S3 = (H-i) * (W-W//2)
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
    S2 = (H-i)//2 * W
    S3 = ((H-i)-(H-i)//2) * W
    print(S1, S2, S3)
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
for i in range(1, W):
    S1 = i * H
    S2 = (W-i) * (H//2)
    S3 = (W-i) * (H-H//2)
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
    S2 = (W-i)//2 * H
    S3 = ((W-i)-(W-i)//2) * H
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
print(Smin)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
Smin = 10**5 * 10**5
for i in range(1, H):
    S1 = i * W
    S2 = (H-i) * (W//2)
    S3 = (H-i) * (W-W//2)
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
for i in range(1, W):
    S1 = i * H
    S2 = (W-i) * (H//2)
    S3 = (W-i) * (H-H//2)
    Smin = min(Smin, max(S1, S2, S3)-min(S1, S2, S3))
print(Smin)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()

res = 10**1000

for _ in range(2):
    a,b = h//3,h//3
    c = h-a-b
    mx = max(a,b,c)
    mn = min(a,b,c)
    res = min(res, mx*w-mn*w)
    h,w = w,h

for _ in range(2):
    for i in range(1,h):
        l = [i * w]
        j = h - i
        if w % 2 == 0:
            l.append(w//2 * j)
            l.append(w//2 * j)
        else:
            l.append(w//2 * j)
            l.append((w//2+1) * j)
        res = min(res, max(l) - min(l))
    h,w = w,h

print(res)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()

res = 10**1000

for _ in range(2):
    a,b,c = h//3,h//3,h//3+h%3
    res = min(res, c*w-a*w)
    h,w = w,h

for _ in range(2):
    for i in range(1,h):
        l = [i * w]
        j = h - i
        if w % 2 == 0:
            l.append(w//2 * j)
            l.append(w//2 * j)
        else:
            l.append(w//2 * j)
            l.append((w//2+1) * j)
        res = min(res, max(l) - min(l))
    h,w = w,h

print(res)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()

res = 10**1000

for _ in range(2):
    for i in range(1,h):
        l = [i * w]
        j = h - i
        if w % 2 == 0:
            l.append(w//2 * j)
            l.append(w//2 * j)
        else:
            l.append(w//2 * j)
            l.append((w//2+1) * j)
        res = min(res, max(l) - min(l))
    h,w = w,h

print(res)

Submission status: Wrong Answer

Solution code:

def read_input():
    h, w = map(int, input().split())

    return h, w

def long_first(h, w):
    long_side = max(h, w)
    short_side = min(h, w)

    mindiff = float('inf')

    for i in range(1, long_side):
        long_block = i * short_side

        long_rest = long_side - i
        short_short_side = short_side // 2
        short_long_side = short_side - short_short_side

        short_short_block = short_short_side * long_rest
        short_long_block = short_long_side * long_rest

        maxarea = max(long_block, short_short_block, short_long_block)
        minarea = min(long_block, short_short_block, short_long_block)

        if mindiff > maxarea - minarea:
            mindiff = maxarea - minarea

    return mindiff


def short_first(h, w):
    long_side = max(h, w)
    short_side = min(h, w)

    mindiff = float('inf')

    for i in range(1, short_side):
        short_block = i * long_side

        short_rest = short_side - i
        long_short_side = long_side // 2
        long_long_side = long_side - long_short_side

        long_short_block = long_short_side * short_rest
        long_long_block = long_long_side * short_rest

        maxarea = max(short_block, long_short_block, long_long_block)
        minarea = min(short_block, long_short_block, long_long_block)

        if mindiff > maxarea - minarea:
            mindiff = maxarea - minarea

    return mindiff



def submit():
    h, w = read_input()

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

    print(min(long_first(h, w), short_first(h, w)))

if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

Solution code:

def read_input():
    h, w = map(int, input().split())

    return h, w

def submit():
    h, w = read_input()

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

    long_side = max(h, w)
    short_side = min(h, w)

    mindiff = float('inf')

    for i in range(1, long_side):
        long_block = i * short_side

        long_rest = long_side - i
        short_short_side = short_side // 2
        short_long_side = short_side - short_short_side

        short_short_block = short_short_side * long_rest
        short_long_block = short_long_side * long_rest

        maxarea = max(long_block, short_short_block, short_long_block)
        minarea = min(long_block, short_short_block, short_long_block)

        if mindiff > maxarea - minarea:
            mindiff = maxarea - minarea

    print(mindiff)


if __name__ == '__main__':
    submit()

Submission status: Wrong Answer

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

def solve(h, w):
    w1 = w
    w2 = w // 2
    w3 = w - w2
    ans = h * w
    for h1 in range(1, h):
        h2 = h3 = h - h1
        s = [h1 * w1, h2 * w2, h3 * w3]
        ans = min(ans, max(s) - min(s))
    return ans

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

H,W=LI()
if H%3==0 or W%3==0:
	print(0)
	exit()
ans=inf
for h in range(H//2, H):
	items=[(H-h)*W, h*(W//2), h*(W-(W//2))]

	big=max(items)
	sml=min(items)
	ans = min(ans,big-sml)
	#(((() print(h,big,sml,items)

for w in range(W//2, W):
	items=[(W-w)*H,w*(H//2),w*(H-(H//2))]

	big=max(items)
	sml=min(items)
	ans=min(ans,big-sml)

print(ans)

Submission status: Wrong Answer

Solution code:
# 全体から三分の一切り出し、残りから二分の一切り出し、みたいな
# 切り方が,ww,wh,hh,hwの4パターンあるので全部やったらいいと思う
import math
h,w = map(int,input().split())
ans = []

#切り方：ヨコヨコ
s1 = math.ceil(w/3) * h
w_tmp = w - math.ceil(w/3)
s2 = math.ceil(w_tmp/2) * h
s3 = h*w-s1-s2
maxv = max([s1,s2,s3])
minv = min([s1,s2,s3])
ans.append(maxv-minv)
#切り方：ヨコたて
#s1までは上と同じ
s2 = math.ceil(h/2) * w_tmp
s3 = h*w-s1-s2
maxv = max([s1,s2,s3])
minv = min([s1,s2,s3])
ans.append(maxv-minv)
#切り方：たてたて
s1 = math.ceil(h/3) * w
h_tmp = h - math.ceil(h/3)
s2 = math.ceil(h_tmp/2) * w
s3 = h*w-s1-s2
maxv = max([s1,s2,s3])
minv = min([s1,s2,s3])
ans.append(maxv-minv)
#切り方：たて横
#s1までは上と同じ
s2 = math.ceil(w/2) * h_tmp
s3 = h*w-s1-s2
maxv = max([s1,s2,s3])
minv = min([s1,s2,s3])

print(min(ans))

Submission status: Wrong Answer

Solution code:
import math

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

R=[]



for i in range(1,h+1):
    s1=i*w
    s2=(h-i)*(math.ceil(w/2))
    s3=(h-i)*(w//2)
    R.append(max(s1,s2,s3)-min(s1,s2,s3))
    
    s2=(math.ceil((h-i)/2))*w
    s3=((h-i)//2)*w
    R.append(max(s1,s2,s3)-min(s1,s2,s3))

print(min(R))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
result = H * W
h = H // 3
result = min(result, (H - 3 * h) * W)
w = W // 3
result = min(result, H * (W - 3 * w))
for h in range(1, H):
    x = h * W
    w = W // 2
    y = (H - h) * w
    z = (H - h) * (W - w)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
for w in range(1, W):
    x = w * H
    h = H // 2
    y = (W - w) * h
    z = (W - w) * (H - h)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
print(result)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
result = H * W
h = H // 3
result = min(result, (H - h) * W - h * W)
w = W // 3
result = min(result, H * (W - w) - H * w)
for h in range(1, H):
    x = h * W
    w = W // 2
    y = (H - h) * w
    z = (H - h) * (W - w)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
for w in range(1, W):
    x = w * H
    h = H // 2
    y = (W - w) * h
    z = (W - w) * (H - h)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
print(result)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
result = H * W
for h in range(1, H):
    x = h * W
    w = W // 2
    y = (H - h) * w
    z = (H - h) * (W - w)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
for w in range(1, W):
    x = w * H
    h = H // 2
    y = (W - w) * h
    z = (W - w) * (H - h)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
print(result)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
result = H * W
for h in range(1, H // 2 + 1):
    x = h * W
    w = W // 2
    y = (H - h) * w
    z = (H - h) * (W - w)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
for w in range(1, W // 2 + 1):
    x = w * H
    h = H // 2
    y = (W - w) * h
    z = (W - w) * (H - h)
    diff = max(x, y, z) - min(x, y, z)
    result = min(result, diff)
print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")

H,W = map(int,input().split())
ans = INF
for i in range(1,H):
    SA = i * W
    #横半分に分割するケース
    h = math.ceil((H-i)/2)
    SB1 = h * W
    SC1 = (H-i-h)*W
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    #縦半分に分割するケース
    w = math.ceil(W/2)
    SB2 = (H-i)*w
    SC2 = (H-i)*(W-w)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)
print(ans)

Submission status: Wrong Answer

Solution code:
H , W = map(int , input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    if H > W :
        l = H
        s = W
    else :
        l = W
        s = H
    l2 = (l // 3) + 1
    smax = l2 * s
    if (l - l2) % 2 == 0 or s % 2 == 0:
        smin = (l - l2) * s // 2
    elif (l - l2) > s:
        smin = ((l - l2) // 2) * s
    else : 
        smin = (l - l2)  *  (s // 2)
    temp1 = smax - smin
    l2 = (l // 3) 
    smin = l2 * s
    if (l - l2) % 2 == 0 or s % 2 == 0:
        smax = (l - l2) * s // 2
    elif (l - l2) > s:
        smax = ((l - l2) // 2 + 1) * s
    else : 
        smax = (l - l2)  *  (s // 2 + 1)
    temp2 = smax - smin
    print(min(temp1,temp2))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-h*(w-w//3-1)//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (w-w//3)%2==0 or h%2==0:
  x2=h*(w-w//3)//2-h*(w//3)
else:
  x2=(h*w-h*(w//3)-min((w+w//3),h))//2-h*(w//3)
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-w*(h-h//3-1)//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
if (h-h//3)%2==0 or w%2==0:
  y2=w*(h-h//3)//2-w*(h//3)
else:
  y2=(h*w-w*(h//3)+min((h-h//3),h))//2-w*(h//3)
print(min(x,y,x2,y2))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-h*(w-w//3-1)//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (w-w//3)%2==0 or h%2==0:
  x2=h*(w-w//3)//2-h*(w//3)
else:
  x2=(h*w-h*(w//3)-min((w-w//3),h))//2-h*(w//3)
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-w*(h-h//3-1)//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
if (h-h//3)%2==0 or w%2==0:
  y2=w*(h-h//3)//2-w*(h//3)
else:
  y2=(h*w-w*(h//3)-min((h-h//3),h))//2-w*(h//3)
print(min(x,y,x2,y2))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
print(1)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
  exit()
if (w-w//3-1)%2==0 or h%2==0:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1))//2
else:
  x=h*(w//3 +1)-(h*w-h*(w//3 +1)-min((w-w//3-1),h))//2
if (h-h//3-1)%2==0 or w%2==0:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1))//2
else:
  y=w*(h//3 +1)-(h*w-w*(h//3 +1)-min((h-h//3-1),h))//2
print(min(x,y))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H == W == 2:
    print(1)
elif H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    b = H // 3 * W
    c = (H // 3 + 1) * W
    d = W // 3 * H
    e = (W // 3 + 1) * H
    print(min(max(b, (H - H // 3) * ((W + 1) // 2)) - min(b, (H - H // 3) * (W // 2)),
              max(c, (H - H // 3 - 1) * ((W + 1) // 2)) - min(c, (H - H // 3 - 1) * (W // 2)),
              max(d, (W - W // 3) * ((H + 1) // 2)) - min(d, (W - W // 3) * (H // 2)),
              max(e, (W - W // 3 - 1) * ((H + 1) // 2)) - min(e, (W - W // 3 - 1) * (H // 2))), H, W)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
if H == W == 2:
    print(1)
elif H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    a = H * W
    b = H // 3 * W
    c = (H // 3 + 1) * W
    d = W // 3 * H
    e = (W // 3 + 1) * H
    print(min(max(b, (H - H // 3) * ((W + 1) // 2)) - min(b, (H - H // 3) * (W // 2)),
              max(c, (H - H // 3 - 1) * ((W + 1) // 2)) - min(c, (H - H // 3 - 1) * (W // 2)),
              max(d, (W - W // 3) * ((H + 1) // 2)) - min(d, (W - W // 3) * (H // 2)),
              max(e, (W - W // 3 - 1) * ((H + 1) // 2)) - min(e, (W - W // 3 - 1) * (H // 2))))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
num = H*W
ls = []
if H%3 == 0 or W%3 == 0:
    print(0)
elif H%2 == 0 or W%2 == 0:
    s = 0
    t = 0
    if H%2 == 0 and W%2 == 0:
        for i in range(max(H, W)):
            s += min(H, W)
            t = (num-s)//2
            ls.append(abs(s-t))
        s, t = 0, 0
        for i in range(min(H, W)):
            s += max(H, W)
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    elif H%2 == 0:
        for i in range(W):
            s += H
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    else:
        for i in range(H):
            s += W
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
else:
    s, t, f = 0, 0, 0
    for i in range(W):
        s += H
        t = (W-(i+1))*(H//2)
        f = (W-(i+1))*(H//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    s, t, f = 0, 0, 0
    for i in range(H):
        s += W
        t = (H-(i+1))*(W//2)
        f = (H-(i+1))*(W//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    print(min(ls))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
num = H*W
ls = []
if H%3 == 0 or W%3 == 0:
    print(0)
elif H%2 == 0 or W%2 == 0:
    s = 0
    t = 0
    if H%2 == 0 and W%2 == 0:
        for i in range(max(H, W)):
            s += min(H, W)
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    elif H%2 == 0:
        for i in range(W):
            s += H
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    else:
        for i in range(H):
            s += W
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
else:
    s, t, f = 0, 0, 0
    for i in range(W):
        s += H
        t = (W-(i+1))*(H//2)
        f = (W-(i+1))*(H//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    s, t, f = 0, 0, 0
    for i in range(H):
        s += W
        t = (H-(i+1))*(W//2)
        f = (H-(i+1))*(W//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    print(min(ls))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
num = H*W
ls = []
if H%3 == 0 or W%3 == 0:
    print(0)
elif H%2 == 0 or W%2 == 0:
    s = 0
    t = 0
    if H%2 == 0 and W%2 == 0:
        for i in range(max(H, W)):
            s += min(H, W)
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    elif H%2 == 0:
        for i in range(W):
            s += H
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    else:
        for i in range(H):
            s += W
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
else:
    s, t, f = 0, 0, 0
    for i in range(W):
        s += H
        t = (W-i)*(H//2)
        f = (W-i)*(H//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    s, t, f = 0, 0, 0
    for i in range(H):
        s += W
        t = (H-i)*(W//2)
        f = (H-i)*(W//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    print(min(ls))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
num = H*W
ls = []
if H%3 == 0 or W%3 == 0:
    print(0)
elif H%2 == 0 or W%2 == 0:
    s = 0
    t = 0
    if H%2 == 0 and W%2 == 0:
        for i in range(max(H, W)+1):
            s += min(H, W)
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    elif H%2 == 0:
        for i in range(W+1):
            s += H
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
    else:
        for i in range(H+1):
            s += W
            t = (num-s)//2
            ls.append(abs(s-t))
        print(min(ls))
else:
    s, t, f = 0, 0, 0
    for i in range(W+1):
        s += H
        t = (W-i)*(H//2)
        f = (W-i)*(H//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    s, t, f = 0, 0, 0
    for i in range(H+1):
        s += W
        t = (H-i)*(W//2)
        f = (H-i)*(W//2+1)
        ls.append(max(s, t, f)-min(s, t, f))
    print(min(ls))

Submission status: Wrong Answer

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

def score(_list):
  return max(_list)-min(_list)

answer=H*W

# 縦割り
for i in range(1,W//2+1):
  a=score([H*i, (W-i)*(H//2), (W-i)*(H-H//2)])
  answer=min(a,answer)
  
# 横割り
for i in range(1,H//2+1):
  a=score([W*i, (H-i)*(W//2), (H-i)*(W-W//2)])
  answer=min(a,answer)
  
print(answer)

Submission status: Wrong Answer

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

def score(_list):
  return max(_list)-min(_list)

answer=H*W

# 縦割り
for i in range(W//3,W//3+2):
  a=score([H*i, (W-i)*(H//2), (W-i)*(H-H//2)])
  answer=min(a,answer)
  
# 横割り
for i in range(H//3,H//3+2):
  a=score([W*i, (H-i)*(W//2), (H-i)*(W-W//2)])
  answer=min(a,answer)
  
print(answer)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import sys
INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

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

    res = INF
    j = w // 2
    for i in range(1, h // 2 + 1):
        S = [i * w, (h - i) * j, (h - i) * (w - j)]
        res = min(res, max(S) - min(S))
    i = h // 2
    for j in range(1, w // 2 + 1):
        S = [j * h, (w - j) * i, (w - j) * (h - i)]
        res = min(res, max(S) - min(S))

    return res


print(main())

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
ans = float('inf')
if H == 2 and W == 2: ans = 1
elif H % 3 == 0 or W % 3 == 0: ans = 0
elif H == 2 or W == 2: ans = 1
else:
    for h in range(1,H+1):
        HH = H - h
        a = h*W
        b = HH*(W//2)
        c = HH*(W-W//2)
        ans = min(ans,max(a,b,c)-min(a,b,c))

    for w in range(1,W+1):
        WW = W - w
        a = w*H
        b = WW*(H//2)
        c = WW*(H-H//2)
        ans = min(ans,max(a,b,c)-min(a,b,c))
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
ans = float('inf')
if H == 2 and W == 2: ans = 1
elif H % 3 == 0 or W % 3 == 0: ans = 0
#elif H == 2 or W == 2: ans = 2
else:
    for h in range(1,H+1):
        HH = H - h
        a = h*W
        b = HH*(W//2)
        c = HH*(W-W//2)
        ans = min(ans,max(a,b,c)-min(a,b,c))

    for w in range(1,W+1):
        WW = W - w
        a = w*H
        b = WW*(H//2)
        c = WW*(H-H//2)
        ans = min(ans,max(a,b,c)-min(a,b,c))
print(ans)

Submission status: Wrong Answer

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

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

else:
    s = h * w
    l = []
    for i in range(0,2):
        if w == 2 and i == 0:
            continue
        a = (int(w/3) + i) * h
        b = (w - (int(w/3) + i)) * int(h/2)
        c = s - a - b
        #print([a,b,c])
        l.append(max([a,b,c])-min([a,b,c]))
    for j in range(0,2):
        if h == 2 and j == 0:
            continue
        a = (int(h/3) + j) * w
        b = (h - (int(h/3) + j)) * int(w/2)
        c = s - a - b
        #print([a,b,c])
        l.append(max([a,b,c])-min([a,b,c]))
    print(min(l))

Submission status: Wrong Answer

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

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

else:
    s = h * w
    l = []
    for i in range(0,2):
        a = (int(w/3) + i) * h
        b = (w - (int(w/3) + i)) * int(h/2)
        c = s - a - b
        l.append(max([a,b,c])-min([a,b,c]))
    for j in range(0,2):
        a = (int(h/3) + j) * w
        b = (h - (int(h/3) + j)) * int(w/2)
        c = s - a - b
        l.append(max([a,b,c])-min([a,b,c]))
    print(min(l))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/24
Solved on 2019/3/
@author: shinjisu
"""


# ABC 062 C - Chocolate Bar
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n

def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x

def divideStraight3(leng, other):
    long = (leng+2) // 3
    short = leng // 3
    return long*other, short*other
    
def prob():
    d = Debug()
    d.off()
    H, W = getIntList()
    d.dmp((H, W), 'H, W')

    # 縦か横の分割
    large1 = (H+2) // 3 * W
    small1 = H // 3 * W
    large2 = (W+2) // 3 * H
    small2 = W // 3 * H
    if large1-small1 < large2-small2:
        large, small = large1, small1
    else:
        large, small = large2, small2
    d.dmp((large, small), 'large, small')
    cand = large - small

    # 縦及び横の分割
    area = H*W
    d.dmp((area), 'area')
#    for i in range(area//large,  area//small+1):
    for i in range(max(1, min(H, W)//3),  (max(H, W)+1)//2):
        #d.dmp((i), 'i')
        div1 = i*W
        div2 = (H-i)*(W//2)
        div3 = (H-i)*((W+1)//2)
        #d.dmp((div1, div2, div3), 'div1, div2, div3')
        cand0 = max(div1, div2, div3) - min(div1, div2, div3)
        #d.dmp((cand0), 'cand0')
        cand = min(cand, cand0)
        div1 = i*H
        div2 = (W-i)*(H//2)
        div3 = (W-i)*((H+1)//2)
        #d.dmp((div1, div2, div3), 'div1, div2, div3')
        cand0 = max(div1, div2, div3) - min(div1, div2, div3)
        #d.dmp((cand0), 'cand0')
        cand = min(cand, cand0)
        #d.dmp((cand), 'cand')
    return cand


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)

Submission status: Wrong Answer

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

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

ans = 10**10
for h in range(1,H):
    S1 = W*h
    if W % 2 == 0:
        S2 = (W/2)*(H-h)
        S3 = (W/2)*(H-h)
    else:
        S2 = (W//2+1)*(H-h)
        S3 = (W//2)*(H-h)
    Smax = max(S1,S2)
    Smin = min(S1,S3)
    ans = min(ans , Smax - Smin )

for w in range(1,W):
    S1 = H*w
    if H % 2 == 0:
        S2 = (H/2)*(W-w)
        S3 = (H/2)*(W-w)
    else:
        S2 = (H//2+1)*(W-w)
        S3 = (H//2)*(W-w)
    Smax = max(S1,S2)
    Smin = min(S1,S3)
    ans = min(ans , Smax - Smin )

print(int(ans))

Submission status: Wrong Answer

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

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

ans = 10**10
for h in range(1,H):
    S1 = W*h
    if W % 2 == 0:
        S2 = (W/2)*(H-h)
        S3 = (W/2)*(H-h)
    else:
        S2 = (W//2+1)*(H-h)
        S3 = (W//2)*(H-h)
    Smax = max(S1,S2,S3)
    Smin = min(S1,S2,S3)
    ans = min(ans , Smax - Smin )

for w in range(1,W):
    S1 = H*w
    if H % 2 == 0:
        S2 = (H/2)*(W-w)
        S3 = (H/2)*(W-w)
    else:
        S2 = (H//2+1)*(W-w)
        S3 = (H//2)*(W-w)
    Smax = max(S1,S2,S3)
    Smin = min(S1,S2,S3)
    ans = min(ans , Smax - Smin )

print(int(ans))

Submission status: Wrong Answer

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

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

ans = 10**10
for h in range(1,H+1):
    S1 = W*h
    if W % 2 == 0:
        S2 = (W/2)*(H-h)
        S3 = (W/2)*(H-h)
    else:
        S2 = (W//2+1)*(H-h)
        S3 = (W//2)*(H-h)
    Smax = max(S1,S2,S3)
    Smin = min(S1,S2,S3)
    ans = min(ans , Smax - Smin )
for w in range(1,W+1):
    S1 = H*w
    if H % 2 == 0:
        S2 = (H/2)*(W-w)
        S3 = (H/2)*(W-w)
    else:
        S2 = (H//2+1)*(W-w)
        S3 = (H//2)*(W-w)
    Smax = max(S1,S2,S3)
    Smin = min(S1,S2,S3)
    ans = min(ans , Smax - Smin )

print(int(ans))

Submission status: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
    ans = 0

for hh in range(H + 1):
    s1 = hh * W
    ww = W // 2
    s2 = (H - hh) * ww
    s3 = (H - hh) * (W - ww)
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))

for ww in range(W + 1):
    s1 = ww * H
    hh = H // 2
    s2 = (W - ww) * hh
    s3 = (W - ww) * (H - hh)
    ans = min(ans, max(s1, s2, s3) - min(s1, s2, s3))

print(ans)

Submission status: Wrong Answer

Solution code:
w,h = map(int,input().split())
res = []
if w%3 == 0 or h%3 == 0:
    print(0)
    
elif w%2 == 0 and h%2 == 0:
    a = min(w,h)
    b = max(w,h)
    for i in range(1,b):
        S1 = i*a
        S2 = (h-i)*(a//2)
        res.append(abs(S1-S2))
    print(min(res))

elif w%2 == 0 or h%2 == 0:
    if w%2 != 0:
        w,h = h,w
    for i in range(1,h):
        S1 = i*w
        S2 = (h-i)*(w//2)
        res.append(abs(S1-S2))
    print(min(res))

else:
    for i in range(1,h):
        S1 = i*w
        S2 = (h-i)*(w//2)
        S3 = (h-i)*(w//2+1)
        res.append(max(S1,S2,S3)-min(S1,S2,S3))
    print(min(res))

Submission status: Wrong Answer

Solution code:
w,h = map(int,input().split())
res = []
if w%3 == 0 or h%3 == 0:
    print(0)
elif w%2 == 0 or h%2 == 0:
    if w%2 != 0:
        w,h = h,w
    for i in range(1,h):
        S1 = i*w
        S2 = (h-i)*(w//2)
        res.append(abs(S1-S2))
    print(min(res))
else:
    for i in range(1,h):
        S1 = i*w
        S2 = (h-i)*(w//2)
        S3 = (h-i)*(w//2+1)
        res.append(max(S1,S2,S3)-min(S1,S2,S3))
    print(min(res))

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

ans = float('inf')
for i in range(1,w):
    s = []
    s.append(i*h)
    if h%2 == 1:
        s.append((w-i)*(h//2+1))
    s.append((w-i)*(h//2))
    ans = min(ans,max(s)-min(s))

for i in range(1,h):
    s = []
    s.append(i*w)
    if w%2 == 1:
        s.append((h-i)*(w//2+1))
    s.append((h-i)*(w//2))
    ans = min(ans,max(s)-min(s))
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

if h > w:
    h,w = w,h
if h == 2:
    print(1)
    exit()

ans = float('inf')
for i in range(1,w):
    s = []
    s.append(i*h)
    if h%2 == 1:
        s.append((w-i)*(h//2+1))
    s.append((w-i)*(h//2))
    ans = min(ans,max(s)-min(s))

for i in range(1,h):
    s = []
    s.append(i*w)
    if w%2 == 1:
        s.append((h-i)*(w//2+1))
    s.append((h-i)*(w//2))
    ans = min(ans,max(s)-min(s))
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

if h > w:
    h,w = w,h
if h == 2:
    print(1)
    exit()

ans = float('inf')
for i in range(1,w):
    s = []
    s.append(i*h)
    if h%2 == 1:
        s.append((w-i)*(h//2+1))
    s.append((w-i)*(h//2))
    ans = min(ans,max(s)-min(s))
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

if h > w:
    h,w = w,h
if h == 2:
    print(1)
    exit()

ans = float('inf')
for i in range(1,w+1):
    s = []
    s.append(i*h)
    if h%2 == 1:
        s.append((w-i)*(h//2+1))
    s.append((w-i)*(h//2))
    ans = min(ans,max(s)-min(s))
print(ans)