#!/bin/python3 import sys moves = [] def bfs(n,a,b): dist = {} #if b < a: # a,b=b,a #print(a,b) start = 0,0 goal = n-1,n-1 queue = [start] dist[start] = 0 #ways[start] = 1 #print(dist) while len(queue): cur = queue[0] queue.pop(0) #print(cur) if cur == goal: moves.append(dist[cur]) #print ("reached goal in %d moves and %d ways"%(dist[cur],ways[cur])) #print(dist) #print(moves) return for move in [ (a,b),(b,a),(-a,-b),(-b,-a),(a,-b),(-a,b),(-b,a),(b,-a) ]: next_pos = cur[0]+move[0], cur[1]+move[1] #print(next_pos, queue) if next_pos[0] > goal[0] or next_pos[1] > goal[1] or next_pos[0] < 0 or next_pos[1] < 0 or (next_pos[0] == 0 and next_pos[1] == 0): #print(next_pos, move, "if1") continue #if next_pos[0] == 0 and next_pos[1] == 0: # print(next_pos, move, "if2") # continue #if next_pos in dist and dist[next_pos] == dist[cur]+1: #ways[next_pos] += ways[cur] if next_pos not in dist: #print(next_pos, move, "if3") dist[next_pos] = dist[cur]+1 #ways[next_pos] = ways[cur] queue.append(next_pos) #else: #print(next_pos,"I AM THROWN AWAY TO THE PITS OF 4444") moves.append(-1) queue.clear() dist.clear() return n = int(input().strip()) # your code goes here for j in range(1,n): for k in range(1,n): bfs(n,j,k) print(*moves) moves.clear()