#include <bits/stdc++.h>
using namespace std;
const int MAXn = 2500 + 17;
int mat[MAXn][MAXn];
vector<int> tree[MAXn];
vector<pair<int, int> > ans;
vector<int> radj;
vector<int> ladj;
int n;
int B[MAXn][MAXn];
bool mark[MAXn];
int dest[MAXn];
void make_set() {
  for (int i = 0; i < n; i++) dest[i] = i;
}
int find(int x) {
  if (dest[x] == x) return x;
  dest[x] = find(dest[x]);
  return dest[x];
}
void union_set(int x, int y) { dest[find(x)] = find(y); }
bool sym() {
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (n); j++) {
      if (mat[i][j] != mat[j][i]) return 0;
    }
  }
  return 1;
}
bool is_zero() {
  for (long long i = 0; i < (n); i++) {
    if (mat[i][i] != 0) return 0;
  }
  return 1;
}
void dfs1(int u) {
  mark[u] = 1;
  radj.push_back(u);
  for (int i = 0; i < tree[u].size(); i++) {
    if (mark[tree[u][i]] == 0) dfs1(tree[u][i]);
  }
}
void dfs2(int u) {
  mark[u] = 1;
  ladj.push_back(u);
  for (int i = 0; i < tree[u].size(); i++) {
    if (mark[tree[u][i]] == 0) dfs2(tree[u][i]);
  }
}
void krus() {
  make_set();
  vector<pair<int, pair<int, int> > > edges;
  for (long long i = 0; i < (n); i++) {
    for (int j = i + 1; j < n; j++) {
      edges.push_back(
          pair<int, pair<int, int> >(mat[i][j], pair<int, int>(i, j)));
    }
  }
  sort((edges).begin(), (edges).end());
  for (int i = 0; i < edges.size(); i++) {
    if (ans.size() == n - 1) break;
    if (find(edges[i].second.first) == find(edges[i].second.second)) continue;
    ans.push_back(
        pair<int, int>(edges[i].second.first, edges[i].second.second));
    union_set(edges[i].second.first, edges[i].second.second);
  }
  for (long long ish = 0; ish < (ans.size()); ish++) {
    radj.clear();
    dfs1(ans[ish].first);
    ladj.clear();
    dfs2(ans[ish].second);
    for (int i = 0; i < radj.size(); i++) {
      for (int j = 0; j < ladj.size(); j++) {
        B[radj[i]][ladj[j]] = B[ladj[j]][radj[i]] =
            mat[ans[ish].first][ans[ish].second];
        mark[radj[i]] = 0;
        mark[ladj[j]] = 0;
      }
    }
    tree[ans[ish].first].push_back(ans[ish].second);
    tree[ans[ish].second].push_back(ans[ish].first);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (n); j++) {
      cin >> mat[i][j];
    }
  }
  if (!sym() || !is_zero()) {
    cout << "NOT MAGIC" << endl;
    return 0;
  }
  krus();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (B[i][j] != mat[i][j]) {
        cout << "NOT MAGIC" << endl;
        return 0;
      }
    }
  }
  cout << "MAGIC" << endl;
  return 0;
}
