#!/bin/python3 import collections as col import sys def valids(n, a, b, v): ws = [] x, y = v if 0 <= x + a < n and 0 <= y + b < n: ws.append((x + a, y + b)) if 0 <= x + a < n and 0 <= y - b < n: ws.append((x + a, y - b)) if 0 <= x - a < n and 0 <= y + b < n: ws.append((x - a, y + b)) if 0 <= x - a < n and 0 <= y - b < n: ws.append((x - a, y - b)) if 0 <= x + b < n and 0 <= y + a < n: ws.append((x + b, y + a)) if 0 <= x + b < n and 0 <= y - a < n: ws.append((x + b, y - a)) if 0 <= x - b < n and 0 <= y + a < n: ws.append((x - b, y + a)) if 0 <= x - b < n and 0 <= y - a < n: ws.append((x - b, y - a)) return ws ''' Find min path length from (0, 0) to (n-1, n-1). ''' def bfs(n, a, b): marked =[False for _ in range(n * n)] marked[0] = True dist = [0 for _ in range(n * n)] q = col.deque() q.append((0, 0)) while len(q) > 0: v = q.popleft() vIndex = v[0] * n + v[1] for w in valids(n, a, b, v): wIndex = w[0] * n + w[1] if not marked[wIndex]: marked[wIndex] = True dist[wIndex] = dist[vIndex] + 1 if w == (n-1, n-1): return dist[wIndex] q.append(w) return -1 n = int(input().strip()) res = [[-1 for _ in range(n)] for _ in range(n)] for i in range(n - 1): for j in range(i, n - 1): res[i][j] = res[j][i] = bfs(n, i + 1, j + 1) for i in range(n - 1): print(' '.join([str(res[i][j]) for j in range(n - 1)]))