#000094

Magic

A Magic Square is an N by N matrix such that the sum of all the elements in each row, each column and the two diagonals is the same. Also, all the elements of a Magic Square are different and are in the range from 1 to N^2.


Your are given a matrix with some element missing. Your task is to complete the matrix so that it is a Magic Square (if it is possible).


InputThe first line of the standard input will contain one integer N, 1 <= N <= 5. Each of the next N lines will contain N integers representing the elements in the matrix. The number 0 represents an empty element.

OutputIf it is possible to complete the matrix so that it is a Magic Square, then output the matrix to the standard output - in N lines output N integers separated by a single space that represent the matrix. If it is impossible to fill out the empty elements so that the marix is a Magic Square, then output -1 to the standard output.

Input:
2
1 0
2 3

Output:
-1

Input:
3
2 7 6
9 0 1
4 0 0

Output:
2 7 6
9 5 1
4 3 8

Submit solution

Coming later

The grading service will be connected in a later migration step. You can inspect the task and your previous results now.