#include <bits/stdc++.h>
using namespace std;
const int N = 2505;
int a[N][N], q[N];
vector<pair<int, int>> v[N];
struct E {
  int x, y, w;
  bool operator<(const E &oth) const { return w < oth.w; }
};
int findSet(int x) { return q[x] < 0 ? x : q[x] = findSet(q[x]); }
bool un(int x, int y) {
  x = findSet(x);
  y = findSet(y);
  if (x == y) return false;
  if (q[x] > q[y]) swap(x, y);
  q[x] += q[y];
  q[y] = x;
  return true;
}
bool ok = true;
void dfs(int node, int from, int anc = -1, int mx = 0) {
  if (a[from][node] != mx) ok = false;
  for (auto e : v[node]) {
    if (e.first != anc) dfs(e.first, from, node, max(mx, e.second));
  }
}
int getInt() {
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x;
}
signed main() {
  int n;
  n = getInt();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = getInt();
    }
  }
  fill(q, q + n, -1);
  for (int i = 0; i < n; i++) {
    if (a[i][i]) {
      puts("NOT MAGIC");
      return 0;
    }
    for (int j = 0; j < n; j++) {
      if (a[i][j] != a[j][i]) {
        puts("NOT MAGIC");
        return 0;
      }
    }
  }
  vector<E> t;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      t.push_back({i, j, a[i][j]});
    }
  }
  sort(t.begin(), t.end());
  for (auto p : t) {
    if (un(p.x, p.y)) {
      v[p.x].push_back({p.y, p.w});
      v[p.y].push_back({p.x, p.w});
    }
  }
  for (int i = 0; i < n; i++) {
    dfs(i, i);
  }
  if (!ok)
    puts("NOT MAGIC");
  else
    puts("MAGIC");
  return 0;
}
