#include <bits/stdc++.h>
using namespace std;
const int maxn = 2501;
int n, a[maxn][maxn], d[maxn], from[maxn];
vector<int> g[maxn];
bool xuan[maxn];
void no() {
  printf("NOT MAGIC");
  exit(0);
}
void dfs(int start, int t, int fa, int dist) {
  if (dist != a[start][t]) no();
  for (int i = 0; i < (int)g[t].size(); i++)
    if (g[t][i] != fa) dfs(start, g[t][i], t, max(dist, a[t][g[t][i]]));
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) scanf("%d", a[i] + j);
  for (int i = 1; i <= n; i++)
    if (a[i][i]) no();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (a[i][j] != a[j][i]) no();
  for (int i = 2; i <= n; i++) d[i] = a[1][i], from[i] = 1;
  xuan[1] = 1;
  for (int i = 2; i <= n; i++) {
    int k = 0;
    for (int j = 2; j <= n; j++)
      if (!xuan[j] && (!k || d[j] < d[k])) k = j;
    xuan[k] = 1;
    g[from[k]].push_back(k);
    g[k].push_back(from[k]);
    for (int j = 2; j <= n; j++)
      if (!xuan[j] && a[k][j] < d[j]) d[j] = a[k][j], from[j] = k;
  }
  for (int i = 1; i <= n; i++) dfs(i, i, 0, 0);
  printf("MAGIC\n");
  return 0;
}
