#include <bits/stdc++.h>
using namespace std;
const int N = 2505;
int n;
int mat[N][N];
int p[N];
int f(int x) { return x == p[x] ? x : p[x] = f(p[x]); }
int sz;
tuple<int, int, int> edges[N * N / 2];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &mat[i][j]);
    }
  for (int i = 0; i < n; i++) {
    if (mat[i][i] != 0) return printf("NOT MAGIC\n"), 0;
    for (int j = 0; j < n; j++) {
      if (mat[i][j] != mat[j][i]) return printf("NOT MAGIC\n"), 0;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      edges[sz++] = make_tuple(mat[i][j], i, j);
    }
  sort(edges, edges + sz);
  iota(p, p + n, 0);
  for (int i = 0; i < sz; i++) {
    int j = i;
    int w = get<0>(edges[i]);
    while (j + 1 < sz and get<0>(edges[j + 1]) == w) j++;
    int a, b;
    for (int k = i; k <= j; k++) {
      tie(ignore, a, b) = edges[k];
      if (f(a) == f(b)) return printf("NOT MAGIC\n"), 0;
    }
    for (int k = i; k <= j; k++) {
      tie(ignore, a, b) = edges[k];
      p[f(a)] = f(b);
    }
    i = j;
  }
  printf("MAGIC\n");
}
