Balance Stone

One cell of an N by N grid is 0; find the number M that makes all rows, columns, and both diagonals share one common sum, or print -1.

Medium4ImplementationMathMatrixInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

Thanojins, a villain who wants to cut the population of the universe in half, is after the Balance Stone, a gem that controls how many people the universe holds. Captain Hakgyu of the Cvengers stands against him and wants to find the Balance Stone first and destroy it.

The Balance Stone is the prize for completing a number puzzle made of N×NN \times N blocks. One block of the puzzle is empty, and the puzzle is complete once you write a number MM in that block that satisfies the rules below.

  1. After MM is written in, every row has the same sum.
  2. After MM is written in, every column has the same sum.
  3. After MM is written in, the two diagonals have the same sum.
  4. The sums from rules 1, 2 and 3 are all the same value.
  5. If no number written in place of MM satisfies rules 1, 2 and 3, write -1 in the block to finish the puzzle.

Help Captain Hakgyu complete the puzzle and keep the universe at peace.

Input

The first line contains the puzzle size NN. (2N5002 \le N \le 500)

Each of the next NN lines contains the NN numbers written in the blocks of one row. Each number is a natural number between 11 and 10910^9, and the empty block is given as 00. One block is empty. When an MM that satisfies the rules exists, that MM is always a natural number.

Output

Print the number MM that satisfies the puzzle rules. Print -1 if no such number exists.