#include <bits/stdc++.h>
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,b,a) for ( int i=(b);i>=(a);i-- )
#define GO(i,x) for ( int i=head[x];i;i=e[i].nex )
#define mem(x,s) memset(x,s,sizeof(x))
#define cpy(x,s) memcpy(x,s,sizeof(x))
#define YES return puts("YES"),0
#define NO return puts("NO"),0
#define GG return puts("-1"),0
#define pb push_back
using namespace std;
void build(vector<vector<int> > b);
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE],*p1,*p2;
char pbuf[MAXSIZE],*pp;
IO():p1(buf),p2(buf),pp(pbuf){}
inline char gc() {
return getchar();
if (p1==p2) p2=(p1=buf)+fread(buf,1,MAXSIZE,stdin);
return p1==p2?' ':*p1++;
}
inline bool blank(char ch) {return ch==' '||ch =='\n'||ch == '\r'||ch == '\t';}
template <class T>
inline void read(T &x)
{
register double tmp=1;register bool sign=0; x=0;
register char ch=gc();
for (;!isdigit(ch);ch=gc()) if(ch=='-') sign=1;
for (;isdigit(ch);ch=gc()) x=x*10+(ch-'0');
if (ch=='.') for (ch=gc();isdigit(ch);ch=gc()) tmp/=10.0,x+=tmp*(ch-'0');
if (sign) x=-x;
}
inline void read(char *s)
{
register char ch=gc();
for (;blank(ch);ch=gc());
for (;!blank(ch);ch=gc()) *s++=ch;
*s=0;
}
inline void read(char &c) {for(c=gc();blank(c);c=gc());}
template<class t> inline void write(t x){
if(x<0) putchar('-'),write(-x);
else{if(x>9) write(x/10);putchar('0'+x%10);}
}
} io;
const int mod=1e9+7;
const int mo=998244353;
const int N=1e3+5;
vector<int> G[N],F[N];
int n,m,fa[N],col[N],vis[N],p[N][N],cnt;
inline int find(int x)
{
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
inline int construct(vector<vector<int> > p)
{
n=p[0].size();
For(i,0,n-1) For(j,i+1,n-1) if(p[i][j]==3) return 0;
For(i,0,n-1) fa[i]=i;
For(i,0,n-1) For(j,i+1,n-1) if(p[i][j]==1) fa[find(i)]=find(j);
For(i,0,n-1) For(j,i+1,n-1) if(find(i)==find(j)&&p[i][j]!=1) return 0;
For(i,0,n-1) vis[i]=-1;
For(i,0,n-1)
{
int x=find(i);
if(vis[x]==-1) vis[x]=m++;
col[i]=vis[x];
G[vis[x]].pb(i);
}
For(i,0,m) fa[i]=i;
For(i,0,n-1) For(j,i+1,n-1) if(p[i][j]==2) fa[find(col[i])]=find(col[j]);
For(i,0,n-1) For(j,i+1,n-1) if(!p[i][j]&&find(col[i])==find(col[j])) return 0;
For(i,0,m-1) F[find(i)].pb(G[i][0]);
For(i,0,m-1) if(F[i].size()==2) return 0;
vector<vector<int> > ans;
ans.resize(n);
For(i,0,n-1) ans[i].resize(n,0);
For(i,0,m-1) For(j,0,(int)G[i].size()-2) ans[G[i][j]][G[i][j+1]]=ans[G[i][j+1]][G[i][j]]=1;
For(i,0,m-1)
{
For(j,0,(int)F[i].size()-2) ans[F[i][j]][F[i][j+1]]=ans[F[i][j+1]][F[i][j]]=1;
if(F[i].size()>1) ans[F[i][0]][F[i][F[i].size()-1]]=ans[F[i][F[i].size()-1]][F[i][0]]=1;
}
build(ans);
return 1;
}