import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static boolean legalMove(int row, int column, int n) { return (row >= 0 && column >= 0 && row < n && column < n); } public static ArrayList validMoves(int x, int y, int i, int j, int n) { ArrayList moves = new ArrayList(); if (legalMove(y-j, x-i, n)) { moves.add(new Node(y-j, x-i)); } if(legalMove(y-j, x+i, n)) { moves.add(new Node(y-j, x+i)); } if (legalMove(y+j, x-i, n)) { moves.add(new Node(y+j, x-i)); } if(legalMove(y+j, x+i, n)) { moves.add(new Node(y+j, x+i)); } if (legalMove(y-i, x-j, n)) { moves.add(new Node(y-i, x-j)); } if(legalMove(y-i, x+j, n)) { moves.add(new Node(y-i, x+j)); } if (legalMove(y+i, x-j, n)) { moves.add(new Node(y+i, x-j)); } if(legalMove(y+i, x+j, n)) { moves.add(new Node(y+i, x+j)); } return moves; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // your code goes here HashMap results = new HashMap(); for(int i = 1; i < n; i++) { for(int j = 1; j < n; j++) { Result opposite = new Result(j, i); if (results.containsKey(opposite)) { System.out.print(results.get(opposite) + " "); } else { Queue positionQueue = new LinkedList(); HashSet posExplored = new HashSet(); int[][] chessBoard = new int[n][n]; Node startPos = new Node(0, 0); positionQueue.add(startPos); posExplored.add(startPos); Node endPos = new Node(n-1, n-1); chessBoard[0][0] = 0; while(positionQueue.peek() != null) { Node currentPosition = positionQueue.poll(); int currMoves = chessBoard[currentPosition.x][currentPosition.y]; if(currentPosition.equals(endPos)) { break; } ArrayList moves = validMoves(currentPosition.x, currentPosition.y, i, j, n); for (Node nextPos : moves) { if (!posExplored.contains(nextPos)) { posExplored.add(nextPos); positionQueue.add(nextPos); chessBoard[nextPos.x][nextPos.y] = currMoves + 1; } } } int answer = chessBoard[n-1][n-1]; if (answer == 0) { Result newResult = new Result(i, j); results.put(newResult, -1); System.out.print(-1 + " "); } else { Result newResult = new Result(i, j); results.put(newResult, answer); System.out.print(chessBoard[n-1][n-1] + " "); } } } System.out.println(); } } } class Node { public Integer x; public Integer y; public Node(Integer xPos, Integer yPos) { x = xPos; y = yPos; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!Node.class.isAssignableFrom(obj.getClass())) { return false; } final Node other = (Node) obj; if (this.x != other.x) { return false; } if (this.y != other.y) { return false; } return true; } @Override public int hashCode() { int hash = 7; hash = 53 * hash + (this.x != 0 ? this.x.hashCode() : 0); hash = 53 * hash + this.y; return hash; } } class Result { public Integer i; public Integer j; public Result(Integer iCount, Integer jCount) { i = iCount; j = jCount; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!Result.class.isAssignableFrom(obj.getClass())) { return false; } final Result other = (Result) obj; if (this.i != other.i) { return false; } if (this.j != other.j) { return false; } return true; } @Override public int hashCode() { int hash = 7; hash = 53 * hash + (this.i != 0 ? this.i.hashCode() : 0); hash = 53 * hash + this.j; return hash; } }