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 calculateMinimalPath(n, a, b, row, col, visited) { let queue = [ { row: row, col: col, steps: 0 } ] while(queue.length) { const item = queue.shift(); if(item.row === n && item.col === n) return item.steps; if(item.row < 0 || item.col < 0 || item.row > n || item.col > n) continue; const key = item.row + '-' + item.col; if(visited[key]) continue; visited[key] = true; queue.push( { row: item.row + a, col: item.col + b, steps: item.steps + 1 }, { row: item.row + a, col: item.col - b, steps: item.steps + 1 }, { row: item.row - a, col: item.col + b, steps: item.steps + 1 }, { row: item.row - a, col: item.col - b, steps: item.steps + 1 }, { row: item.row + b, col: item.col + a, steps: item.steps + 1 }, { row: item.row + b, col: item.col - a, steps: item.steps + 1 }, { row: item.row - b, col: item.col + a, steps: item.steps + 1 }, { row: item.row - b, col: item.col - a, steps: item.steps + 1 } ) } return -1; } function main() { var n = parseInt(readLine()); for(let row = 1; row < n; row += 1) { let rowResult = [ ]; for(let col = 1; col < n; col += 1) { const result = calculateMinimalPath(n - 1, row, col, 0, 0, { }); rowResult.push(result === Infinity ? -1 : result); } console.log(rowResult.join(' ')); } }