#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int n;
int mat[2510][2510];
bitset<2510> r[2510], c[2510];
pii p[2510 * 2510];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", &mat[i][j]);
  for (int i = 1; i <= n; i++) {
    if (mat[i][i]) return puts("NOT MAGIC");
    for (int j = 1; j <= n; j++)
      if (mat[i][j] != mat[j][i]) return puts("NOT MAGIC");
  }
  int nn = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) p[++nn] = pii(i, j);
  sort(p + 1, p + nn + 1, [&](pii u, pii v) {
    return mat[u.first][u.second] > mat[v.first][v.second];
  });
  for (int i = 1; i <= nn;) {
    int j = i;
    for (; j <= nn and
           mat[p[j].first][p[j].second] == mat[p[i].first][p[i].second];
         j++)
      ;
    for (int k = i; k < j; k++) {
      int u = p[k].first, v = p[k].second;
      r[u].set(v), c[v].set(u);
    }
    for (int k = i; k < j; k++) {
      int u = p[k].first, v = p[k].second;
      if ((r[u] | c[v]).count() != n) return puts("NOT MAGIC");
    }
    i = j;
  }
  puts("MAGIC");
}
