#include using namespace std; int main() { int n; cin >> n; vector> a(n, vector(n, 0)); pair now(0, 0); int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, p = 0; auto inside = [](int a, int b, int alim, int blim) { return 0 <= a && a < alim && 0 <= b && b < blim; }; for (int num = 1; num <= n * n; num++) { a[now.first][now.second] = num; if (!inside(now.first + dx[p], now.second + dy[p], n, n) || a[now.first + dx[p]][now.second + dy[p]]) { p++; p %= 4; } now.first += dx[p]; now.second += dy[p]; } for (auto &i : a) { for (auto &j : i) { cout << setw(3) << setfill('0') << j << ' '; } cout << endl; } return 0; }