#include using namespace std; int main() { int N; cin >> N; vector> G(N, vector(N)); int i = 0; int j = 0; int count = 2; vector di = {0, 1, 0, -1}; vector dj = {1, 0, -1, 0}; int dii = 0; vector> visited(N, vector(N)); visited[i][j] = true; G[i][j] = 1; while (count <= N * N) { int next_i = i + di[dii % 4]; int next_j = j + dj[dii % 4]; if (next_i < 0 || next_j < 0 || next_i >= N || next_j >= N) { dii++; next_i = i + di[dii % 4]; next_j = j + dj[dii % 4]; } else if (visited[next_i][next_j]) { dii++; next_i = i + di[dii % 4]; next_j = j + dj[dii % 4]; } i = next_i; j = next_j; visited[i][j] = true; G[i][j] = count; count++; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { printf("%03d ",G[i][j]); } cout << "\n"; } }