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 moves = ['UL', 'UR', 'R', 'LR', 'LL', 'L']; function getNewLocation({i, j}, move) { switch (move) { case 'UL': return {i: i - 2, j: j - 1}; case 'UR': return {i: i - 2, j: j + 1}; case 'R': return {i, j: j + 2}; case 'LR': return {i: i + 2, j: j + 1}; case 'LL': return {i: i + 2, j: j - 1}; case 'L': return {i, j: j - 2} } } function getNewTraceLocation({i, j}, move) { switch (move) { case 'UL': return {i: i + 2, j: j + 1}; case 'UR': return {i: i + 2, j: j - 1}; case 'R': return {i, j: j - 2}; case 'LR': return {i: i - 2, j: j - 1}; case 'LL': return {i: i - 2, j: j + 1}; case 'L': return {i, j: j + 2} } } function makeArray(w, h, val) { let arr = []; for(let i = 0; i < h; i++) { arr[i] = []; for(let j = 0; j < w; j++) { arr[i][j] = val; } } return arr; } function printShortestPath(n, i_start, j_start, i_end, j_end) { let map = makeArray(n,n, 0); let locations = [{i: i_start, j: j_start}]; let stop = false; while(locations.length !== 0 && !stop) { let currentLocation = locations.shift(); moves.forEach(move => { let newLocation = getNewLocation(currentLocation, move); if ( ((newLocation.i >= i_start && newLocation.i <= i_end) || (newLocation.i <= i_start && newLocation.i >= i_end) || (newLocation.j <= j_start && newLocation.j >= j_end) || (newLocation.j >= j_start && newLocation.i <= j_end)) && (newLocation.i >= 0 && newLocation.i < n && newLocation.j >= 0 && newLocation.j < n) && (map[newLocation.i][newLocation.j] === 0) ) { if (map[currentLocation.i][currentLocation.j] === 0) { map[currentLocation.i][currentLocation.j] = 1; } map[newLocation.i][newLocation.j] = map[currentLocation.i][currentLocation.j] + 1; locations.push(newLocation); if (newLocation.i === i_end && newLocation.j === j_end) { stop = true; } } }) } if (map[i_end][j_end] === 0) { console.log('Impossible'); } else { const reverseMoves = moves.reverse(); const solution = []; let currentLocation = {i: i_end, j: j_end}; while (currentLocation.i !== i_start || currentLocation.j !== j_start) { for (let i = 0; i <= reverseMoves.length - 1; i++) { const move = reverseMoves[i]; let newLocation = getNewTraceLocation(currentLocation, move); if ( newLocation.i >= 0 && newLocation.i < n && newLocation.j >= 0 && newLocation.j < n && map[newLocation.i][newLocation.j] !== 0 && map[newLocation.i][newLocation.j] < map[currentLocation.i][currentLocation.j]){ solution.unshift(move); currentLocation.i = newLocation.i; currentLocation.j = newLocation.j; break; } } } console.log(solution.length); let string = ''; solution.forEach(s => string += s + ' '); console.log(string.trim()); } } 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); }