import strutils, sequtils let N = parseInt readLine stdin var a = newSeqWith(N, newSeqWith(N, 0)) cnt, dir, cls = 0 dirlist = [[0, 1], [1, 0], [0, -1], [-1, 0]] pos: tuple[r, c: int] = (0, -1) while true: var r = pos.r + dirlist[dir][0] c = pos.c + dirlist[dir][1] if r < 0 or N <= r or c < 0 or N <= c or a[r][c] != 0: dir = (dir + 1) mod 4 cls += 1 if cls == 4: break else: cls = 0 cnt += 1 a[r][c] = cnt pos = (r, c) for i, ai in a: write stdout, mapIt(ai, align($it, 3, '0')).join(" "), "\n"