Problem: p03713
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
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)


Failing test case input:
101111 000001

Expected output:
1


Actual output:
50556


Fixed submission (verdict: Accepted):
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,h,w)
  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,h,w)
print(ans)

Problem: p03713
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

def main(H,W):
    ans = float('inf')
    w = math.floor(W / 2)
    for i in range(H):
        Smin = min(i * W, w * (H - i), (W - w) * (H - i))
        Smax = max(i * W, w * (H - i), (W - w) * (H - i))
        ans = min(ans, Smax-Smin)
    return ans

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

Failing test case input:
100111 000101

Expected output:
101


Actual output:
50089


Fixed submission (verdict: Accepted):
import math

def main(H,W):
    ans = float('inf')
    w = math.floor(W / 2)
    for i in range(H):
        Smin = min(i * W, w * (H - i), (W - w) * (H - i))
        Smax = max(i * W, w * (H - i), (W - w) * (H - i))
        ans = min(ans, Smax-Smin)
    return min(H,ans)

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

Problem: p03713
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math

H,W = map(int, input().split()) 

def func(h,w,ans):
    for i in range(1,h+1):
        a = i * w 
        w1 = int(w/2)
        b = (h-i)*w1
        c = (h-i)*(w-w1)
        M = max(a,b,c)
        m = min(a,b,c)
        s = M-m
        ans = min(s,ans)

        h1 = int(h/3)
        a = h1*w
        c = (h-2*h1)*w
        s = abs(a-c)
        ans = min(s,ans)
    return ans

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

ans = float('inf')

ans = func(H,W,ans)
ans = func(W,H,ans)

print(ans)

Failing test case input:
011111 100100

Expected output:
11111


Actual output:
22222


Fixed submission (verdict: Accepted):
import math

H,W = map(int, input().split()) 

def func(h,w,ans):
    for i in range(1,h+1):

        if((h-i) % 2 == 0): 
            a = i*w
            b = ( (h-i)
            s = abs(a-b)
            ans = min(s,ans)
    
        else:
            a = i * w 
            w1 = w
            b = (h-i)*w1
            c = (h-i)*(w-w1)
            M = max(a,b,c)
            m = min(a,b,c)
            s = M-m
            ans = min(s,ans)
    return ans

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

ans = float('inf')

ans = func(H,W,ans)
ans = func(W,H,ans)

print(ans)