#include <bits/stdc++.h>
using namespace std;
const int N = 2510;
int a[N][N];
vector<pair<int, int> > v;
bitset<N> b[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
      v.push_back(make_pair(a[i][j], i * n + j));
    }
    if (a[i][i] != 0) {
      printf("NOT MAGIC\n");
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] != a[j][i]) {
        printf("NOT MAGIC\n");
        return 0;
      }
    }
  }
  sort(v.begin(), v.end());
  int l = 0;
  for (int k = 0; k < v.size(); k++) {
    int i = v[k].second / n, j = v[k].second % n;
    if ((b[i] & b[j]).any()) {
      printf("NOT MAGIC\n");
      return 0;
    }
    if (k != v.size() - 1 && v[k].first != v[k + 1].first) {
      for (; l <= k; l++) {
        b[v[l].second / n][v[l].second % n] = 1;
        b[v[l].second / n][v[l].second % n] = 1;
      }
    }
  }
  printf("MAGIC\n");
}
