#include <bits/stdc++.h>
using namespace std;
inline long long Min(long long x, long long y) {
  if (x < y) return x;
  return y;
}
inline long long Max(long long x, long long y) {
  if (x > y) return x;
  return y;
}
inline void read(long long &x) {
  x = 0;
  long long f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s ^ 48);
    s = getchar();
  }
  x *= f;
}
struct node {
  long long Val, x, y;
  node() { Val = 0x3f3f3f3f3f3f3f3f; }
  friend bool operator<(node A, node B) { return A.Val < B.Val; }
} P[2505 * 2505];
bool cmp(node A, node B) { return A.Val < B.Val; }
bitset<2505> Jzm, Hang[2505], Lie[2505];
long long tot, a[2505][2505];
int main() {
  long long n;
  read(n);
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= n; ++j) {
      read(a[i][j]);
      P[++tot].Val = a[i][j];
      P[tot].x = i, P[tot].y = j;
    }
  for (register int i = 1; i <= n; ++i)
    for (register int j = 1; j <= n; ++j) {
      if (a[i][j] != a[j][i]) return !printf("NOT MAGIC");
      if (i == j && a[i][j] != 0) return !printf("NOT MAGIC");
    }
  sort(P + 1, P + 1 + tot);
  for (register int i = 1; i <= tot;) {
    register int j = i;
    while (P[j + 1].Val == P[i].Val) j++;
    for (register int k = i; k <= j; ++k) {
      Jzm = Hang[P[k].x] & Lie[P[k].y];
      bool PPL = Jzm.any();
      if (PPL) return !printf("NOT MAGIC");
    }
    for (register int k = i; k <= j; ++k)
      Hang[P[k].x][P[k].y] = Lie[P[k].y][P[k].x] = 1;
    i = j + 1;
  }
  printf("MAGIC");
  return 0;
}
