#include <bits/stdc++.h>
const int MAXN = 2510;
bool check;
int n, now, a[MAXN][MAXN];
std::bitset<MAXN> bit[MAXN];
typedef struct matrix {
  int x, y, val;
} matrix;
matrix mat[MAXN * MAXN];
inline int read() {
  int X = 0, flag = 0;
  char ch = 0;
  while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return flag ? -X : X;
}
inline bool cmp(matrix a, matrix b) { return a.val < b.val; }
signed main() {
  n = read();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = read();
      mat[i * n + j].val = a[i][j];
      mat[i * n + j].x = i, mat[i * n + j].y = j;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i][i] != 0) {
      check = true;
      break;
    }
  }
  if (check) {
    printf("NOT MAGIC\n");
    return 0;
  }
  for (int i = 0; i < n && check == 0; i++) {
    for (int j = 0; j < i; j++) {
      if (a[i][j] != a[j][i]) {
        check = true;
        break;
      }
    }
  }
  if (check) {
    printf("NOT MAGIC\n");
    return 0;
  }
  std::sort(mat, mat + n * n, cmp);
  for (int i = 0; i < n * n; i++) {
    while (now < n * n && mat[now].val < mat[i].val) {
      bit[mat[now].x][mat[now].y] = 1;
      bit[mat[now].y][mat[now].x] = 1;
      now++;
    }
    if ((bit[mat[i].x] & bit[mat[i].y]).any()) {
      check = true;
      break;
    }
  }
  if (check)
    printf("NOT MAGIC\n");
  else
    printf("MAGIC\n");
  fclose(stdin), fclose(stdout);
  return 0;
}
