#include <bits/stdc++.h>
const int N = 2500;
const int K = 40;
int n;
std::pair<int, int> a[N * N];
unsigned long long r[N][K], c[N][K];
void set(unsigned long long *a, int i) {
  a[i >> 6] |= (unsigned long long)1 << (i & 63);
}
bool test(unsigned long long *a, unsigned long long *b) {
  for (int i = 0; i < K; ++i)
    if (~a[i] & b[i]) return false;
  return true;
}
int main() {
  scanf("%d", &n);
  bool ok = true;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      scanf("%d", &a[i * n + j].first);
      a[i * n + j].second = i * n + j;
      if (i == j && a[i * n + j].first ||
          i > j && a[i * n + j].first != a[j * n + i].first)
        ok = false;
    }
  std::sort(a, a + n * n);
  for (int i = 0; i < n * n;) {
    int j = i;
    do {
      set(r[a[i].second / n], a[i].second % n);
      ++i;
    } while (a[i].first == a[j].first);
    do {
      set(c[a[j].second % n], a[j].second / n);
      if (!test(r[a[j].second / n], c[a[j].second % n])) ok = false;
      ++j;
    } while (j < i);
  }
  if (ok)
    printf("MAGIC\n");
  else
    printf("NOT MAGIC\n");
  return 0;
}
