BlueBook - Magic Square

View as PDF

Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 16M

Problem type
BlueBook

Determine if a table of numbers containing N rows and N columns is a magic square.

A N\times N table of numbers (1 \le N \le 50) is a magic square if and only the sum of the numbers along any row or column is constant. The diagonals are not required to have the same sum.

Input Specification

The first line of input contains an integer T (1 \le T \le 10), the number of test cases to follow.
Each test case starts with an integer N (1 \le N \le 50), which is followed by N^2 integers, each on its own line - the entries of the table, in reading order. This means that the first N integers represent the first row of the table, from left to right, the next N integers the second row likewise, and so on. There is a blank line between each pair of adjacent cases.

Output Specification

For each test case, print yes if it is a magic square, and no if it is not.

Sample Input

3
2
1
2
2
1

1
5

2
1
2
3
4

Sample Output

yes
yes
no

Comments

There are no comments at the moment.