#include #include using namespace std; const vector dx = {1, 0, -1, 0}; const vector dy = {0, -1, 0, 1}; int main() { int N; cin >> N; vector> A(N, vector(N, 0)); A[0][0] = 1; int H = 0, W = 0; int cnt = 2; int d = 0; while (1) { int nh = H + dy[d]; int nw = W + dx[d]; if (0 <= nh && nh < N && 0 <= nw && nw < N && A[nh][nw] == 0) { H = nh; W = nw; A[H][W] = cnt; cnt++; } else { d++; d %= 4; bool ok = false; if (H + 1 < N && A[H + 1][W] == 0) { ok = true; } if (H - 1 >= 0 && A[H - 1][W] == 0) { ok = true; } if (W + 1 < N && A[H][W + 1] == 0) { ok = true; } if (W - 1 >= 0 && A[H][W - 1] == 0) { ok = true; } if (!ok) { break; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { printf("%03d", A[i][j]); if (j == N - 1) { printf("\n"); } else { printf(" "); } } } }