qyliang/CodeNanoFix huggingface dataset:
Buggy code:
h,w = map(int,input().split())
if (h%3 == 0) or (w%3 == 0):
  print(0)
else:
  ans = h*w
  for i in range(1,max(h,w)//2):
    a = min(h,w)*i
    b = (max(h,w)-i)*(min(h,w)//2)
    if min(h,w)%2 != 0:
      c = (max(h,w)-i)*(min(h,w)//2 + 1)
    else:
      c = b
    kari = max(a,b,c)-min(a,b,c)
    if ans > kari:
      ans = kari
  ans2 = ((max(h,w)//3 + 1)*min(h,w))-((max(h,w)//3)*min(h,w))
  print(min(ans,ans2))

Fixed code:
h,w = map(int,input().split())
if (h%3 == 0) or (w%3 == 0):
  print(0)
else:
  ans = h*w
  for i in range(1,max(h,w)//2 + 1):
    a = min(h,w)*i
    b = (max(h,w)-i)*(min(h,w)//2)
    if min(h,w)%2 != 0:
      c = (max(h,w)-i)*(min(h,w)//2 + 1)
    else:
      c = b
    kari = max(a,b,c)-min(a,b,c)
    if ans > kari:
      ans = kari
  ans3 = h*w
  for i in range(1,min(h,w)//2 + 1):
    a = max(h,w)*i
    b = (min(h,w)-i)*(max(h,w)//2)
    if max(h,w)%2 != 0:
      c = (min(h,w)-i)*(max(h,w)//2 + 1)
    else:
      c = b
    kari = max(a,b,c)-min(a,b,c)
    if ans3 > kari:
      ans3 = kari
  ans2 = ((max(h,w)//3 + 1)*min(h,w))-((max(h,w)//3)*min(h,w))
  print(min(ans,ans2,ans3))
Buggy code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

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

if H%3 == 0:
    print(0)
elif W%3 == 0:
    print(0)
else:
    ans = H*W
    A = [0]*3
    for i in range(1,H):
        A[0] = i*W
        A[1] = (H-i)*(W//2)
        A[2] = (H-i)*(W-W//2)
        A.sort()
        ans = min(ans,A[2]-A[0])
    
    for j in range(1,W):
        A[0] = H*j
        A[1] = (H//2)*(W-j)
        A[2] = (H-H//2)*(W-j)
        A.sort()
        ans = min(ans,A[2]-A[0])

    ans = min(ans, H*(W//3), (H//3)*W)

    print(ans)

Fixed code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

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

if H%3 == 0:
    print(0)
elif W%3 == 0:
    print(0)
else:
    ans = H*W
    A = [0]*3
    for i in range(1,H):
        A[0] = i*W
        A[1] = (H-i)*(W//2)
        A[2] = (H-i)*(W-W//2)
        A.sort()
        ans = min(ans,A[2]-A[0])
    
    for j in range(1,W):
        A[0] = H*j
        A[1] = (H//2)*(W-j)
        A[2] = (H-H//2)*(W-j)
        A.sort()
        ans = min(ans,A[2]-A[0])

    ans = min(ans, H, W)

    print(ans)
Buggy code:
H,W=map(int, input().split())
a=10**10
S=H*W
s=[None]*3
for i in range(W):
    s[0]=H*i
    s[1]=(W-i)//2*H
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
    s[1]=H//2*(W-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
for i in range(H):
    s[0]=W*i
    s[1]=(H-i)//2*W
    a=min(a,max(s)-min(s))
    s[1]=W//2*(H-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
print(a)

Fixed code:
H,W=map(int, input().split())
a=10**10
S=H*W
s=[None]*3
for i in range(W):
    s[0]=H*i
    s[1]=(W-i)//2*H
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
    s[1]=H//2*(W-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
for i in range(H):
    s[0]=W*i
    s[1]=(H-i)//2*W
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
    s[1]=W//2*(H-i)
    s[2]=S-s[0]-s[1]
    a=min(a,max(s)-min(s))
print(a)
Buggy code:
h,w=map(int,input().split())
ans=10**9
for i in range(1,w):
  ans=min(abs(i*h-h//2*(w-i)),ans)
for i in range(1,h):
  ans=min(abs(i*w-w//2*(h-i)),ans)
if h%3==0 or w%3==0:
  ans=0
else:
  ans=min(ans,h,w)
print(ans)

Fixed code:
h,w=map(int,input().split())
ans=10**9
for i in range(1,w):
  ans=min(max(abs(i*h-h//2*(w-i)),abs(i*h-(h+1)//2*(w-i)),((h+1)//2-h//2)*(w-i)),ans)
for i in range(1,h):
  ans=min(max(abs(i*w-w//2*(h-i)),abs(i*w-(w+1)//2*(h-i)),((w+1)//2-w//2)*(h-i)),ans)
if h%3==0 or w%3==0:
  ans=0
else:
  ans=min(ans,h,w)
print(ans)
Buggy code:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

def calc(main,sub):
    if main%3==1:
        a=main//3
    else:
        a=main//3+1
    b=sub//2
    temp=[a*sub,(main-a)*b,(main-a)*(sub-b)]
    
    return max(temp)-min(temp)
        

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(H,W),calc(W,H),sub,main))
    


Fixed code:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())

def calc(main,sub):
    if main%3==1:
        a=main//3
    else:
        a=main//3+1
    b=sub//2
    temp=[a*sub,(main-a)*b,(main-a)*(sub-b)]
    
    return max(temp)-min(temp)
        

if H%3==0 or W%3==0:
    print(0)
else:
    print(min(calc(H,W),calc(W,H),H,W))
Buggy code:
x,y = map(int,input().split())
if x%3 == 0 or y%3 == 0:
    print(0)
    exit()
ans = []
ans.append(x)
ans.append(y)
a1 = x//3
a2 = x-a1
b1 = y//2
b2 = y-y//2
ans.append(max(a1*y,a2*b1,a2*b2)-min(a1*y,a2*b1,a2*b2))
a1 = x//3+1
a2 = x-a1
ans.append(max(a1*y,a2*b1,a2*b2)-min(a1*y,a2*b1,a2*b2))
print(min(ans))

Fixed code:
x,y = map(int,input().split())
if x%3 == 0 or y%3 == 0:
    print(0)
    exit()
ans = []
ans.append(x)
ans.append(y)
for x,y in (x,y),(y,x):
    a1 = x//3
    a2 = x-a1
    b1 = y//2
    b2 = y-y//2
    ans.append(max(a1*y,a2*b1,a2*b2)-min(a1*y,a2*b1,a2*b2))
    a1 = x//3+1
    a2 = x-a1
    ans.append(max(a1*y,a2*b1,a2*b2)-min(a1*y,a2*b1,a2*b2))
print(min(ans))
Buggy code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
ans = H * W
for i in range(2):
    for h in range(1, H):
        s = [h * W, W // 2 * (H - h), (W - W // 2) * (H - h)]
        s2 = [h * W, (H - h) // 2 * W]
        ans = min(ans, min(max(s) - min(s), max(s2) - min(s2)))
    H, W = W, H
print(ans)


Fixed code:
H, W = map(int, input().split())
if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()
ans = H * W
for i in range(2):
    for h in range(1, H):
        s = [h * W, W // 2 * (H - h), (W - W // 2) * (H - h)]
        s2 = [h * W, (H - h) // 2 * W, ((H - h) - (H - h) // 2) * W]
        ans = min(ans, min(max(s) - min(s), max(s2) - min(s2)))
    H, W = W, H
print(ans)
Buggy code:
import sys
import math
h,w=map(int,input().split())
x=max(h,w)
y=min(h,w)

ans=x*y

for i in range(1,x):
    x1=i
    
    x2=(x-x1)//2
    x3=x-x1-x2
    s1=x1*y
    s2=x2*y
    s3=x3*y
    a_yoko=max(s1,s2,s3)-min(s1,s2,s3)
    
    y2=y//2
    y3=y-y2
    x2=x-x1
    x3=x2
    y1=y
    
    s1=x1*y1
    s2=x2*y2
    s3=x3*y3
    a_tate=max(s1,s2,s3)-min(s1,s2,s3)
    
    ans=min(a_yoko,a_tate,ans)
print(ans)    

Fixed code:
import sys
import math
h,w=map(int,input().split())
x=h
y=w

ans=x*y

for i in range(1,x):
    x1=i
    
    x2=(x-x1)//2
    x3=x-x1-x2
    s1=x1*y
    s2=x2*y
    s3=x3*y
    a_yoko=max(s1,s2,s3)-min(s1,s2,s3)
    
    y2=y//2
    y3=y-y2
    x2=x-x1
    x3=x2
    y1=y
    
    s1=x1*y1
    s2=x2*y2
    s3=x3*y3
    a_tate=max(s1,s2,s3)-min(s1,s2,s3)
    
    ans=min(a_yoko,a_tate,ans)

x=w
y=h
 
for i in range(1,x):
    x1=i
    
    x2=(x-x1)//2
    x3=x-x1-x2
    s1=x1*y
    s2=x2*y
    s3=x3*y
    a_yoko=max(s1,s2,s3)-min(s1,s2,s3)
    
    y2=y//2
    y3=y-y2
    x2=x-x1
    x3=x2
    y1=y
    
    s1=x1*y1
    s2=x2*y2
    s3=x3*y3
    a_tate=max(s1,s2,s3)-min(s1,s2,s3)
    
    ans=min(a_yoko,a_tate,ans)
    
print(ans)
Buggy code:
h, w = map(int, input().split())

s_org = h * w

answer = h * w
for i in range(2):
  if i == 1:
    h, w = w, h
  for height in range(1, h+1):
    s1 = height * w
    remain_height = h - height
    s2 = remain_height * int(w / 2)
    s3 = s_org - (s1 + s2)
    s_max = max([s1, s2, s3])
    s_min = min([s1, s2, s3])
    answer = min([answer, (s_max - s_min)])

    s1 = height * w
    s2 = (h - height) * w
    s3 = s_org - (s1 + s2)
    s_max = max([s1, s2, s3])
    s_min = min([s1, s2, s3])
    answer = min([answer, (s_max - s_min)])
  
print(answer)

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

s_org = h * w

answer = h * w
for i in range(2):
  if i == 1:
    h, w = w, h
  for height in range(1, h+1):
    s1 = height * w
    remain_height = h - height
    s2 = remain_height * int(w / 2)
    s3 = s_org - (s1 + s2)
    s_max = max([s1, s2, s3])
    s_min = min([s1, s2, s3])
    answer = min([answer, (s_max - s_min)])

    s1 = height * w
    s2 = int((h - height) / 2) * w
    s3 = s_org - (s1 + s2)
    s_max = max([s1, s2, s3])
    s_min = min([s1, s2, s3])
    answer = min([answer, (s_max - s_min)])
  
print(answer)
Buggy code:
H, W = list(map(int,input().split()))
ans = H*W
h = H
w = W
for i in range(1,h//2+1):
    p1 = i*w
    for j in range(1,(h-i)//2+1):
        p2 = (h-i-j)*W
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
    for j in range(1,w//2+1):
        p2 = (h-i)*(w-j)
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
h = W
w = H
for i in range(1,h//2+1):
    p1 = i*w
    for j in range(1,(h-i)//2+1):
        p2 = (h-i-j)*W
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
    for j in range(1,w//2+1):
        p2 = (h-i)*(w-j)
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
print(ans)

Fixed code:
H, W = list(map(int,input().split()))
ans = H*W
h = H
w = W
for i in range(h//3,h//2+1):
    p1 = i*w
    for j in range((h-i)//2-1,(h-i)//2+1):
        p2 = (h-i-j)*W
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
    for j in range(w//2-1,w//2+1):
        p2 = (h-i)*(w-j)
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
h = W
w = H
for i in range(h//3,h//2+1):
    p1 = i*w
    for j in range((h-i)//2-1,(h-i)//2+1):
        p2 = (h-i-j)*H
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
    for j in range(w//2-1,w//2+1):
        p2 = (h-i)*(w-j)
        ans = min(ans, max(p1,p2,h*w-p1-p2)-min(p1,p2,h*w-p1-p2))
print(ans)
Buggy code:
h,w = map(int,input().split())
ans = min(h,w)
if w%3 == 1:
    a = w//3
else:
    a = w//3+1
c = abs(h*a-(h//2)*(w-a))
if h % 3== 1:
    b = h//3
else:
    b = h//3+1
d = abs(w*b-(w//2)*(h-b))
print(min(ans,c,d))

Fixed code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
else:
    if w%2==0:
        a=w*(h//3)
        b=(h-h//3)*(w//2)
        c=w*(h//3+1)
        d=(h-h//3-1)*(w//2)
    else:
        a=w*(h//3)
        b=(h-h//3)*(w//2+1)
        c=w*(h//3+1)
        d=(h-h//3-1)*(w//2)
    ans=min(b-a,c-d,h,w)
    if h%2==0:
        a=h*(w//3)
        b=(w-w//3)*(h//2)
        c=h*(w//3+1)
        d=(w-w//3-1)*(h//2)
    else:
        a=h*(w//3)
        b=(w-w//3)*(h//2+1)
        c=h*(w//3+1)
        d=(w-w//3-1)*(h//2)
    ans=min(ans,b-a,c-d)
    print(ans)
Buggy code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  ans=h*w
  v=w//2
  for i in range(1,h):
    a=i*w
    y=(h-i)//2
    z=h-i-y
    b=y*w
    c=z*w
    d=(h-i)*v
    e=(h-i)*(w-v)
    ans=min(ans,max(a,b,c)-min(a,b,c),max(a,d,e)-min(a,d,e))
  print(ans)

Fixed code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
  print(0)
else:
  ans=h*w
  v=w//2
  for i in range(1,h):
    a=i*w
    y=(h-i)//2
    z=h-i-y
    b=y*w
    c=z*w
    d=(h-i)*v
    e=(h-i)*(w-v)
    ans=min(ans,max(a,b,c)-min(a,b,c),max(a,d,e)-min(a,d,e))
  v=h//2
  for i in range(1,w):
    a=i*h
    y=(w-i)//2
    z=w-i-y
    b=y*h
    c=z*h
    d=(w-i)*v
    e=(w-i)*(h-v)
    ans=min(ans,max(a,b,c)-min(a,b,c),max(a,d,e)-min(a,d,e))
  print(ans)
Buggy code:
h,w = map(int,input().split())
ans = float("Inf")
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
for i in range(1,h-1):
    a = (h-i)*(w//2)
    b = (h-i)*-(-w//2)
    ans = min(ans,max(i*w,a,b)-min(i*w,a,b))
for i in range(1,w-1):
    a = (w-i)*(h//2)
    b = (w-i)*-(h-(h//2))
    ans = min(ans,max(i*h,a,b)-min(i*h,a,b))
print(min(ans,h,w))

Fixed code:
h,w = map(int,input().split())
ans = float("Inf")
if h % 3 == 0 or w % 3 == 0:
    print(0)
    exit()
for i in range(1,h):
    a = (h-i)*(w//2)
    b = (h-i)*-(-w//2)
    ans = min(ans,abs(max(i*w,a,b)-min(i*w,a,b)))
for i in range(1,w):
    a = (w-i)*(h//2)
    b = (w-i)*-(-h//2)
    ans = min(ans,abs(max(i*h,a,b)-min(i*h,a,b)))
print(min(ans,h,w))
Buggy code:
H, W = map(int, input().split())
ans = 10**9

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    for h in range(1,H):
        A = h * W
        B = (H - h) * (W // 2 + (W % 2))
        C = (H - h) * (W // 2) 
        ans = min(ans, max(A,B,C)-min(A,B,C))
        
    H, W = W, H
    for w in range(1,W):
        A = w * H
        B = (W - w) * (H // 2 + (H % 2))
        C = (W - w) * (H // 2) 
        ans = min(ans, max(A,B,C)-min(A,B,C))
    print(ans)

Fixed code:
H, W = map(int, input().split())
ans = 10**9

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    for h in range(1,H):
        A = h * W
        B = (H - h) * -(-W // 2)
        C = (H - h) * (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 // 2) 
        ans = min(ans, max(A,B,C)-min(A,B,C))
    print(min(ans, H, W))
Buggy code:
h,w=map(int,input().split())
if h%3==0:
    print(0)
if w%3==0:
    print(0)
else:
    ansh=h*w
    for j in range(1,h):
        area1=w*j
        number=w//2
        area2=(h-j)*number
        area3=(h-j)*(w-number)
        check=max(abs(area1-area2),abs(area1-area3),abs(area2-area3))
        if check<ansh:
            ansh=check
        else:
            continue  
    answ=w*h
    for j in range(1,w):
        area1=h*j
        number=h//2
        area2=(w-j)*number
        area3=(w-j)*(h-number)
        check=max(abs(area1-area2),abs(area1-area3),abs(area2-area3))
        if check<answ:
            answ=check
        else:
            continue
print(min(ansh,answ))   

Fixed code:
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
if h%3!=0 and w%3!=0:
    ansh=h*w
    for j in range(1,h):
        area1=w*j
        number=w//2
        area2=(h-j)*number
        area3=(h-j)*(w-number)
        check=max(abs(area1-area2),abs(area1-area3),abs(area2-area3))
        if check<ansh:
            ansh=check
        else:
            continue  
    answ=w*h
    for j in range(1,w):
        area1=h*j
        number=h//2
        area2=(w-j)*number
        area3=(w-j)*(h-number)
        check=max(abs(area1-area2),abs(area1-area3),abs(area2-area3))
        if check<answ:
            answ=check
        else:
             continue
    print(min(ansh,answ,w,h))
Buggy code:
h,w=map(int,input().split())
if h*w%3==0:
  print(0)
else:
  a=sorted([(h//3)*w,(h-h//3)*(w//2),(h-h//3)*(w//2+w%2)])
  c=sorted([(w//3)*h,(w-w//3)*(h//2),(w-w//3)*(h//2+h%2)])
  print(min(h,w,abs(a[2]-a[0]),abs(c[2]-c[0])))

Fixed code:
h,w=map(int,input().split())
if h*w%3==0:
  print(0)
else:
  a=sorted([(h//3)*w,(h-h//3)*(w//2),(h-h//3)*(w//2+w%2)])
  b=sorted([(h//3+1)*w,(h-h//3-1)*(w//2),(h-h//3-1)*(w//2+w%2)])
  c=sorted([(w//3)*h,(w-w//3)*(h//2),(w-w//3)*(h//2+h%2)])
  d=sorted([(w//3+1)*h,(w-w//3-1)*(h//2),(w-w//3-1)*(h//2+h%2)])
  print(min(h,w,abs(a[2]-a[0]),abs(b[2]-b[0]),abs(c[2]-c[0]),abs(d[2]-d[0])))
Buggy code:
h, w = map(int, input().split())

if h%3 == 0 or w%3 == 0:
    ans = 0
else:
    low = min(h, w)
    high = max(h, w)
    a = round(high/3)*low
    high = max(high-round(high/3), low)
    low = min(high-round(high/3), low)
    b = round(high/2)*low
    c = (high-round(high/2))*low
    ans = max(a,b,c) - min(a, b, c)
print (ans)

Fixed code:
h,w=map(int,input().split())
ans=h*w
if h%3==0 or w%3==0:
  ans=0
else:
  ans=min(h,w)
a=round(h/3)*w
b=(h-round(h/3))*(w//2)
c=h*w-a-b
d=max(a,b,c)-min(a,b,c)
ans=min(ans,d)
a=round(w/3)*h
b=(w-round(w/3))*(h//2)
c=h*w-a-b
d=max(a,b,c)-min(a,b,c)
ans=min(ans,d)
print(ans)
Buggy code:
import math

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

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    L = [[H,W], [W,H]]
    ans = 1e10
    for H,W in L: 
        Hp = [H, math.ceil(H/2), math.floor(H/2)]
        for x in range(1, W):
            S = [Hp[0]*x, Hp[1]*(W-x), Hp[2]*(W-x)]
            temp = max(S) - min(S)
            if ans > temp:  ans = temp
            else:   break
    print(ans)

Fixed code:
import math

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

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    L = [[H,W], [W,H]]
    ans = 1e10
    for H,W in L: 
        Hp = [H, math.ceil(H/2), math.floor(H/2)]
        for x in range(1, W):
            S = [Hp[0]*x, Hp[1]*(W-x), Hp[2]*(W-x)]
            temp = max(S) - min(S)
            if ans > temp:  ans = temp

    ans = min([ans, W, H])
    print(ans)
Buggy code:
a, b = map(int, input().split())
if a % 3 == 0 or b % 3 == 0:
  print(0)
  exit()

ds = a * b

s0 = (a//3) * b
s1 = (a - (a//3)) * (b//2)
s2 = (a - (a//3)) * (b - (b//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))
  print(s0, s1, s2)

s0 = (a//3 + 1) * b
s1 = (a - (a//3) - 1) * (b//2)
s2 = (a - (a//3) - 1) * (b - (b//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))
  print(s0, s1, s2)

s0 = (b//3) * a
s1 = (b - (b//3)) * (a//2)
s2 = (b - (b//3)) * (a - (a//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))
  print(s0, s1, s2)

s0 = (b//3 + 1) * a
s1 = (b - (b//3) - 1) * (a//2)
s2 = (b - (b//3) - 1) * (a - (a//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))
  print(s0, s1, s2)

print(ds)

Fixed code:
a, b = map(int, input().split())
if a % 3 == 0 or b % 3 == 0:
  print(0)
  exit()

ds = min(a, b)

s0 = (a//3) * b
s1 = (a - (a//3)) * (b//2)
s2 = (a - (a//3)) * (b - (b//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))

s0 = (a//3 + 1) * b
s1 = (a - (a//3) - 1) * (b//2)
s2 = (a - (a//3) - 1) * (b - (b//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))

s0 = (b//3) * a
s1 = (b - (b//3)) * (a//2)
s2 = (b - (b//3)) * (a - (a//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))

s0 = (b//3 + 1) * a
s1 = (b - (b//3) - 1) * (a//2)
s2 = (b - (b//3) - 1) * (a - (a//2))
if 0 not in (s0, s1, s2):
  ds = min(ds, max(s0, s1, s2) - min(s0, s1, s2))

print(ds)
Buggy code:
H,W = map(int,input().split())

anss = []

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

def vertical_horizontal(H,W):
    left_width = W//3+1
    left_area = H*left_width
    right_width = W - left_width
    if H % 2 == 0:
        right_upper_area = H//2*right_width
        right_lower_area = H//2*right_width
        return left_area - right_upper_area
    else:
        right_upper_area = (H//2+1)*right_width
        right_lower_area = H//2*right_width
        return max(left_area,right_upper_area) - right_lower_area

anss.append(vertical_twice(H,W))
anss.append(vertical_twice(W,H))
anss.append(vertical_horizontal(H,W))
anss.append(vertical_horizontal(W,H))

print(min(anss))

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

anss = []

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

def vertical_horizontal(H,W):
    if W % 3 != 2:
        left_width = W//3
        left_area = H*left_width
        right_width = W - left_width
        if H % 2 == 0:
            right_upper_area = H//2*right_width
            right_lower_area = H//2*right_width
#             return left_area - right_upper_area
        else:
            right_upper_area = (H//2+1)*right_width
            right_lower_area = H//2*right_width
#             return max(left_area,right_upper_area) - right_lower_area
    
    if W % 3 == 2:
        left_width = W//3+1
        left_area = H*left_width
        right_width = W - left_width
        if H % 2 == 0:
            right_upper_area = H//2*right_width
            right_lower_area = H//2*right_width
#             return left_area - right_upper_area
        else:
            right_upper_area = (H//2+1)*right_width
            right_lower_area = H//2*right_width
#             return max(left_area,right_upper_area) - right_lower_area
    return (max([left_area,right_upper_area, right_lower_area])-
            min([left_area,right_upper_area, right_lower_area]))
            
anss.append(vertical_twice(H,W))
anss.append(vertical_twice(W,H))
anss.append(vertical_horizontal(H,W))
anss.append(vertical_horizontal(W,H))

print(min(anss))
Buggy 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)


Fixed 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 = h
  c4 = ((h//3+1)*w)-((h-1-h//3)*(w//2))
  c5 = ((h-h//3)*(w-w//2))-(h//3*w)
  ret = min(c1,c2,c3,c4,c5)
print(ret)
Buggy code:
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 1):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 1):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)

Fixed code:
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    min_diff = h * w

    h1 = h // 2
    h2 = h - h1
    for w3 in range(w // 3, w // 3 + 3):
        s = [h * w3, h1 * (w - w3), h2 * (w - w3)]
        min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 2
    w2 = w - w1
    for h3 in range(h // 3, h // 3 + 3):
        s = [w * h3, w1 * (h - h3), w2 * (h - h3)]
        min_diff = min(min_diff, max(s) - min(s))

    h1 = h // 3
    h2 = (h - h1) // 2
    h3 = h - h1 - h2
    s = [w * h1, w * h2, w * h3]
    min_diff = min(min_diff, max(s) - min(s))

    w1 = w // 3
    w2 = (w - w1) // 2
    w3 = w - w1 - w2
    s = [h * w1, h * w2, h * w3]
    min_diff = min(min_diff, max(s) - min(s))

    print(min_diff)
Buggy code:
h,w = map(int,input().split())
if (h*w)%3==0:
  print(0)
else:
  ans = w
  for i in range(1,h):
    s1 = w*i
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w-w//2)
    s = [s1,s2,s3]
    ds = max(s)-min(s)
    ans = min([ans,ds])
  print (ans)

Fixed code:
def calc(h,w):
  ans = w
  for i in range(1,h):
    s1 = w*i
    s2 = (h-i)*(w//2)
    s3 = (h-i)*(w-w//2)
    s = [s1,s2,s3]
    ds = max(s)-min(s)
    ans = min([ans,ds])
  return ans

h,w = map(int,input().split())
if (h*w)%3==0:
  print(0)
else:
  print(min([calc(h,w),calc(w,h)]))
Buggy code:
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    s1 = round(h / 3) * w
    S1 = h * round(w / 3)
    h2 = h - round(h / 3)
    w2 = w - round(w / 3)
    if h2 % 2 == 0 or w % 2 == 0:
        s2 = h2 * w // 2
        s3 = s2
    else:
        h2, w = min(h2, w), max(h2, w)
        s2 = h2 * (w // 2)
        s3 = h2 * (w // 2 + 1)
    if h % 2 == 0 or w2 % 2 == 0:
        S2 = h * w2 // 2
        S3 = s2
    else:
        h, w2 = min(h, w2), max(h, w2)
        S2 = h * (w2 // 2)
        S3 = h * (w2 // 2 + 1)
    print(min(min(s1, s2, s3), min(S1, S2, S3)))

Fixed code:
h, w = map(int, input().split())
if h % 3 == 0 or w % 3 == 0:
    print(0)
else:
    s1 = round(h / 3) * w
    S1 = h * round(w / 3)
    h2 = h - round(h / 3)
    w2 = w - round(w / 3)
    if h2 % 2 == 0 or w % 2 == 0:
        s2 = h2 * w // 2
        s3 = s2
    else:
        h2, w = min(h2, w), max(h2, w)
        s2 = h2 * (w // 2)
        s3 = h2 * (w // 2 + 1)
    if h % 2 == 0 or w2 % 2 == 0:
        S2 = h * w2 // 2
        S3 = S2
    else:
        h, w2 = min(h, w2), max(h, w2)
        S2 = h * (w2 // 2)
        S3 = h * (w2 // 2 + 1)
    print(min(max(s1, s2, s3) - min(s1, s2, s3), max(S1, S2, S3) - min(S1, S2, S3)))