#include <bits/stdc++.h>
using namespace std;
const int maxn = 2505;
struct pi {
  int to;
  int cost;
} pp[maxn];
struct ppi {
  int x;
  int y;
  int p;
} pp1[maxn * maxn];
int cmp(ppi a, ppi b) { return a.p < b.p; }
vector<pi> g[maxn];
int fa[maxn];
int find(int p) {
  if (fa[p] == -1 || fa[p] == p) return fa[p] = p;
  return fa[p] = find(fa[p]);
}
void merg(int a, int b) {
  int p = find(a);
  int q = find(b);
  if (p != q) fa[p] = q;
}
int flag;
int a[2505][2505];
void dfs(int u, int pa, int root, int s) {
  if (a[u][root] != s) {
    flag = 1;
    return;
  }
  int p = g[u].size();
  for (int i = 0; i < p; i++) {
    if (g[u][i].to != pa) {
      dfs(g[u][i].to, u, root, max(s, g[u][i].cost));
    }
  }
}
int main() {
  int i, j, n, m = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      ++m;
      pp1[m].x = i;
      pp1[m].y = j;
      pp1[m].p = a[i][j];
    }
  }
  int f = 0;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i == j && a[i][j] != 0) {
        f = 1;
      }
      if (a[i][j] != a[j][i]) {
        f = 1;
      }
    }
  }
  if (f == 0) {
    sort(pp1 + 1, pp1 + 1 + m, cmp);
    memset(fa, -1, sizeof(fa));
    for (i = 1; i <= m; i++) {
      if (find(pp1[i].x) != find(pp1[i].y)) {
        merg(pp1[i].x, pp1[i].y);
        pi p1;
        p1.to = pp1[i].y;
        p1.cost = pp1[i].p;
        g[pp1[i].x].push_back(p1);
        p1.to = pp1[i].x;
        g[pp1[i].y].push_back(p1);
      }
    }
    for (i = 1; i <= n; i++) {
      dfs(i, -1, i, 0);
      if (flag) break;
    }
    if (flag)
      printf("NOT MAGIC\n");
    else
      printf("MAGIC\n");
  } else
    printf("NOT MAGIC\n");
}
