#K41262. Magic Square Checker
Magic Square Checker
Magic Square Checker
In this problem, you are given one or more square grids of integers. Your task is to determine whether each grid is a magic square. A magic square is defined as an (N \times N) matrix where the sum of the numbers in each row, each column, and in both main diagonals are all equal. Formally, if we denote the grid by (a_{ij}) for (1 \le i,j \le N), then it is magic if: [ \sum_{j=1}^{N}a_{ij} = S, \quad \sum_{i=1}^{N}a_{ij} = S, \quad \sum_{i=1}^{N}a_{ii} = S, \quad \sum_{i=1}^{N}a_{i,N+1-i} = S ] for some constant (S) (which is typically the sum of the first row). Note that even an all-zero grid is considered a magic square since all sums are equal. The input terminates when a test case with (N=0) is encountered, which should not be processed.
inputFormat
The input consists of multiple test cases. Each test case starts with a positive integer (N) indicating the dimension of the square grid. This is followed by (N) lines, each containing (N) space-separated integers representing the grid. The input is terminated by a test case where (N=0); this case should not be processed. All input is provided via standard input (stdin).
outputFormat
For each grid, output either 'True' if the grid is a magic square or 'False' otherwise. Each result should be printed on a separate line to standard output (stdout).## sample
3
2 7 6
9 5 1
4 3 8
0
True
</p>