#include <bits/stdc++.h>
using namespace std;
const int maxn = 2505;
int a[maxn][maxn];
pair<int, pair<int, int> > d[maxn * maxn];
int n, tot, last;
int fa[maxn];
int fi(int x) { return x == fa[x] ? x : fa[x] = fi(fa[x]); }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    for (int j = 1; j <= n; j++) {
      if (i == j && a[i][j]) return puts("NOT MAGIC");
      if (a[i][j] != a[j][i]) return puts("NOT MAGIC");
      if (i > j) d[tot++] = make_pair(a[i][j], make_pair(i, j));
    }
  }
  sort(d, d + tot);
  for (int i = 0; i < tot; i++) {
    if (i + 1 < tot && d[i].first == d[i + 1].first) continue;
    for (int j = last; j <= i; j++) {
      int p1 = fi(d[j].second.first);
      int p2 = fi(d[j].second.second);
      if (p1 == p2) return puts("NOT MAGIC");
    }
    for (int j = last; j <= i; j++) {
      int p1 = fi(d[j].second.first);
      int p2 = fi(d[j].second.second);
      fa[p2] = p1;
    }
    last = i + 1;
  }
  puts("MAGIC");
}
