#!/bin/python3 import sys from queue import Queue def next_valid_cells(visited, x, y, a_delta, b_delta, n): valid_cells = [] up = x - a_delta down = x + a_delta left = y - b_delta right = y + b_delta if (up >= 0 and left >= 0) and (up, left) not in visited: valid_cells.append((up, left)) visited.add((up, left)) if (up >= 0 and right < n) and (up, right) not in visited: valid_cells.append((up, right)) visited.add((up, right)) if (down < n and left >= 0) and (down, left) not in visited: valid_cells.append((down, left)) visited.add((down, left)) if (down < n and right < n) and (down, right) not in visited: valid_cells.append((down, right)) visited.add((down, right)) return valid_cells def breadth_first_search(a_delta, b_delta, n): visited = set() q = Queue() q.put([(0,0), 0]) while q.empty() == False: (curr_x, curr_y), depth = q.get() if curr_x == n - 1 and curr_y == n - 1: return depth next_cells = next_valid_cells(visited, curr_x, curr_y, a_delta, b_delta, n) next_cells += next_valid_cells(visited, curr_x, curr_y, b_delta, a_delta, n) for cell in next_cells: if cell == (n - 1, n - 1): return depth + 1 q.put([cell, depth + 1]) return -1 #print() def main(): n = int(input().strip()) final_result = [["-1"] * (n - 1) for _ in range(n - 1)] for outer in range(1, n): for inner in range(outer, n): if inner == 1 and outer == 1: final_result[0][0] = str(n - 1) elif inner == n - 1 and outer == n - 1: final_result[inner - 1][outer - 1] = "1" else: r = str(breadth_first_search(outer, inner, n)) final_result[inner - 1][outer - 1] = r final_result[outer - 1][inner - 1] = r for row in final_result: print(" ".join(row)) main()