using System; public class Program { public static void Main() { int N = int.Parse(Console.ReadLine()); int[,] grid = new int[N, N]; int[,] move = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int[] pos = {0, 0}; int moveId = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { grid[i, j] = 0; } } for (int i = 1; i <= N * N; i++) { grid[pos[0], pos[1]] = i; if (pos[0] + move[moveId, 0] < 0 || N <= pos[0] + move[moveId, 0] || pos[1] + move[moveId, 1] < 0 || N <= pos[1] + move[moveId, 1] || grid[pos[0] + move[moveId, 0], pos[1] + move[moveId, 1]] > 0) { moveId = (moveId + 1) % 4; } pos[0] += move[moveId, 0]; pos[1] += move[moveId, 1]; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Console.Write("{0:000}", grid[j, i]); if (j < N - 1) { Console.Write(' '); } } Console.WriteLine(); } } }