atcoder#AGC037D. [AGC037D] Sorting a Grid
[AGC037D] Sorting a Grid
Score : points
Problem Statement
We have a grid with rows and columns of squares. Each integer from to is written in this grid once. The number written in the square at the -th row from the top and the -th column from the left is .
You need to rearrange these numbers as follows:
- First, for each of the rows, rearrange the numbers written in it as you like.
- Second, for each of the columns, rearrange the numbers written in it as you like.
- Finally, for each of the rows, rearrange the numbers written in it as you like.
After rearranging the numbers, you want the number written in the square at the -th row from the top and the -th column from the left to be . Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.
Constraints
- are distinct.
Input
Input is given from Standard Input in the following format:
Output
Print one way to rearrange the numbers in the following format:
Here is the number written in the square at the -th row from the top and the -th column from the left after Step , and is the number written in that square after Step .
3 2
2 6
4 3
1 5
2 6
4 3
5 1
2 1
4 3
5 6
3 4
1 4 7 10
2 5 8 11
3 6 9 12
1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10