#include <bits/stdc++.h>
using namespace std;
const int N = 6.25e6 + 2, M = 2.5e3 + 2;
bitset<M> h[M], s[M];
int x[N], y[N], z[N], a[M][M];
int i, j, tp, n, m, k;
char c[N * 11 + 10];
inline void read(int &x) {
  ++tp;
  while ((c[tp] < 48) || (c[tp] > 57)) ++tp;
  x = c[tp++] ^ 48;
  while ((c[tp] >= 48) && (c[tp] <= 57)) x = x * 10 + (c[tp++] ^ 48);
}
void qs(int l, int r) {
  int i = l, j = r, m = z[l + r >> 1];
  while (i <= j) {
    while (z[i] < m) ++i;
    while (z[j] > m) --j;
    if (i <= j) {
      swap(x[i], x[j]);
      swap(y[i], y[j]);
      swap(z[i++], z[j--]);
    }
  }
  if (i < r) qs(i, r);
  if (l < j) qs(l, j);
}
int main() {
  scanf("%d", &n);
  fread(c + 1, 1, n * n * 11 + 2, stdin);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++) {
      read(a[i][j]);
      z[++m] = a[i][j];
      x[m] = i;
      y[m] = j;
    }
  for (i = 1; i <= n; i++)
    if (a[i][i]) {
      puts("NOT MAGIC");
      return 0;
    }
  for (i = 1; i < n; i++)
    for (j = i + 1; j <= n; j++)
      if (a[i][j] != a[j][i]) {
        puts("NOT MAGIC");
        return 0;
      }
  qs(1, m);
  for (i = j = 1; i <= m; i = j) {
    while ((j <= m) && (z[j] == z[i])) ++j;
    for (k = i; k < j; k++)
      if ((h[x[k]] & s[y[k]]).any()) {
        puts("NOT MAGIC");
        return 0;
      }
    for (k = i; k < j; k++) {
      h[x[k]][y[k]] = 1;
      s[y[k]][x[k]] = 1;
    }
  }
  puts("MAGIC");
}
