Magic squares P99555


Statement
 

pdf   zip

html

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



||

618
753
294

||



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 = 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 n2. Assume 1 ≤ n ≤ 100.

Output

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

Public test cases
  • Input

    3
    6 1 8
    7 5 3
    2 9 4
    3
    6 1 8
    7 5 9
    2 3 4
    3
    1 6 8
    5 7 3
    9 2 4
    1
    1
    2
    1 2
    3 4
    4
    4 5 16 9
    14 11 2 7
    1 8 13 12
    15 10 3 6
    

    Output

    yes
    no
    no
    yes
    no
    yes
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++ Python
    User solutions
    C++ Java Python