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 printShortestPath(n, i_start, j_start, i_end, j_end) { let currentPosition = { top: i_start, left: j_start }; const endPosition = { top: i_end, left: j_end }; // Print the distance along with the sequence of moves. if (currentPosition.top % 2 !== endPosition.top % 2 || ((Math.abs(currentPosition.top - endPosition.top) / 2) % 2 !== (Math.abs(currentPosition.left - endPosition.left)) % 2)) { console.log('Impossible'); return; } const possibleMoves = { UL: (position) => ({ top: position.top - 2, left: position.left - 1 }), UR: (position) => ({ top: position.top - 2, left: position.left + 1 }), R: (position) => ({ top: position.top, left: position.left + 2 }), LR: (position) => ({ top: position.top + 2, left: position.left + 1 }), LL: (position) => ({ top: position.top + 2, left: position.left - 1 }), L: (position) => ({ top: position.top, left: position.left - 2 }) }; //UL, UR, R, LR, LL, L let moves = []; for(let i = 0;i < n; i++) { const currentDistance = distance(currentPosition, endPosition); const possibilities = Object.keys(possibleMoves) .map(k => ({ move: k, newPosition: possibleMoves[k](currentPosition), newDistance: distance(possibleMoves[k](currentPosition), endPosition) })).filter(m => isPositionValid(m.newPosition) && m.newDistance < currentDistance) .sort((m1, m2) => { let score = m1.newDistance - m2.newDistance; if (score === 0) { return Object.keys(possibleMoves).indexOf(m1.move) - Object.keys(possibleMoves).indexOf(m2.move); } return score; }); if (possibilities.length){ const move = possibilities[0]; moves.push(move.move); currentPosition = move.newPosition; } } moves = moves.sort((m1, m2) => { return Object.keys(possibleMoves).indexOf(m1) - Object.keys(possibleMoves).indexOf(m2); }) console.log(moves.length); console.log(moves.join(' ')); function distance (a,b) { return Math.abs(a.top - b.top) + Math.abs(a.left - b.left); } function isPositionValid(position) { return position.top >= 0 && position.top < n && position.left >= 0 && position.left < n; } } function main() { var n = parseInt(readLine()); var i_start_temp = readLine().split(' '); var i_start = parseInt(i_start_temp[0]); var j_start = parseInt(i_start_temp[1]); var i_end = parseInt(i_start_temp[2]); var j_end = parseInt(i_start_temp[3]); printShortestPath(n, i_start, j_start, i_end, j_end); }