#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MB = 20;
const int MOD = 998244353;
void solve() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i][i]) {
      cout << "NOT MAGIC";
      return;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (a[i][j] != a[j][i]) {
        cout << "NOT MAGIC";
        return;
      }
    }
  }
  vector<pair<int, pair<int, int>>> c;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      c.push_back({a[i][j], {i, j}});
    }
  }
  sort(c.begin(), c.end());
  vector<bitset<2500>> b(n);
  for (int i = 0; i < c.size(); i++) {
    if (i && c[i].first != c[i - 1].first) {
      int j = i - 1;
      while (j >= 0 && (j == i - 1 || c[j].first == c[j + 1].first)) {
        int one = c[j].second.first;
        int two = c[j].second.second;
        b[one][two] = 1;
        j--;
      }
    }
    int one = c[i].second.first;
    int two = c[i].second.second;
    if ((b[one] & b[two]) != 0) {
      cout << "NOT MAGIC";
      return;
    }
  }
  cout << "MAGIC";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(12);
  cout << fixed;
  solve();
}
