C-PROM 2014 (PROBLEM 2 :MAGIC SQUARES)

PROBLEM 2 : MAGIC SQUARES


A magic square is a two-dimensional arrangement of positive integers with a special property: All rows, columns and diagonals total the same number. Below, for example, the 3-by-3 arrangement of nine (9) numbers is a magic square:


 
2
7
6
15

9
5
1
15
4
3
8
15
15
15
15
15
15

Your assignment is to read a square of numbers as input and determine whether it is a magic square or not.

Input

The first line will contain a positive integer  2 < N < 6, which represents the number of columns and rows in the square. The next N lines will each contains N positive integers separated by spaces.

The input must be read from standard input.

Output

The output of the program should print the result, either MAGIC or NO.

The output must be written to standard output.

Sample Input
Sample Output
3
2 7 6
9 5 1
4 3 8

3
1 2 3
4 5 6
7 8 9
MAGIC




No


Problem Setter : Mohd Nizam Osman


Share this

Related Posts

Previous
Next Post »