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 //////////////////// const isPossible = (i_start, j_start, i_end, j_end) => { // can only reach rows that are multiples of 2 away if ((i_start % 2) !== (i_end % 2)) { return false; } // every 2 rows, must alternate even/odd columns if ((Math.abs(i_start - i_end) % 4 === 0) && (j_start % 2 !== j_end % 2)) { return false; } if ((Math.abs(i_start - i_end) % 4 === 2) && (j_start % 2 === j_end % 2)) { return false; } return true; } const nextMove = (n, i_start, j_start, i_end, j_end) => { if (i_end > i_start) { // move down if (j_end < j_start || (j_start + 1) === n) { // move down left return {dir: 'LL', newCoords: {i: i_start + 2, j: j_start - 1}}; } // move down right return {dir: 'LR', newCoords: {i: i_start + 2, j: j_start + 1}}; } if (i_end < i_start) { // move up if (j_end > j_start || (j_start - 1) < 0) { return {dir: 'UR', newCoords: {i: i_start - 2, j: j_start + 1}}; } // move up left return {dir: 'UL', newCoords: {i: i_start - 2, j: j_start - 1}}; } // move sideways if (j_end > j_start) { // move right return {dir: 'R', newCoords: {i: i_start, j: j_start + 2}}; } // move left return {dir: 'L', newCoords: {i: i_start, j: j_start - 2}}; } const prioritisePath = (path) => { const priorities = ['UL', 'UR', 'R', 'LR', 'LL', 'L']; return path.sort((a, b) => (priorities.indexOf(a) - priorities.indexOf(b))); } function printShortestPath(n, i_start, j_start, i_end, j_end) { if (!isPossible(i_start, j_start, i_end, j_end)) { console.log('Impossible') return; } let i = i_start; let j = j_start; let path = []; let dir; while (i !== i_end || j !== j_end) { const next = nextMove(n, i, j, i_end, j_end); i = next.newCoords.i; j = next.newCoords.j; path.push(next.dir); } path = prioritisePath(path); console.log(path.length); console.log(path.join(' ')); // Print the distance along with the sequence of moves. } 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); }