Puzzle Piece Problems
Statement
Goal
For a given regular jigsaw puzzle of of size h x w how many tabs (the bits that stick out) are there?- A rectangular jigsaw puzzle has pieces arranged in a grid.
- Each piece has a single tab or socket on each side that is in contact with an adjacent piece.
Input
Line 1: Two space-separated integers h and w for the height and width of the puzzle in terms of pieces.
Output
Line 1: The numbers of tabs as an integer.
Constraints
1 ≤ h, w ≤ 100
Example
Input
2 2
Output
4
Game modes
Fastest, Shortest
Test cases
small square Test
Input
2 2
Output
4
small square Validator
Input
3 3
Output
12
medium square Test
Input
8 8
Output
112
medium square Validator
Input
7 7
Output
84
small rectangle Test
Input
4 3
Output
17
small rectangle Validator
Input
3 4
Output
17
large rectangle Test
Input
13 7
Output
162
large rectangle Validator
Input
9 11
Output
178
huge puzzle Test
Input
30 50
Output
2920
huge puzzle Validator
Input
48 25
Output
2327
tiny puzzle Test
Input
2 1
Output
1
tiny puzzle Validator
Input
1 1
Output
0
Solution language
Solution
Stub generator input