#!/bin/python3 import sys def find_shortest_path(graph1, start, end, path=[]): path = path + [start] if start == end: return path if start not in graph1: return None shortest = None for node in graph1[start]: if node not in path: newpath = find_shortest_path(graph1, node, end, path) if newpath: if not shortest or len(newpath) < len(shortest): shortest = newpath return shortest n = int(input().strip()) # your code goes here ret_mat = [[0 for y in range(n-1)] for x in range(n-1)] for i in range(n-1): #row for m in range(n-1): #col if m= 0 and j-b >= 0: graph[(k,j)].append((k-a,j-b)) if k-a >= 0 and j+b < n: graph[(k,j)].append((k-a,j+b)) if k+a < n and j-b >= 0: graph[(k,j)].append((k+a,j-b)) if k+a < n and j+b < n: graph[(k,j)].append((k+a,j+b)) if a!=b: if k-b >= 0 and j-a >= 0: graph[(k,j)].append((k-b,j-a)) if k-b >= 0 and j+a < n: graph[(k,j)].append((k-b,j+a)) if k+b < n and j-a >= 0: graph[(k,j)].append((k+b,j-a)) if k+b < n and j+a < n: graph[(k,j)].append((k+b,j+a)) path = [] shortest_path = find_shortest_path(graph,(0,0),(n-1,n-1),path) if shortest_path is None: ret_mat[i][m] = -1 else: ret_mat[i][m] = len(shortest_path)-1 for k in range(len(ret_mat)): print(str(ret_mat[k]).strip('[]').replace(',',''))