#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 2550;
int grid[N][N];
int minimo[N][N];
vector<pair<int, int> > matrix[N];
bool flagI[N];
bool flagJ[N];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      scanf("%d", &grid[i][j]);
      matrix[i].push_back(make_pair(grid[i][j], -j));
    }
    sort(matrix[i].begin(), matrix[i].end());
  }
  for (int i = 0; i < n; i++) {
    if (grid[i][i]) {
      cout << "NOT MAGIC" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (grid[i][j] != grid[j][i]) {
        cout << "NOT MAGIC" << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    minimo[i][i] = grid[i][0];
    for (int j = 1; j < n; j++) {
      minimo[i][i] = min(minimo[i][i], grid[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      memset(flagI, false, sizeof flagI);
      memset(flagJ, false, sizeof flagJ);
      for (int k = 0; k < n; k++) {
        int I = -matrix[i][k].second, J = -matrix[j][k].second;
        if (I == J) {
          minimo[i][j] = max(matrix[i][k].first, matrix[j][k].first);
          break;
        } else if (flagJ[I] and flagI[J]) {
          minimo[i][j] = max(matrix[i][k].first, matrix[j][k].first);
          break;
        } else if (flagJ[I]) {
          minimo[i][j] = max(matrix[i][k].first, grid[j][J]);
          break;
        } else if (flagI[J]) {
          minimo[i][j] = max(matrix[j][k].first, grid[i][I]);
          break;
        }
        flagI[I] = flagJ[J] = true;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (grid[i][j] > (j > i ? minimo[i][j] : minimo[j][i])) {
        cout << "NOT MAGIC" << endl;
        return 0;
      }
    }
  }
  cout << "MAGIC" << endl;
  return 0;
}
