Time limit
2s
Memory limit
128 MB
Draw a snail-shaped line that fills every cell of an M-row, N-column table.
| ○ | ||
The drawing above shows the table for M = 5, N = 3. Start in the upper-left cell marked ○ and move to the right. Whenever the line would leave the table or enter a cell that has already been used, turn clockwise and continue.
| ○ | → | ↘ |
| ↗ | ↘ | ↓ |
| ↑ | ↓ | ↓ |
| ↑ | end | ↓ |
| ↖ | ← | ↙ |
The second drawing shows the completed path. Diagonal marks indicate cells where the line turns. How many times does the line turn before every cell is filled, and at which cell does it end?
The first line contains two integers M and N separated by a space. (2 ≤ M, N ≤ 2,100,000,000)
On the first line, output the number of times the line turns before every cell is filled. On the second line, output the coordinates of the cell where the line ends. The upper-left cell has coordinates (1, 1), and the lower-right cell has coordinates (M, N).