#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int n; cin >> n; vector> ans(n, vector(n)); int num = 1; int x = 0, y = 0, d = 0; for(int i = 0; i < n * n; i++) { ans[x][y] = num; num++; int xx = x + dx[d % 4]; int yy = y + dy[d % 4]; if(xx >= 0 && yy >= 0 && xx < n && yy < n && !ans[xx][yy]) { x = xx; y = yy; } else { d++; x = x + dx[d % 4]; y = y + dy[d % 4]; } } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(j > 0) cout << " "; cout << setw(3) << setfill('0') << ans[i][j]; } cout << '\n'; } return 0; }