#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
const int M = 2505;
int n, a[M][M], tot;
bitset<M> b[M];
struct node {
  int x, y;
  node() {}
  node(const int X, const int Y) { x = X, y = Y; }
  bool operator<(const node t) const { return a[x][y] < a[t.x][t.y]; }
} s[M * M];
int main() {
  n = get();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) a[i][j] = get(), s[++tot] = node(i, j);
  for (int i = 1; i <= n; ++i)
    if (a[i][i]) return !printf("NOT MAGIC");
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j)
      if (a[i][j] ^ a[j][i]) return !printf("NOT MAGIC");
  sort(s + 1, s + tot + 1);
  for (int i = 1, j; i <= tot; i = j + 1) {
    j = i;
    while (j < tot && a[s[i].x][s[i].y] == a[s[j + 1].x][s[j + 1].y]) ++j;
    for (int k = i; k <= j; ++k)
      if ((b[s[k].x] & b[s[k].y]).any()) return !printf("NOT MAGIC");
    for (int k = i; k <= j; ++k) b[s[k].x][s[k].y] = b[s[k].y][s[k].x] = 1;
  }
  printf("MAGIC");
  return 0;
}
