import sequtils, strutils let n = parseInt stdin.readLine var t = newSeq[string](n).repeat n yTop = 1 xRight, yBottom = n.pred xLeft = 0 direction = 0 cnt = 1 x, y = 0 while cnt <= n * n: t[y][x] = intToStr(cnt, 3) case direction of 0: if x < xRight: x.inc else: direction.inc y.inc xRight.dec of 1: if y < yBottom: y.inc else: direction.inc x.dec yBottom.dec of 2: if x > xLeft: x.dec else: direction.inc y.dec xLeft.inc else: if y > yTop: y.dec else: direction = 0 x.inc yTop.inc cnt.inc for seq1 in t: echo seq1.join " "