#include <bits/stdc++.h>
using namespace std;
inline char read() {
  static const int IN_LEN = 1000000;
  static char buf[IN_LEN], *s, *t;
  return (s == t               ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
          (s == t ? -1 : *s++) : *s++);
}
template <class T>
inline void read(T &x) {
  static bool iosig;
  static char c;
  for (iosig = false, c = read(); !isdigit(c); c = read()) {
    if (c == '-') iosig = true;
    if (c == -1) return;
  }
  for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0');
  if (iosig) x = -x;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
  if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
  *ooh++ = c;
}
template <class T>
inline void print(T x) {
  static int buf[30], cnt;
  if (x == 0)
    print('0');
  else {
    if (x < 0) print('-'), x = -x;
    for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
    while (cnt) print((char)buf[cnt--]);
  }
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
void judge() {
  freopen("matrix.in", "r", stdin);
  freopen("matrix.out", "w", stdout);
}
const int N = 5100, inf = 1 << 30;
int n, a[N][N], f[N], pre[N], dis[N];
bool used[N];
struct info {
  int to, nxt, w;
} e[N << 1];
int head[N], opt;
void add(int x, int y, int z) {
  e[++opt] = (info){y, head[x], z};
  head[x] = opt;
}
void wt(int x, int y, int z) {
  puts("NOT MAGIC");
  exit(0);
}
void dfs(int s, int u, int fa, int Max) {
  if (a[s][u] != Max) wt(s, u, fa);
  for (int i = head[u]; i; i = e[i].nxt) {
    int k = e[i].to, w = e[i].w;
    if (k == fa) continue;
    dfs(s, k, u, max(Max, w));
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) read(a[i][j]);
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][i] != 0) wt(i, 0, 0);
    for (int j = i + 1; j <= n; j++) {
      if (a[i][j] != a[j][i]) wt(i, j, 0);
    }
  }
  used[1] = 1;
  for (int i = 2; i <= n; i++) pre[i] = 1, dis[i] = a[1][i];
  for (int i = 1; i < n; i++) {
    int u = -1;
    for (int j = 1; j <= n; j++)
      if (!used[j] && (u == -1 || dis[j] < dis[u])) u = j;
    used[u] = 1;
    add(pre[u], u, a[pre[u]][u]);
    add(u, pre[u], a[pre[u]][u]);
    for (int j = 1; j <= n; j++)
      if (!used[j] && a[u][j] < dis[j]) dis[j] = a[u][j], pre[j] = u;
  }
  for (int i = 1; i <= n; i++) dfs(i, i, 0, 0);
  puts("MAGIC");
  return 0;
}
