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 needsToMove(pos, endPos, axis, direction) { if (!direction[axis]) return false; return direction[axis] > 0 ? pos < endPos : pos > endPos; } function xyWithinBounds(x, y, limit) { return !(x < 0 || x > limit || y < 0 || y > limit); } function movePiece(x, y, xDelta, yDelta, moves) { let str = `${yDelta ? (yDelta > 0 ? 'L' : 'U') : ''}${xDelta > 0 ? 'R' : 'L'}`; moves.push(str); return [x + xDelta, y + yDelta]; } function printShortestPath(n, i_start, j_start, i_end, j_end) { const moves = []; let counter = 0, [x, y] = [j_start, i_start], direction = { y: i_end > i_start ? 1 : (i_end === i_start ? 0 : -1), x: j_end > j_start ? 1 : (j_end === j_start ? 0 : -1), }, status = 'Impossible'; if (i_start === i_end && j_start === j_end) return 0; while ((needsToMove(x, j_end, 'x', direction) || needsToMove(y, i_end, 'y', direction)) && xyWithinBounds(x, y, n - 1)) { let xDelta = 0, yDelta = 0, xDistance = Math.abs(j_end - x), yDistance = Math.abs(i_end - y); // Going up and to the left if (direction.x < 0 && direction.y < 0 && y - 2 >= 0 && x - 1 >= 0) { yDelta = -2; xDelta = -1; } // Going up to the right else if (direction.y < 0 && direction.x >= 0 && y - 2 >= 0 && x - 1 < n) { yDelta = -2; xDelta = 1; } // Going right else if (direction.x > 0 || (!direction.x && direction.y > 0 && !(yDistance % 4))) { if (direction.x > 0 && x + 2 <= j_end && yDistance % 4 && xDistance % 2 && x + 2 < n) { xDelta = 2; yDelta = 0; } else if (x + 1 < n && y + 2 < n) { xDelta = 1; yDelta = 2; } } // Going down to the left else if (direction.y > 0 && direction.x <= 0 && x -1 >= 0 && y + 2 < n) { xDelta = -1; yDelta = 2; } // Going left else if (direction.x < 0 && x - 2 >= 0) { xDelta = -2; } [x, y] = movePiece(x, y, xDelta, yDelta, moves); counter++; if (counter > 10) break; if (x < j_end) direction.x = 1; else if (x > j_end) direction.x = -1; else if (x === j_end) direction.x = 0; if (y < i_end) direction.y = 1; else if (y > i_end) direction.y = -1; else if (y === i_end) direction.y = 0; if (!direction.x && !direction.y) { status = counter; break; } } console.log(status); if (status !== 'Impossible') { console.log(moves.join(' ')); } } 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); }