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 = [int(x) for x in input().split()]

if (H*W) % 3 == 0:
    print("0")
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))
    elif H % 2 == 0 and W % 2 == 1:
        rects.append(H * (W // 2))
        rects.append(((H*W)-rects[0])//2)
    elif H % 2 == 1 and W % 2 == 0:
        rects.append(W * (H // 2))
        rects.append(((H*W)-rects[0])//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:
H,W = [int(x) for x in input().split()]

if (H*W) % 3 == 0:
    print("0")
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))
    elif H % 2 == 0 and W % 2 == 1:
        rects.append(H * (W // 2))
        rects.append(((H*W)-rects[0])//2)
    elif H % 2 == 1 and W % 2 == 1:
        rects.append(W * (H // 2))
        rects.append(((H*W)-rects[0])//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:
# -*- 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
    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 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)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

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

def vertical_cut(H, W):
    if W < 3:
        return float('inf')

    min_w = W // 3
    max_w = W - 2 * min_w

    S_max = max_w * H
    S_min = min_w * H

    return S_max - S_min

def horizontal_cut(H, W):
    return vertical_cut(W, H)

def vertical_and_horizontal_cut(H, W):
    min_score = float('inf')

    for cut_i in range(1, W // 2 + 1):
        left_S = cut_i * H
        right_W = W - cut_i

        right_H_top = H // 2
        right_H_bottom = H - right_H_top

        right_top_S = right_W * right_H_top
        right_bottom_S = right_W * right_H_bottom

        A = [left_S, right_top_S, right_bottom_S]
        score = max(A) - min(A)
        if score < min_score:
            min_score = score
    return min_score

def horizontal_and_vertical_cut(H, W):
    return vertical_and_horizontal_cut(W, H)

a = vertical_cut(H, W)
b = horizontal_cut(H, W)
c = vertical_and_horizontal_cut(H, W)
d = horizontal_and_vertical_cut(H, W)

print(min(a, b, c, d))

Submission status: Wrong Answer

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

if H % 3 == 0 or W % 3 == 0:
    print(0)
else:
    entire_s = H * W
    key_s = entire_s // 3
    mod_s = entire_s % 3

    min_s = min(H * (W % 3), W * (H % 3))

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

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

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

    S_max = W * (H - H % 3)
    S_min = (H % 3) * (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:
def splt(H, W, S, den):
    S_1, H_1, W_1 = 0, 0, 0
    mini = 10**13

    for h in range(H):
        if abs(S/den - h*W) < mini:
            H_1 = H - h
            W_1 = W
            mini = abs(S/den - h*W)

    for w in range(W):
        if abs(S/den - w*H) < mini:
            H_1 = H
            W_1 = W - w
            mini = abs(S/den - w*H)

    return H_1, W_1, S - H_1*W_1


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

S = H*W

H_1, W_1, S_1 = splt(H, W, S, 3)
H_2, W_2, S_2 = splt(H_1, W_1, H_1*W_1, 2)
S_3 = H_2 * W_2

df = [abs(S_1-S_2), abs(S_2-S_3), abs(S_3-S_1)]

print(max(df))

Submission status: Wrong Answer

Solution code:
import math

def get_max_dif1(a, b):
	return abs(a-b)

def get_max_dif2(a, b, c):
	return max(abs(a-b), abs(b-c), abs(c-a))

def chocolate_bar():
	h, w = map(int, input().split())

	a = math.floor(w/3)
	b = math.ceil(w/3)
	c = math.floor(h/3)
	d = math.ceil(h/3)
		
	if h%3 == 0 or w%3 == 0:
		print(0)
	elif h%2 == 0 and w%2 != 0:
		print(int(min(get_max_dif1(a*h, (w-a)*h/2), get_max_dif1(b*h, (w-b)*h/2))))
	elif h%2 != 0 and w%2 == 0:
		print(int(min(get_max_dif1(c*w, (h-c)*w/2), get_max_dif1(d*w, (h-d)*w/2))))
	elif h%2 == 0 and w%2 == 0:
		print(int(min(
			get_max_dif1(a*h, (w-a)*h/2),
			get_max_dif1(b*h, (w-b)*h/2),
			get_max_dif1(c*w, (h-c)*w/2),
			get_max_dif1(d*w, (h-d)*w/2))))
	else:
		print(int(min(
			get_max_dif2(a*h, (w-a)*(h+1)/2, (w-a)*(h-1)/2),
			get_max_dif2(b*h, (w-b)*(h+1)/2, (w-b)*(h-1)/2),
			get_max_dif2(c*w, (h-c)*(w+1)/2, (h-c)*(w-1)/2),
			get_max_dif2(d*w, (h-d)*(w+1)/2, (h-d)*(w-1)/2))))

if __name__ == '__main__':
	chocolate_bar()

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(3):
            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:
h, w = map(int, input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
else:
    m = 1000000000
    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))])
    print(m)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

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

def vertical_cut(H, W):
    if H < 3:
        return float('inf')

    min_w = W // 3
    max_w = W - 2 * min_w

    S_max = max_w * H
    S_min = min_w * H

    return S_max - S_min

def horizontal_cut(H, W):
    return vertical_cut(W, H)

def vertical_and_horizontal_cut(H, W):
    min_score = float('inf')

    for cut_i in range(1, W // 2 + 1):
        left_S = cut_i * H
        right_W = W - cut_i

        right_H_top = H // 2
        right_H_bottom = H - right_H_top

        right_top_S = right_W * right_H_top
        right_bottom_S = right_W * right_H_bottom

        A = [left_S, right_top_S, right_bottom_S]
        score = max(A) - min(A)
        if score < min_score:
            min_score = score
    return min_score

def horizontal_and_vertical_cut(H, W):
    return vertical_and_horizontal_cut(W, H)

a = vertical_cut(H, W)
b = horizontal_cut(H, W)
c = vertical_and_horizontal_cut(H, W)
d = horizontal_and_vertical_cut(H, W)

print(min(a, b, c, d))

Submission status: Wrong Answer

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

if x % 3 == 0 or y % 3 == 0:
	print 0
else:
	m = 100000000
	for i in range(1, x):
		for j in range(y / 2 - 1, y / 2 + 1):
			s1 = y * i
			s2 = (x - i) * j
			s3 = (x - i) * (y - j)
			l = [s1, s2, s3]
			l.sort()
			if l[-1] - l[0] < m:
				m = l[-1] - l[0]
			# ix = i
			# ij = j
	# print m
	x, y = y, x
	for i in range(1, x):
		for j in range(y / 2 - 1, y / 2 + 1):
			s1 = y * i
			s2 = (x - i) * j
			s3 = (x - i) * (y - j)
			l = [s1, s2, s3]
			l.sort()
			if l[-1] - l[0] < m:
				m = l[-1] - l[0]
	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
  ret = min(c1,c2,c3)
print(ret)

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

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
        w-=1
        for _ in range(4):
            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 max_minus_min(_a, _b, _c):
    return max(_a, _b, _c) - min(_a, _b, _c)


H, W = list(map(int, input().split()))
# 横幅が必ず縦幅以上となるようにする
if W <= H:
    tmp = W
    W = H
    H = tmp

if W % 3 == 0 or H % 3 == 0:
    print(0)
else:
    yoko_to_two1 = max_minus_min(
        int(H / 2) * (W - (int(W / 3) + 1)), (H - int(H / 2)) * (W - (int(W / 3) + 1)), ((int(W / 3) + 1) * H))
    yoko_to_two2 = max_minus_min(
        int(H / 2) * (W - (int(W / 3))), (H - int(H / 2)) * (W - (int(W / 3))), ((int(W / 3)) * H))
    yoko_to_two3 = max_minus_min(
        (int(H / 2) + 1) * (W - (int(W / 3) + 1)), (H - (int(H / 2) + 1)) * (W - (int(W / 3) + 1)),
        ((int(W / 3) + 1) * H))
    yoko_to_two4 = max_minus_min(
        (int(H / 2) + 1) * (W - (int(W / 3))), (H - (int(H / 2) + 1)) * (W - (int(W / 3))), ((int(W / 3)) * H))

    tate_to_two1 = max_minus_min(int(W / 2) * (H - (int(H / 3) + 1)), (W - int(W / 2)) * (H - (int(H / 3) + 1)),
                                 ((int(H / 3) + 1) * W))
    tate_to_two2 = max_minus_min(int(W / 2) * (H - (int(H / 3))), (W - int(W / 2)) * (H - (int(H / 3))),
                                 ((int(H / 3)) * W))
    tate_to_two3 = max_minus_min((int(W / 2) + 1) * (H - (int(H / 3) + 1)),
                                 (W - (int(W / 2) + 1)) * (H - (int(H / 3) + 1)),
                                 ((int(H / 3) + 1) * W))
    tate_to_two4 = max_minus_min((int(W / 2) + 1) * (H - (int(H / 3))), (W - (int(W / 2) + 1)) * (H - (int(H / 3))),
                                 ((int(H / 3)) * W))

    print(min(yoko_to_two1, yoko_to_two2, yoko_to_two3, yoko_to_two4, tate_to_two1, tate_to_two2, tate_to_two3,
              tate_to_two4))

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()
    ans = min(ans, abs(W//3 - (W-(W//3)*2))*H)
    ans = min(ans, abs((W//3 + 1) - (W-(W//3 + 1)*2))*H)
    ans = min(ans, abs(H//3 - (H-(H//3)*2))*W)
    ans = min(ans, abs((H//3 + 1) - (H-(H//3 + 1)*2))*W)
    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
  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:
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))
        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
        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))
        lll.append(max(p,q,r)-min(p,q,r))
        
    print(min(lll))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math

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

def vertical_cut(H, W):
    min_w = W // 3
    max_w = W - 2 * min_w

    S_max = max_w * H
    S_min = min_w * H

    return S_max - S_min

def horizontal_cut(H, W):
    return vertical_cut(W, H)

def vertical_and_horizontal_cut(H, W):
    min_score = float('inf')

    for cut_i in range(1, W // 2 + 1):
        left_S = cut_i * H
        right_W = W - cut_i

        right_H_top = H // 2
        right_H_bottom = H - right_H_top

        right_top_S = right_W * right_H_top
        right_bottom_S = right_W * right_H_bottom

        A = [left_S, right_top_S, right_bottom_S]
        score = max(A) - min(A)
        if score < min_score:
            min_score = score
    return min_score

def horizontal_and_vertical_cut(H, W):
    return vertical_and_horizontal_cut(W, H)

a = vertical_cut(H, W)
b = horizontal_cut(H, W)
c = vertical_and_horizontal_cut(H, W)
d = horizontal_and_vertical_cut(H, W)

print(min(a, b, c, d))

Submission status: Wrong Answer

Solution code:
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 = round(high/3)*low
    b = (high-round(high/3))*int(low/2)
    print (abs(a-b))

Submission status: Wrong Answer

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

if (H*W) % 3 == 0:
    print("0")
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:
x, y = map(int, raw_input().split())

if x % 3 == 0 or y % 3 == 0:
	print 0
else:
	m = 100000000
	for i in range(1, x):
		j = y / 2
		s1 = y * i
		s2 = (x - i) * j
		s3 = (x - i) * (y - j)
		l = [s1, s2, s3]
		l.sort()
		if l[-1] - l[0] < m:
			m = l[-1] - l[0]
			# ix = i
			# ij = j
	# print m
	x, y = y, x
	for i in range(1, x):
		j = y / 2
		s1 = y * i
		s2 = (x - i) * j
		s3 = (x - i) * (y - j)
		l = [s1, s2, s3]
		l.sort()
		if l[-1] - l[0] < m:
			m = l[-1] - l[0]
	print m

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
        w-=1
        for _ in range(3):
            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:
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]


def calc3(h, w):
        W = H = "x"
        r = []
        for a in range(h/3-3, h/3+4):
                if a < 0 or a > h:
                        continue
                for b in range(w/2-2, w/2+3):
                        if b < 0 or b > w:
                                continue
                        S1 = a * w
                        S2 = (h - a) * b
                        S3 = (h - a) * (w - b)
                        assert S1 + S2 + S3 == w * h
                        q = max(S1, S2, S3) - min(S1, S2, S3)
                        r.append(q)
                for b in range((h-a)/2-2, (h-a)/2+3):
                        if b < 0 or b > h-a:
                                continue
                        S1 = a * w
                        S2 = b * w
                        S3 = (h - a - b) * w
                        assert S1 + S2 + S3 == w * h
                        q = max(S1, S2, S3) - min(S1, S2, S3)
        return min(r)

H, W = rdi()

print min(calc3(H, W), calc3(W, H))

Submission status: Wrong Answer

Solution code:
def max_minus_min(_a, _b, _c):
    return max(_a, _b, _c) - min(_a, _b, _c)


H, W = list(map(int, input().split()))
# 横幅が必ず縦幅以上となるようにする
if W <= H:
    tmp = W
    W = H
    H = tmp

if W % 3 == 0 or H % 3 == 0:
    print(0)
else:
    yoko_to_two1 = max_minus_min(
        int(H / 2) * (W - (int(W / 3) + 1)), (H - int(H / 2)) * (W - (int(W / 3) + 1)), ((int(W / 3) + 1) * H))
    yoko_to_two2 = max_minus_min(
        int(H / 2) * (W - (int(W / 3))), (H - int(H / 2)) * (W - (int(W / 3))), ((int(W / 3)) * H))

    tate_to_two1 = max_minus_min(int(W / 2) * (H - (int(H / 3) + 1)), (W - int(W / 2)) * (H - (int(H / 3) + 1)),
                                 ((int(H / 3) + 1) * W))
    tate_to_two2 = max_minus_min(int(W / 2) * (H - (int(H / 3))), (W - int(W / 2)) * (H - (int(H / 3))),
                                 ((int(H / 3)) * W))

    print(min(yoko_to_two1, yoko_to_two2, tate_to_two1, tate_to_two2))

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

Submission status: Wrong Answer

Solution code:
x, y = map(int, raw_input().split())
if x < y:
	x, y = y, x

if x % 3 == 0 or y % 3 == 0:
	print 0
else:
	m = 1000000
	for i in range(1, x):
		j = y / 2
		s1 = y * i
		s2 = (x - i) * j
		s3 = (x - i) * (y - j)
		l = [s1, s2, s3]
		l.sort()
		if l[-1] - l[0] < m:
			m = l[-1] - l[0]
			# ix = i
			# ij = j
	# print m
	for i in range(1, y):
		j = x / 2
		s1 = x * i
		s2 = (y - i) * j
		s3 = (y - i) * (x - j)
		l = [s1, s2, s3]
		l.sort()
		if l[-1] - l[0] < m:
			m = l[-1] - l[0]
			# ix = i
			# ij = j		
	print m

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=(W-(i+1))*(int(H/2)+1)
        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 = sorted(list(map(int,input().split())))
if h % 3 == 0 or w % 3 == 0:
  ret = 0
else:
  ret = min(((w-w//3)*(h-h//2))-(w//3*h),((w//3+1)*h)-((w-1-w//3)*(h//2)))
print(ret)

Submission status: Wrong Answer

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

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    w1 = W//3
    w2 = w1+1
    rw1 = W - w1
    rw2 = W - w2
    h1 = H//2
    h2 = H - h1
    s11 = H * w1
    s12 = rw1 * h1
    s13 = rw1 * h2
    diff1 = max(abs(s11-s12), abs(s12-s13), abs(s13-s11))
    s21 = H * w2
    s22 = rw2 * h1
    s23 = rw2 * h2
    diff2 = max(abs(s21-s22), abs(s22-s23), abs(s23-s21))
    delta = min(diff1, diff2)
    print(delta)

Submission status: Wrong Answer

Solution code:
def max_minus_min(_a, _b, _c):
    return max(_a, _b, _c) - min(_a, _b, _c)


H, W = list(map(int, input().split()))
# 横幅が必ず縦幅以上となるようにする
if W <= H:
    tmp = W
    W = H
    H = tmp

if W % 3 == 0 or H % 3 == 0:
    print(0)
else:
    yoko_to_two1 = max_minus_min(
        int(H / 2) * (W - (int(W / 3) + 1)), (H - int(H / 2)) * (W - (int(W / 3) + 1)), ((int(W / 3) + 1) * H))
    yoko_to_two2 = max_minus_min(
        int(H / 2) * (W - (int(W / 3))), (H - int(H / 2)) * (W - (int(W / 3))), ((int(W / 3)) * H))

    tate_to_two1 = max_minus_min(int(W / 2) * (H - (int(H / 3) + 1)), (W - int(W / 2)) * (H - (int(H / 3) + 1)),
                                 ((int(H / 3) + 1) * W))
    tate_to_two1 = max_minus_min(int(W / 2) * (H - (int(H / 3))), (W - int(W / 2)) * (H - (int(H / 3))),
                                 ((int(H / 3)) * W))

    print(min(yoko_to_two1, yoko_to_two2, tate_to_two1, ))

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

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()
    ans = min(ans, abs(W//3 - (W-(W//3)*2))*H)
    ans = min(ans, abs(H//3 - (H-(H//3)*2))*W)
    print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
else:
    m = 10000000
    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))])
    print(m)

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:
                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:
# -*- coding:utf-8 -*-
h,w = map(int,input().split())
if w % 3 == 0 or h % 3 == 0:
    print(0)
elif h % 2 == 1 and w % 2 == 0:
    arr = []
    smax = (h // 3 + 1) * w
    smin = (h - (h//3 + 1)) * (w//2)
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w - (w//3 + 1)) * (h//2)
    arr.append(smax - smin)

    
    smax = (h // 3) * w
    smin = (h - (h//3)) * (w//2)
    if smax - smin >= 0:
        arr.append(smax - smin)
    smax = (w//3) * h
    smin = (w - (w//3)) * (h//2)    
    if smax - smin >= 0:
        arr.append(smax - smin)    
    
    smax = (h//3 + 1) * w
    smin = (h//3) * w
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w//3) * h
    arr.append(smax - smin)    
    print(min(arr))
elif h % 2 == 0 and w % 2 == 1:
    arr = []
    smax = (h // 3 + 1) * w
    smin = (h - (h//3 + 1)) * (w//2)
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w - (w//3 + 1)) * (h//2)
    arr.append(smax - smin)

    smax = (h // 3) * w
    smin = (h - (h//3)) * (w//2)
    if smax - smin >= 0:
        arr.append(smax - smin)
    smax = (w//3) * h
    smin = (w - (w//3)) * (h//2)    
    if smax - smin >= 0:
        arr.append(smax - smin)
    
    
    smax = (h//3 + 1) * w
    smin = (h//3) * w
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w//3) * h
    arr.append(smax - smin)    
    print(min(arr))
elif h % 2 == 1 and w % 2 == 1:
    arr = []
    smax = (h // 3 + 1) * w
    smin = (h - (h//3 + 1)) * (w//2)
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w - (w//3 + 1)) * (h//2)
    arr.append(smax - smin)
    
    smax = (h//3 + 1) * w
    smin = (h//3) * w
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w//3) * h
    arr.append(smax - smin)    
    print(min(arr))
    
else:
    arr = []
    smax = (h // 3 + 1) * w
    smin = (h - (h//3 + 1)) * (w//2)
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w - (w//3 + 1)) * (h//2)
    arr.append(smax - smin)
    
    smax = (h // 3) * w
    smin = (h - (h//3)) * (w//2)
    arr.append(abs(smax - smin))
    smax = (w//3) * h
    smin = (w - (w//3)) * (h//2)    
    arr.append(abs(smax - smin))
    
    smax = (h//3 + 1) * w
    smin = (h//3) * w
    arr.append(smax - smin)
    smax = (w//3 + 1) * h
    smin = (w//3) * h
    arr.append(smax - smin)    
    print(min(arr))

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:
  ret = min(((w-w//3)*(h//2))-(w//3*h),((w//3+1)*h)-((w-1-w//3)*(h//2)))
print(ret)

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 = H - a
        c = W // 2
        lis = [H*a, b*c, (H-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    for i in range(W-1):
        a = W - i
        b = W - a
        c = H // 2
        lis = [W*a, b*c, (W-c)*b]
        ans = min(ans, max(lis) - min(lis))
        lis.clear()
    ans = min(ans, abs(W//3 - (W-(W//3)*2))*H)
    ans = min(ans, abs(H//3 - (H-(H//3)*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>W):
    H,W=W,H
    
if(H%2!=0):
    for i in range(W-1):
        A=(i+1)*H
        B=(W-(i+1))*int(H/2)
        C=(W-(i+1))*(int(H/2)+1)
        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)
print(min_dif)

Submission status: Wrong Answer

Solution code:
def splt(H, W, S, den):
    S_1, H_1, W_1 = 0, 0, 0
    mini = 10**11

    for h in range(H):
        if abs(S/den - h*W) < mini:
            H_1 = H - h
            W_1 = W
            mini = abs(S/den - h*W)

    for w in range(W):
        if abs(S/den - w*H) < mini:
            H_1 = H
            W_1 = W - w
            mini = abs(S/den - w*H)

    return H_1, W_1, S - H_1*W_1


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

S = H*W

H_1, W_1, S_1 = splt(H, W, S, 3)
H_2, W_2, S_2 = splt(H_1, W_1, S - S_1, 2)
S_3 = H_2 * W_2

df = [abs(S_1-S_2), abs(S_2-S_3), abs(S_3-S_1)]

print(max(df))

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
        if w>W:
            continue
        for _ in range(2):
            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