V_AYP2_C - Magic

no tags 

Español 

A group of numbers which have the same value when added by row, column and diagonal are known as magic groups. These groups are known to have the same amount of rows and columns. For example:

|16|3 |2 |13|

|5 |10|11|8 |

|9 |6 |7 |12|

|4 |15|14|1 |

In this magic group the magical sum is 34 in rows, columns and diagonals. If the sum of one or two of the diagonals don ́t match with the magical sum this group is considered semi-magical.

Following a much known practice, divide and conquer, we have developed a program that verifies that the columns sum match, you will only have to verify the rows and both main diagonals sums match.

 

Input details:

The first line will contain an integer N indicating the size of the group. N lines follow with N integers each having the numbers of the group. Groups will continue being read until N=0.

 

Output details:

The output line will indicate if the group (square) is magical (M), semi-magical(SM) or not magical (NM).

 

 

INPUT

OUTPUT

3

1 2 3

2 3 1

3 1 2

4

16 3 2 13

5 10 11 8

9 6 7 12

4 15 14 1

0

SM

M

 

Constraints:

1 <= N <= 50

 



Added by:Venezuelan Programming League
Date:2013-02-02
Time limit:4s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64