#include <bits/stdc++.h>
const int maxSize = 2500;
int minDist[maxSize][maxSize], maxDist[maxSize][maxSize];
struct Edge {
  Edge(){};
  Edge(int from, int to, int c) : nodeX(from), nodeY(to), cost(c){};
  int cost;
  int nodeX, nodeY;
};
bool operator<(Edge e1, Edge e2) { return (e1.cost > e2.cost); }
class FindUnion {
 public:
  FindUnion(int N);
  int find(int x);
  void merge(int x, int y);

 private:
  int *parent;
  int *rank;
};
int main() {
  int n;
  std::priority_queue<Edge> Q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      scanf("%d", &minDist[i][j]);
      if (((i == j) && (minDist[i][j] != 0)) ||
          ((i > j) && (minDist[i][j] != minDist[j][i]))) {
        printf("NOT MAGIC\n");
        return 0;
      }
      maxDist[i][j] = minDist[i][j];
      if (i > j) Q.push(Edge(i, j, minDist[i][j]));
    }
  FindUnion fu_struct(n);
  Edge e;
  int rep1, rep2;
  while (!Q.empty()) {
    e = Q.top();
    Q.pop();
    rep1 = fu_struct.find(e.nodeX);
    rep2 = fu_struct.find(e.nodeY);
    if (rep1 != rep2) {
      if (minDist[rep1][rep2] != maxDist[rep1][rep2]) {
        printf("NOT MAGIC\n");
        return 0;
      }
      fu_struct.merge(rep1, rep2);
      for (int i = 0; i < n; i++) {
        if (minDist[rep1][i] < minDist[rep2][i])
          minDist[i][rep2] = minDist[rep2][i] = minDist[rep1][i];
        else
          minDist[i][rep1] = minDist[rep1][i] = minDist[rep2][i];
        if (maxDist[rep1][i] > maxDist[rep2][i])
          maxDist[i][rep2] = maxDist[rep2][i] = maxDist[rep1][i];
        else
          maxDist[i][rep1] = maxDist[rep1][i] = maxDist[rep2][i];
      }
    }
  }
  printf("MAGIC\n");
  return 0;
}
FindUnion::FindUnion(int n) {
  parent = new int[n];
  rank = new int[n];
  for (int i = 0; i < n; i++) {
    rank[i] = 0;
    parent[i] = i;
  }
}
int FindUnion::find(int x) {
  if (parent[x] == x) return x;
  parent[x] = find(parent[x]);
  return parent[x];
}
void FindUnion::merge(int x, int y) {
  int r1 = find(x);
  int r2 = find(y);
  if (r1 == r2) return;
  if (rank[r1] > rank[r2])
    parent[r2] = r1;
  else if (rank[r2] > rank[r1])
    parent[r1] = r2;
  else {
    parent[r2] = r1;
    rank[r1]++;
  }
}
