#include <bits/stdc++.h>
using namespace std;
const int N = 2510;
int n, g[N][N], len;
bitset<N> bt[N];
struct node {
  int num, x, y;
  friend bool operator<(const node n1, const node n2) {
    return n1.num < n2.num;
  }
} nod[N * N / 2];
int main() {
  len = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &g[i][j]);
      if (i < j) {
        nod[len].num = g[i][j], nod[len].x = i, nod[len].y = j, len++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (g[i][j] != g[j][i] || (i == j && g[i][j])) {
        cout << "NOT MAGIC" << endl;
        return 0;
      }
    }
  }
  sort(nod, nod + len);
  int tot = 0;
  for (int i = 0; i < len; i++) {
    while (tot < len && nod[tot].num < nod[i].num) {
      bt[nod[tot].x][nod[tot].y] = 1;
      bt[nod[tot].y][nod[tot].x] = 1;
      tot++;
    }
    if ((bt[nod[i].x] & bt[nod[i].y]).any()) {
      cout << "NOT MAGIC" << endl;
      return 0;
    }
  }
  cout << "MAGIC" << endl;
  return 0;
}
