#C13348. Magic Square Checker

    ID: 42876 Type: Default 1000ms 256MiB

Magic Square Checker

Magic Square Checker

Your task is to check whether a given square matrix is a magic square.

A magic square is defined as an \(N \times N\) matrix in which every row, every column, and the two main diagonals all have the same sum, \(S\). In other words, if the matrix is denoted by \(a_{ij}\) (with \(1 \leq i,j \leq N\)), then the following conditions must hold:

  • \(\sum_{j=1}^{N} a_{ij} = S\) for every row \(i\).
  • \(\sum_{i=1}^{N} a_{ij} = S\) for every column \(j\).
  • \(\sum_{i=1}^{N} a_{ii} = S\) (main diagonal).
  • \(\sum_{i=1}^{N} a_{i,N-i+1} = S\) (secondary diagonal).

For \(N=1\), the matrix always qualifies as a magic square.

Read the input from stdin and print "True" if the matrix is a magic square; otherwise, print "False".

inputFormat

The first line contains a single integer \(N\) representing the size of the matrix. The following \(N\) lines each contain \(N\) space-separated integers representing the rows of the matrix.

outputFormat

Output a single line with either "True" if the matrix is a magic square, or "False" otherwise.

## sample
3
2 7 6
9 5 1
4 3 8
True