#include <bits/stdc++.h>
using namespace std;
const char *WA = "NOT MAGIC";
const char *AC = "MAGIC";
int a[2500][2500];
int p[2500];
struct E {
  int u, v, c;
  bool operator<(const E &rhs) const { return c < rhs.c; }
} e[2500 * 2499 / 2];
struct ET {
  int v, c;
};
vector<ET> G[2500];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
int b[2500][2500];
int dfs(int u, int r) {
  for (vector<ET>::iterator it = G[u].begin(); it != G[u].end(); it++)
    if (b[r][it->v] == -1) {
      b[r][it->v] = max(b[r][u], it->c);
      dfs(it->v, r);
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", a[i] + j);
  for (int i = 0; i < n; i++)
    if (a[i][i]) {
      puts(WA);
      return 0;
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] != a[j][i]) {
        puts(WA);
        return 0;
      }
  for (int i = 0; i < n; i++) p[i] = i;
  int ee = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) e[ee++] = E{i, j, a[i][j]};
  sort(e, e + ee);
  for (int i = 0; i < ee; i++) {
    int u = find(e[i].u);
    int v = find(e[i].v);
    if (u != v) {
      G[e[i].u].push_back(ET{e[i].v, e[i].c});
      G[e[i].v].push_back(ET{e[i].u, e[i].c});
      p[u] = v;
    }
  }
  for (int i = 0; i < n; i++) {
    memset(b[i], -1, sizeof(b[i]));
    b[i][i] = 0;
    dfs(i, i);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i][j] != b[i][j]) {
        puts(WA);
        return 0;
      }
  puts(AC);
  return 0;
}
