import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int min = -1; public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // your code goes here for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { int count = 0; min = -1; int[][] bb = new int[n][n]; for(int k = 0; k < n; k++){ for(int p = 0; p < n; p++){ bb[k][p] = 0; } } int[] curren = {0,0}; int[] location = {i,j}; move(n, bb, curren, location, count); System.out.printf("%d ", min); } System.out.println(""); } } public static void move(int n, int[][] board, int[] current, int[] ab, int counter) { if (0 <= current[0] && current[0] < n && 0 <= current[1] && current[1] < n ) { if(current[0] == n-1 && current[1] == n-1 ) { if (min == -1) { min = counter; } else if (counter < min) { min = counter; } } else if (board[current[0]][current[1]] > counter || board[current[0]][current[1]] == 0 ) { board[current[0]][current[1]] = counter; int[] newLocation = new int[]{current[0]+ab[0], current[1]+ab[1]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]-ab[0], current[1]+ab[1]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]+ab[0], current[1]-ab[1]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]-ab[0], current[1]-ab[1]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]+ab[1], current[1]+ab[0]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]-ab[1], current[1]+ab[0]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]+ab[1], current[1]-ab[0]}; move(n, board, newLocation, ab, counter+1 ); newLocation = new int[]{current[0]-ab[1], current[1]-ab[0]}; move(n, board, newLocation, ab, counter+1 ); } else { //do nothing } } else { //do nothing } } }