#abc232h. [abc232_h]King's Tour
[abc232_h]King's Tour
Problem Statement
We have an chessboard with rows and columns, and a king.
Let denote the square at the -th row from the top and -th column from the left .
The king can move one square in any direction. Formally, the king on can move to if and only if .
A tour is the process of moving the king on the chessboard as follows.
- Start by putting the king on . Then, move the king to put it on each square exactly once.
For example, when , going $(1,1) \\to (1,2) \\to (1, 3) \\to (2, 3) \\to (2, 2) \\to (2, 1)$ is a valid tour.
You are given a square other than . Construct a tour ending on and print it. It can be proved that a solution always exists under the Constraints of this problem.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the -th square the king is put on, in the following format:
Here, note that the -st line should contain , and the -th line should contain .
Sample Input 1
3 2 3 2
Sample Output 1
1 1
1 2
2 1
2 2
3 1
3 2
The king goes $(1, 1) \\to (1, 2) \\to (2, 1) \\to (2, 2)\\to (3, 1) \\to (3, 2)$, which is indeed a tour ending on .
There are some other valid tours, three of which are listed below.
- $(1, 1) \\to (1, 2) \\to (2, 2) \\to (2, 1) \\to (3, 1) \\to (3, 2)$
- $(1, 1) \\to (2, 1) \\to (1, 2) \\to (2, 2) \\to (3, 1) \\to (3, 2)$
- $(1, 1) \\to (2, 2) \\to (1, 2) \\to (2, 1) \\to (3, 1) \\to (3, 2)$