#include <bits/stdc++.h>
using namespace std;
int a[2555][2555], m[2555][2555];
void puts() { printf("NOT MAGIC\n"); }
const int z = 5;
int main() {
  int n, t = 0;
  memset(m, 0x3f, sizeof(m));
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
      if (a[i][j] == 2) t++;
    }
  if (t > 1000) {
    puts();
    return 0;
  }
  for (int i = 0; i < n; i++)
    if (a[i][i]) {
      puts();
      return 0;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] != a[j][i]) {
        puts();
        return 0;
      }
  for (int i = 2; i < n; i++) {
    int m = 0x3f3f3f3f;
    for (int j = 0; j < n; j++) m = min(m, max(a[i - 1][j], a[i][j]));
    if (a[i][i - 1] > m) {
      puts();
      return 0;
    }
  }
  srand((unsigned)time(NULL));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      for (int k = 0; k < min(n, z); k++) {
        int kk = n <= z ? k : rand() % n;
        m[i][j] = min(max(a[i][kk], a[j][kk]), m[i][j]);
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] > m[i][j]) {
        puts();
        return 0;
      }
  puts("MAGIC");
  return 0;
}
