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 3² = 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 n of a square,
followed by n rows, each with n natural numbers between 1 and n². Assume
1 ≤ n ≤ 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
