Magic Square
Is the N×N matrix a magic square — all rows, all columns and both diagonals sharing the same sum? (Values need not be distinct.)
Input: the first line has N and N; the next N lines each have N integers.
Output: YES or NO.
Constraints:
- 1 ≤ N ≤ 100
Sample Tests
Input 1
3 3 2 7 6 9 5 1 4 3 8
Output 1
YES
Input 2
2 2 1 2 3 4
Output 2
NO
Discussion (opens after you solve — no spoilers before)
No comments yet.