#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}
int n, tot, a[2505][2505];
bitset<2505> s[2505];
struct node {
  int x, r, c;
  node(int _x = 0, int _r = 0, int _c = 0) {
    x = _x;
    r = _r;
    c = _c;
  }
} c[2505 * 2505];
inline bool cmp(const node &x, const node &y) { return x.x < y.x; }
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) a[i][j] = rd();
  for (int i = 1; i <= n; ++i)
    if (a[i][i] != 0) {
      puts("NOT MAGIC");
      return 0;
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (a[i][j] != a[j][i]) {
        puts("NOT MAGIC");
        return 0;
      }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) c[++tot] = node(a[i][j], i, j);
  sort(c + 1, c + 1 + tot, cmp);
  for (int i = 1, ptr = 1, x, y; i <= tot; ++i) {
    while (c[ptr].x < c[i].x) {
      x = c[ptr].r;
      y = c[ptr].c;
      s[x][y] = s[y][x] = 1;
      ++ptr;
    }
    x = c[i].r;
    y = c[i].c;
    if ((s[x] & s[y]).any()) {
      puts("NOT MAGIC");
      return 0;
    }
  }
  puts("MAGIC");
  return 0;
}
