#include <bits/stdc++.h>
using namespace std;
const int maxn = 2500 + 5;
int n, a[maxn][maxn];
int tot;
struct Data {
  int x, y, z;
  bool operator<(const Data &a) const { return z < a.z; }
} b[maxn * maxn];
bitset<2505> bt[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      scanf("%d", &a[i][j]), b[++tot] = (Data){i, j, a[i][j]};
  for (int i = 1; i <= n; ++i)
    if (a[i][i]) puts("NOT MAGIC"), exit(0);
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (a[i][j] != a[j][i]) puts("NOT MAGIC"), exit(0);
  sort(b + 1, b + 1 + tot);
  for (int i = 1, p = 1; i <= tot; i = p) {
    while (b[p].z == b[i].z && p <= tot) {
      int x = b[p].x, y = b[p].y;
      if ((bt[x] & bt[y]).count()) puts("NOT MAGIC"), exit(0);
      p++;
    }
    for (int j = i; j < p; ++j) bt[b[j].x][b[j].y] = 1;
  }
  puts("MAGIC");
  return 0;
}
