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:
h, w = map(int,input().split())
ans = 10 ** 10
if h % 3 == 0 or w % 3 == 0 :
    print(0)
    exit()

if h % 3 != 0 :
    ans = min(ans, w)
if w % 3 != 0 :
    ans = min(ans, h)

for j in range(1, h // 2 + 1):
    a = [w * j, (h - j) * (w // 2), (h - j) * (w // 2 + w % 2)]
    a.sort()
    ans = min(ans, a[2] - a[0])

for j in range(1, w // 2 + 1):
    a = [h * j, (w - j) * (h // 2), (h - j) * (h // 2 + h % 2)]
    a.sort()
    ans = min(ans, a[2] - a[0])

print(ans)

Submission status: Wrong Answer

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

if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for h in range(1,H+1):
        w=W/2
        v1=(h*W,(H-h)*w,(H-h)*(W-w))
        s1=max(v1)-min(v1)
        h_p=(H-h)/2
        v2=(h*W,h_p*W,(H-h-h_p)*W)
        s2=max(v2)-min(v2)
        s=min(s1,s2)
        if s_min>s:
            s_min=s

    print s_min

Submission status: Wrong Answer

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

if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for h in range(1,H+1):
        w=W/2
        v=(h*W,(H-h)*w,(H-h)*(W-w))
        s=max(v)-min(v)
        if s_min>s:
            s_min=s

    print s_min

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())
 
area = [0,0,0]
ans = 10**15
if(h%3 == 0 or w%3 == 0):
    ans = 0
else:
    for i in range(1,h/2+1):
        area[0] = i*w
        tmp = w/2
        area[1] = tmp*(h-i)
        area[2] = (w-tmp)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
        
    for i in range(1,w/2+1):
        area[0] = i*h
        tmp = h/2
        area[1] = tmp*(w-i)
        area[2] = (h-tmp)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)

Submission status: Wrong Answer

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
    if min(h,w)%2 == 0:
        tmp_area_a11 = (max(h,w)-len_area1) * int(min(h,w)/2)
        tmp_area_aa = (abs(tmp_area_a1 - tmp_area_a11))
    else:
        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_a111-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
    if min(h,w)%2 == 0:
        tmp_area_b11 = (max(h,w)-len_area2) * int(min(h,w)/2)
        tmp_area_ba = (abs(tmp_area_b1 - tmp_area_b11))
    else:
        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_b111-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))

    tmp_dis1 = min(tmp_area_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: Wrong Answer

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
 
    t = int((x - a) * y / 2)
    if t > s :
      print (t - s)
    else :
      print (s - t)
  else :
    s = a * y 
    x = x - a
  
    if y > x :
      z = y
      y = x
      x = z
  
    b = int(x / 2)
    t = b * y 
    print (s - t)

Submission status: Wrong Answer

Solution code:
h,w = sorted(list(map(int,input().split())))
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)

Submission status: Wrong Answer

Solution code:
print (50000)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
else:
    m = 100000000000
    for i in range(1, h):
        if m > max([i*w, (h-i)*(w//2), (h-i)*(w-(w//2))]) - min([i*w, (h-i)*(w//2), (h-i)*(w-(w//2))]):
            m = max([i*w, (h-i)*(w//2), (h-i)*(w-(w//2))]) - min([i*w, (h-i)*(w//2), (h-i)*(w-(w//2))])
    for i in range(1, w):
        if m > max([i*h, (w-i)*(h//2), (w-i)*(h-(h//2))]) - min([i*h, (w-i)*(h//2), (w-i)*(h-(h//2))]):
            m = max([i*h, (w-i)*(h//2), (w-i)*(h-(h//2))]) - min([i*h, (w-i)*(h//2), (w-i)*(h-(h//2))])
    if m > max([w//3, w-2*(w//3)])*h - min([w//3, w-2*(w//3)])*h:
        m = max([w//3, w-2*(w//3)])*h - min([w//3, w-2*(w//3)])*h
    if m > max([h//3, h-2*(h//3)])*w - min([h//3, h-2*(h//3)])*w:
        m = max([h//3, h-2*(h//3)])*w - min([h//3, h-2*(h//3)])*w
    print(m)

Submission status: Wrong Answer

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 = h
  c4 = w-w//3
  ret = min(c1,c2,c3,c4)
print(ret)

Submission status: Wrong Answer

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_a111-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_b111-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))

    tmp_dis1 = min(tmp_area_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: Wrong Answer

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 = h
  c4 = w
  ret = min(c1,c2,c3,c4)
print(ret)

Submission status: Wrong Answer

Solution code:
import math

def solve() :
    ri = raw_input()

    inarr = ri.split(' ')
    h = int(inarr[0])
    w = int(inarr[1])

    if h % 3 == 0 or w % 3 == 0 : return 0
    score = min(h, w)
    ave = (h*w)/3

    if h % 2 == 0:
         x = ave/2
         a1 = x * h/2
         a2 = (w-x) * h
         score = min(score, abs(a1-a2))
         x = x + 1
         a1 = x * h/2
         a2 = (w-x) * h
         score = min(score, abs(a1-a2))
         x = x - 2
         a1 = x * h/2
         a2 = (w-x) * h
         score = min(score, abs(a1-a2))
    elif w % 2 == 0:
         y = ave/2
         a1 = y * w/2
         a2 = (h-y) * w
         score = min(score, abs(a1-a2))
         y = y + 1
         a1 = y * w/2
         a2 = (h-y) * w
         score = min(score, abs(a1-a2))
         y = y - 2
         a1 = y * w/2
         a2 = (h-y) * w
         score = min(score, abs(a1-a2))
    else:
        x = w/3
        a1 = x*h
        a2 = (w-x) * math.floor(h/2)
        a3 = a2 + (w-x)
        if a2 > a1 : score2 = a3-a1
        elif a3 < a1 : score2 = a1-a2
        else : score2 = a3-a2
        score = min(score, score2)    
        x = w/3 + 1
        a1 = x*h
        a2 = (w-x) * math.floor(h/2)
        a3 = a2 + (w-x)
        if a2 > a1 : score2 = a3-a1
        elif a3 < a1 : score2 = a1-a2
        else : score2 = a3-a2
        score = min(score, score2)    
        y = h/3
        a1 = y*w
        a2 = (h-y) * math.floor(w/2)
        a3 = a2 + (h-y)
        if a2 > a1 : score2 = a3-a1
        elif a3 < a1 : score2 = a1-a2
        else : score2 = a3-a2
        score = min(score, score2)    
        y = h/3 + 1
        a1 = y*w
        a2 = (h-y) * math.floor(w/2)
        a3 = a2 + (h-y)
        if a2 > a1 : score2 = a3-a1
        elif a3 < a1 : score2 = a1-a2
        else : score2 = a3-a2
        score = min(score, score2)    

    return int(score)


if __name__ == '__main__':
    print solve()

Submission status: Wrong Answer

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 s > t :
      print (s - t, end = '')
    else :
      print (t - s, end = '')
  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: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    min_s = min(H * (W % 3), W * (H % 3))

    S_max = H * (W // 2)
    S_min = (W - (W // 2)) * (H // 2)
    if S_max - S_min > 0:
        min_s = min(min_s, S_max - S_min)

    S_max = H * (W - (W // 2))
    S_min = ((W // 2)) * (H // 2)
    if S_max - S_min > 0:
        min_s = min(min_s, S_max - S_min)

    S_max = W * ((H // 2))
    S_min = (H - (H // 2)) * (W // 2)
    if S_max - S_min > 0:
        min_s = min(min_s, S_max - S_min)

    S_max = W * (H - (H // 2))
    S_min = ((H // 2)) * (W // 2)
    if S_max - S_min > 0:
        min_s = min(min_s, S_max - S_min)
    print(min_s)

Submission status: Wrong Answer

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 int(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: Wrong Answer

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: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))
 
 
H, W = rren()
if(H % 3 == 0 or W % 3 == 0):
    print(0)
else:
    lis = []
    ans = 114514810
    for i in range(H-1):
      for j in range(10):
        a = H - i
        b = i
        c = abs(W // 2 + j)
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
      for j in range(10):
        a = W - i
        b = i
        c = abs(H // 2 + j)
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W//4, W//2):
        ans = min(ans, abs(i - (W-i*2))*H)
    for i in range(H//4, H//2):
        ans = min(ans, abs(i - (H-i*2))*W)
    print(ans)

Submission status: Wrong Answer

Solution code:
#AtCoder Beginner Contest 062 C - Chocolate Bar
H,W=[int(x) for x in input().split()]
if(H%3==0 or W%3==0):
    print(0)
if(H>W):
    min_dif=W
else:
    min_dif=H
    
if(H%2!=0):
    for i in range(W-1):
        A=(i+1)*H
        B=(W-(i+1))*int(H/2)
        C=H*W-A-B
        D=[A,B,C]
        D.sort()
        if(min_dif>abs(D[0]-D[2])):
            min_dif=abs(D[0]-D[2])
            
if(H%2==0):
    for i in range(W-1):
        A=(i+1)*H
        B=(W-(i+1))*int(H/2)
        if(min_dif>abs(A-B)):
            min_dif=abs(A-B)
            
if(W%2!=0):
    for i in range(H-1):
        A=W*(i+1)
        B=int(W/2)*(H-(i+1))
        C=H*W-A-B
        D=[A,B,C]
        D.sort()
        if(min_dif>abs(D[0]-D[2])):
            min_dif=abs(D[0]-D[2])
            
if(W%2==0):
    for i in range(H-1):
        A=W*(i+1) 
        B=int(W/2)*(H-(i+1))
        if(min_dif>abs(A-B)):
            min_dif=abs(A-B)
print(min_dif)

Submission status: Wrong Answer

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

if h % 3 == 0 or w % 3 == 0:
    print 0
elif h == 1 or h == 2:
    print w % 3
elif w == 1 or w == 2:
    print h % 3
else:
    best = h * w
    s = [0, 0, 0]
    for i in range(h / 3, h / 3 + 3):
        for j in range(w / 2, w / 2 + 2):
            max = 0
            min = h * w
            s[0] = i * w
            s[1] = (h - i) * j
            s[2] = h * w - s[0] - s[1]
            for ss in s:
                if max < ss:
                    max = ss
                if min > ss:
                    min = ss
            if best > max - min:
                best = max - min

            h, w = w, h
            i, j = j, i
            max = 0
            min = h * w
            s[0] = i * w
            s[1] = (h - i) * j
            s[2] = h * w - s[0] - s[1]
            for ss in s:
                if max < ss:
                    max = ss
                if min > ss:
                    min = ss
            if best > max - min:
                best = max - min
            h, w = w, h
            i, j = j, i
    print best

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
h,w = map(int, raw_input().split())
 
area = [0,0,0]
ans = 10**15
if(h%3 == 0 or w%3 == 0):
    ans = 0
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: Wrong Answer

Solution code:
def solve(H,W,d=3.0):
    ave = (((H*W)/d))
    h = 0
    w = 0
    for i in xrange(H):
        div = abs(1.0*(i+1)*W-ave)
        bdiv = abs(1.0*(h+1)*W-ave)
        #print div,bdiv
        if div <= bdiv:
            h = i
        else:
            break
    for i in xrange(W):
        div = abs(1.0*(i+1)*H-ave)
        bdiv = abs(1.0*(w+1)*H-ave)
        if div <= bdiv:
            w = i
        else:
            break
    hdiv = abs(1.0*(h+1)*W-ave)
    wdiv = abs(1.0*(w+1)*H-ave)
    if hdiv<wdiv:
        return (h+1,0)
    else:
        return (0,w+1)
 
H,W = map(int,raw_input().split(' '))
s_ = H*W
S = []
a = solve(H,W)
#print a
s = a[0]*W + a[1]*H
S.append(s)
H -= a[0]
W -= a[1]
b= solve(H,W,2.0)
#print b
s = b[0]*W + b[1]*H
S.append(s)
S.append((s_-sum(S)))
print max(S)-min(S)

Submission status: Wrong Answer

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

if h % 3 == 0 or w % 3 == 0:
    print 0
elif h == 1 or h == 2:
    print w % 3
elif w == 1 or w == 2:
    print h % 3
else:
    best = h * w
    s = [0, 0, 0]
    for i in range(h / 3, h / 3 + 2):
        for j in range(w / 2, w / 2 + 1):
            max = 0
            min = h * w
            s[0] = i * w
            s[1] = (h - i) * j
            s[2] = h * w - s[0] - s[1]
            for ss in s:
                if max < ss:
                    max = ss
                if min > ss:
                    min = ss
            if best > max - min:
                best = max - min

            h, w = w, h
            i, j = j, i
            max = 0
            min = h * w
            s[0] = i * w
            s[1] = (h - i) * j
            s[2] = h * w - s[0] - s[1]
            for ss in s:
                if max < ss:
                    max = ss
                if min > ss:
                    min = ss
            if best > max - min:
                best = max - min
            h, w = w, h
            i, j = j, i
    print best

Submission status: Wrong Answer

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 int(high/3) > low:
    print((high - int(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: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	h = min(H, W)
	w = max(H, W)
	if h % 2 == 0:
		a = (h//3 + 1) + (w//3 + 1)
		b = h/2
		print(int(min(a, b)))
	else:
		if w % 2 == 0:
			a = (h//3 + 1) + (w//3 + 1)
			b = w/2
			print(int(min(a, b)))
		else:
			a = (h//3 + 1) + (w//3 + 1)
			print(int(a))

Submission status: Wrong Answer

Solution code:
def solve(H,W,d=3.0):
    ave = (((H*W)/d))
    h = 0
    w = 0
    for i in xrange(H):
        div = abs((i+1)*W-ave)
        bdiv = abs((h+1)*W-ave)
        #print div,bdiv
        if div <= bdiv:
            h = i
        else:
            break
    for i in xrange(W):
        div = abs(1.0*(i+1)*H-ave)
        bdiv = abs(1.0*(w+1)*H-ave)
        if div <= bdiv:
            w = i
        else:
            break
    hdiv = abs(1.0*(h+1)*W-ave)
    wdiv = abs(1.0*(w+1)*H-ave)
    if hdiv<wdiv:
        return (h+1,0)
    else:
        return (0,w+1)
 
H,W = map(int,raw_input().split(' '))
s_ = H*W
S = []
a = solve(H,W)
#print a
s = a[0]*W + a[1]*H
S.append(s)
H -= a[0]
W -= a[1]
b= solve(H,W,2.0)
#print b
s = b[0]*W + b[1]*H
S.append(s)
S.append((s_-sum(S)))
print max(S)-min(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    if s > t :
      print (s - t)
    else :
      print (t - s)

Submission status: Wrong Answer

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 - int(high/3))
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: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))


H, W = rren()
if(H % 3 == 0 or W % 3 == 0):
    print(0)
else:
    lis = []
    ans = 114514810
    for i in range(H-1):
        a = H - i
        b = i
        c = W // 2
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
        a = W - i
        b = i
        c = H // 2
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W//4, W//2):
        ans = min(ans, abs(i - (W-i*2))*H)
    for i in range(H//4, H//2):
        ans = min(ans, abs(i - (H-i*2))*W)
    print(ans)

Submission status: Wrong Answer

Solution code:
#AtCoder Beginner Contest 062 C - Chocolate Bar
H,W=[int(x) for x in input().split()]
if(H%3==0 or W%3==0):
    print(0)
if(H>W):
    min_dif=W
else:
    min_dif=H
    
if(H%2!=0):
    for i in range(W-1):
        A=(i+1)*H
        B=(W-(i+1))*int(H/2)
        C=H*W-A-B
        D=[A,B,C]
        D.sort()
        if(min_dif>abs(D[0]-D[2])):
            min_dif=abs(D[0]-D[2])
            
if(H%2==0):
    for i in range(W-1):
        A=(i+1)*H
        B=(W-(i+1))*int(H/2)
        if(min_dif>abs(A-B)):
            min_dif=abs(A-B)
            
if(W%2!=0):
    for i in range(H-1):
        A=W*(i+1)
        B=int(W/2)*(H-i-1)
        C=H*W-A-B
        D=[A,B,C]
        D.sort()
        if(min_dif>abs(D[0]-D[2])):
            min_dif=abs(D[0]-D[2])
            
if(W%2==0):
    for i in range(H-1):
        A=W*(i+1) 
        B=int(W/2)*(H-i-1)
        if(min_dif>abs(A-B)):
            min_dif=abs(A-B)
print(min_dif)

Submission status: Wrong Answer

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 s > t :
      print (s - t)
    else :
      print (t - s)
  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: Wrong Answer

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)
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: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))


H, W = rren()
if(H % 3 == 0 or W % 3 == 0):
    print(0)
else:
    lis = []
    ans = 114514810
    for i in range(H-1):
      for j in range(100):
        a = H - i
        b = i
        c = abs(W // 2 + j)
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
      for j in range(100):
        a = W - i
        b = i
        c = abs(H // 2 + j)
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W//3, W//2):
        ans = min(ans, abs(i - (W-i*2))*H)
    for i in range(H//3, H//2):
        ans = min(ans, abs(i - (H-i*2))*W)
    print(ans)

Submission status: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))


H, W = rren()
if(H % 3 == 0 or W % 3 == 0):
    print(0)
else:
    lis = []
    ans = 114514810
    for i in range(H-1):
      for j in range(1000):
        a = H - i
        b = i
        c = abs(W // 2 + j)
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
      for j in range(1000):
        a = W - i
        b = i
        c = abs(H // 2 + j)
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W//3, W//2):
        ans = min(ans, abs(i - (W-i*2))*H)
    for i in range(H//3, H//2):
        ans = min(ans, abs(i - (H-i*2))*W)
    print(ans)

Submission status: Wrong Answer

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):
    ans = 0
for i in range(1,h/2+1):
    area[0] = i*w
    for j in range(w/2-1,w/2+1):
        area[1] = j*(h-i)
        area[2] = (w-j)*(h-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
    
for i in range(1,w/2+1):
    area[0] = i*h
    for j in range(h/2-1,h/2+1):
        area[1] = (j)*(w-i)
        area[2] = (h-j)*(w-i)
        S = max(area)-min(area)
        if(S<ans):
            ans = S
print(ans)

Submission status: Wrong Answer

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

if (H*W) % 3 == 0:
    print("0")
elif H == 2 and W == 2:
        print("1")
else:
    rects = []
    if H % 2 == 0 and W % 2 == 0:
        rects.append((max(H,W) // 3) * min(H,W))
        rects.append((max(H,W) - max(H,W)//3) * (min(H,W) // 2))
    else:
        rects.append(min(H,W) * (max(H,W) // 2))
        rects.append((max(H,W) - max(H,W)//2) * (min(H,W) // 2))
        
    print(max(rects) - min(rects))

Submission status: Wrong Answer

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
        for j in range(3):
            if b % 2 == 1:
                q = (a - i) * (int(b / 2) + 1 + j)
            elif b % 2 == 0:
                q = (a - i) * (int(b / 2) + j)
            r = (a - i) * (int(b / 2) - j)
            lll.append(max(p, q, r) - min(p, q, r))

    temp = b
    b = a
    a = temp
    for i in range(1, a):
        p = b * i
        for j in range(3):
            if b % 2 == 1:
                q = (a - i) * (int(b / 2) + 1 + j)
            elif b % 2 == 0:
                q = (a - i) * (int(b / 2) + j)
            r = (a - i) * (int(b / 2) - j)
            lll.append(max(p, q, r) - min(p, q, r))
        

    print(min(lll))

Submission status: Wrong Answer

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

if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for h in range(1,H+1):
        for i in range(3):
            w=(H*W/3+i)/h
            for _ in range(2):
                if w>W or w<1:
                    continue
                v1=(h*w,(W-w)*h,W*(H-h))
                v2=(h*w,(W-w)*H,w*(H-h))
                s=min(max(v1)-min(v1),max(v2)-min(v2))
                if s_min>s:
                    s_min=s
                w+=1

    print s_min

Submission status: Wrong Answer

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
        for j in range(3):
            if b % 2 == 1:
                q = (a - i) * (int(b / 2) + 1 + j)
            elif b % 2 == 0:
                q = (a - i) * (int(b / 2) + j)
            r = (a - i) * (int(b / 2) + j)
            lll.append(max(p, q, r) - min(p, q, r))

    temp = b
    b = a
    a = temp
    for i in range(1, a):
        p = b * i
        for j in range(3):
            if b % 2 == 1:
                q = (a - i) * (int(b / 2) + 1 + j)
            elif b % 2 == 0:
                q = (a - i) * (int(b / 2) + j)
            r = (a - i) * (int(b / 2) + j)
            lll.append(max(p, q, r) - min(p, q, r))
        print(p,q,r)

    print(min(lll))

Submission status: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	h = min(H, W)
	w = max(H, W)
	if h % 2 == 0:
		print(int(h/2))
	else:
		if w % 2 == 0:
			a = (h//3 + 1) + (w//3 + 1)
			b = w/2
			print(int(min(a, b)))
		else:
			a = (h//3 + 1) + (w//3 + 1)
			print(int(a))

Submission status: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	h = min(H, W)
	w = max(H, W)
	if h % 2 == 0:
		print(h/2)
	else:
		if w % 2 == 0:
			a = (h//3 + 1) + (w//3 + 1)
			b = w/2
			print(min(a, b))
		else:
			a = (h//3 + 1) + (w//3 + 1)
			print(a)

Submission status: Wrong Answer

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_a11 = (max(h,w)-len_area1) * int(min(h,w)/2)
    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_a12 = max(abs(tmp_area_a1-tmp_area_a121),abs(tmp_area_a1-tmp_area_a122))

    tmp_area_b1 = min(h,w)*len_area2
    tmp_area_b11 = (max(h,w)-len_area2) * int(min(h,w)/2)
    tmp_area_b121 = int((max(h,w)-len_area1)/2) * min(h,w)
    tmp_area_b122 = int((max(h,w)-len_area1)/2+1) * min(h,w)
    tmp_area_b12 = max(abs(tmp_area_a1-tmp_area_a121),abs(tmp_area_a1-tmp_area_a122))

    tmp_dis1 = min(abs(tmp_area_a1-tmp_area_a11),abs(tmp_area_a1-tmp_area_a12))
    tmp_dis2 = min(abs(tmp_area_b1-tmp_area_b11),abs(tmp_area_b1-tmp_area_b12))
    dis_area = min(tmp_dis1,tmp_dis2)
    print(dis_area)

Submission status: Wrong Answer

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

if (H*W)%3==0:
    print 0
else:
    s_min=float('inf')
    for h in range(1,H+1):
        w=(H*W/3)/h
        for _ in range(2):
            if w>W or w<1:
                continue
            v1=(h*w,(W-w)*h,W*(H-h))
            v2=(h*w,(W-w)*H,w*(H-h))
            s=min(max(v1)-min(v1),max(v2)-min(v2))
            if s_min>s:
                s_min=s
            w+=1

    print s_min

Submission status: Wrong Answer

Solution code:
def rren(): return list(map(int, input().split()))


H, W = rren()
if(H % 3 == 0 or W % 3 == 0):
    print(0)
else:
    lis = []
    ans = 114514810
    for i in range(H-1):
        a = H - i
        b = i
        c = W // 2
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
        a = W - i
        b = i
        c = H // 2
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W//3, W//2):
        ans = min(ans, abs(i - (W-i*2))*H)
    for i in range(H//3, H//2):
        ans = min(ans, abs(i - (H-i*2))*W)
    print(ans)