#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mp make_pair #define pb push_back #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector vb; typedef vector vi; typedef vector vvb; typedef vector vvi; typedef pair pii; const int INF=1<<29; const double EPS=1e-9; int main(int argc, char const *argv[]) { int N; cin >> N; std::vector > m(N, vector(N, 0)); std::vector > ok(N, vector(N, 0)); if (N % 2 == 1) { int px = N / 2; int py = 0; int count = 0; while(count != N * N) { if (m[py][px] != 0) { py = (py + 1) % N; px = (px + N - 1) % N; py = (py + 1) % N; } else { m[py][px] = count + 1; px = (px + 1) % N; py = (py + N - 1) % N; count++; } } } else if (N % 4 == 0) { for (int i = 0; i < N / 4; ++i) { for (int j = 0; j < N / 4; ++j) { ok[i * 4][j * 4] = 1; ok[i * 4 + 1][j * 4 + 1] = 1; ok[i * 4 + 2][j * 4 + 2] = 1; ok[i * 4 + 3][j * 4 + 3] = 1; ok[i * 4 + 3][j * 4] = 1; ok[i * 4 + 2][j * 4 + 1] = 1; ok[i * 4 + 1][j * 4 + 2] = 1; ok[i * 4][j * 4 + 3] = 1; } } int count = 0; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { count++; if (ok[i][j]) { m[i][j] = count; } } } count = 0; for (int i = N - 1; i >= 0; i--) { for (int j = N - 1; j >= 0; j--) { count++; if (!ok[i][j]) { m[i][j] = count; } } } } else { int n = N / 2; std::vector > lux(n, vector(n, 0)); std::vector > lux_m(n, vector(n, 0)); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i <= n / 2) {lux[i][j] = 'l';} else if (i == n / 2 + 1) {lux[i][j] = 'u';} else {lux[i][j] = 'x';} } } char temp = lux[n / 2][n / 2]; lux[n / 2][n / 2] = lux[n / 2 + 1][n / 2]; lux[n / 2 + 1][n / 2] = temp; int px = n / 2; int py = 0; int count = 0; while(count != n * n) { if (lux_m[py][px] != 0) { py = (py + 1) % n; px = (px + n - 1) % n; py = (py + 1) % n; } else { lux_m[py][px] = count + 1; px = (px + 1) % n; py = (py + n - 1) % n; count++; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { lux_m[i][j]--; lux_m[i][j] <<= 2; } } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { int px = 2 * j; int py = 2 * i; if (lux[i][j] == 'l') { m[py][px] = lux_m[i][j] + 4; m[py + 1][px] = lux_m[i][j] + 2; m[py][px + 1] = lux_m[i][j] + 1; m[py + 1][px + 1] = lux_m[i][j] + 3; } else if (lux[i][j] == 'u') { m[py][px] = lux_m[i][j] + 1; m[py + 1][px] = lux_m[i][j] + 2; m[py][px + 1] = lux_m[i][j] + 4; m[py + 1][px + 1] = lux_m[i][j] + 3; } else { m[py][px] = lux_m[i][j] + 1; m[py + 1][px] = lux_m[i][j] + 3; m[py][px + 1] = lux_m[i][j] + 4; m[py + 1][px + 1] = lux_m[i][j] + 2; } } } } for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { cout << m[i][j] << " "; } cout << endl; } return 0; }