def make_arr(N): arr = [[1 for i in range(N)] for i in range(N)] return arr def next_pos(start, dist, arr, N): # dist = 1(right), -1(left) k = start[0] l = start[1] pos = k,l while arr[k][l+dist] == 1: if (k,l+dist) == (0,0): break num = arr[k][l] l += dist arr[k][l] = num + 1 if l == N-1 or l == 0: break pos = l,k return pos def main(): N = int(input()) if N == 1: print('001') else: arr = make_arr(N) i = 0 pos = 0,0 while i >= 0: phase = i % 4 pre_pos = pos if phase < 2: pos = next_pos(pre_pos, 1, arr, N) else: pos = next_pos(pre_pos, -1, arr, N) arr = list(map(list, zip(*arr))) if (pos[1], pos[0]) == pre_pos: for col in arr: print(' '.join('{0:0>3}'.format(n) for n in col)) break else: i += 1 return 0 main()