#include <bits/stdc++.h>
using namespace std;
int n;
int a[2501][2501];
vector<pair<int, pair<int, int> > > E;
vector<pair<int, int> > adj[2501];
int p[2501];
int anc(int x) {
  if (p[x] == x) return x;
  return p[x] = anc(p[x]);
}
void join(int x, int y) { p[anc(x)] = anc(y); }
int f[2501][2501];
void dfs(int u, int par, int cur_mx, int org) {
  f[org][u] = cur_mx;
  for (pair<int, int> p : adj[u]) {
    int v = p.first, w = p.second;
    if (v != par) dfs(v, u, max(cur_mx, w), org);
  }
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  bool ok = true;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j && a[i][j]) ok = false;
      if (a[i][j] != a[j][i]) ok = false;
    }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      E.push_back(pair<int, pair<int, int> >(a[i][j], pair<int, int>(i, j)));
  sort(E.begin(), E.end());
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < E.size(); i++) {
    int w = E[i].first;
    int u = E[i].second.first, v = E[i].second.second;
    if (anc(u) != anc(v)) {
      join(u, v);
      adj[u].push_back(pair<int, int>(v, w));
      adj[v].push_back(pair<int, int>(u, w));
    }
  }
  for (int i = 1; i <= n; i++) dfs(i, -1, 0, i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[i][j] != f[i][j]) ok = false;
    }
  }
  cout << ((ok) ? "MAGIC" : "NOT MAGIC");
}
