#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) #define RREP(i, n) for(int i=(n-1); i>=0; i--) int pymod(int i, int j) { return (i % j + j) % j; } int N,T; int M[30][30]; void oddsqure(int n) { int r = 0; int c = n / 2; REP(i,n*n) { M[r][c] = i + 1; int nr = pymod(r - 1, n); int nc = pymod(c + 1, n); if (M[nr][nc] != 0) { r = pymod(r + 1, n); } else { r = nr; c = nc; } } } void times4square(int n) { int i = 0; REP(r,n) REP(c,n) { i++; if (r%4 == c%4 || r%4 == 3 - c%4) { M[r][c] = i; } } i = 0; RREP(r,n) RREP(c,n) { i++; if (M[r][c]) continue; M[r][c] = i; } } void aaa(int b[2][2]) { } signed main() { cin >> N; if (N%2) oddsqure(N); else if (N%4 == 0) times4square(N); else { oddsqure(N/2); int P[30][30]; int L[2][2] = {{4, 1}, {2, 3}}; int U[2][2] = {{1, 4}, {2, 3}}; int X[2][2] = {{1, 4}, {3, 2}}; REP(r,N) REP(c,N) M[r][c] = 4 * (M[r][c] - 1); REP(r,N/2) REP(c,N/2) { int (*K)[2]; if (r > N/2/2 + 1) { K = X; } else if (r == N/2/2 + 1 && c != N/2/2) { K = U; } else if (r == N/2/2 && c == N/2/2) { K = U; } else { K = L; } REP(ar, 2) REP(ac, 2) { P[2*r + ar][2*c + ac] = M[r][c] + K[ar][ac]; } } REP(r,N) REP(c,N) M[r][c] = P[r][c]; } REP(col,N) { REP(row,N) { if (row) cout << " "; cout << M[col][row]; } cout << endl; } return 0; }