Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/matritsa-sehrli-kvadrat

Magic square

Medium 1000 ms 128 MB 52%
Share

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.

A magic square with equal row, column and diagonal sums

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

Sign in to submit a solution

Signing up is free and takes a minute.