#include <bits/stdc++.h>
using namespace std;
long long pow(long long a, long long b, long long M) {
  long long t = 1;
  for (a %= M; b; b >>= 1) {
    if (b & 1) t = t * a % M;
    a = a * a % M;
  }
  return t;
}
inline int getc() {
  static const int N = 222;
  static char buf[N];
  static int n = 0, p = 0;
  if (p == n) p = 0, n = fread(buf, 1, N, stdin);
  if (p == n) exit(0);
  return buf[p++];
}
inline int R(int& first) {
  int f = 1, c = getc();
  first = 0;
  while (c <= 32) c = getc();
  if (c == '-') f = -1, c = getc();
  for (; '0' <= c && c <= '9'; c = getc()) first = first * 10 + c - '0';
  first *= f;
}
const int N = 2555;
struct P {
  int p, i, j;
  friend int operator<(P a, P b) { return a.p < b.p; }
};
vector<P> p;
int n, a[N][N];
bitset<N> f[N];
int out() {
  puts("NOT MAGIC");
  exit(0);
}
int main() {
  cin >> n;
  for (int i = 1; i <= int(n); i++) {
    for (int j = 1; j <= int(n); j++) {
      scanf("%d", &a[i][j]);
      p.push_back({a[i][j], i, j});
    }
  }
  for (int i = 1; i <= int(n); i++) {
    if (a[i][i] != 0) out();
    for (int j = 1; j <= int(n); j++)
      if (a[i][j] != a[j][i]) out();
  }
  sort((p).begin(), (p).end());
  for (int i = 0; i <= int(((int)(p).size()) - 1); i++) {
    if (i > 0 && p[i].p != p[i - 1].p) {
      int j = i - 1;
      f[p[j].i][p[j].j] = 1;
      while (j > 0 && p[j - 1].p == p[j].p) f[p[j - 1].i][p[j - 1].j] = 1, j--;
    }
    if ((f[p[i].i] & f[p[i].j]).any()) out();
  }
  puts("MAGIC");
}
