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: Runtime Error

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

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

Submission status: Runtime Error

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

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

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

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

print(min(ans))

Submission status: Runtime Error

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

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

m = math.inf
m = min(m, (1 if h % 3 else 0) * w)
m = min(m, (1 if w % 3 else 0) * h)
for _ in range(2):
    for i in range(1, h+1):
        v = np.array([i*w, w//2*(h-i), (w-w//2)*(h-i)])
        m = min(m, max(v) - min(v))
    h, w = w, h

print(m)

Submission status: Runtime Error

Solution code:
N = sys.stdin.readline().replace('\n','')
N = int(N)

def Func(a,b):
	if a > b:
		return digit(a)
	else: return digit(b)
		
def digit(num):
	d = len(str(num))
	return d

ans = 10

for i in range(1,N):
	if i*i > N: break
	if N % i == 0:
		dum = Func(N//i,i)
		if ans > dum:
			ans = dum

print(ans)

Submission status: Runtime Error

Solution code:
def calc(ox, oy):
    if(ox % 3 == 0):
        return 0
    s1 = s2 = s3 = 10 ** 10
    ans = 10 * 10
    for i in range(0,ox):
        s1 = i * oy
        s2 = (ox - i) * (oy // 2)
        s3 = (ox - i) * (oy - oy // 2)
        ans_ = max(s1, s2, s3) - min(s1, s2, s3)
        if(ans < ans_):
            return ans
        else:
            ans = ans_
H, W = map(int, input().split())
print(min(calc(H,W), calc (W,H)))

Submission status: Runtime Error

Solution code:
def calc(ox, oy):
    s1 = s2 = s3 = 10 ** 10
    ans = 10 * 10
    for i in range(0,ox):
        s1 = i * oy
        s2 = (ox - i) * (oy // 2)
        s3 = (ox - i) * (oy - oy // 2)
        ans_ = max(s1, s2, s3) - min(s1, s2, s3)
        if(ans < ans_):
            return ans
        else:
            ans = ans_
H, W = map(int, input().split())
print(min(calc(H,W), calc (W,H)))

Submission status: Runtime Error

Solution code:
import math
import sys

T = list(map(int, input().split()))
S = T[0] * T[1]

if ((T[0] % 3 == 0) or (T[1] % 3 == 0)):
    print(0)
    sys.exit()

minS = 100000000
#T[0]からせめる
for i in range(1, math.ceil(T[0]/2)):
    A = i * T[1]
    F = math.floor(T[1] / 2) * (T[0] - i)
    C = S - (A + F)
    if (F == C):
        minS = min(minS, abs(A - F))
        continue
    else:
        if (A > C):
            minS = min(minS, abs(A - F))
        elif(C >= A and A >= F):
            minS = min(minS, abs(C - F))
        else:
            minS = min(minS, abs(C - A))
--------
    A = i * T[0]
    F = math.floor(T[0] / 2) * (T[1] - i)
    C = S - (A + F)
    if (F == C):
        minS = min(minS, abs(A - F))
        continue
    else:
        if (A > C):
            minS = min(minS, abs(A - F))
        elif(C >= A and A >= F):
            minS = min(minS, abs(C - F))
        else:
            minS = min(minS, abs(C - A))

for i in range(1, math.ceil(T[1]/2)):
    A = i * T[1]
    F = math.floor(T[1] / 2) * (T[0] - i)
    C = S - (A + F)
    if (F == C):
        minS = min(minS, abs(A - F))
        continue
    else:
        if (A > C):
            minS = min(minS, abs(A - F))
        elif(C >= A and A >= F):
            minS = min(minS, abs(C - F))
        else:
            minS = min(minS, abs(C - A))
    A = i * T[0]
    F = math.floor(T[0] / 2) * (T[1] - i)
    C = S - (A + F)
    if (F == C):
        minS = min(minS, abs(A - F))
        continue
    else:
        if (A > C):
            minS = min(minS, abs(A - F))
        elif(C >= A and A >= F):
            minS = min(minS, abs(C - F))
        else:
            minS = min(minS, abs(C - A))

print(minS)

Submission status: Runtime Error

Solution code:
def check_s(tmp1, tmp2, tmp3):
    S_min = 2 ** 50
    S_max = 0
    S_min = min(S_min, tmp1, tmp2, tmp3)
    S_max = max(S_max, tmp1, tmp2, tmp3)
    return S_max - S_min

if __name__ == "__main__":
    H,W = map(int, input().split())
    if (H > W):
        H,W = W,H
    if (H % 3 == 0 or W % 3 == 0):
        print (0)
        exit()
    if (H == 2 and W == 2):
        print (1)
        exit()
    H1 = H // 2
    H2 = H - H1
    W1 = W // 2
    W2 = W - W1
    result = 2 ** 50
    result = min(result, check1(H1, H2, W1, W2))
    result = min(result, check2(H1, H2, W1, W2))
    result = min(result, check3(H1, H2, W1, W2))
    result = min(result, check4(H1, H2, W1, W2))

    for x in range(1, W + 1):
        H1 = H // 2
        H2 = H - H1

        W1 = x
        W2 = W - W1

        W3 = W2 // 2
        W4 = W2 - W3

        tmp1 = W1 * H
        tmp2 = W3 * H
        tmp3 = W4 * H

        result = min(result, check_s(tmp1, tmp2, tmp3))
        tmp1 = W1 * H
        tmp2 = W2 * H1
        tmp3 = W2 * H2
        result = min(result, check_s(tmp1, tmp2, tmp3))

    for y in range(1,  H+ 1):
        H1 = y
        H2 = H - H1

        H3 = H2 // 2
        H4 = H3 - H2

        W1 = W // 2
        W2 = W - W1


        tmp1 = H1 * W
        tmp2 = H3 * W
        tmp3 = H4 * W

        result = min(result, check_s(tmp1, tmp2, tmp3))
        tmp1 = H1 * W
        tmp2 = H2 * W1
        tmp3 = H2 * W2
        result = min(result, check_s(tmp1, tmp2, tmp3))


    print (result)

Submission status: Runtime Error

Solution code:
def check1(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = H1 * W1
    res2 = H1 * W2
    res3 = H2 * (W1 + W2)
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check2(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = H1 * (W1 + W2)
    res2 = H2 * (W1)
    res3 = H2 * W2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check3(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = W1 * (H1 + H2)
    res2 = W2 * H1
    res3 = W2 * H2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check4(H1, H2, W1, W2):
    S_min = 2 ** 50
    S_max = 0
    res1 = W2 * (H1 + H2)
    res2 = W1 * H1
    res3 = W1 * H2
    S_min = min(S_min, res1)
    S_min = min(S_min, res2)
    S_min = min(S_min, res3)
    S_max = max(S_max, res1)
    S_max = max(S_max, res2)
    S_max = max(S_max, res3)
    return S_max - S_min

def check_s(tmp1, tmp2, tmp3):
    S_min = 2 ** 50
    S_max = 0
    S_min = min(S_min, tmp1, tmp2, tmp3)
    S_max = max(S_max, tmp1, tmp2, tmp3)
    return S_max - S_min

if __name__ == "__main__":
    H,W = map(int, input().split())
    if (H > W):
        H,W = W,H

    for x in range(1, W + 1):
        H1 = H // 2
        H2 = H - H1

        W1 = x
        W2 = W - W1

        W3 = W2 // 2
        W4 = W2 - W3

        tmp1 = W1 * H
        tmp2 = W3 * H
        tmp3 = W4 * H

        result = min(result, check_s(tmp1, tmp2, tmp3))
        tmp1 = W1 * H
        tmp2 = W2 * H1
        tmp3 = W2 * H2
        result = min(result, check_s(tmp1, tmp2, tmp3))

    print (result)

Submission status: Runtime Error

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(a1, b1, area - a1 - b1))) for a, b in tup]
    print(min(lst))

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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
    a = i * p
    b = i // 2 * (j - p)
    c = i * q - (i // 2 * (j - q))

    print(min(abs(a - b), abs(c))

Submission status: Runtime Error

Solution code:
h, w = [int(n) for n in input().split()]
i,j = [h,w].sort()
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: Runtime Error

Solution code:
h, w = [int(n) for n in ipt[:1]]
i,j = [h,w].sort()
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: Runtime Error

Solution code:
y, x = map(int, input().split())
if(x % 3 == 0 or y % 3 == 0):
    print(0)
else:
     if(x < y):
        x1 = x % 3
        x2 = x - x1
        y1 = y // 2
        print(x1 * y - x2 * y1)
    else:
        y1 = y % 3
        y2 = y - y1
        x1 = x // 2
        print(y1 * x - y2 * x1)

Submission status: Runtime Error

Solution code:
    y, x = map(int, input().split())
    if(x % 3 == 0 or y % 3 == 0):
        print(0)
    else:
        if(x < y):
            x1 = x % 3
            x2 = x - x1
            y1 = y // 2
            print(x1 * y - x2 * y1)
        else:
            y1 = y % 3
            y2 = y - y1
            x1 = x // 2
            print(y1 * x - y2 * x1)

Submission status: Runtime Error

Solution code:
def paralell_divide(H, W):
    return 0 if W % 3 == 0 else H

def perpendicular_divide(H, W):
    if W % 2 == 0:
        return W / 2
    a = (H - 1) / 3 if H % 3 == 1 else (H + 1) / 3
    b = (W + 1) / 2 * (H - a)
    c = (W - 1) / 2 * (H - a)
    a = a * W
    return max(a, b, c) - min(a, b, c)

H, W = map(int, input().strip().split(' '))
print min(parallel_divide(H, W), parallel_divide(W, H), perpendicular_divide(H, W), perpendicular_divide(W, H))

Submission status: Runtime Error

Solution code:
//h w
//abc
//arc
#include <iostream>
#include <string>
using namespace std;
int main(){
 int h, w;
 cin >> h >> w;
 string result = "";
 for(int i = 0; i < w + 2; i++) result += "#";
 result += "\n";
 for(int i = 0; i < h; i++){
  string s; cin >> s;
  result += "#" + s + "#\n";
 }
 for(int i = 0; i < w + 2; i++) result += "#";
 result += "\n";
 cout << result << endl;
}

Submission status: Runtime Error

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  #右側面積
        if a1 > a2: #左側面積のほうが大きいとき
            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
        else :
            for j in range(i:W):#さらに縦割り
                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: Runtime Error

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: Runtime Error

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)
print (s)

Submission status: Runtime Error

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

for h in range(1, H-1)
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a1 = []
	a1.append(D)
	A1 = min(a1)

for h in range(1, H-1)
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a2 = []
	a2.append(D)
	A2 = min(a2)

H, W = W, H

for h in range(1, H-1)
	A = h * W
	B = int((H - h)//2) * W
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a3 = []
	a3.append(D)
	A3 = min(a3)

for h in range(1, H-1)
	A = h * W
	B = int(W//2) * (H - h)
	C = H * W - (A + B)
	D = max(A, B ,C) - min(A, B, C)
	a4 = []
	a4.append(D)
	A4 = min(a4)

print(int(min(A1, A2, A3, A4)))

Submission status: Runtime Error

Solution code:
H, W = map(int, raw_input().split())
best = H * W
for h in range(H):
    S[0] = h * W

    S[1] = (H - h) * (W / 2)
    S[2] = (H - h) * (W - W / 2)

    if best > max(S) - min(S):
        best = max(S) - min(S)

    S[1] = (H - h) / 2 * W
    S[2] = (H - h - (H - h) / 2) * W

    if best > max(S) - min(S):
        best = max(S) - min(S)
H, W = W, H
for h in range(H):
    S[0] = h * W

    S[1] = (H - h) * (W / 2)
    S[2] = (H - h) * (W - W / 2)

    if best > max(S) - min(S):
        best = max(S) - min(S)

    S[1] = (H - h) / 2 * W
    S[2] = (H - h - (H - h) / 2) * W

    if best > max(S) - min(S):
        best = max(S) - min(S)

print best

Submission status: Runtime Error

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

if x % 3 == 0 :
  print (0)
elif y % 3 == 0 :
  print (0)
else :
  if y > x :
    z = y
    y = x
    x = z

  a = int(x / 3) + 1
  if y % 2 == 0 :
    a = a - 1
    s = a * y
    #print (s)

    t = int((x - a) * y / 2)
    #print (t)
    if t > s :
      print (t - s)
    else
      print (s - t)
  else :
    s = a * y
    #print (s)

    x = x - a
  
    if y > x :
      z = y
      y = x
      x = z
  
    b = int(x / 2)
    t = b * y
    #print (t)

    print (s - t)

Submission status: Runtime Error

Solution code:
n = input()
tmp_n = n.split(" ")

h = int(tmp_n[0])
w = int(tmp_n[1])

if h%3==0 or w%3==0:
    print("0")
else:
    len_area1 = int(max(h,w)/3)+1
    len_area2 = int(max(h,w)/3)

    tmp_area_a1 = min(h,w)*len_area1
    tmp_area_a111 = (max(h,w)-len_area1) * int(min(h,w)/2)
    tmp_area_a112 = (max(h,w)-len_area1) * int(min(h,w)/2+1)
    tmp_area_aa = max(abs(tmp_area_a1-tmp_area_a111),abs(tmp_area_a1-tmp_area_a112),abs(tmp_area_a121-tmp_area_a112))
    tmp_area_a121 = int((max(h,w)-len_area1)/2) * min(h,w)
    tmp_area_a122 = int((max(h,w)-len_area1)/2+1) * min(h,w)
    tmp_area_ab = max(abs(tmp_area_a1-tmp_area_a121),abs(tmp_area_a1-tmp_area_a122),abs(tmp_area_a121-tmp_area_a122))

    tmp_area_b1 = min(h,w)*len_area2
    tmp_area_b111 = (max(h,w)-len_area2) * int(min(h,w)/2)
    tmp_area_b112 = (max(h,w)-len_area2) * int(min(h,w)/2+1)
    tmp_area_ba = max(abs(tmp_area_b1-tmp_area_b111),abs(tmp_area_b1-tmp_area_b112),abs(tmp_area_b121-tmp_area_b112))
    tmp_area_b121 = int((max(h,w)-len_area2)/2) * min(h,w)
    tmp_area_b122 = int((max(h,w)-len_area2)/2+1) * min(h,w)
    tmp_area_bb = max(abs(tmp_area_b1-tmp_area_b121),abs(tmp_area_b1-tmp_area_b122),abs(tmp_area_b121-tmp_area_b122))
    #print(abs(tmp_area_a1-tmp_area_a11),tmp_area_a2,abs(tmp_area_b1-tmp_area_b11),tmp_area_b2)

    tmp_dis1 = min(tmp_are_aa,tmp_area_ab)
    tmp_dis2 = min(tmp_area_ba,tmp_area_bb)
    dis_area = min(tmp_dis1,tmp_dis2)
    print(dis_area)

Submission status: Runtime Error

Solution code:
H,W=(int(i) for i in input (). split ())
if H%3==0 or W%3==0:
    print (0)
else:
    if H<W:
        T=H
        H=W
        W=H
   W1=W//3

Submission status: Runtime Error

Solution code:
n,m=list(map(int, input().split()))
lll = []
a = n
b = m
if (n * m) % 3 == 0:
    print(0)
else:
    for i in range(1, a):
        p = b * i

        if b % 2 == 1:
            q = (a - i) * (int(b / 2) + 1)
        elif b % 2 == 0:
            q = (a - i) * (int(b / 2))
        r = (a - i) * (int(b / 2))

        if a - i % 2 == 1:
            q2 = b * (int((a - i) / 2) + 1)
        elif (a - i) % 2 == 0:
            q2 = b * (int((a - i) / 2))

        r2 = b * (int((a - i) / 2))

        lll.append(min(max(p, q, r) - min(p, q, r), max(p, q2, r2) - min(p, q2, r2)))

    temp = b
    b = a
    a = temp
    for i in range(1, a):
        p = b * i

        if b % 2 == 1:
            q = (a - i) * (int(b / 2) + 1)
        elif b % 2 == 0:
            q = (a - i) * (int(b / 2))
        r = (a - i) * (int(b / 2))

        if a - i % 2 == 1:
            q2 = b * (int((a - i) / 2) + 1)
        elif (a - i) % 2 == 0:
            q2 = b * (int((a - i) / 2))

        r2 = b * (int((a - i) / 2))

        lll.append(min(max(p, q, r) - min(p, q, r), max(p, q2, r2) - min(p, q2, r2)))


    print(min(lll))

Submission status: Runtime Error

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

if h%3 == 0 or w%3 == 0:
    print (0)
elif (high/3) > low:
    print ((high % 3)*low
else:
    a = math.ceil(high/3)*low
    b = (high-math.ceil(high/3))*int(low/2)
    c = abs(a-b)

    a = round(high/3)*low
    b = (high-round(high/3))*int(low/2)
    d = abs(a-b)

    print (min(c, d))

Submission status: Runtime Error

Solution code:
n,m=list(map(int, input().split()))
lll = []
a = n
b = m
if (n * m) % 3 == 0:
    print(0)
else:
    for i in range(1, a):
        p = b * i
        
        if b % 2 == 1:
            q = (a - i) * (int(b / 2) + 1)
        elif b % 2 == 0:
            q = (a - i) * (int(b / 2))
        r = (a - i) * (int(b / 2))
        
        if a - i % 2 == 1:
            q2 = b * (int((a - i) / 2) + 1)
        elif (a- i) % 2 == 0:
            q2 = b * (int(a - i) / 2)

        r2 = b * (int(a - i) / 2)
        
        lll.append(min(max(p, q, r) - min(p, q, r), max(p, q2, r2) - min(p, q2, r2)))

    temp = b
    b = a
    a = temp
    for i in range(1, a):
        p = b * i

        if b % 2 == 1:
            q = (a - i) * (int(b / 2) + 1)
        elif b % 2 == 0:
            q = (a - i) * (int(b / 2))
        r = (a - i) * (int(b / 2))

        if a - i % 2 == 1:
            q2 = b * (int((a - i) / 2) + 1)
        elif (a - i) % 2 == 0:
            q2 = b * (int(a - i) / 2)

        r2 = b * (int(a - i) / 2)

        lll.append(min(max(p, q, r) - min(p, q, r), max(p, q2, r2) - min(p, q2, r2)))


    print(min(lll))

Submission status: Runtime Error

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

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

elif H%3==W%3:
  if H <= W:
    a = (H*(W/2)) - (H/2*(W/2+1))
    b = ((W/3+1) - (W/3))*H
    if a > b:
      print(int(b))
    else:
      print(int(a))

  else:
    a = (W*(H/2)) - (W/2*(H/2+1))
    b = ((H/3+1) - (H/3))*W
    if a > b:
      print(int(b))
    else:
      print(int(a))
 
else:

Submission status: Runtime Error

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

#一回目
BS = H * W // 3
for i in range(W):
 if H * i >= BS:
  BW = i
  break

for i in range(H):
 if W * i >= BS:
  BH = i
  break

if BH * W - BS > BW * H - BS:
 S1 = BW * H
 BS2 = (H * W - BW * H) // 2
 for i in range(W - BW):
  if H * i >= BS2:
   BH2 = i
   break
 for i in range(H):
  if (W - BW) * i >= BS2:
   BW2 = i
   break
 S2 = min(BH2 * (W - BW) - BS2, BW2 * H - BS2) +BS2
 S3 = min(BH2 * (W - BW) - BS2, BW2 * H - BS2) +BS2

else:
 S1 = W * BH
 BS2 = (H * W - W * BH) // 2
 for i in range(W):
  if (H - BH) * i >= BS2:
   BW2 = i
   break
 for i in range(H -BH):
  if W * i >= BS2:
   BH2 = i
   break
 S2 = min(BH2 * W - BS2, BW2 * (H - BH) - BS2) +BS2
 S3 = min(BH2 * W - BS2, BW2 * (H - BH) - BS2) +BS2

Smax = max(S1, S2, S3)
Smin = min(S1, S2, S3)
Answer = Smax - Smin
print(Answer)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())

area = [0,0,0]
ans = 999999999999
if(h%3 == 0 or w%3 == 0):
    print('0')
    exit(1)
for i in range(1,h/2+1):
    area[0] = i*w
    area[1] = (w/2)*(h-i)
    area[2] = (w-w/2)*(h-i)
    S = max(area)-min(area)
    if(S<ans):
        ans = S
    
for i in range(1,w/2+1):
    area[0] = i*h
    area[1] = (h/2)*(w-i)
    area[2] = (h-h/2)*(w-i)
    S = max(area)-min(area)
    if(S<ans):
        ans = S
print(ans)

Submission status: Runtime Error

Solution code:
h,w = sorted(list(map(int,input().split())))
if h % 3 == 0 or w % 3 == 0:
  ret = 0
else:
  c1 = ((w//3+1)*h)-((w-1-w//3)*(h//2)
  c2 = ((w-w//3)*(h-h//2))-(w//3*h)
  c3 = ((w-w//3)*(h-h//2))-((w-w//3)*(h//2))
  ret = min(c1,c2,c3)
print(ret)

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
if H%3==0 or W%3==0:
    print(0)
else:
    a = int(W/2)*H
    b = int(H/2)*(W-int(W/2))
    c = H*W-a-b
    d1 = max([a,b,c])-min([a,b,c])
    e = int(H/2)*W
    f = int(W/2)*(H-int(H/2))
    g = H*W-a-b
    d2 = max([e,f,g])-min([e,f,g])
print(min([d1,d2]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())

a,b,c = 0,0,0
diff =[0,0,0]   
ans = 999999999999
if(h%3 == 0 or w%3 == 0):
    print('0')
    exit(1)
for i in range(1,h/2+1):
    a = i*w
    b = (w/2)*(h-i)
    c = (w-w/2)*(h-i)
    diff = abs(a-b),abs(a-c),abs(b-c)
    S = max(diff)-min(diff)
    if(S<ans):
        ans = S
    
    
for i in range(1,w/2+1):
    a = i*h
    b = (h/2)*(w-i)
    c = (h-h/2)*(w-i)
    diff = abs(a-b),abs(a-c),abs(b-c)
    S = max(diff)-min(diff)
    if(S<ans):
        ans = S
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
x,y=map(int,input().split())
data=[]
if (x*y)%3==0:
    print(0)
else:
    for i in range(1,max(x,y)):
        a=i*min(x,y)
        if (x*y-a)%2==0:
            data.append(max(a,(x*y-a)//2)-min(a,(x*y-a)//2))
        else:
            b=((x*y-a)/2)-0.5*(max(x,y)-i)
            c=((x*y-a)/2)+0.5*(max(x,y)-i)
            data.append(max(a,b,c)-min(a,b,c))
print(int(min(data)))