#include <bits/stdc++.h>
using namespace std;
int n;
int a[2513][2513];
bitset<2513> big[2513];
vector<int> comp;
vector<pair<int, int> > need[2513 * 2513];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &a[i][j]);
      if (i == j && a[i][j] != 0) return printf("NOT MAGIC\n"), 0;
      if (i > j && a[i][j] != a[j][i]) return printf("NOT MAGIC\n"), 0;
      comp.push_back(a[i][j]);
    }
  sort(comp.begin(), comp.end());
  comp.erase(unique(comp.begin(), comp.end()), comp.end());
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      need[lower_bound(comp.begin(), comp.end(), a[i][j]) - comp.begin()]
          .push_back(make_pair(i, j));
    }
  for (int i = 0; i < n * n; i++) {
    auto& v = need[i];
    for (auto& p : v) {
      if ((big[p.first] & big[p.second]).any()) return printf("NOT MAGIC\n"), 0;
    }
    for (auto& p : v) big[p.first][p.second] = 1;
  }
  printf("MAGIC\n");
  return 0;
}
