#K1566. Special Matrix Determination

    ID: 24406 Type: Default 1000ms 256MiB

Special Matrix Determination

Special Matrix Determination

You are given an N × N matrix. A matrix is called special if the sum of the elements in each row, each column, and both main diagonals are equal. In mathematical terms, let \(S\) be the sum of the elements in the first row. Then for all valid indices:

  • For every row \(i\): \(\sum_{j=1}^{N} a_{ij} = S\)
  • For every column \(j\): \(\sum_{i=1}^{N} a_{ij} = S\)
  • Main diagonal: \(\sum_{i=1}^{N} a_{ii} = S\)
  • Secondary diagonal: \(\sum_{i=1}^{N} a_{i,N-i+1} = S\)

Your task is to determine whether the given matrix is special. Print Yes if it is, otherwise print No.

inputFormat

The input is read from stdin and has the following format:

N
a11 a12 ... a1N
a21 a22 ... a2N
...
aN1 aN2 ... aNN

Where the first line contains an integer N (the size of the matrix), followed by N lines each containing N space-separated integers.

For example, a 3 × 3 matrix input might look like:

3
2 9 4
7 5 3
6 1 8

outputFormat

Output a single line to stdout containing either Yes if the matrix is special, or No otherwise.

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