import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); // your code goes here int[][] grid = new int[n-1][n-1];//for storing output for(int m1 = 1 ; m1 < n; m1++) { /*m1 and m2 are the moving capabilities. So can't be 0*/ for(int m2 = 1; m2 < n; m2++) { System.out.print(KnightL(m1, m2, n)+ " "); }//for System.out.println(); }//for }//main private static int KnightL(int m1, int m2, int n) { int steps = 0; int pace;//used to reference step-1 int[][] grid = new int[n][n]; boolean alreadyPlaced; /*used to determine if it fails to reach goal. Because, if it can't then it cannot be placed at the very end*/ for(int i = 0; i < n; i++) { /*sets all coords in grid to -1.*/ for(int j = 0; j < n; j++) { grid[i][j] = -1; }//for2 }//for grid[0][0] = 0;//the first coord while(true) { /*You can just set while to true and fix things later to avoid infinite loop*/ steps++;//increment at beginning to save time when putting it into grid pace = steps - 1; alreadyPlaced = false; /*while loop purpose is to place in grid. Haven't started yet*/ for(int row = 0; row < n; row++) { /*to go through every spot in the grid*/ for(int col = 0; col < n; col++) { if(grid[row][col] == pace) { /*find where the startPos are and then act on them immediately*/ /*------------------------------------------------------------------ *conditions to see if new coord is within grid. *then, check if space is available. */ if (row + m1 < n && col + m2 < n) { if(grid[row+m1][col+m2] == -1) { grid[row+m1][col+m2] = steps; alreadyPlaced = true; } } if (row + m1 < n && col - m2 > -1) { if(grid[row+m1][col-m2] == -1) { grid[row+m1][col-m2] = steps; alreadyPlaced = true; } } if (row - m1 > -1 && col + m2 < n) { if(grid[row-m1][col+m2] == -1) { grid[row-m1][col+m2] = steps; alreadyPlaced = true; } } if (row - m1 > -1 && col - m2 > -1) { if(grid[row-m1][col-m2] == -1) { grid[row-m1][col-m2] = steps; alreadyPlaced = true; } } if (row + m2 < n && col + m1 < n) { if(grid[row+m2][col+m1] == -1) { grid[row+m2][col+m1] = steps; alreadyPlaced = true; } } if (row + m2 < n && col - m1 > -1) { if(grid[row+m2][col-m1] == -1) { grid[row+m2][col-m1] = steps; alreadyPlaced = true; } } if (row - m2 > -1 && col + m1 < n) { if(grid[row-m2][col+m1] == -1) { grid[row-m2][col+m1] = steps; alreadyPlaced = true; } } if (row - m2 > -1 && col - m1 > -1) { if(grid[row-m2][col-m1] == -1) { grid[row-m2][col-m1] = steps; alreadyPlaced = true; } } } } } if (grid[n-1][n-1] != -1) { /*checks if has found path(bottom right)*/ return steps; } if (!alreadyPlaced) { break; } }//while return -1;//for when it doesn't work. done outside of loop }//KnightL(int, int, int) }//Solution class