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 = [int(n) for n in input().split()]


def max_diff(list):
    l0 = list[0]
    l1 = list[1]
    l2 = list[2]
    max_diff = max([abs(l0 - l1), abs(l0 - l2), abs(l1 - l2)])
    return max_diff


def min_square(h, w):
    w3 = w // 3
    w2 = w // 2
    h3 = h // 3
    h2 = h // 2
    w_3 = [w3, w3 + 1, w3 + 2]
    w_2 = [w2, w2 + 1, w2 + 2]
    h_3 = [h3, h3 + 1, h3 + 2]
    h_2 = [h2, h2 + 1, h2 + 2]
    min_list = []
    for k in w_3:
        for l in h_2:
            if 0 < k < w and 0 < l < h:
                min_list.append(max_diff([h * k, l * (w - k), (h - l) * (w - k)]))
    for k in w_2:
        for l in h_3:
            if 0 < k < w and 0 < l < h:
                min_list.append(max_diff([w * l, k * (h - l), (w - k) * (h - l)]))

    return min(min_list)


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

Submission status: Wrong Answer

Solution code:
import itertools
H, W = [int(n) for n in input().split()]


slice_len = []
for i in range(H):
    slice_len.append(i+1)

slice_wid = []
for i in range(W):
    slice_wid.append(i+1)


slice_lenlen_com = (list(itertools.combinations(slice_len,2)))
slice_widwid_com = (list(itertools.combinations(slice_wid,2)))
slice_widlen_com = [(x, y) for x in slice_wid for y in slice_len]
slice_lenwid_com = [(x, y) for x in slice_len for y in slice_wid]



def get_slice():
    S = H*W
    for i in range(len(slice_lenlen_com)):
        S1 = (H - slice_lenlen_com[i][1])*W
        S2 = (slice_lenlen_com[i][1] - slice_lenlen_com[i][0])*W
        S3 = (slice_lenlen_com[i][1]- 0)*W
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_widwid_com)):
        S1 = (W - slice_widwid_com[i][1])*H
        S2 = (slice_widwid_com[i][1] - slice_widwid_com[i][0])*H
        S3 = (slice_widwid_com[i][1]- 0)*H
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_widlen_com)):
        S1 = slice_widlen_com[i][0] * W
        S2 = (W - slice_widlen_com[i][0]) * slice_widlen_com[i][1]
        S3 = H*W - (S1 + S2)
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_lenwid_com)):
        S1 = slice_lenwid_com[i][0] * H
        S2 = (H - slice_lenwid_com[i][0]) * slice_lenwid_com[i][1]
        S3 = H*W - (S1 + S2)
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    return S

print(get_slice())

Submission status: Wrong Answer

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


def max_diff(list):
    l0 = list[0]
    l1 = list[1]
    l2 = list[2]
    max_diff = max([abs(l0 - l1), abs(l0 - l2), abs(l1 - l2)])
    return max_diff


def min_square(h, w):
    w3 = w // 3
    w2 = w // 2
    h3 = h // 3
    h2 = h // 2
    w_3 = [w3, w3 + 1, w3 + 2]
    w_2 = [w2, w2 + 1, w2 + 2]
    h_3 = [h3, h3 + 1, h3 + 2]
    h_2 = [h2, h2 + 1, h2 + 2]
    min_list = []
    for k in w_3:
        for l in h_2:
            if k > 0 and l > 0:
                min_list.append(max_diff([h * k, l * (w - k), (h - l) * (w - k)]))
    for k in w_2:
        for l in h_3:
            if k > 0 and l > 0:
                min_list.append(max_diff([h * k, l * (w - k), (h - l) * (w - k)]))
    return min(min_list)


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

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i = min(h, w)
j = max(h, w)
area = i * j
if i % 3 == 0 or j % 3 == 0:
    print(0)
else:
    p = j // 3 + 1
    pp = i // 3 + 1
    q = j // 3 - 1
    qq = i // 3 - 1
    a1 = i * p
    aa1 = j * p
    a2 = i * q
    aa2 = j * q
    b1 = i // 2 * (j - p)
    bb1 = j // 2 * (i - p)
    b2 = i // 2 * (j - q)
    bb2 = j // 2 * (i - q)
    c1 = (j - p) // 2 * i
    cc1 = (i - p) // 2 * j
    c2 = (j - q) // 2 * i
    cc2 = (i - q) // 2 * j
    tup=[(a1,b1),(a2,b2),(aa1,bb1),(aa2,bb2),
        (a1,c1),(a2,c2),(aa1,cc1),(aa2,cc2)]
    lst=[abs(max(a,b,area-a-b)-min(a, b, area - a - b)) for a,b in tup]
    print(min(lst))

