#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int n, now = 0, x = 0, y = 0; string grid[33][33]; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { cin >> n; for (int i = 1; i <= n * n; i++) { char s[20]; sprintf(s, "%03d", i); grid[y][x] = s; int nx = x + dx[now]; int ny = y + dy[now]; if (0 > nx || nx >= n || 0 > ny || ny >= n || grid[ny][nx] != "") { now = (now + 1) % 4; } x += dx[now]; y += dy[now]; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) cout << grid[i][j] << " \n"[j == n - 1]; } return 0; }