eolymp
bolt
Try our new interface for solving problems
Problems

Magic square

Magic square

Magic square - a square table, filled \textbf{n^2} numbers so that the sum of the numbers in each row, each column and both diagonals of the same. Sum of the numbers in each row, column and diagonal, is called the magic constant. Check or specify the square is magical. \includegraphics{https://static.e-olymp.com/content/4a/4a6d8ad3e29140243252bf01d63eb803cf131514.gif} \InputFile The first line contains the number \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100}). Next is the \textbf{n} rows of \textbf{n} numbers each. All of the square - the natural numbers not exceeding \textbf{32000}. \OutputFile If the specified array is magic - the magic of its output constant, otherwise the output \textbf{-1}.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
2 7 6
9 5 1
4 3 8
Output example #1
15