#include <bits/stdc++.h>
using namespace std;
const int N = 2500;
int a[N][N];
bitset<N> b[N];
const string OK = "MAGIC";
const string FAIL = "NOT MAGIC";
pair<int, pair<int, int> > p[N * N];
int main() {
  int n;
  scanf("%d", &n);
  int mx = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
      mx = max(mx, a[i][j]);
      p[i * n + j] = {a[i][j], {i, j}};
    }
  }
  sort(p, p + n * n);
  reverse(p, p + n * n);
  for (int i = 0; i < n; i++) {
    if (a[i][i] != 0) {
      cout << FAIL;
      return 0;
    }
    for (int j = i + 1; j < n; j++) {
      if (a[i][j] != a[j][i]) {
        cout << FAIL;
        return 0;
      }
    }
  }
  for (int i = 0; i < n * n;) {
    int j = i;
    for (; j < n * n && p[j].first == p[i].first; j++) {
      b[p[j].second.first].set(p[j].second.second);
    }
    for (int k = i; k < j; k++) {
      if ((b[p[k].second.first] | b[p[k].second.second]).count() != n) {
        cout << FAIL;
        return 0;
      }
    }
    i = j;
  }
  cout << OK;
  return 0;
}
