#include #include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } const std::vector dx{0, 1, 0, -1}, dy{1, 0, -1, 0}; void solve() { int n; std::cin >> n; auto ans = vec(n, vec(n, -1)); int i = 0, x = 0, y = 0, id = 1; ans[x][y] = id++; while (true) { bool update = false; while (true) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || n <= nx || ny < 0 || n <= ny || ans[nx][ny] != -1) break; ans[nx][ny] = id++; x = nx, y = ny; update = true; } if (!update) break; (++i) %= 4; } for (const auto& v : ans) { for (auto a : v) { std::cout << std::setw(3) << std::setfill('0') << a << " "; } std::cout << std::endl; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }