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 sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return

    ans = INF
    for i in range(2):
        if i == 1:
            H, W = W, H

        for h in range(1, H):
            a1 = h * W

            if (H - h) % 2 == 0:
                a2 = (H - h) // 2 * W
                tmp = abs(a1 - a2)
                if tmp < ans:
                    ans = tmp
            else:
                w = W // 2
                a2 = (H - h) * (w)
                a3 = (H - h) * (w + 1)
                tmp = abs(a2 - a3)
                if tmp < ans:
                    ans = tmp

            if W % 2 == 0:
                a2 = (H - h) * (W // 2)
                tmp = abs(a1 - a2)
                if tmp < ans:
                    ans = tmp
            else:
                w = W // 2
                a2 = (w + 1) * (H - h)
                a3 = w * (H - h)
                M = max(a1, a2, a3)
                m = min(a1, a2, a3)
                tmp = abs(M - m)
                if tmp < ans:
                    ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return
    if H % 2 == 0:
        print(H // 2)
        return
    if W % 2 == 0:
        print(W // 2)
        return
    if H == 1:
        print(1)
        return
    if W == 1:
        print(1)
        return
    else:
        answer = float("inf")
        for i in range(1, H):
            m = W // 2
            choco = [i * W, m * (H - i), (m + 1) * (H - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans
        for i in range(1, W):
            m = H // 2
            choco = [i * H, m * (W - i), (m + 1) * (W - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans
        print(min(answer, min(H, W)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return

    ans = INF
    for i in range(2):
        if i == 1:
            H, W = W, H

        for h in range(1, H):
            a1 = h * W
            if W % 2 == 0:
                a2 = (H - h) * (W // 2)
                tmp = abs(a1 - a2)
                if tmp < ans:
                    ans = tmp
            else:
                w = W // 2
                a2 = (w + 1) * (H - h)
                a3 = w * (H - h)
                M = max(a1, a2, a3)
                m = min(a1, a2, a3)
                tmp = abs(M - m)
                if tmp < ans:
                    ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return
    if H % 2 == 0:
        print(H // 2)
        return
    if W % 2 == 0:
        print(W // 2)
        return
    if H == 1:
        print(1)
        return
    if W == 1:
        print(1)
        return
    else:
        answer = float("inf")
        for i in range(1, H):
            m = W // 2
            choco = [i * W, m * (H - i), (m + 1) * (H - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans
        print(min(answer, min(H, W)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return

    if H < W:
        H, W = W, H

    ans = INF
    for h in range(1, H):
        a1 = h * W
        if W % 2 == 0:
            a2 = (H - h) * (W // 2)
            tmp = abs(a1 - a2)
            if tmp < ans:
                ans = tmp
        else:
            w = W // 2
            a2 = (w + 1) * (H - h)
            a3 = w * (H - h)
            M = max(a1, a2, a3)
            m = min(a1, a2, a3)
            tmp = abs(M - m)
            if tmp < ans:
                ans = tmp

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return
    if H % 2 == 0:
        print(H // 2)
        return
    if W % 2 == 0:
        print(W // 2)
        return
    if H == 1:
        print(1)
        return
    if W == 1:
        print(1)
        return
    else:
        answer = float("inf")
        for i in range(1, H):
            m = W // 2
            choco = [i * W, m * (H - i), (m + 1) * (H - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans
        print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    if H % 3 == 0 or W % 3 == 0:
        print(0)
        return
    if H % 2 == 0:
        print(H // 2)
        return
    if W % 2 == 0:
        print(W // 2)
        return
    else:
        answer = float("inf")
        for i in range(1, H - 1):
            m = W // 2
            choco = [i * W, m * (H - i), (m + 1) * (H - i)]
            ans = max(choco) - min(choco)
            if answer > ans:
                answer = ans
        print(answer)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# ちょうど3等分できるなら、0
if H%3==0 or W%3==0:
    print(0)
    quit()

mind = 10**18

for h in range(H+1):
    a = [W*h]
    a.append((W//2)*(H-h))
    a.append(((W//2)+(1 if W%2 else 0))*(H-h))
    mind = min(mind, max(a)-min(a))

for w in range(W+1):
    a = [w*H]
    a.append((W-w)*(H//2))
    a.append((W-w)*((H//2)+(1 if H%2 else 0)))
    mind = min(mind, max(a)-min(a))

print(mind)

Submission status: Wrong Answer

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

# ちょうど3等分できるなら、0
if H%3==0 or W%3==0:
    print(0)

mind = 10**18

for h in range(H+1):
    a = [W*h]
    a.append((W//2)*(H-h))
    a.append(((W//2)+(1 if W%2 else 0))*(H-h))
    mind = min(mind, max(a)-min(a))

for w in range(W+1):
    a = [w*H]
    a.append((W-w)*(H//2))
    a.append((W-w)*((H//2)+(1 if H%2 else 0)))
    mind = min(mind, max(a)-min(a))

print(mind)

Submission status: Wrong Answer

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

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

else:
    mind = float("inf")

    for h in range(1, H):
        a = []
        a.append(W*h)
        a.append((W//2)*(H-h))
        if W%2==0:
            a.append((W//2)*(H-h))
        else:
            a.append(((W//2)+1)*(H-h))
        mind = min(mind, max(a)-min(a))

    for w in range(1, W):
        a = []
        a.append(w*H)
        a.append((H//2)*(W-w))
        if H%2==0:
            a.append((H//2)*(W-w))
        else:
            a.append(((H//2)+1)*(W-w))
        mind = min(mind, max(a)-min(a))

    print(mind)

Submission status: Wrong Answer

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

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

else:
    mind = float("inf")

    for h in range(1, H):
        a = []
        a.append(W*h)
        a.append((W//2)*(H-h))
        if W%2==0:
            a.append((W//2)*(H-h))
        else:
            a.append(((W//2)+1)*(H-h))
        a.sort()
        mind = min(mind, a[2]-a[0])

    for w in range(1, W):
        a = []
        a.append(w*H)
        a.append((H//2)*(W-w))
        if H%2==0:
            a.append((H//2)*(W-w))
        else:
            a.append(((H//2)+1)*(W-w))
        a.sort()
        mind = min(mind, a[2]-a[0])

    print(mind)

Submission status: Wrong Answer

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

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


mind = 10**18

for h in range(1, H):
    a = []
    a.append(W*h)
    a.append((W//2)*(H-h))
    if W%2==0:
        a.append((W//2)*(H-h))
    else:
        a.append(((W//2)+1)*(H-h))
    a.sort()
    mind = min(mind, a[2]-a[0])

for w in range(1, W):
    a = []
    a.append(w*H)
    a.append((H//2)*(W-w))
    if H%2==0:
        a.append((H//2)*(W-w))
    else:
        a.append(((H//2)+1)*(W-w))
    a.sort()
    mind = min(mind, a[2]-a[0])

print(mind)

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:
        h, w = w, h
    m, n = h//2, w//3
    
    ans = h*w
    for i in range(4):
        if h % 2 == 0:
            A = [h*(n+i), m*(w-n-i), m*(w-n-i)]
        else:
            A = [h*(n+i), (m-1)*(w-n-i), m*(w-n-i)]
        ans = min(ans, max(A)-min(A))
    print(min(ans, h))

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:
        h, w = w, h
    m, n = h//2, w//3
    
    ans = h*w
    for i in range(3):
        if h % 2 == 0:
            A = [h*(n+i), m*(w-n-i), m*(w-n-i)]
        else:
            A = [h*(n+i), (m-1)*(w-n-i), m*(w-n-i)]
        ans = min(ans, max(A)-min(A))
    print(min(ans, h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
m, n = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(m)
elif w % 3 == 2 and h % 2 == 0:
    print(m)
elif w % 3 == 1 and h % 2 == 1:
    A = [n*h, (2*n+1)*(m+1), (2*n+1)*m]
    B = [(n+1)*h, 2*n*(m+1), 2*n*m]
    print(min(max(A) - min(A), max(B) - min(B), h))
else:
    A = [(n+1)*h, (2*n+1)*(m+1), (2*n+1)*m]
    B = [(n+2)*h, 2*n*(m+1), 2*n*m]
    print(min(max(A) - min(A), max(B) - min(B), h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
m, n = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(m)
elif w % 3 == 2 and h % 2 == 0:
    print(m)
elif w % 3 == 1 and h % 2 == 1:
    print(min(m + n + 1, h))
else:
    print(min(2*n, m + n + 1, h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
m, n = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(m)
elif w % 3 == 2 and h % 2 == 0:
    print(m)
elif w % 3 == 1 and h % 2 == 1:
    print(min(2*n, m + n + 1, h))
else:
    print(min(2*n, m + n + 1, h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
m, n = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(m)
elif w % 3 == 2 and h % 2 == 0:
    print(m)
elif w % 3 == 1 and h % 2 == 1:
    print(min(2*n, 2*m + n + 1 - min(n, m), h))
else:
    print(min(max(m + n, 2*n) + 1, h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
m, n = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(m)
elif w % 3 == 2 and h % 2 == 0:
    print(n)
elif w % 3 == 1 and h % 2 == 1:
    print(min(2*n, 2*m + n + 1 - min(n, m), h))
else:
    print(min(max(m + n, 2*m) + 1, h))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
n, m = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(n)
elif w % 3 == 1 and h % 2 == 1:
    print(-1)
elif w % 3 == 2 and h % 2 == 0:
    print(n)
else:
    print(max(m + n, 2*m))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h > w:
    h, w = w, h
n, m = h//2, w//3
if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(n)
elif w % 3 == 1 and h % 2 == 1:
    print(min(max(m + n, 2*m), max(2*m + n + 1, 2*n)))
elif w % 3 == 2 and h % 2 == 0:
    print(n)
else:
    print(max(m + n, 2*m))

Submission status: Wrong Answer

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

if h % 3 == 0 or w % 3 == 0:
    print(0)
elif w % 3 == 1 and h % 2 == 0:
    print(h//2)
elif w % 3 == 1 and h % 2 == 1:
    print(max(h, 2*w//3))
elif w % 3 == 2 and h % 2 == 0:
    print(h//2)
else:
    print(max(w//3 + h//2, 2*w//3) + 1)

Submission status: Wrong Answer

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

ans = float('inf')
a,b,c = H//3*W,(H-H//3)*(W//2),(H-H//3)*(W-W//2)
ans = min(ans,max(a,b,c)-min(a,b,c))
a,b,c = (H+2)//3*W,(H-(H+2)//3)*(W//2),(H-(H+2)//3)*(W-W//2)
ans = min(ans,max(a,b,c)-min(a,b,c))
a,b,c = W//3*H,(W-W//3)*(H//2),(W-W//3)*(H-H//2)
ans = min(ans,max(a,b,c)-min(a,b,c))
a,b,c = (W+2)//3*H,(W-(W+2)//3)*(H//2),(W-(W+2)//3)*(H-H//2)
ans = min(ans,max(a,b,c)-min(a,b,c))
a,b,c = H//3*W,H//3*W,(H//3+1)*W
ans = min(ans,max(a,b,c)-min(a,b,c))
a,b,c = W//3*H,W//3*H,(W//3+1)*H
ans = min(ans,max(a,b,c)-min(a,b,c))

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/arc026/tasks/arc026_2
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

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

  ans=inf
  for i in range(h+1):
    a=i*w
    b=(h-i+1)//2*w
    c=(h-i)//2*w
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*w
    b=(h-i)*(w+1)//2
    c=(h-i)*(w//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  for i in range(w+1):
    a=i*h
    b=(w-i+1)//2*h
    c=(w-i)//2*h
    ans=min(ans,max(a,b,c)-min(a,b,c))

    a=i*h
    b=(w-i)*(h+1)//2
    c=(w-i)*(h//2)
    ans=min(ans,max(a,b,c)-min(a,b,c))

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  if h<w:
    tmp=h
    h=w
    w=tmp
  x=math.ceil(h/3)
  ma3=x*w
  mi=(h-x)*math.floor(w/2)
  ma4=h*w-ma3-mi
  dif1=max(ma3,ma4)-mi
  y=math.floor(h/3)
  mi1=y*w
  ma1=(h-y)*math.floor((w+1)/2)
  mi2=w*h-mi1-ma1
  dif2=ma1-min(mi1,mi2)
  print(min(dif1,dif2))

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  if h<w:
    tmp=h
    h=w
    w=tmp
  x=math.ceil(h/3)
  ma=x*w
  mi=(h-x)*math.floor(w/2)
  dif1=ma-mi
  y=math.floor(h/3)
  mi1=y*w
  ma1=(h-y)*math.ceil((w+1)/2)
  mi2=w*h-mi1-ma1
  dif2=ma1-min(mi1,mi2)
  print(min(dif1,dif2))

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  if h<w:
    tmp=h
    h=w
    w=tmp
  x=math.ceil(h/3)
  ma=x*w
  mi=(h-x)*math.floor(w/2)
  dif1=ma-mi
  y=math.floor(h/3)
  mi1=y*w
  ma1=(h-y)*math.floor((w+1)/2)
  mi2=w*h-mi1-ma1
  dif2=ma1-min(mi1,mi2)
  print(min(dif1,dif2))

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  if h<w:
    tmp=h
    h=w
    w=tmp
  x=math.ceil(h/3)
  ma=x*w
  mi=(h-x)*(w//2)
  dif1=ma-mi
  y=math.floor(h/3)
  mi1=y*w
  ma1=(h-y)*math.floor((w+1)/2)
  mi2=w*h-mi1-ma1
  dif2=ma1-min(mi1,mi2)
  print(min(dif1,dif2))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
def f(H,W):
    # if H%3 == 0:
    #     return 0
    w = W//2
    res = H*W
    for h in range(1,H):
        sb = (H-h)*w
        sc = (H-h)*(W-w)
        sa = h*W
        res = min(res, max(sa,sb,sc) - min(sa,sb,sc))
    return res
ans = min(f(H,W), f(W,H))
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
def f(H,W):
    if H%3 == 0:
        return 0
    w = W//2
    res = H*W
    for h in range(1,H):
        sb = (H-h)*w
        sc = (H-h)*(W-w)
        #sa = H*W - sb - sc
        sa = h*W
        res = min(res,max(sa,sb,sc) - min(sa,sb,sc))
    return res
ans = min(f(H,W), f(W,H))
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
def f(H,W):
    if H%3 == 0:
        return 0
    w = W//2
    res = H*W
    for h in range(H):
        sb = (H-h)*w
        sc = (H-h)*(W-w)
        sa = H*W -sb - sc
        res = min(res,max(sa,sb,sc) - min(sa,sb,sc))
    return res
ans = min(f(H,W), f(W,H))
print(ans)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    ans = inf
    for w in range(1,W):
        A=w*H
        remain = H*W-A
        B=remain//(W-w)//2*(W-w)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    for h in range(1,H):
        A=h*W
        remain = W*H-A
        B=remain//(H-h)//2*(H-h)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    if W%3==0 or H%3==0:
        print(0)
        return
    A = H//3*W
    if A:
        remain = H*W-A
        B=remain//2
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    
    A = W//3*H
    if A:
        remain = W*H-A
        B=remain//2
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    ans = inf
    for w in range(1,W):
        A=w*H
        remain = H*W-A
        B=remain//(W-w)//2*(W-w)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    for h in range(1,H):
        A=h*W
        remain = W*H-A
        B=remain//(H-h)//2*(H-h)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    if W%3==0 or H%3==0:
        print(0)
        return
    A = H//3*W
    remain = H*W-A
    B=remain//2
    C=remain-B
    ans = min(ans, max(A,B,C)-min(A,B,C))
    
    A = W//3*H
    remain = W*H-A
    B=remain//2
    C=remain-B
    ans = min(ans, max(A,B,C)-min(A,B,C))
    

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    ans = inf
    for w in range(1,W):
        A=w*H
        remain = H*W-A
        B=remain//(W-w)//2*(W-w)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    for h in range(1,H):
        A=h*W
        remain = W*H-A
        B=remain//(H-h)//2*(H-h)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    if W%3==0 or H%3==0:
        print(0)
        return
    A = H//3*W
    remain = H*W-A
    B=remain//2
    C=remain-B
    ans = min(ans, max(A,B,C)-min(A,B,C))
    
    A = H//3*W
    remain = H*W-A
    B=remain//2
    C=remain-B
    ans = min(ans, max(A,B,C)-min(A,B,C))
    

    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    ans = inf
    for w in range(1,W):
        A=w*H
        remain = H*W-A
        B=remain//(W-w)//2*(W-w)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    for h in range(1,H):
        A=h*W
        remain = W*H-A
        B=remain//(H-h)//2*(H-h)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    if W%3==0 or H%3==0:
        print(0)
        return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    H,W=MI()
    ans = inf
    for w in range(W):
        A=w*H
        remain = H*W-A
        B=remain//(W-w)//2*(W-w)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    for h in range(H):
        A=h*W
        remain = W*H-A
        B=remain//(H-h)//2*(H-h)
        C=remain-B
        ans = min(ans, max(A,B,C)-min(A,B,C))
    if W%3==0 or H%3==0:
        print(0)
        return
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
ans=10**6
for i in range(1,h):
    A=i*w
    bh=int((h-i)/2)
    B1=bh*w
    C1=(h-i-bh)*w
    tmp1=max(A,B1,C1)-min(A,B1,C1)
    bw=int(w/2)
    B2=(h-i)*bw
    C2=(h-i)*(w-bw)
    tmp2=max(A,B2,C2)-min(A,B2,C2)
    ans=min(ans,tmp1,tmp2)
x=w
w=h
h=x
ans2=10**6
for i in range(1,h):
    A=i*w
    bh=int((h-i)/2)
    B1=bh*w
    C1=(h-i-bh)*w
    tmp1=max(A,B1,C1)-min(A,B1,C1)
    bw=int(w/2)
    B2=(h-i)*bw
    C2=(h-i)*(w-bw)
    tmp2=max(A,B2,C2)-min(A,B2,C2)
    ans2=min(ans,tmp1,tmp2)
print(min(ans,ans2))
#解説参照済み

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
mnr = 10**18
for i in range(1, H):
    w1 = W//2
    w2 = W-w1
    s1, s2, s3 = i*W, w1*(H-i), w2*(H-i)
    t = max([s1, s2, s3]) - min([s1, s2, s3])
    mnr = min(mnr, t)
H, W = W, H
for i in range(1, H):
    w1 = W//2
    w2 = W-w1
    s1, s2, s3 = i*W, w1*(H-i), w2*(H-i)
    t = max([s1, s2, s3]) - min([s1, s2, s3])
    mnr = min(mnr, t)
if H % 3 == 0 or W % 3== 0:
    mnr = 0
elif H % 3:
    mnr = min(W, mnr)
else:
    mnr = min(H, mnr)
print(mnr)

Submission status: Wrong Answer

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

mnr = 10**9
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    if b1:
        mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
        mnr = min(mc, mnr)
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min(mnr, mc2)
H, W = W, H
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    if b1:
        mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
        mnr = min(mc, mnr)
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min(mnr, mc2)
if H % 3 == 0 or W % 3== 0:
    mnr = 0
elif H % 3:
    mnr = min(W, mnr)
else:
    mnr = min(H, mnr)
print(mnr)

Submission status: Wrong Answer

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

mnr = 10**9
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
H, W = W, H
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-a*b1), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-a*b2), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
if H % 3 == 0 or W % 3== 0:
    mnr = 0
elif H % 3:
    mnr = min(W, mnr)
else:
    mnr = min(H, mnr)
print(mnr)

Submission status: Wrong Answer

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

mnr = 10**9
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-(H-b1)*W), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-(H-b2)*W), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
H, W = W, H
for a in range(1, W//2 + 1):
    b1 = (H*W)//(a + W)
    b2 = b1+1
    mc = max(abs((W-a)*b1-(H-b1)*W), abs(b1*(a+W) - H*W))
    mc2 = max(abs((W-a)*b2-(H-b2)*W), abs(b2*(a+W) - H*W))
    mnr = min([mnr, mc, mc2])
if H % 3 == 0 or W % 3== 0:
    mnr = 0
elif H % 3:
    mnr = min(W, mnr)
else:
    mnr = min(H, mnr)
print(mnr)

Submission status: Wrong Answer

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

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

#print(h, w)
min_ = float('inf')
for i in range(1, h):
    s1 = w*i
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w-w//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

#print('-')

for i in range(1, w):
    s1 = h*i
    s2 = (w-i)*(h//2)
    s3 = (w-i)*(h-h//2)
    d = max([s1, s2, s3]) - min([s1, s2, s3])
    #print(i, s1, s2, s3, d)
    min_ = min(min_, d)

print(min_)