#define _USE_MATH_DEFINES #include using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; templateinline bool chmax(T& a,T b){if(ainline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end typedef vector> VV; VV magic(int n){ VV res(n,vector(n)); if(n&1){ int x=0,y=n/2,cur=1; rep(_,0,n*n){ res[x][y]=cur++; int nx=(x-1+n)%n; int ny=(y+1)%n; if(res[nx][ny])x=(x+1)%n; else{swap(x,nx); swap(y,ny);} } } else if(n%4==0){ rep(i,0,n)rep(j,0,n){ int cur=i*n+j+1; if((i%4==1 or i%4==2)+(j%4==1 or j%4==2)==1){ res[i][j]=n*n+1-cur; } else{ res[i][j]=cur; } } } else{ auto sub=magic(n/2); for(auto& v:sub)for(auto& x:v)x=(x-1)*4; int add[3][2][2]={{{4,1},{2,3}},{{1,4},{2,3}},{{1,4},{3,2}}}; rep(i,0,n/2)rep(j,0,n/2){ int type; if(i<=n/2){ if(j==n/2)type=1; else type=0; } else if(i==n/2+1){ if(j==n/2)type=0; else type=1; } else type=2; rep(a,0,2)rep(b,0,2)res[i*2+a][j*2+b]=sub[i][j]+add[type][a][b]; } } return res; } int main(){ int n; cin>>n; auto res=magic(n); rep(i,0,n){ rep(j,0,n)cout<