#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; ll MOD=1000000007; ll MOD9=998244353; int inf=1e9+10; ll INF=1e18; ll dy[8]={1,0,-1,0,1,1,-1,-1}; ll dx[8]={0,1,0,-1,1,-1,1,-1}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } vvl solve1(ll n){ vvl mat(n,vl(n)); ll now=1,r=0,c=n/2; while(now<=n*n){ mat[r][c]=now; now++; r=(r-1+n)%n,c=(c+1+n)%n; if(mat[r][c]){ r=(r+2+n)%n,c=(c-1+n)%n; } } return mat; } vvl solve2(ll n){ vvl mat(n,vl(n)); ll now=1; rep(i,n){ rep(j,n){ if(abs(i-j)%4==0||(i+j)%4==3)mat[i][j]=now; now++; } } now=1; per(i,n){ per(j,n){ if(!(abs(i-j)%4==0||(i+j)%4==3))mat[i][j]=now; now++; } } return mat; } vvl solve3(ll n){ vvl pl=solve1(n/2); rep(i,n/2)rep(j,n/2)pl[i][j]=(pl[i][j]-1)*4; vvl lux(n/2,vl(n/2)); rep(i,n/2)lux[n/2/2+1][i]=1;//u rep(j,n/2){ for(int i=n/2/2+2;imat[k][l])ret++; } } } } return ret; } int main(){ /*vl ep={{11,24,7,20,3},{4,12,25,8,16},{17,5,13,21,9},{10,18,1,14,22},{23,6,19,2,15}}; cout << inversion(ep) << endl; for(ll n=3;n<=50;n++){ vvl ans=solve(n); ll f=inversion(ans); rep(i,n)rev(all(ans[i])); ll g=inversion(ans); /*rep(i,n){ ll left=0,right=n-1; while(left> n; if(n==2)cout << "impossible" << endl,exit(0); if(n==1){ cout << "possible" << endl; cout << 1 << endl;return 0; } vvl mat(n,vl(n)); rep(i,n){ rep(j,n){ cin >> mat[i][j]; if(mat[i][j]==0)mat[i][j]=n*n; } } ll ret=inversion(mat); vvl ans=solve(n); /*rep(i,n){ rep(j,n)cout << mat[i][j] <<" ";cout << endl; } rep(i,n){ rep(j,n)cout << ans[i][j] <<" ";cout << endl; }*/ ll f=inversion(ans); if(ret%2==f%2){ cout << "possible" << endl; rep(i,n){ rep(j,n){ if(j)cout <<" "; cout << ans[i][j]; } cout << endl; } return 0; } rep(i,n)rev(all(ans[i])); ll g=inversion(ans); if(ret%2==g%2){ cout << "possible" << endl; rep(i,n){ rep(j,n){ if(j)cout <<" "; cout << ans[i][j]; } cout << endl; } return 0; } cout << "possible" << endl; random_device rnd;mt19937 mt(rnd()); ll csum=accumulate(all(ans[0]),0LL); while(1){ shuffle(all(ans),mt); ll ret=0; rep(i,n){ ret+=ans[i][i]; } if(ret!=csum)continue; ret=0; rep(i,n){ ret+=ans[n-1-i][i]; } if(ret!=csum)continue; ll h=inversion(ans); //cout << h << endl; if(ret%2==h%2){ rep(i,n){ rep(j,n){ if(j)cout <<" "; cout << ans[i][j]; } cout << endl; } return 0; } } }