~/algor $ cat problems/matritsa-sehrli-kvadrat
Magic square
Medium
1000 ms
128 MB
52%
A square integer matrix of size $n \times n$ is given. If the sums of every row, every column and both diagonals are all equal (a magic square), print YES, otherwise print NO.
Input
The first line contains two equal positive integers $n$ and $n$. Each of the next $n$ lines contains $n$ integers.
Output
YES or NO.
Note
$1 \le n \le 30$
$1 \le a_{i,j} \le 10^{4}$
Examples
Input #1
3 3 2 7 6 9 5 1 4 3 8
Output #1
YES
Input #2
3 3 1 2 3 4 5 6 7 8 9
Output #2
NO