Statement
In BCD 67, trashmouse mistook this problem for Nostalgia (https://doj.kr/ko/problems/595) and got it wrong. Let us avoid making the same mistake.
There are buildings arranged in a grid. Let be the height of the building in row and column .
All building heights are distinct, and each integer from through appears exactly once.
When viewed from the front, the visible height of column is
Let be the minimum of these values.
When viewed from the side, the visible height of row is
Let be the minimum of these values.
An integer is given. Construct one arrangement of the building heights such that . If no such arrangement exists, determine that it is impossible.
Input
The input is given from Standard Input in the following format:
Each case is given in the following format:
Output
For each test case, if no valid arrangement exists, print -1 on one line.
Otherwise, print the matrix in lines. On the -th line, print separated by spaces.
The printed matrix must contain each of exactly once, and it must satisfy for the values defined in the statement.
If there are multiple solutions, print any of them.
Constraints
- .
- .
- .
- The sum of over all test cases does not exceed .
Subtasks
Samples
The column maxima are and , so . The row maxima are and , so . Therefore .