process.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function KnightL(n, a, b) { var x0 = 0, y0 = 0; var visited = []; function generateMoves(x0, y0, hops) { var moves = []; function add(x, y) { if ((x < 0 || y < 0) || (x > n - 1 || y > n - 1)) return; if (!moves.some(m => m.x == x && m.y == y)) { moves.push({ x, y, hops }); } } add(x0 + a, y0 + b); add(x0 + a, y0 - b); add(x0 - a, y0 + b); add(x0 - a, y0 - b); add(x0 + b, y0 + a); add(x0 + b, y0 - a); add(x0 - b, y0 + a); add(x0 - b, y0 - a); return moves; } var hops = 1; var moves = generateMoves(n-1, n-1, hops); while (moves.length > 0) { var move = moves.shift(); if (move.x === x0 && move.y === y0) { return move.hops; } if (!visited.some(n => n.x === move.x && n.y === move.y)) { var movesn = generateMoves(move.x, move.y, move.hops + 1); moves = moves.concat(movesn); visited.push({ x: move.x, y: move.y, value: move.hops }); } } return -1; } function main() { var n = parseInt(readLine()); // your code goes here var pairs = {}; for (var i = 1; i < n; i++) { var line = ""; for (var j = 1; j < n; j++) { var moves = pairs[j] && pairs[j][i]; if (!moves) { moves = KnightL(n, i, j); pairs[i] = pairs[i] || []; pairs[i][j] = moves; } line = line.concat(moves + " "); } console.log(line); } }