import java.util.*;
public class cpromB {
public static void main(String [] args) {
Scanner scn = new Scanner(System.in);
while (scn.hasNextInt()) {
int num = scn.nextInt();
int [][] array = new int [num][num];
int total = 0;
for(int x=0;x<num;x++) {
for(int y=0;y<num;y++) {
array[x][y] = scn.nextInt();
if(x==0)
total+= array[x][y];
}
}
boolean checkTrue = true;
if(!isRowCheck(array,total,num)) {
checkTrue = false;
}
if(!isColumnCheck(array,total,num) || !checkTrue) {
checkTrue = false;
}
if(!isDiagonalRight(array,total,num) || !checkTrue) {
checkTrue = false;
}
if(!isDiagonalLeft(array,total,num) || !checkTrue) {
checkTrue = false;
}
if(checkTrue)
System.out.println("MAGIC");
else
System.out.println("No");
}
}
public static boolean isRowCheck(int [][] array, int total,int num) {
int temp = 0;
boolean check = true;
for(int x=0;x<num;x++) {
temp = 0;
for(int y=0;y<num;y++) {
temp += array[x][y];
}
if(temp != total) {
check = false;
return check;
}
}
return check;
}
public static boolean isColumnCheck(int [][] array, int total,int num) {
int temp = 0;
boolean check = true;
for(int x=0;x<num;x++) {
temp = 0;
for(int y=0;y<num;y++) {
temp += array[y][x];
}
if(temp != total) {
check = false;
return check;
}
}
return check;
}
public static boolean isDiagonalRight(int [][] array, int total,int num) {
int temp = 0;
boolean check = true;
for(int x=0;x<num;x++) {
temp += array[x][x];
}
if(temp != total) {
check = false;
return check;
}
return check;
}
public static boolean isDiagonalLeft(int [][] array, int total,int num) {
int temp = 0;
boolean check = true;
for(int x=num-1;x>=0;x--) {
temp += array[num-x-1][x];
}
if(temp != total) {
check = false;
return check;
}
return check;
}
}