404996: GYM101733 B Permutation Recovery
Description
Vladislav invented a new algorithm of the distributed key construction.
The distributed key consists of 2n numerical sequences of length n. To construct the key Vladislav gets some permutation p of length n2. Next step is to put the elements of p into a square matrix a. The first n elements of p form the first row of a, next n elements form the second row, etc. Finally, 2n numerical sequences of the distributed key are rows and columns of the matrix a.
These 2n sequences were given to Vladislav in some arbitrary order. He spent a while trying to come up with an algorithm for recovering the permutation. Try to restore the permutation before the end of the round!
InputThe first input line contains one integer n (1 ≤ n ≤ 100).
Each of the next 2n lines contains n integers from 1 to n2, rows and columns of the matrix a in some order.
It is guaranteed that the input is correct, there is at least one suitable permutation p.
OutputPrint a permutation p of integers from 1 to n2.
ExamplesInput2Output
1 2
1 3
2 4
3 4
1 2 3 4Input
4Output
1 6 14 7
5 4 1 13
13 16 12 10
8 3 6 16
11 2 7 10
15 9 14 12
4 3 9 2
5 8 15 11
5 4 1 13 8 3 6 16 15 9 14 12 11 2 7 10