import strutils, sequtils, math 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 cnt < N ^ 2: 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 else: cnt += 1 a[r][c] = cnt pos = (r, c) for i, ai in a: echo mapIt(ai, align($it, 3, '0')).join(" ")