Problem:


Score : 400 points

Problem Statement

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

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

Constraints

2 ≤ H, W ≤ 10^5

Input

Input is given from Standard Input in the following format:

H W

Output

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

Sample Input 1

3 5

Sample Output 1

0

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

Sample Input 2

4 5

Sample Output 2

2

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

Sample Input 3

5 5

Sample Output 3

4

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

Sample Input 4

100000 2

Sample Output 4

1

Sample Input 5

100000 100000

Sample Output 5

50000



Sample input:
3 5


Sample output:
0

Submission status: Wrong Answer

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    h,w = i_map()
    if h%3 == 0 or w%3 == 0: # 綺麗に三等分できるケース
        print(0)
        exit()

    ans = INF
    th = h//2
    for i in range(1,w//2+1):
        tate = i*h
        yoko1 = (w-i)*th
        yoko2 = (w-i)*(h-th)
        M = max(tate,yoko1,yoko2)
        m = min(tate,yoko1,yoko2)
        ans = min(ans,M-m)

    tw = w//2
    for i in range(1,h//2+1):
        tate = i*w
        yoko1 = (h-i)*tw
        yoko2 = (h-i)*(w-tw)
        M = max(tate,yoko1,yoko2)
        m = min(tate,yoko1,yoko2)
        ans = min(ans,M-m)
    print(ans)







if __name__=="__main__":
    main()

Submission status: Wrong Answer

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

if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
ans = 10 ** 10
if h >= 3:
    temph = h // 3
    num1 = temph * w
    num2 = ((h - temph) // 2) * w
    num3 = (h - -temph - ((h - temph) // 2)) * w
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
    # print(kouho)

if w >= 3:
    tempw = w // 3
    num1 = tempw * h
    num2 = ((w - tempw) // 2) * h
    num3 = (w - -tempw - ((w - tempw) // 2)) * h
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
    # print(kouho)

for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
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()
ans = 10 ** 10
if h >= 3:
    temph = h // 3
    num1 = temph * w
    num2 = ((h - temph) // 2) * w
    num3 = (h - ((h - temph) // 2)) * w
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
    # print(kouho)

if w >= 3:
    tempw = w // 3
    num1 = tempw * h
    num2 = ((w - tempw) // 2) * h
    num3 = (w - ((w - tempw) // 2)) * h
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
    # print(kouho)

for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
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()
ans = 10 ** 10
if h >= 3:
    temph = h // 3
    num1 = temph * w
    num2 = (h - temph) // 2 * w
    num3 = (h - (h - temph) // 2) // 2 * w
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])

if w >= 3:
    tempw = w // 3
    num1 = tempw * h
    num2 = (w - tempw) // 2 * h
    num3 = (w - (w - tempw) // 2) // 2 * h
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])

for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
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()
ans = 10 ** 10
temph = h // 3
num1 = temph * w
num2 = (h - temph) // 2 * w
num3 = (h - (h - temph) // 2) // 2 * w
kouho = [num1, num2, num3]
kouho.sort()
ans = min(ans, kouho[-1] - kouho[0])

tempw = w // 3
num1 = tempw * h
num2 = (w - tempw) // 2 * h
num3 = (w - (w - tempw) // 2) // 2 * h
kouho = [num1, num2, num3]
kouho.sort()
ans = min(ans, kouho[-1] - kouho[0])

for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
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()
ans = 10 ** 10
for i in range(1, h):
    num1 = w * (i)
    num2 = (h - i) * (w // 2)
    num3 = (h - i) * (w - w // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
for i in range(1, w):
    num1 = h * (i)
    num2 = (w - i) * (h // 2)
    num3 = (w - i) * (h - h // 2)
    kouho = [num1, num2, num3]
    kouho.sort()
    ans = min(ans, kouho[-1] - kouho[0])
print(ans)

Submission status: Wrong Answer

Solution code:
h,w = list(map(int, input().split()))
ans = 10**10
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()
    
for H in range(1, h // 2 + 1):
    a = H * w
    b = (h - H) * (w // 2)
    c = (h - H) * (w - w // 2)
    ans = min(ans, max(a,b,c) - min(a,b,c))

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
h,w = list(map(int, input().split()))
ans = 10**10
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()
    
for H in range(1, h):
    a = H * w
    b = (h - H) * (w // 2)
    c = (h - H) * (w - w // 2)
    ans = min(ans, max(a,b,c) - min(a,b,c))

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

print(ans)

Submission status: Wrong Answer

Solution code:
h,w = list(map(int, input().split()))
ans = 10**10
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()
    
for H in range(1, h//2 + 1):
    a = H * w
    b = (h - H) * (w // 2)
    c = (h - H) * (w - w // 2)
    ans = min(ans, max(a,b,c) - min(a,b,c))

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

print(ans)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

h,w=ma()
if h%3==0 or w%3==0:
    print(0)
    exit()
elif h==1 or w==1:
    print(1)
    exit()
ans = 10**10+1

for a in range(1,w):
    if h%2==0:
        s1,s2 = h*a//2,h*a//2
    else:
        s1= h//2 *a
        s2= (h+1)//2 *a
    s3 = h*(w-a)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))

for b in range(1,h):
    if w%2==0:
        s1,s2 = w*b//2,w*b//2
    else:
        s1=  w//2*b
        s2= (w+1)//2*b
    s3 = w*(h-b)
    ans = min(ans,max(s1,s2,s3)-min(s1,s2,s3))
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()
def chocolate(a:int,b:int):
    if a%2==0:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            temp=min(temp,abs(x-y))
        
    else:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            z=(b-i)*(a//2+1)
            l=[x,y,z]
            s=max(l)-min(l)
            temp=min(temp,s)
        
    
    for j in range(a):
        temp2=10**12
        if (a-j)%2==0:
            x=j*b
            y=((a-j)//2)*b
            temp2=min(temp2,abs(x-y))
        else:
            x=j*b
            y=((a-j)//2)*b
            z=((a-j)//2+1)*b
            l=[x,y,z]
            temp2=min(temp2,max(l)-min(l))
    return min(temp,temp2)



print(min(chocolate(h,w),chocolate(w,h)))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
    exit()
def chocolate(a:int,b:int):
    if a%2==0:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            temp=min(temp,abs(x-y))
        return temp
    else:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            z=(b-i)*(a//2+1)
            l=[x,y,z]
            s=max(l)-min(l)
            temp=min(temp,s)
        return temp
print(min(chocolate(h,w),chocolate(w,h)))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
def chocolate(a:int,b:int):
    if a%2==0:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            temp=min(temp,abs(x-y))
        return temp
    else:
        temp=10**12
        for i in range(b+1):
            x=a*i
            y=(b-i)*(a//2)
            z=(b-i)*(a//2+1)
            l=[x,y,z]
            s=max(l)-min(l)
            temp=min(temp,s)
        return temp
print(min(chocolate(h,w),chocolate(w,h)))

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%2==0:
    x=w
    y=h
    ans1=10**12
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==0:
        x=h
        y=w
        ans2=10**12
        for i in range(0,x+1):
            a=i*y
            b=(x-i)*(y//2)
            c=(x-i)*(y//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
        
    
    else:
        x=h
        y=w
        ans2=10**12
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))



    
else:
    x=w
    y=h
    ans1=10**12
    for i in range(0,x+1):
        a=i*w
        b=(x-i)*(y//2)
        c=(x-i)*(y//2+1)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==1:
        x=h
        y=w
        ans2=10**12
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
    else:
        ans2=10**12
        for i in range(0,h+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(ans1,ans2)

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%2==0:
    x=w
    y=h
    ans1=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==0:
        ans2=10**5
        for i in range(0,h+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
        
    
    else:
        x=w
        y=h
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))



    
else:
    x=h
    y=w
    ans1=10**5
    for i in range(0,x+1):
        a=i*w
        b=(x-i)*(y//2)
        c=(x-i)*(y//2+1)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==1:
        x=w
        y=h
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
    else:
        ans2=10**5
        for i in range(0,h+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(ans1,ans2)

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%2==0:
    x=w
    y=h
    ans1=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==0:
        ans2=10**5
        for i in range(0,h+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
        
    
    else:
        x=w
        y=h
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))

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%2==0:
    x=w
    y=h
    ans1=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==0:
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
    
    else:
        x=w
        y=h
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))



    
else:
    x=h
    y=w
    ans1=10**5
    for i in range(0,x+1):
        a=i*w
        b=(x-i)*(y//2)
        c=(x-i)*(y//2+1)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans1=min(temp,ans1)
    if w%2==1:
        x=w
        y=h
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(x-i)*(y//2)
            c=(x-i)*(y//2+1)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(min(ans1,ans2))
    else:
        ans2=10**5
        for i in range(0,x+1):
            a=i*w
            b=(h-i)*(w//2)
            c=(h-i)*(w//2)
            l=[a,b,c]
            temp=max(l)-min(l)
            ans2=min(temp,ans2)

        print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
    exit()
if (min(h,w))%2==0:
    x=max(h,w)
    y=min(h,w)
    ans=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans=min(temp,ans)
    print(ans)
    
else:
    x=max(h,w)
    y=min(h,w)
    ans=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2+1)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans=min(temp,ans)
    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 (min(h,w))%2==0:
    print((min(h,w)//2))
else:
    x=max(h,w)
    y=min(h,w)
    ans=10**5
    for i in range(0,x+1):
        a=i*y
        b=(x-i)*(y//2)
        c=(x-i)*(y//2+1)
        l=[a,b,c]
        temp=max(l)-min(l)
        ans=min(temp,ans)
    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 (min(h,w))%2==0:
    print((min(h,w)//2))
else:
    print(((min(h,w))//2)*2)

Submission status: Wrong Answer

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

#横切れ2
if H%3==0:
    print(0)
    exit()
else:
    ans = min(ans, W)

#タテ2
if W%3==0:
    print(0)
    exit()
else:
    ans = min(ans, H)

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

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

print(ans)

Submission status: Wrong Answer

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

#横切れ2
if H%3==0:
    print(0)
    exit()
else:
    ans = min(ans, W)

#タテ2
if W%3==0:
    print(0)
    exit()
else:
    ans = min(ans, H)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
answer = 10**6
if H%3 == 0 or W%3 == 0:
  print(0)
else:
  # h 1 w 2
  S = H*W
  s1 = s2 = s3 = 0
  for h in range(1, H):
    s1 = h*W
    s2 = (H-h)*(W//2)
    s3 = S-s1-s2
    answer = min(answer, max(s1, s2, s3)-min(s1, s2, s3))
  for w in range(1, W):
    s1 = w*H
    s2 = (W-w)*(H//2)
    s3 = S-s1-s2
    answer = min(answer, max(s1, s2, s3)-min(s1, s2, s3))
  print(answer)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
answer = 10**6
if H%3 == 0 or W%3 == 0:
  print(0)
else:
  # h 1 w 2
  S = H*W
  s1 = s2 = s3 = 0
  for i in range(3):
    s1 = (H//3 + i)*W
    s2 = (H-(H//3+i))*(W//2)
    s3 = S-s1-s2
    answer = min(answer, max(s1, s2, s3)-min(s1, s2, s3))
  for j in range(3):
    s1 = (W//3 + j)*H
    s2 = (W-(W//3+j))*(H//2)
    s3 = S-s1-s2
    answer = min(answer, max(s1, s2, s3)-min(s1, s2, s3))
  print(answer)

Submission status: Wrong Answer

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

answer = 0


def judge(x, y):
    asn_memo = 0
    ans = 10**11
    s1 = 0
    s2 = 0
    s3 = 0
    for i in range(x//4, (2*x)//3):
        s1 = i*y
        s2 = (x-i)*(y//2)
        s3 = x*y -s1-s2
        ans_memo = max(s1, s2, s3) - min(s1, s2, s3)
        #print(s1, s2, s3)
        #print(ans_memo, ans)
        if ans_memo>ans:
            return ans
        else:
            ans = ans_memo
    return ans


def judge2(x,y):
    ans = 0
    s = 0
    if x%3 == 1:
        s1 = y*(x//3)
        ans = x*y-2*s1
    elif x%3 == 2:
        s1 = y*(x//3)
        ans = ((x*y)-s)//2
    return ans


'''
def less1(x, y):
    if x%3 == 1:
        pass




def less2(x, y):
    ans = 0
    s1 = 0
    s2 = 0
    s3 = 0
    if x <= 2:
        pass
        
'''

ans1 = judge2(h,w)
ans2 = judge2(w,h)

if h%3 == 0 or w %3 == 0:
    pass
else:
    answer = min(judge(h,w), judge(w,h), ans1, ans2)

print(answer)

Submission status: Wrong Answer

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

answer = 0


def judge(x, y):
    asn_memo = 0
    ans = 10**6
    s1 = 0
    s2 = 0
    s3 = 0
    for i in range(x//3, (2*x)//3):
        s1 = i*y
        s2 = (x-i)*(y//2)
        s3 = x*y -s1-s2
        ans_memo = max(s1, s2, s3) - min(s1, s2, s3)
        if ans_memo>=ans:
            break
        else:
            ans = ans_memo
    return ans


def judge2(x,y):
    ans = 0
    s = 0
    if x%3 == 1:
        s1 = y*(x//3)
        ans = x*y-2*s1
    elif x%3 == 2:
        s1 = y*(x//3)
        ans = ((x*y)-s)//2
    return ans


'''
def less1(x, y):
    if x%3 == 1:
        pass




def less2(x, y):
    ans = 0
    s1 = 0
    s2 = 0
    s3 = 0
    if x <= 2:
        pass
        
'''

ans1 = judge2(h,w)
ans2 = judge2(w,h)

if h % 3 == 0 or w %3 == 0:
    pass
else:
    if judge(h,w) > judge(w,h):
        answer = judge(w,h)
    else:
        answer = judge(h,w)
answer = min(answer, ans1, ans2)

print(answer)

Submission status: Wrong Answer

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

answer = 0


def judge(x, y):
    asn_memo = 0
    ans = 10**6
    s1 = 0
    s2 = 0
    s3 = 0
    for i in range(x//3, (2*x)//3):
        s1 = i*y
        s2 = (x-i)*(y//2)
        s3 = x*y -s1-s2
        ans_memo = max(s1, s2, s3) - min(s1, s2, s3)
        if ans_memo>=ans:
            break
        else:
            ans = ans_memo
    return ans
'''
def less1(x, y):
    if x%3 == 1:
        pass




def less2(x, y):
    ans = 0
    s1 = 0
    s2 = 0
    s3 = 0
    if x <= 2:
        pass
        
'''
if h % 3 == 0 or w %3 == 0:
    pass
else:
    if judge(h,w) > judge(w,h):
        answer = judge(w,h)
    else:
        answer = judge(h,w)

print(answer)

Submission status: Wrong Answer

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

answer = 0


def judge(x, y):
    asn_memo = 0
    ans = 10**5
    s1 = 0
    s2 = 0
    s3 = 0
    for i in range(x//3, (2*x)//3):
        s1 = i*y
        s2 = (x-i)*(y//2)
        s3 = x*y -s1-s2
        ans_memo = max(s1, s2, s3) - min(s1, s2, s3)
        if ans_memo>ans:
            break
        else:
            ans = ans_memo
    return ans

def less1(x, y):
    if x%3 == 1:
        pass




def less2(x, y):
    ans = 0
    s1 = 0
    s2 = 0
    s3 = 0
    if x <= 2:
        pass
        






if h % 3 == 0 or w %3 == 0:
    pass
else:
    if judge(h,w) > judge(w,h):
        answer = judge(w,h)
    else:
        answer = judge(h,w)





print(answer)

Submission status: Wrong Answer

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



def hkara(h,w):
  hans = 10**9
  for i in range(1,h):
    fst = w*i
    snd = w//2*(h-i)
    trd = (w-w//2)*(h-i)
    mx = max(max(fst,snd),trd)
    mn = min(min(fst,snd),trd)
    hans = min(mx-mn,hans)
  return hans

def wkara(h,w):
  wans = 10**9
  for i in range(1,w):
    fst = h*i
    snd = h//2*(w-i)
    trd = (h-h//2)*(w-i)
    mx = max(max(fst,snd),trd)
    mn = min(min(fst,snd),trd)
    wans = min(mx-mn,wans)
  return wans

if h*w%3==0:
  print(0)
else:
  print(min(hkara(h,w),wkara(h,w)))

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
ans,cnt=h*w,0
if h%3==0 or w%3==0:
  ans=0
else:
  for i in range(1,h):
    cnt=max((h-i)*(w%2),abs(math.floor(w/2)*(h-i)-w*i),abs(math.ceil(w/2)*(h-i)-w*i))
    ans=min(ans,cnt)
  for i in range(1,w):
    cnt=max((w-i)*(h%2),abs(math.floor(h/2)*(w-i)-h*i),abs(math.ceil(h/2)*(w-i)-h*i))
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
h,w=map(int,input().split())
ans,cnt=h*w,0
if h%3==0 or w%3==0:
  ans=0
else:
  for i in range(1,h//3+2):
    cnt=max((h-i)*(w%2),abs(math.floor(w/2)*(h-i)-w*i),abs(math.ceil(w/2)*(h-i)-w*i))
    ans=min(ans,cnt)
  for i in range(1,w//3+2):
    cnt=max((w-i)*(h%2),abs(math.floor(h/2)*(w-i)-h*i),abs(math.ceil(h/2)*(w-i)-h*i))
    ans=min(ans,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
Min = float('inf')
if H >= 3:
    Min = min(Min, (H%3)*W)
if W>=3:
    Min = min(Min, (W%3)*H)

for h in range(1,H):
    cake1 = h*W
    cake2 = (H-h)*(W//2)
    cake3 = (H-h)*(-(-W//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)


for w in range(1,W):
    cake1 = w*H
    cake2 = (W-w)*(H//2)
    cake3 = (W-w)*(-(-H//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)

print(Min)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
Min = min((H%3)*W,(W%3)*H)

for h in range(1,H):
    cake1 = h*W
    cake2 = (H-h)*(W//2)
    cake3 = (H-h)*(-(-W//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)


for w in range(1,W):
    cake1 = w*H
    cake2 = (W-w)*(H//2)
    cake3 = (W-w)*(-(-H//2))
    big = max(cake1,cake2,cake3)
    small = min(cake1,cake2,cake3)
    Min = min(Min,big-small)

print(Min)

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
print((N*M) % 3)

Submission status: Wrong Answer

Solution code:
H,W = (int(T) for T in input().split())
if H%3==0 or W%3==0:
    print(0)
elif H%2==0 or W%2==0:
    if H%2==0 and W%2==0:
        print(min(H//2,W//2))
    else:
        print([H//2,W//2][W%2==0])
else:
    if H%3==1:
        print(min(H-2*(H//3)+(W//2)+1,W-2*(W//3)+(H//2)+1))
    elif H%3==2:
        print(min(H-2*(H//3)+(W//2)-1,W-2*(W//3)+(H//2)-1))

Submission status: Wrong Answer

Solution code:
H,W = (int(T) for T in input().split())
if H%3==0 or W%3==0:
    print(0)
elif H%2==0 or W%2==0:
    print([H//2,W//2][W%2==0])
else:
    if H%3==1:
        print(H-2*(H//3)+(W//2)+1)
    if H%3==2:
        print(H-2*(H//3)+(W//2)-1)

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
if H % 3 == 0 or W % 3 == 0:
  print(0)
  exit()
  
def area_diff(idx_1,idx_2):
  a1 = W * max(0,idx_1)
  a2 = max(0,H-idx_1) * max(0,idx_2)
  a3 = max(0,H-idx_1) * max(0,W-idx_2)
  
  b1 = H * max(0,idx_1)
  b2 = max(0,W-idx_1) * max(0,idx_2)
  b3 = max(0,W-idx_1) * max(0,H-idx_2)
  
  return min(max(a1,a2,a3)-min(a1,a2,a3),max(b1,b2,b3)-min(b1,b2,b3))

def area_diff2(idx_1,idx_2):
  a1 = H*idx_1
  a2 = H*(idx_2-idx_1)
  a3 = H*(W-idx_2)
  return max(a1,a2,a3)-min(a1,a2,a3)
  
ans=10**9
delta = list(range(-10,11))

H,W=sorted([H,W])
if (H,W)==(2,2):
  print(1)
  exit()
  
idx1 = W // 3
for i in range(len(delta)):
  idx2 = idx1 + W//3
  for j in range(len(delta)):
    val = area_diff2(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
  
idx1 = H // 3
idx2 = W // 2

for i in range(len(delta)):
  for j in range(len(delta)):
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
    idx1 = W // 3
    idx2 = H // 2
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
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()
  
def area_diff(idx_1,idx_2):
  a1 = W * max(0,idx_1)
  a2 = max(0,H-idx_1) * max(0,idx_2)
  a3 = max(0,H-idx_1) * max(0,W-idx_2)
  
  b1 = H * max(0,idx_1)
  b2 = max(0,W-idx_1) * max(0,idx_2)
  b3 = max(0,W-idx_1) * max(0,H-idx_2)
  
  return min(max(a1,a2,a3)-min(a1,a2,a3),max(b1,b2,b3)-min(b1,b2,b3))

def area_diff2(idx_1,idx_2):
  a1 = H*idx_1
  a2 = H*(idx_2-idx_1)
  a3 = H*(W-idx_2)
  return max(a1,a2,a3)-min(a1,a2,a3)
  
ans=10**9
delta = [-2,-1,0,1,2]

H,W=sorted([H,W])
if (H,W)==(2,2):
  print(1)
  exit()
  
idx1 = W // 3
for i in range(len(delta)):
  idx2 = idx1 + W//3
  for j in range(len(delta)):
    val = area_diff2(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
  
idx1 = H // 3
idx2 = W // 2

for i in range(len(delta)):
  for j in range(len(delta)):
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
    idx1 = W // 3
    idx2 = H // 2
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
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()
  
idx1 = H // 3
idx2 = W // 2
delta = list(range(-10,11))

def area_diff(idx_1,idx_2):
  a1 = W * max(0,idx_1)
  a2 = max(0,H-idx_1) * max(0,idx_2)
  a3 = max(0,H-idx_1) * max(0,W-idx_2)
  
  b1 = H * max(0,idx_1)
  b2 = max(0,W-idx_1) * max(0,idx_2)
  b3 = max(0,W-idx_1) * max(0,H-idx_2)
  
  return min(max(a1,a2,a3)-min(a1,a2,a3),max(b1,b2,b3)-min(b1,b2,b3))

ans=10**9
for i in range(len(delta)):
  for j in range(len(delta)):
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
    idx1 = W // 3
    idx2 = H // 2
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
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()
  
idx1 = H // 3
idx2 = W // 2
delta = [-2,-1,0,1,2]

def area_diff(idx_1,idx_2):
  a1 = W * max(0,idx_1)
  a2 = max(0,H-idx_1) * max(0,idx_2)
  a3 = max(0,H-idx_1) * max(0,W-idx_2)
  
  b1 = H * max(0,idx_1)
  b2 = max(0,W-idx_1) * max(0,idx_2)
  b3 = max(0,W-idx_1) * max(0,H-idx_2)
  
  return min(max(a1,a2,a3)-min(a1,a2,a3),max(b1,b2,b3)-min(b1,b2,b3))

ans=10**9
for i in range(5):
  for j in range(5):
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
    idx1 = W // 3
    idx2 = H // 2
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
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()
  
idx1 = H // 3
idx2 = W // 2
delta = [-2,-1,0,1,2]

def area_diff(idx_1,idx_2):
  a1 = W * max(0,idx_1)
  a2 = max(0,H-idx_1) * max(0,idx_2)
  a3 = max(0,H-idx_1) * max(0,W-idx_2)
  
  b1 = H * max(0,idx_1)
  b2 = max(0,W-idx_1) * max(0,idx_2)
  b3 = max(0,W-idx_1) * max(0,H-idx_2)
  
  return min(max(a1,a2,a3)-min(a1,a2,a3),max(b1,b2,b3)-min(b1,b2,b3))

ans=10**9
for i in range(5):
  for j in range(5):
    val = area_diff(idx1+delta[i],idx2+delta[j])
    ans = min(ans, val)
    
print(ans)