#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 2511;
int a[N][N];
int e[N * N], id[N * N], num = 0;
int fa[N];
int v[N * 2], pre[N * 2], bia[N], c[N * 2];
void addedge(int l, int r, int cost) {
  num++;
  v[num] = r;
  pre[num] = bia[l];
  bia[l] = num;
  c[num] = cost;
}
bool cmp(int i, int j) { return (e[i] < e[j]); }
int findf(int x) {
  if (x == fa[x])
    return x;
  else
    return fa[x] = findf(fa[x]);
}
int f[N][13], mx[N][13], dep[N];
void dfs(int l, int fa) {
  int r;
  for (int i = bia[l]; i != 0; i = pre[i]) {
    r = v[i];
    if (fa == r) continue;
    f[r][0] = l;
    dep[r] = dep[l] + 1;
    mx[r][0] = c[i];
    dfs(r, l);
  }
}
void lcaprep() {
  for (int k = 1; k <= 12; k++) {
    for (int i = 1; i <= n; i++) {
      f[i][k] = f[f[i][k - 1]][k - 1];
      mx[i][k] = max(mx[i][k - 1], mx[f[i][k - 1]][k - 1]);
    }
  }
}
int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 12; i >= 0; i--) {
    if (dep[f[u][i]] >= dep[v]) {
      u = f[u][i];
    }
  }
  if (u == v) return u;
  for (int i = 12; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
int getmx(int u, int fa) {
  int ans = 0;
  for (int i = 12; i >= 0; i--) {
    if (dep[f[u][i]] >= dep[fa]) {
      ans = max(ans, mx[u][i]);
      u = f[u][i];
    }
  }
  return ans;
}
int ans[N][N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    for (int j = 1; j <= n; j++) {
      scanf("%d", &a[i][j]);
      e[num++] = a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][i] != 0) {
      cout << "NOT MAGIC";
      return 0;
    }
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != a[j][i]) {
        cout << "NOT MAGIC";
        return 0;
      }
    }
  }
  for (int i = 0; i < num; i++) {
    id[i] = i;
  }
  sort(id, id + num, cmp);
  int x, y, fx, fy;
  num = 0;
  for (int i = 0; i < n * n; i++) {
    x = id[i] / n + 1;
    y = id[i] % n + 1;
    fx = findf(x);
    fy = findf(y);
    if (fx == fy) continue;
    addedge(x, y, a[x][y]);
    addedge(y, x, a[y][x]);
    fa[fx] = fy;
  }
  dep[1] = 1;
  dfs(1, 0);
  lcaprep();
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int t = getlca(i, j);
      ans[i][j] = ans[j][i] = max(getmx(i, t), getmx(j, t));
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (ans[i][j] < a[i][j]) {
        cout << "NOT MAGIC";
        return 0;
      }
    }
  }
  cout << "MAGIC";
  return 0;
}
