Woburn Challenge 1995
A square arrangement of numbers such as
Copy
1 2 3 4 5
2 1 4 5 3
3 4 5 1 2
4 5 2 3 1
5 3 1 2 4
is a Latin square because each whole number 1, 2, 3, 4 and 5 appears exactly once in each row and column of the square.
Of all the possible
is the smallest one possible.
Input Specification
On the first line is
On each of the next
Output Specification
Output the smallest
Sample Input
Copy
1
5
Sample Output
Copy
1 2 3 4 5
2 1 4 5 3
3 4 5 1 2
4 5 2 3 1
5 3 1 2 4
Comments