#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
  int Res = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') f = (ch == '-' ? -f : f), ch = getchar();
  while (ch >= '0' && ch <= '9') Res = Res * 10 + ch - '0', ch = getchar();
  return Res * f;
}
int N, G[2505][2505], Ans[2505][2505], low[2505], pre[2505];
bool vis[2505];
int tot, lnk[2505], son[5005], nxt[5005], w[5005];
inline void add(int x, int y, int z) {
  son[++tot] = y;
  nxt[tot] = lnk[x];
  lnk[x] = tot;
  w[tot] = z;
}
void Prim() {
  vis[1] = 1;
  for (int i = 2; i <= N; i++) low[i] = G[1][i], pre[i] = 1;
  for (int i = 1; i < N; i++) {
    int Min = 1e9, id = 0;
    for (int j = 1; j <= N; j++)
      if (!vis[j] && low[j] < Min) Min = low[j], id = j;
    add(id, pre[id], Min);
    add(pre[id], id, Min);
    vis[id] = 1;
    for (int j = 1; j <= N; j++)
      if (!vis[j] && low[j] > G[j][id]) low[j] = G[j][id], pre[j] = id;
  }
}
void dfs(int x, int fa, int S, int Max) {
  Ans[S][x] = Ans[x][S] = Max;
  for (int i = lnk[x]; i; i = nxt[i]) {
    if (son[i] == fa) continue;
    dfs(son[i], x, S, max(Max, w[i]));
  }
}
int main() {
  N = read();
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) G[i][j] = read();
  }
  for (int i = 1; i <= N; i++)
    if (G[i][i]) return puts("NOT MAGIC"), 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++)
      if (G[i][j] != G[j][i]) return puts("NOT MAGIC"), 0;
  }
  Prim();
  for (int i = 1; i <= N; i++) dfs(i, 0, i, 0);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j++)
      if (Ans[i][j] != G[i][j]) return puts("NOT MAGIC"), 0;
  }
  puts("MAGIC");
  return 0;
}
