#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 10;
int mx[maxn][maxn], a[maxn][maxn];
void shit() {
  cout << "NOT MAGIC" << '\n';
  exit(0);
}
vector<int> adj[maxn];
int val[maxn], n;
bool mark[maxn];
void relax(int v) {
  mark[v] = 1;
  for (int i = 0; i < n; i++)
    if (!mark[i]) val[i] = min(val[i], a[v][i]);
}
void dfs(int r, int v, int p, int d) {
  mx[r][v] = d;
  for (auto u : adj[v]) {
    if (u == p) continue;
    dfs(r, u, v, max(d, a[u][v]));
  }
}
int main() {
  memset(val, 63, sizeof val);
  cin >> n;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int x;
      scanf("%d", &x);
      a[i][j] = x;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if ((i == j && a[i][j]) || a[i][j] != a[j][i]) shit();
  relax(0);
  for (int it = 0; it < n - 1; it++) {
    int idx = -1, best = 2e9;
    for (int j = 0; j < n; j++) {
      if (mark[j]) continue;
      if (val[j] < best) {
        best = val[j];
        idx = j;
      }
    }
    for (int j = 0; j < n; j++) {
      if (!mark[j]) continue;
      if (a[j][idx] == best) {
        adj[j].push_back(idx);
        adj[idx].push_back(j);
        break;
      }
    }
    relax(idx);
  }
  for (int i = 0; i < n; i++) dfs(i, i, i, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (mx[i][j] != a[i][j]) shit();
  cout << "MAGIC" << '\n';
}
