#include #include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max() / 32 * 15 + 208; int main() { int n; cin >> n; vector> v(n, vector(n, 0)); if(n%2){ int y = n-1, x = n/2; int cnt = 1; while(cnt <= n*n){ v[y][x] = cnt++; int yy = (y+1)%n, xx = (x+1)%n; if(v[yy][xx]) yy = (y+n-1)%n, xx = x; y = yy, x = xx; } }else if(n%4 == 0){ for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if((((i+1)%4 >= 2) ^ (((j+1)%4) >= 2))){ v[n-i-1][n-j-1] = i*n+j+1; }else { v[i][j] = i*n+j+1; } } } }else { int m = n/2; vector> u(m, vector(m, -1)); int y = m-1, x = m/2; int cnt = 1; while(cnt <= m*m){ u[y][x] = cnt++; int yy = (y+1)%m, xx = (x+1)%m; if(u[yy][xx] != -1) yy = (y+m-1)%m, xx = x; y = yy, x = xx; } for (int i = 0; i < m; ++i) { for (int j = 0; j < m; ++j) { u[i][j]--; if(m/2+1 < i){ v[2*i][2*j] = u[i][j]*4+1; v[2*i+1][2*j] = u[i][j]*4+3; v[2*i][2*j+1] = u[i][j]*4+4; v[2*i+1][2*j+1] = u[i][j]*4+2; }else if(m/2+1 == i && j != m/2){ v[2*i][2*j] = u[i][j]*4+1; v[2*i+1][2*j] = u[i][j]*4+2; v[2*i][2*j+1] = u[i][j]*4+4; v[2*i+1][2*j+1] = u[i][j]*4+3; }else if(i == m/2 && j == m/2){ v[2*i][2*j] = u[i][j]*4+1; v[2*i+1][2*j] = u[i][j]*4+2; v[2*i][2*j+1] = u[i][j]*4+4; v[2*i+1][2*j+1] = u[i][j]*4+3; }else { v[2*i][2*j] = u[i][j]*4+4; v[2*i+1][2*j] = u[i][j]*4+2; v[2*i][2*j+1] = u[i][j]*4+1; v[2*i+1][2*j+1] = u[i][j]*4+3; } } puts(""); } } for (int i = 0; i < n; ++i) { int s = 0; for (int j = 0; j < n; ++j) { if(j) printf(" "); printf("%d", v[i][j]); } puts(""); } return 0; }