#include using namespace std; int main() { int n; cin >> n; static int a[30][30]; const int dy[] = { 0, 1, 0, -1 }; const int dx[] = { 1, 0, -1, 0 }; int y = 0; int x = 0; int k = 0; for (int i = 1; i <= n * n; i++) { a[y][x] = i; if (i == n * n) break; while (true) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || nx < 0 || ny >= n || nx >= n || a[ny][nx] != 0) { k = (k + 1) % 4; continue; } y = ny; x = nx; break; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { printf("%03d ", a[i][j]); } cout << endl; } }