Submission status: Wrong Answer

Solution code:

H, W = [int(n) for n in input().split()]

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

else:
    m = H * W
    for i in range(1,W+1):
        a = i * W
        b = (H-i) * (W//2)
        c = (H-i) * (W - W//2)
        if m > max(a,b,c)-min(a,b,c):
            m = max(a,b,c)-min(a,b,c)
    for i in range(1,H+1):
        a = i * H
        b = (W-i) * (H//2)
        c = (W-i) * (H - H//2)
        if m > max(a,b,c)-min(a,b,c):
            m = max(a,b,c)-min(a,b,c)
    if m > H:
        m = H
    if m > W:
        m = W
    print(m)

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i = min(h, w)
j = max(h, w)
area = i * j
if i % 3 == 0 or j % 3 == 0:
    print(0)
else:
    p = j // 3 + 1
    pp = i // 3 + 1
    q = j // 3 - 1
    qq = i // 3 - 1
    a1 = i * p
    aa1 = j * p
    a2 = i * q
    aa2 = j * q
    b1 = i // 2 * (j - p)
    bb1 = j // 2 * (i - p)
    b2 = i // 2 * (j - q)
    bb2 = j // 2 * (i - q)
    c1 = (j - p) // 2 * i
    cc1 = (i - p) // 2 * j
    c2 = (j - q) // 2 * i
    cc2 = (i - q) // 2 * j

    print(min(
        abs(max(a1, b1, area - a1 - b1) - min(a1, b1, area - a1 - b1)),
        abs(max(aa1, bb1, area - aa1 - bb1) - min(aa1, b1, area - aa1 - bb1)),
        abs(max(aa2, bb2, area - aa2 - bb2) - min(aa2, bb2, area - aa2 - bb2)),
        abs(max(a2, b2, area - a2 - b2) - min(a2, b2, area - a2 - b2)),
        abs(max(a1, c1, area - a1 - c1) - min(a1, c1, area - a1 - c1)),
        abs(max(aa1, cc1, area - aa1 - cc1) - min(aa1, c1, area - aa1 - cc1)),
        abs(max(aa2, cc2, area - aa2 - cc2) - min(aa2, cc2, area - aa2 - cc2)),
        abs(max(a2, c2, area - a2 - c2) - min(a2, c2, area - a2 - c2))

    ))

Submission status: Wrong Answer

Solution code:

H, W = [int(n) for n in input().split()]

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

else:
    m = H * W
    for i in range(1,W+1):
        a = i * W
        b = (H-i) * (W//2)
        c = (H-i) * (W - W//2)
        if m > abs(max(a,b,c)-min(a,b,c)):
            m = abs(max(a,b,c)-min(a,b,c))
    for i in range(1,H+1):
        a = i * H
        b = (W-i) * (H//2)
        c = (W-i) * (H - H//2)
        if m > abs(max(a,b,c)-min(a,b,c)):
            m = abs(max(a,b,c)-min(a,b,c))
    if m > H:
        m = H
    if m > W:
        m = W
    print(m)

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i = min(h, w)
j = max(h, w)
area = i * j
if i % 3 == 0 or j % 3 == 0:
    print(0)
else:
    p = j // 3 + 1
    pp = i // 3 + 1
    q = j // 3 - 1
    qq = i // 3 - 1
    a1 = i * p
    aa1 = j * p
    a2 = i * q
    aa2 = j * q
    b1 = i // 2 * (j - p)
    bb1 = j // 2 * (i - p)
    b2 = i // 2 * (j - q)
    bb2 = j // 2 * (i - q)
    c1 = (j - p) // 2 * i
    cc1 = (i - p) // 2 * j
    c2 = (j - q) // 2 * i
    cc2 = (i - q) // 2 * j

    print(min(
        abs(a1 - b1), abs(aa1 - bb1), abs(aa2 - bb2), abs(a2 - b2),
        abs(a1 - c1), abs(aa1 - cc1), abs(aa2 - cc2), abs(a2 - c2)
    ))

Submission status: Wrong Answer

Solution code:
import itertools
H, W = [int(n) for n in input().split()]


slice_len = []
for i in range(H):
    slice_len.append(i+1)

slice_wid = []
for i in range(W):
    slice_wid.append(i+1)


slice_lenlen_com = (list(itertools.combinations(slice_len,2)))
slice_widwid_com = (list(itertools.combinations(slice_wid,2)))
slice_widlen_com = [(x, y) for x in slice_wid for y in slice_len]
slice_lenwid_com = [(x, y) for x in slice_len for y in slice_wid]



def get_slice():
    S = H*W
    for i in range(len(slice_lenlen_com)):
        S1 = (H - slice_lenlen_com[i][1])*W
        S2 = (slice_lenlen_com[i][1] - slice_lenlen_com[i][0])*W
        S3 = (slice_lenlen_com[i][1]- 0)*W
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_widwid_com)):
        S1 = (H - slice_widwid_com[i][1])*W
        S2 = (slice_widwid_com[i][1] - slice_widwid_com[i][0])*W
        S3 = (slice_widwid_com[i][1]- 0)*W
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_widlen_com)):
        S1 = slice_widlen_com[i][0] * W
        S2 = (W - slice_widlen_com[i][0]) * slice_widlen_com[i][1]
        S3 = H*W - (S1 + S2)
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    for i in range(len(slice_lenwid_com)):
        S1 = slice_lenwid_com[i][0] * H
        S2 = (H - slice_lenwid_com[i][0]) * slice_lenwid_com[i][1]
        S3 = H*W - (S1 + S2)
        if S >= max(S1,S2,S3) - min(S1,S2,S3):
            S = max(S1,S2,S3) - min(S1,S2,S3)

    return S

print(get_slice())

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i = min(h, w)
j = max(h, w)
area = i * j
if i % 3 == 0 or j % 3 == 0:
    print(0)
else:
    p = j // 3 + 1
    pp = i // 3 + 1
    q = j // 3 - 1
    qq = i // 3 - 1
    a1 = i * p
    aa1 = j * p
    a2 = i * q
    aa2 = j * q
    b1 = i // 2 * (j - p)
    bb1 = j // 2 * (i - p)
    b2 = i // 2 * (j - q)
    bb2 = j // 2 * (i - q)

    print(min(abs(a1 - b1), abs(aa1 - bb1), abs(aa2 - bb2), abs(a2 - b2)))

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i = min(h, w)
j = max(h, w)
area = i * j
if i % 3 == 0 or j % 3 == 0:
    print(0)
else:
    p = j // 3 + 1
    q = j // 3 - 1
    a1 = i * p
    a2 = i * q
    b1 = i // 2 * (j - p)
    b2 = i // 2 * (j - q)

    print(min(abs(a1 - b1), abs(a2 - b2)))

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i=min(h,w)
j = max(h,w)
area = i*j
if i % 3 == 0 or j % 3==0:
    print(0)
else:
    p=j//3+1
    a = i*(p)
    b= i//2*(j-p)
    print(abs(a-b))

Submission status: Wrong Answer

Solution code:
h, w = [int(n) for n in input().split()]
i=min(h,w)
j = max(h,w)
area = i*j
if i % 3 == 0 or j % 3:
    print(0)
else:
    p=j//3+1
    a = i*(p)
    b= i//2*(j-p)
    print(abs(a-b))

Submission status: Wrong Answer

Solution code:
def div2(h, w):
    if h % 2 == 0 or w % 2 == 0:
        return [h * w // 2] * 2
    if h > w:
        h, w = w, h
    return [h * (w - 1) // 2, h * (w + 1) // 2]


def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if h > w:
        h, w = w, h
    d1 = w // 3
    areas1 = sorted([h * d1] + div2(h, w - d1))
    ans1 = areas1[-1] - areas1[0]
    d1 += 1
    areas2 = sorted([h * d1] + div2(h, w - d1))
    ans2 = areas2[-1] - areas2[0]
    return min(ans1, ans2)


print(solve(*map(int, input().split())))

Submission status: Wrong Answer

Solution code:
def solve(h, w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if h > w:
        h, w = w, h
    d1 = w // 3
    if w % 3 == 2:
        d1 += 1
    area1 = h * d1
    nw = w - d1
    if h % 2 == 0 or nw % 2 == 0:
        areas = [area1, h * nw // 2, h * nw // 2]
    else:
        if h < nw:
            h, nw = nw, h
        d2 = h // 2
        areas = [area1, d2 * nw, (h - d2) * nw]
    areas.sort()
    return areas[2] - areas[0]


print(solve(*map(int, input().split())))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
x, y = map(int, input().split(" "))
if x % 3 == 0 or y % 3 == 0:
    answer = 0

else:
    s = x * y
    if x > y:
        tmp = (x // 3) + 1
        s_max = y * tmp
        s_min = y // 2 * (x - tmp)
        answer = abs(s_max - s_min)

        tmp = (x // 3)
        s_max = y * tmp
        s_min = y // 2 * (x - tmp)

        if answer > abs(s_max - s_min):
            answer = abs(s_max - s_min)

        s_min = s_max
        s_max = (tmp + 1) * y

        if answer > abs(s_max - s_min):
            answer = abs(s_max - s_min)

    if x <= y:
        tmp = (y // 3) + 1
        s_max = x * tmp
        s_min = x // 2 * (y - tmp)
        answer = abs(s_max - s_min)

        tmp = (y // 3)
        s_max = x * tmp
        s_min = x // 2 * (y - tmp)
        if answer > abs(s_max - s_min):
            answer = abs(s_max - s_min)

        s_min = s_max
        s_max = (tmp + 1) * x
        if answer > abs(s_max - s_min):
            answer = abs(s_max - s_min)

print(answer)

Submission status: Wrong Answer

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

    if H % 3 == 0 or W % 3 == 0:
        ans = 0
    else:
        ans1 = choco(H, W)
        ans2 = choco(W, H)
        ans = min(ans1, ans2)

    print(ans)

def choco(h, w):
    i = 1
    min_ = float('inf')
    max_ = 4
    diff = float('inf')
    while i <= w / 2:
        w2 = w - i
        s1 = h * i
        s2 = h * w2 // 2
        s3 = h * w2 + 1 // 2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        s2 = h // 2 * w2
        s3 = h * w2 + 1 // 2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        i += 1

    return diff

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    if H % 3 == 0 or W % 3 == 0:
        ans = 0
    else:
        ans1 = choco(H, W)
        ans2 = choco(W, H)
        ans = min(ans1, ans2)

    print(ans)

def choco(h, w):
    i = 1
    min_ = float('inf')
    max_ = 4
    diff = float('inf')
    while i <= w / 2:
        w2 = w - i
        s1 = h * i
        s2 = h * w2 // 2
        s3 = h * w2 + 1 // 2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        s2 = h // 2 * w2
        s3 = (h + 1) // 2 * w2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        i += 1

    return diff

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    if H % 3 == 0 or W % 3 == 0:
        ans = 0
    else:
        ans1 = choco(H, W)
        ans2 = choco(W, H)
        ans = min(ans1, ans2)

    print(ans)

def choco(h, w):
    i = 1
    min_ = 10000000000
    max_ = 4
    diff = 10000000000
    while i <= w / 2:
        w2 = w - i
        s1 = h * i
        s2 = h * w2 // 2
        s3 = h * w2 + 1 // 2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        s2 = h // 2 * w2
        s3 = (h + 1) // 2 * w2
        min_ = min(s1, s2, s3)
        max_ = max(s1, s2, s3)
        if max_ - min_ < diff:
            diff = max_ - min_

        i += 1

    return diff

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def calc(big, small1, small2):
    sqs = [big, small1, small2]
    if None in sqs:
        return float("inf")
    sqs = sorted(sqs)
    return abs(sqs[0] - sqs[-1])


results = []
def sq_split(h, w, depth, target=None, target2=None):
    if depth == 2:
        results.append([h*w, target, target2])
        return
    if h != 1:
        sq_split(h//2, w, depth + 1, target=((h + 1)//2) * w, target2=target)
        if depth == 0:
            sq_split((h + 1)//2, w, depth + 1, target=(h//2) * w, target2=target)
    if w != 1:
        sq_split(h, w//2, depth + 1, target=h * ((w + 1) // 2), target2=target)
        if depth == 0:
            sq_split(h, (w + 1)//2, depth + 1, target=h * (w//2), target2=target)

sq_split(h, w, 0)
print(sorted(map(lambda x: calc(*x), results))[0])

Submission status: Wrong Answer

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

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

else:
    for i in range(W):#縦方向に可変なバーを作成
        a1 = i*H      #左側面積
        a2 = (W-i)*H  #右側面積
        for j in range(i):#さらに縦割り
            a3 = i*H      #左側面積
            a4 = (i-j)*H  #真ん中面積
            a5 = (W-i)*H  #右側面積
            a6 = max(a3,a4,a5)-min(a3,a4,a5)
            if a6 < min_tmp: min_tmp = a6
        for k in range(H):#今度は横割
            a7 = k*i      #上側面積
            a8 = (H-k)*i  #下側面積
            a9 = max(a1,a2,a7,a8)-min(a1,a2,a7,a8)
            if a9 < min_tmp: min_tmp = a9
    print(min_tmp)

Submission status: Wrong Answer

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

tmp1 = round(H/3)
tmp2 = round(W/3)

if abs(H-(tmp1*3)) * W <= abs(W-(tmp2*3)) * H:
    area = [tmp1 * W]
    A  = H-tmp1
    B  = W
else:
    area = [tmp2 * H]
    A  = W-tmp2
    B  = H

tmp1 = round(A/2)
tmp2 = round(B/2)    
 
if abs(A-(tmp1*2)) * B <= abs(B-(tmp2*2)) * A:
    area.extend([tmp1 * B,(A -tmp1) * B])
else:
    area.extend([tmp2 * A,(B -tmp2) * A])

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    print(max(area) - min(area))

Submission status: Wrong Answer

Solution code:

# C
H, W = map(int, input().split())
 
res = min(H, W)
# split H
for h in range(H // 3, H // 3 + 1):
    w = W // 2
    s1 = h*W
    s2 = (H-h)*w
    s3 = (H-h)*(W-w)
    res = min(res, max(s1,s2,s3) - min(s1,s2,s3))
# split W
for w in range(W // 3, W // 3 + 1):
    h = H // 2
    s1 = w*H
    s2 = (W-w)*h
    s3 = (W-w)*(H-h)
    res = min(res, max(s1,s2,s3) - min(s1,s2,s3))
    
# 3
if H % 3 == 0 or W % 3 == 0:
    res = 0
print(res)

Submission status: Wrong Answer

Solution code:
H ,W = map(int,input().split(" "))
 
tmp1 = round(H/3)
tmp2 = round(W/3)
if abs(H-(tmp1*3)) * W < abs(W-(tmp2*3)) * H:
    area = [tmp1 * W]
    A  = H-tmp1
    B  = W
else:
    area = [tmp2 * H]
    A  = W-tmp2
    B  = H
 
tmp1 = round(A/2)
tmp2 = round(B/2)    
 
if abs(A-(tmp1*2)) * B <= abs(B-(tmp2*2)) * A:
    area.extend([tmp1 * B,(A -tmp1) * B])
else:
    area.extend([tmp2 * A,(B -tmp2) * A])
 
print(max(area) - min(area))

Submission status: Wrong Answer

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

tmp1 = round(H/3)
tmp2 = round(W/3)
if abs(H-(tmp1*3)) * W <= abs(W-(tmp2*3)) * H:
    area = [tmp1 * W]
    A  = H-tmp1
    B  = W
else:
    area = [tmp2 * H]
    A  = W-tmp2
    B  = H

tmp1 = round(A/2)
tmp2 = round(B/2)    

if abs(A-(tmp1*2)) * B <= abs(B-(tmp2*2)) * A:
    area.extend([tmp1 * B,(A -tmp1) * B])
else:
    area.extend([tmp2 * A,(B -tmp2) * A])

print(max(area) - min(area))

Submission status: Wrong Answer

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

tmp1 = round(H/3)
tmp2 = round(W/3)

if abs(H-(tmp1*3)) * W <= abs(W-(tmp2*3)) * H:
    area = [tmp1 * W]
    A  = H-tmp1
    B  = W
else:
    area = [tmp2 * W]
    A  = W-tmp2
    B  = H

tmp1 = round(A/2)
tmp2 = round(B/2)    

if abs(A-(tmp1*2)) * B <= abs(B-(tmp2*2)) * A:
    area.extend([tmp1 * B,(A -tmp1) * B])
else:
    area.extend([tmp2 * A,(B -tmp2) * A])

print(max(area) - min(area))

Submission status: Wrong Answer

Solution code:
def div3(h,w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w > h:
        t = w
        w = h
        h = t
    mn = h * w
    for p in range(1, h):
        a = p * w
        r = h - p
        if w > r:
            s = r
            r = w
        else:
            s = w
        if s % 2 == 0:
            b = r * s / 2
            c = b
        else:
            q = r / 2
            b = q * s
            c = (r - q) * s
        t = (a,b,c)
        d = max(t) - min(t)
        mn = min(mn,d)
    return mn

h,w = map(int, raw_input().split())
print div3(h,w)

Submission status: Wrong Answer

Solution code:
def div3(h,w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w > h:
        t = w
        w = h
        h = t
    mn = h * w
    for p in range(1, h/2+1):
        a = p * w
        r = h - p
        if w > r:
            s = r
            r = w
        else:
            s = w
        if s % 2 == 0:
            b = r * s / 2
            c = b
        else:
            q = r / 2
            b = q * s
            c = (r - q) * s
        t = (a,b,c)
        d = max(t) - min(t)
        mn = min(mn,d)
    return mn

h,w = map(int, raw_input().split())
print div3(h,w)

Submission status: Wrong Answer

Solution code:
def div3(h,w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w > h:
        t = w
        w = h
        h = t
    mn = h * w
    for p in range(1,h/2):
        a = p * w
        r = h - p
        if w > r:
            s = r
            r = w
        else:
            s = w
        q = r / 2
        b = q * s
        c = (r - q) * s
        t = (a,b,c)
        d = max(t) - min(t)
        mn = min(mn,d)
    return mn

h,w = map(int, raw_input().split())
print div3(h,w)

Submission status: Wrong Answer

Solution code:
def div3(h,w):
    if h % 3 == 0 or w % 3 == 0:
        return 0
    if w > h:
        t = w
        w = h
        h = t
    mn = h * w
    for p in range(h/3, h/3+2):
        a = p * w
        r = h - p
        if w > r:
            s = r
            r = w
        else:
            s = w
        q = r / 2
        b = q * s
        c = (r - q) * s
        t = (a,b,c)
        d = max(t) - min(t)
        mn = min(mn,d)
    return mn

h,w = map(int, raw_input().split())
print div3(h,w)

Submission status: Wrong Answer

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

rets = float('inf')

for i in range(1, w):
    s1 = i * h
    s2 = (w - i) * math.floor(h * 0.5)
    s3 = (w - i) * math.ceil(h * 0.5)
    rets = min(rets, max(s1, s2, s3) - min(s1, s2, s3))

for j in range(1, h):
    s1 = i * w
    s2 = (h - i) * math.floor(w * 0.5)
    s3 = (h - i) * math.ceil(w * 0.5)
    rets = min(rets, max(s1, s2, s3) - min(s1, s2, s3))

for k in range(1, math.ceil(w / 3) + 1):
    s1 = k * h
    s2 = math.floor((w - k) / 2) * h
    s3 = math.ceil((w - k) / 2) * h
    rets = min(rets, max(s1, s2, s3) - min(s1, s2, s3))

for l in range(1, math.ceil(h / 3) + 1):
    s1 = l * w
    s2 = math.floor((h - l)/ 2) * w
    s3 = math.ceil((h - l) / 2) * w
    sum = l + math.floor((h - l) / 2) + math.ceil((h - l) / 2)
    rets = min(rets, max(s1, s2, s3) - min(s1, s2, s3))

print(rets)

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
longer = max(h, w)
shorter = min(h, w)
ans = float("inf")
for x in range(1, longer):
    y = shorter / 2
    s1 = x * shorter
    s2 = (longer - x) * y
    s3 = (shorter - y) * (longer - x)
    smax = max(s1, s2, s3)
    smin = min(s1, s2, s3)
    diff = smax - smin
    if diff < ans:
        ans = diff
print ans

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
if h % 3 == 0 or w % 3 == 0:
    print 0
else:
    longer = max(h, w)
    shorter = min(h, w)
    ans = float("inf")
    for x in range(1, longer/2+1):
        y = shorter / 2
        s1 = x * shorter
        s2 = (longer - x) * y
        s3 = (shorter - y) * (longer - x)
        smax = max(s1, s2, s3)
        smin = min(s1, s2, s3)
        diff = smax - smin
        if diff < ans:
            ans = diff
    print ans

Submission status: Wrong Answer

Solution code:
h, w = map(int, raw_input().split())
if h % 3 == 0 or w % 3 == 0:
    print 0
else:
    longer = max(h, w)
    shorter = min(h, w)
    ans = float("inf")
    for x in range(longer/3+1, longer/2+2):
        for y in range(shorter/3+1, shorter/2+2):
            s1 = shorter * x
            s2 = (longer - x) * y
            s3 = (longer - x) * (shorter - y)
            smax = max(s1, s2, s3)
            smin = min(s1, s2, s3)
            diff = smax - smin
            if ans > diff:
                ans = diff
    print ans

Submission status: Wrong Answer

Solution code:

def abc_3() :
	H, W = map(int, input().split())
	print (min(div_3(H, W), div_3(W, H), div_s(H, W), div_s(W, H)))

def div_3(H, W) :
	if W % 3 == 0 :
		return 0
	else :
		return 10000000000

def div_s(H, W) :
	min_diff = 10000000000
	for w in range(1, W) :
		s1 = w * H
		s2 = (W - w) * (H // 2)
		s3 = W * H - s2 - s1
		diff = max(s1, s2, s3) - min(s1, s2, s3)
		if diff < min_diff :
			min_diff = diff
	return min_diff

#for i in range(5) :
#	abc_3()
#	print ('input:', end = '')
#	if input() == 'q' :
#		exit()

abc_3()

Submission status: Wrong Answer

Solution code:

def abc_3() :
	H, W = map(int, input().split())
	print (min(div_3(H, W), div_s(H, W), div_s(W, H)))

def div_3(H, W) :
	if H % 3 == 0 or W % 3 == 0 :
		return 0
	else :
		return 10000000000

def div_s(H, W) :
	min_diff = 10000000000
	for w in range(1, W) :
		s1 = w * H
		s2 = (W - w) * (H // 2)
		s3 = W * H - s2 - s1
		diff = max(s1, s2, s3) - min(s1, s2, s3)
		if diff < min_diff :
			min_diff = diff
	return min_diff

#for i in range(5) :
#	abc_3()
#	print ('input:', end = '')
#	if input() == 'q' :
#		break

abc_3()

Submission status: Wrong Answer

Solution code:

def abc_3() :
	x, y = map(int,input().split())
	print (min(div_3(x, y), div_s(x, y), div_s(y, x)))

def div_3(x, y) :
	if x % 3 == 0 or y % 3 == 0 :
		return 0
	else :
		return 1000000000

def div_s(x, y) :
	min_diff = 1000000000
	for i in range(1, y) :
		s1 = i * x
		s2 = (y - i) * (x // 2)
		s3 = x * y - s1 - s2
		diff = max(s1, s2, s3) - min(s1, s2, s3)
		if diff < min_diff :
			min_diff = diff
	return min_diff

#for i in range(5) :
#	abc_3()
#	print ('input:', end = '')
#	if input() == 'q' :
#		break

abc_3()

Submission status: Wrong Answer

Solution code:

def abc_3() :
	x, y = map(int,input().split())
	if y > x : x, y = y, x
	print (min(div_3(x, y), div_s(x, y)))

def div_3(x, y) :
	if x % 3 == 0 or y % 3 == 0 :
		return 0
	else :
		return 1000000000

def div_s(x, y) :
	min_diff = 1000000000
	for i in range(1, y) :
		s1 = i * x
		s2 = (y - i) * (x // 2)
		s3 = x * y - s1 - s2
		diff = max(s1, s2, s3) - min(s1, s2, s3)
		if diff < min_diff :
			min_diff = diff
	return min_diff

#for i in range(5) :
#	abc_3()
#	print ('input:', end = '')
#	if input() == 'q' :
#		break

abc_3()

Submission status: Wrong Answer

Solution code:
print (0)

Submission status: Wrong Answer

Solution code:

def abc_3() :
	x, y = map(int,input().split())

	if x % 3 == 0 :
		print (0)
		return()

	if y % 3 == 0 :
		print (0)
		return()

	if y > x :
		x, y = y, x

	a = int(x / 3)
	s = a * y
	t =	int((x - a) * y / 2)
	s1 = abs(s - t)


	a = int(x / 3) + 1
	s = a * y
	x = x - a
	if y > x :
		x, y = y, x
	t = (int(x / 2) * y)
	s2 = abs(s - t)

	if s1 > s2 : 
		print (s2)
	else :
		print (s1)

#for i in range(5) :
#	abc_3()
#	print ('input:', end = '')
#	if input() == 'q' :
#		break

abc_3()

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())

if x % 3 == 0 :
    print (0)
    exit()

if y % 3 == 0 :
	print (0)
	exit()

if y > x :
	x, y = y, x

if y % 2 == 0 :
	a = int(x / 3)
	s = a * y
	t =	int((x - a) * y / 2)
	print (abs(s - t))

else :
	a = int(x / 3) + 1
	s = a * y
	x = x - a
	if y > x :
		x, y = y, x
	t = (int(x / 2) * y)
	print (abs(s - t))

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())

if x % 3 == 0 :
  print (0)
  exit()

if y % 3 == 0 :
  print (0)
  exit()

if y > x :
  x, y = y, x

a = int(x / 3)
s = a * y
t = int((x - a) * y / 2)

s1 = abs(s - t)
  
a = int(x / 3) + 1
s = a * y

x = x - a
if y > x :
  x, y = y, x

t = int((x / 2) * y)

s2 = int(abs(s - t))

if s1 > s2 :
  print (int(s2))
else :
  print (int(s1))

Submission status: Wrong Answer

Solution code:
x, y = map(int,input().split())

if x % 3 == 0 :
  print (0)
  exit()

if y % 3 == 0 :
  print (0)
  exit()

if y > x :
  x, y = y, x

a = int(x / 3)
s = a * y
t = int((x - a) * y / 2)

s1 = abs(s - t)
  
b = int(x / 3) + 1
s = a * y
t = int((x - a) * y / 2)

s2 = int(abs(s - t))

if s1 > s2 :
  print (int(s2))
else :
  print (int(s1))

Submission status: Wrong Answer

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

if h%3 == 0 or w%3 == 0:
    ans = 0
else:
    s = []
    high = max(h, w)
    low = min(h, w)
    s.append(round(high/3)*low)
    high2 = max(high-round(high/3), low)
    low2 = min(high-round(high/3), low)
    s.append(round(high2/2)*low2)
    s.append((high2-round(high2/2))*low2)
    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:
    ans = 0
else:
    low = min(h, w)
    high = max(h, w)
    a = round(high/3)*low
    high = max(high-round(high/3), low)
    low = min(high-round(high/3), low)
    b = round(high/2)*low
    c = (high-round(high/2))*low
    ans = max(a,b,c) - min(a, b, c)
print (ans)

Submission status: Wrong Answer

Solution code:
# -*- 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/2
        area[1] = tmp*(h-i)
        area[2] = (h-tmp)*(h-i)
        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/2
        area[1] = tmp*(h-i)
        area[2] = (w-tmp)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)

Submission status: Wrong Answer

Solution code:
H,W=map(int,raw_input().split(' '))
         
if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for __ in range(2):
        for h in range(1,H+1):
            w=(H*W/3)/h
            for _ in range(2):
                v1=(h*w,(W-w)*h,W*(H-h))
                v2=(h*w,(W-w)*H,w*(H-h))
                s=min(max(v1)-min(v1),max(v2)-min(v2))
                if s_min>s:
                    s_min=s
                    w+=1
        W,H=H,W
        
    print s_min

Submission status: Wrong Answer

Solution code:
H,W=map(int,raw_input().split(' '))
         
if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for __ in range(2):
        for h in range(1,H+1):
            for i in range(3):
                w=(H*W/3+i)/h
                for _ in range(2):
                    if w>W or w<1:
                        continue
                    v1=(h*w,(W-w)*h,W*(H-h))
                    v2=(h*w,(W-w)*H,w*(H-h))
                    s=min(max(v1)-min(v1),max(v2)-min(v2))
                    if s_min>s:
                        s_min=s
                        w+=1
        H,W=W,H
                
    print s_min