#include <bits/stdc++.h>
const int N = 2550;
using namespace std;
int n;
int a[N][N];
unsigned int one = 1;
unsigned int bmask[N][N / 32 + 2];
vector<pair<pair<int, int>, pair<int, int> > > order;
bool solve() {
  for (int i = 0; i < n; i++) {
    if (a[i][i] != 0) return false;
    for (int j = 0; j < n; j++) {
      if (a[i][j] != a[j][i]) return false;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      order.push_back(make_pair(make_pair(a[i][j], 1), make_pair(i, j)));
      order.push_back(make_pair(make_pair(a[i][j], 2), make_pair(i, j)));
    }
  }
  sort(order.begin(), order.end());
  for (int i = 0; i < order.size(); i++) {
    if (order[i].first.second == 2) {
      int ps1, ps2;
      ps1 = order[i].second.first;
      ps2 = order[i].second.second;
      bmask[ps1][ps2 / 32] += (one << (ps2 % 32));
      if (ps1 != ps2) {
        bmask[ps2][ps1 / 32] += (one << (ps1 % 32));
      }
    } else {
      int ps1 = order[i].second.first;
      int ps2 = order[i].second.second;
      for (int p = 0; p <= n / 32; p++) {
        if (bmask[ps1][p] & bmask[ps2][p]) return false;
      }
    }
  }
  return true;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  if (solve()) {
    puts("MAGIC");
  } else {
    puts("NOT MAGIC");
  }
  cin.get();
  cin.get();
  return 0;
}
