#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);i>=0;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;
//Data
const int N=2500;
int n,a[N][N];
bitset<N> row[N];
void give(bool ns){
if(ns) cout<<"MAGIC\n";
else cout<<"NOT MAGIC\n";
exit(0);
}
map<int,vector<pair<int,int>>> ma;
//Main
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n;
R(i,n)R(j,n) cin>>a[i][j];
R(i,n)if(a[i][i]) give(false);
R(j,n)R(i,j)if(a[i][j]!=a[j][i]) give(false);
R(j,n)R(i,j) ma[-a[i][j]].pb(mp(i,j));
R(i,n){
row[i].set();
R(j,n) row[i].reset(j);
}
for(auto u:ma){
vector<pair<int,int>> &now=u.y;
for(pair<int,int> t:now)
row[t.x].set(t.y),row[t.y].set(t.x);
for(pair<int,int> t:now)
if(!(row[t.x]|row[t.y]).all()) give(false);
}
give(true);
return 0;
}