#!/bin/python3 import sys n = int(input().strip()) results = [[None for _ in range(n-1)] for _ in range(n-1)] multiplier = [(1, 1),(1, -1),(-1, 1),(-1, -1)] # For each "move set" for i in range(1, n): for j in range(i, n): # Visited positions visited = dict() visited[(0, 0)] = 0 # Positions to try moves from move_from = [(0, 0)] # While there are moves to try while move_from != []: old_move = move_from.pop(0) # Plausable moves pos_moves = [(old_move[0] + i*x, old_move[1] + j*y) for x, y in multiplier] pos_moves.extend([(old_move[0] + j*x, old_move[1] + i*y) for x, y in multiplier]) for new_move in pos_moves: # Check if valid move if new_move[0] >= 0 and new_move[1] >= 0 and new_move[0] < n and new_move[1] < n: # Check if visited if visited.get(new_move, None) == None: #if i == 1 and j == 1: # print("Old: {} {}".format(old_move, visited[old_move])) # print("New: {} {}".format(new_move, visited[old_move] + 1)) # Update if our current move is smaller visited[new_move] = visited.get(old_move) + 1 move_from.append(new_move) elif visited.get(new_move) > visited.get(old_move) + 1: visited[new_move] = visited.get(old_move) + 1 if visited.get((n-1, n-1), None) != None: results[i-1][j-1] = visited.get((n-1,n-1), -1) if i != j: results[j-1][i-1] = visited.get((n-1,n-1), -1) if visited.get((n-1, n-1), None) == None: results[i-1][j-1] = -1 if i != j: results[j-1][i-1] = -1 for row in results: out = str() for col in row: out += str(col) + ' ' print(out.rstrip())