#!/bin/python3 import sys n = int(input().strip()) # your code goes here class Graph: def __init__(self, board_size, a, b): self.board_size = board_size nodes = [(x,y) for x in range(board_size) for y in range(board_size)] self.path_dict = {k:set() for k in nodes} for node in self.path_dict: self.path_dict[node] = {(node[0]+x,node[1]+y) for (x,y) in [(a,b),(-a,-b),(a,-b),(-a,b),(b,a),(-b,-a),(b,-a),(-b,a)] if (0<=(node[0]+x) 0: #print(toVisitNext) newDestinations = set() currentDistance += 1 for node in toVisitNext: visited.add(node) distance[node] = currentDistance newDestinations |= self.path_dict[node] #newDestinations = {edge for edge in self.path_dict[node] for node in toVisitNext if edge not in visited} toVisitNext = set(newDestinations) - visited return distance[(0,0)] #test = Graph(6,1,1) #print(test.solution()) for a in range(1,n): row = "" for b in range(1,n): graph = Graph(n,a,b) row += str(graph.solution()) + " " print(row.strip())