#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;xN2/2+1) T[y][x]=2; } swap(T[N2/2][N2/2],T[N2/2+1][N2/2]); FOR(y,N2) FOR(x,N2) { if(T[y][x]==0) R[y*2][x*2]=RR[y][x]+4, R[y*2][x*2+1]=RR[y][x]+1; else R[y*2][x*2]=RR[y][x]+1, R[y*2][x*2+1]=RR[y][x]+4; if(T[y][x]!=2) R[y*2+1][x*2]=RR[y][x]+2, R[y*2+1][x*2+1]=RR[y][x]+3; else R[y*2+1][x*2]=RR[y][x]+3, R[y*2+1][x*2+1]=RR[y][x]+2; } } } int dodo() { int vis[2501]={}; int num=0,i; FOR(i,N*N) if(vis[i]==0) { int hoge=0; int cur=i; while(vis[cur]==0) { vis[cur]=1; num++; cur=B[cur]-1; } num--; } return num; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(y,N) FOR(x,N) { cin>>A[y][x]; if(A[y][x]==0) A[y][x]=N*N; } if(N==2) return _P("p\n"); magic(N); FOR(y,N) FOR(x,N) B[y*N+x]=A[y][x]; int numA=dodo(); FOR(y,N) FOR(x,N) B[y*N+x]=R[y][x]; int numR=dodo(); _P("impossible\n"); if((numA+numR)%2==1) { //_P("impossible\n"); //FOR(y,N) FOR(x,N) _P("%d%c",R[x][y],(x==N-1)?'\n':' '); } else { //_P("possible\n"); //FOR(y,N) FOR(x,N) _P("%d%c",R[y][x],(x==N-1)?'\n':' '); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); solve(); return 0; }