#C4462. Magic Square Verification

    ID: 48003 Type: Default 1000ms 256MiB

Magic Square Verification

Magic Square Verification

In this problem, you are given an integer (N) and an (N\times N) matrix. Your task is to determine whether the given matrix is a magic square. A magic square is one where the sums of the elements in every row, every column, and both main diagonals are equal. The magic constant, (M), is defined as the sum of the elements in the first row, i.e., (M = \sum_{j=1}^{N} a_{1,j}). Note that a 1 (\times) 1 matrix is trivially a magic square.

You need to read the input from the standard input (stdin) and write the output to the standard output (stdout).

inputFormat

The first line contains a single integer (N) representing the dimensions of the square matrix. The following (N) lines each contain (N) space-separated integers representing the elements of the matrix.

outputFormat

Output a single string: "YES" if the matrix is a magic square, otherwise "NO".## sample

3
2 7 6
9 5 1
4 3 8
YES