#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool f = false;
  char ch = getchar();
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return f ? -x : x;
}
void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + 48);
}
const int N = 2505, INF = 0x7fffffff;
int n;
int a[N][N];
int fa[N], d[N];
bool vis[N];
inline void prim() {
  for (int i = 2; i <= n; i++) fa[i] = 1, d[i] = a[1][i];
  memset(vis, false, sizeof(vis));
  vis[1] = true;
  int k, minn;
  for (int tot = 2; tot <= n; tot++) {
    minn = INF;
    for (int i = 1; i <= n; i++)
      if (minn > d[i] && !vis[i]) minn = d[i], k = i;
    vis[k] = true;
    for (int i = 1; i <= n; i++)
      if (a[k][i] < d[i] && !vis[i]) d[i] = a[k][i], fa[i] = k;
  }
}
int dep[N];
void getdep(int x) {
  if (!dep[fa[x]]) getdep(fa[x]);
  dep[x] = dep[fa[x]] + 1;
}
int main() {
  n = read();
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= n; j++) a[i][j] = read();
  for (register int i = 1; i <= n; i++)
    if (a[i][i]) return puts("NOT MAGIC"), 0;
  for (register int i = 1; i <= n; i++)
    for (register int j = i + 1; j <= n; j++)
      if (a[i][j] != a[j][i]) return puts("NOT MAGIC"), 0;
  prim();
  dep[1] = 1;
  for (register int i = 2; i <= n; i++)
    if (!dep[i]) getdep(i);
  for (register int i = 1; i <= n; i++)
    for (register int j = i + 1; j <= n; j++) {
      int x = i, y = j;
      if (dep[x] < dep[y]) swap(x, y);
      if (a[x][y] > max(a[fa[x]][y], a[fa[x]][x])) return puts("NOT MAGIC"), 0;
    }
  return puts("MAGIC"), 0;
}
