Magic squares

Once, a messenger of the sultan found a wall with this square filled with numbers:

6 1 8
7 5 3
2 9 4

Asked, Beremiz told the sultan that it was a “magic square” of order 3, that is, a square of size 3, where all the numbers between 1 and 32=93^2 = 9 appear once, and where all the rows, all the columns and the two diagonals add up to the same number, 15 in the example.

Input

Input consists of several cases, each with the order nn of a square, followed by nn rows, each with nn natural numbers between 1 and n2n^2. Assume 1n1001 \le n \le 100.

Output

For every case, print “yes” if the given square is magic, and “no” otherwise.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T12:22:07.368Z

© Jutge.org, 2006–2026.
https://jutge.org