forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc.py
More file actions
executable file
·30 lines (29 loc) · 659 Bytes
/
Copy pathc.py
File metadata and controls
executable file
·30 lines (29 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
# https://abc062.contest.atcoder.jp/tasks/arc074_a
def s(a1, a2, a3): return max([a1, a2, a3]) - min([a1, a2, a3])
h, w = map(int, input().split())
h1 = h // 3
h2 = (h - h1) // 2
h3 = h - h1 - h2
t = s(h1 * w, h2 * w, h3 * w)
w1 = w // 3
w2 = (w - w1) // 2
w3 = w - w1 - w2
t = min(t, s(h * w1, h * w2, h * w3))
w1 = w // 3
w2 = w - w1
h1 = h // 2
h2 = h - h1
t = min(t, s(h * w1, h1 * w2, h2 * w2))
w1 = (w // 3) + 1
w2 = w - w1
t = min(t, s(h * w1, h1 * w2, h2 * w2))
h1 = h // 3
h2 = h - h1
w1 = w // 2
w2 = w - w1
t = min(t, s(h1 * w, h2 * w1, h2 * w2))
h1 = h // 3 + 1
h2 = h - h1
t = min(t, s(h1 * w, h2 * w1, h2 * w2))
print(t)