#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  bool b = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  if (c == '-') c = getchar(), b = 1;
  x = c - 48;
  while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48;
  if (b) x = -x;
}
template <typename T>
inline void wrip(T x) {
  if (x > 9) wrip(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  wrip(x);
}
void reads(string &s) {
  char c;
  while (!isalpha(c = getchar()))
    ;
  s = c;
  while (isalpha(c = getchar())) s += c;
}
const double pi = acos(-1);
const int mod = 998244353;
const int inf = 1e9;
const int N = 2502;
int n, m, a[N][N];
bitset<N> line[N];
struct stc {
  int val, i, j;
  stc() : val(0), i(0), j(0) {}
  inline stc(const int &_val, const int &_i, const int &_j) {
    val = _val, i = _i, j = _j;
  }
};
stc ds[N * N];
inline bool cmp(const stc &a, const stc &b) { return a.val > b.val; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(n);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) read(a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j && a[i][j] != 0) return cout << "NOT MAGIC", 0;
      if (i != j && a[i][j] != a[j][i]) return cout << "NOT MAGIC", 0;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) ds[++m] = stc(a[i][j], i, j);
  sort(ds + 1, ds + m + 1, cmp);
  ds[m + 1].val = ds[m].val + 1;
  for (int i = 1; i <= n; i++) line[i][i] = 1;
  int i = 1;
  for (int j = 1; j <= m; j++) {
    if (j < m && ds[j].val == ds[j + 1].val) continue;
    for (int k = i; k <= j; k++) line[ds[k].i][ds[k].j] = 1;
    for (int k = i; k <= j; k++)
      if ((line[ds[k].i] | line[ds[k].j]).count() != n)
        return cout << "NOT MAGIC", 0;
    i = j + 1;
  }
  return cout << "MAGIC", 0;
}
