#include <bits/stdc++.h>
using namespace std;
int tab[2501][2501];
int mi[2501];
int ojc[2501];
bool por(pair<int, int> x, pair<int, int> y) {
  return tab[x.first][x.second] < tab[y.first][y.second];
}
vector<int> spojne[2501];
vector<pair<int, int> > w;
bool lacz(int x, int y, int z) {
  int cz = 1;
  for (int i = 0; i < spojne[x].size(); i++)
    for (int j = 0; j < spojne[y].size(); j++)
      if (tab[spojne[x][i]][spojne[y][j]] > z) cz = 0;
  for (int i = 0; i < spojne[y].size(); i++) {
    spojne[x].push_back(spojne[y][i]);
    ojc[spojne[y][i]] = x;
  }
  spojne[y].clear();
  return cz;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    ojc[i] = i;
    spojne[i].push_back(i);
    tab[i][0] = 1000000009;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      scanf("%d", &tab[i][j]);
      if (tab[i][j] < tab[i][mi[i]]) mi[i] = j;
      w.push_back(make_pair(i, j));
    }
  sort(w.begin(), w.end(), por);
  int czy = 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (tab[i][j] != tab[j][i]) czy = 0;
      if (tab[i][i] != 0) czy = 0;
    }
  if (czy == 0) {
    printf("NOT MAGIC");
    return 0;
  }
  for (int i = 0; i < w.size(); i++) {
    if (czy == 0) break;
    int x = w[i].second, y = mi[w[i].first];
    if (ojc[x] != ojc[y])
      if (lacz(ojc[x], ojc[y], tab[w[i].first][w[i].second]) == 0) czy = 0;
  }
  if (czy == 1)
    printf("MAGIC");
  else
    printf("NOT MAGIC");
}
