#K9461. Magic Square Checker

    ID: 38680 Type: Default 1000ms 256MiB

Magic Square Checker

Magic Square Checker

Given an (n \times n) matrix, determine whether it is a magic square. A magic square is defined such that every row, every column, and both main diagonals have the same sum. Formally, if (M) is the magic constant (i.e., the sum of the elements of the first row), then for all valid rows (i) and columns (j), the following conditions must hold:

[ \sum_{j=1}^{n}a_{ij}= M, \quad \sum_{i=1}^{n}a_{ij}= M, \quad \sum_{i=1}^{n}a_{ii}= M, \quad \sum_{i=1}^{n}a_{i,n-i+1}= M ]

Note that the matrix elements can be arbitrary integers. Your task is to check whether the given matrix satisfies these conditions and hence qualifies as a magic square.

inputFormat

The first line of input contains a single integer (n) (the size of the matrix). This is followed by (n) lines, each containing (n) space-separated integers, representing the rows of the matrix.

outputFormat

Output a single line containing either "True" or "False". Output "True" if the input matrix is a magic square, and "False" otherwise.## sample

3
2 7 6
9 5 1
4 3 8
True