#include <bits/stdc++.h>
using namespace std;
const int max_n = 2500;
int a[max_n][max_n];
vector<pair<int, pair<int, int> > > E;
int par[max_n];
int B[max_n][max_n];
vector<int> va, vb;
int anc(int v) { return par[v] == v ? v : par[v] = anc(par[v]); }
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]);
  for (int i = 0; i < (n); i++) par[i] = i;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (i); j++)
      E.push_back(make_pair(a[i][j], make_pair(i, j)));
  sort(E.begin(), E.end());
  for (int k = 0; k < (E.size()); k++) {
    int a = E[k].second.first, b = E[k].second.second;
    if (anc(a) != anc(b)) {
      va.clear();
      for (int i = 0; i < (n); i++)
        if (anc(i) == anc(a)) va.push_back(i);
      vb.clear();
      for (int i = 0; i < (n); i++)
        if (anc(i) == anc(b)) vb.push_back(i);
      for (int i = 0; i < (va.size()); i++)
        for (int j = 0; j < (vb.size()); j++)
          B[va[i]][vb[j]] = B[vb[j]][va[i]] = E[k].first;
      par[anc(a)] = anc(b);
    }
  }
  bool magic = true;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      if (a[i][j] != a[j][i] || (i == j && a[i][j])) magic = false;
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++)
      if (a[i][j] != B[i][j]) magic = false;
  cout << (magic ? "" : "NOT ") << "MAGIC" << endl;
  return 0;
}
