Time limit
2s
Memory limit
128 MB
Draw a line on an M-row, N-column grid. Start from the upper-left cell and move to the right first.
| ㅇ | ||
The diagram below shows the path for M=5 and N=3. If the next cell would be outside the grid or has already been visited by the line, turn clockwise and continue.
| ㅇ | → | ↘ |
| ↗ | ↘ | ↓ |
| ↑ | ↓ | ↓ |
| ↑ | end | ↓ |
| ↖ | ← | ↙ |
Diagonal arrows indicate cells where the direction changes. Determine how many times the line changes direction before every cell of the grid is filled.
The first line contains M and N separated by a space.
Print the number of direction changes made before every cell of the grid is filled.