#include <bits/stdc++.h>
using namespace std;
bool solve() {
  int n;
  cin >> n;
  int** board = new int*[n];
  for (int i = 0; i < n; i++) {
    board[i] = new int[n];
    for (int j = 0; j < n; j++) cin >> board[i][j];
  }
  for (int i = 0; i < n; i++) {
    if (board[i][i]) return cout << "NOT MAGIC", false;
    for (int j = 0; j < n; j++) {
      if (board[i][j] != board[j][i]) {
        return cout << "NOT MAGIC", false;
      }
    }
  }
  vector<pair<int, int> > cells;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < i; j++) {
      cells.emplace_back(make_pair(i, j));
    }
  auto comparator = [&](const pair<int, int>& a, const pair<int, int>& b) {
    return board[a.first][a.second] < board[b.first][b.second];
  };
  sort(cells.begin(), cells.end(), comparator);
  bitset<2500> row[n];
  auto jt = cells.begin();
  for (auto it = cells.begin(); it != cells.end(); it++) {
    for (; jt != cells.end() and comparator((*jt), (*it)); jt++) {
      row[(*jt).first].set((*jt).second);
      row[(*jt).second].set((*jt).first);
    }
    int x = (*it).first, y = (*it).second;
    if ((row[x] & row[y]) != 0) return cout << "NOT MAGIC", true;
  }
  return cout << "MAGIC", true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  bool answer = solve();
}
