#agc037d. [agc037_d]Sorting a Grid
[agc037_d]Sorting a Grid
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 .