#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2.5e3 + 10;
int n, a[MAXN][MAXN];
vector<int> val, pos[MAXN * MAXN];
bitset<MAXN> mark[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
      val.push_back(a[i][j]);
    }
    if (a[i][i] != 0) return cout << "NOT MAGIC" << '\n', 0;
    ;
  }
  sort(val.begin(), val.end());
  auto ptr = unique(val.begin(), val.end());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = lower_bound(val.begin(), ptr, a[i][j]) - val.begin();
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] != a[j][i]) return cout << "NOT MAGIC" << '\n', 0;
      ;
      pos[a[i][j]].push_back(i * n + j);
    }
  }
  for (int i = 0; i < n * n; i++) {
    for (int p : pos[i]) {
      auto q = mark[p / n] & mark[p % n];
      if (q.count() > 0) return cout << "NOT MAGIC" << '\n', 0;
      ;
    }
    for (int p : pos[i]) {
      mark[p / n][p % n] = true;
    }
  }
  cout << "MAGIC" << '\n';
}
