#include <bits/stdc++.h>
using namespace std;
int N;
int A[2510][2510] = {{0}};
int Link[2510] = {0};
struct bian_ {
  int p, q;
  int dis;
} bian[6250000] = {{0, 0, 0}};
int bp = 0;
int F[20][2510] = {{0}};
int Max[20][2510] = {{0}};
int logN = 0;
int depth[2510] = {0};
bool cmp(struct bian_ a, struct bian_ b) { return a.dis < b.dis; }
int Find(int x) {
  if (Link[x] == x) return x;
  Link[x] = Find(Link[x]);
  return Link[x];
}
void Pre() {
  for (int i = 1; i <= logN; i++)
    for (int j = 1; j <= N; j++) {
      F[i][j] = F[i - 1][F[i - 1][j]];
      Max[i][j] = max(Max[i - 1][j], Max[i - 1][F[i - 1][j]]);
    }
  return;
}
int Up(int &p, int k) {
  int ret = 0;
  for (int i = logN; i >= 0; i--) {
    if (k >= (1 << i)) {
      k -= 1 << i;
      ret = max(ret, Max[i][p]);
      p = F[i][p];
    }
  }
  return ret;
}
int getMax(int p, int q) {
  int ret = 0;
  if (depth[p] > depth[q])
    ret = Up(p, depth[p] - depth[q]);
  else
    ret = Up(q, depth[q] - depth[p]);
  for (int i = logN; i >= 0; i--) {
    if (F[i][p] != F[i][q]) {
      ret = max(ret, max(Max[i][p], Max[i][q]));
      p = F[i][p];
      q = F[i][q];
    }
  }
  if (p != q) ret = max(ret, max(Max[0][p], Max[0][q]));
  return ret;
}
int main() {
  cin >> N;
  logN = log(N) / log(2) + 1;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      scanf("%d", &A[i][j]);
      bp++;
      bian[bp].p = i;
      bian[bp].q = j;
      bian[bp].dis = A[i][j];
    }
  sort(bian + 1, bian + bp + 1, cmp);
  for (int i = 1; i <= N; i++) {
    Link[i] = i;
    if (A[i][i] != 0) {
      puts("NOT MAGIC");
      return 0;
    }
    for (int j = 1; j <= N; j++) {
      if (A[i][j] != A[j][i]) {
        puts("NOT MAGIC");
        return 0;
      }
    }
  }
  for (int i = 1; i <= bp; i++) {
    int p = Find(bian[i].p), q = Find(bian[i].q);
    if (p == q) continue;
    if (p > q) swap(p, q);
    Link[q] = p;
    F[0][q] = p;
    Max[0][q] = bian[i].dis;
  }
  Pre();
  for (int i = 1; i <= N; i++) depth[i] = depth[F[0][i]] + 1;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (getMax(i, j) != A[i][j]) {
        puts("NOT MAGIC");
        return 0;
      }
    }
  }
  puts("MAGIC");
  return 0;
}
