import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Solution { // a < b, x, y // knight(a,b) for position x,y static int[][][][] dyn = new int[25][25][25][25]; public static void main(String[] args) { Scanner in = new Scanner(System.in); // for (int i1 = 0; i1 < 25; i1++) { // for (int i2 = 0; i2 < 25; i2++) { // for (int i3 = 0; i3 < 25; i3++) { // Arrays.fill(dyn[i1][i2][i3], -1); // } // } // } int n = in.nextInt(); for (int a = 1; a < n; a++) { for (int b = 1; b < n; b++) { List path = new ArrayList(); System.out.print((b == 1 ? "" : " ") + knight(a, b, n - 1, n - 1, n, path)); } System.out.println(); } } private static int knight(int a, int b, int x, int y, int n, List path) { if (x == 0 && y == 0) { return 0; } if (x < 0 || x >= n || y < 0 || y >= n || path.contains(new Position(x, y))) { return -1; } if (dyn[x][y][a][b] != 0) { return dyn[x][y][a][b]; } path.add(new Position(x, y)); int min = Integer.MAX_VALUE; int tmp = knight(a, b, x + a, y + b, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x + a, y - b, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x - a, y + b, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x - a, y - b, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x + b, y + a, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x + b, y - a, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x - b, y + a, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } tmp = knight(a, b, x - b, y - a, n, new ArrayList(path)); if (tmp != -1) { min = Math.min(min, 1 + tmp); } if (min == Integer.MAX_VALUE) { min = -1; } dyn[x][y][a][b] = min; dyn[x][y][b][a] = min; return min; } static class Position { int x; int y; Position(int x, int y) { this.x = x; this.y = y; } @Override public boolean equals(Object other) { if (!(other instanceof Position)) { return false; } Position p = (Position) other; return this.x == p.x && this.y == p.y; } } }