#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &n) {
  n = 0;
  T f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) n = n * 10 + c - '0', c = getchar();
  n *= f;
}
template <typename T>
void write(T n) {
  if (n < 0) putchar('-'), n = -n;
  if (n > 9) write(n / 10);
  putchar(n % 10 + '0');
}
int n;
int fa[3005], vis[3005];
long long a[3005][3005], dis[3005][3005], mn[3005];
bool prim() {
  memset(dis, 0x3f, sizeof(dis));
  vis[1] = 1;
  for (int i = 1; i <= n; i++) fa[i] = 1, mn[i] = a[1][i], dis[i][i] = 0;
  for (int i = 2; i <= n; i++) {
    int id = 0;
    for (int j = 1; j <= n; j++) {
      if (vis[j]) continue;
      if (!id || mn[j] < mn[id]) id = j;
    }
    vis[id] = 1;
    for (int j = 1; j <= n; j++) {
      if (!vis[j]) {
        if (mn[j] > a[id][j]) mn[j] = a[id][j], fa[j] = id;
      } else {
        dis[id][j] = dis[j][id] = min(dis[id][j], max(mn[id], dis[j][fa[id]]));
        if (dis[id][j] < a[id][j]) return false;
      }
    }
  }
  return true;
}
int main() {
  cin >> n;
  int flag = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      read(a[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i][i]) flag = 0;
    for (int j = i + 1; j <= n; j++) {
      if (a[i][j] != a[j][i]) flag = 0;
    }
  }
  if (!flag) {
    puts("NOT MAGIC");
    return 0;
  }
  flag &= prim();
  if (flag)
    puts("MAGIC");
  else
    puts("NOT MAGIC");
  return 0;
}
