using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var map = new string[n, n]; putMap(map, n); print(map, n); } public static void print(string[,] map, int n) { var ans = new string[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) ans[j] = map[i, j]; Console.WriteLine(string.Join(" ", ans)); } } public static void putMap(string[,] map, int n) { int[] dx = { 0, 1, 0, -1 }; int[] dy = { 1, 0, -1, 0 }; var used = new bool[n, n]; var x = 0; var y = 0; var dir = 0; var p = 1; var cango = true; while (cango) { used[x, y] = true; map[x, y] = string.Format("{0:000}", p++); cango = false; for (int i = 0; i < 4; i++) { var te = dir + i; if (te >= 4) te -= 4; var nx = x + dx[te]; var ny = y + dy[te]; if (nx >= 0 && nx < n && ny >= 0 && ny < n && !used[nx, ny]) { x = nx; y = ny; dir = te; cango = true; break; } } } } }