import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int[][] paths; static Stack printStack = new Stack<>(); static boolean arrive_flag = false; static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. paths = new int[n][n]; moveTo(n, i_start, j_start, i_end, j_end, 1); if(!arrive_flag) { System.out.println("Impossible"); } else { printPath(n, i_start, j_start, i_end, j_end); System.out.println(printStack.size()); while(!printStack.empty()) { System.out.print(printStack.pop()+" "); } } /* System.out.println(); for(int i=0; i=n || j_curr <0 || j_curr >= n) { // out of bounds return ret_val; } ret_val[1] = paths[i_curr][j_curr]; if(i_curr == i_dest && j_curr == j_dest){ // reached dest ret_val[0] = 1; return ret_val; } //System.out.println("LA "+i_curr+" "+j_curr); int[][] possible_move = new int[6][2]; if(explorePath(n, i_curr-2, j_curr-1)!= -1 && explorePath(n, i_curr-2, j_curr-1) == paths[i_curr][j_curr] + 1) possible_move[0] = printPath(n, i_curr - 2, j_curr - 1, i_dest, j_dest); // UL if(explorePath(n, i_curr-2, j_curr+1)!= -1 && explorePath(n, i_curr-2, j_curr+1) == paths[i_curr][j_curr] + 1) possible_move[1] = printPath(n, i_curr - 2, j_curr + 1, i_dest, j_dest); // UR if(explorePath(n, i_curr, j_curr+2)!= -1 && explorePath(n, i_curr, j_curr+2) == paths[i_curr][j_curr] + 1) possible_move[2] = printPath(n, i_curr, j_curr + 2, i_dest, j_dest); // R if(explorePath(n, i_curr+2, j_curr+1)!= -1 && explorePath(n, i_curr+2, j_curr+1) == paths[i_curr][j_curr] + 1) possible_move[3] = printPath(n, i_curr + 2, j_curr + 1, i_dest, j_dest); // LR if(explorePath(n, i_curr+2, j_curr-1)!= -1 && explorePath(n, i_curr+2, j_curr-1) == paths[i_curr][j_curr] + 1) possible_move[4] = printPath(n, i_curr + 2, j_curr - 1, i_dest, j_dest); // LL if(explorePath(n, i_curr, j_curr-2)!= -1 && explorePath(n, i_curr, j_curr-2) == paths[i_curr][j_curr] + 1) possible_move[5] = printPath(n ,i_curr, j_curr - 2, i_dest, j_dest); // L int move = -1; for(int i=5; i>=0; i--) { // Reverse path to favor correct ordering if(possible_move[i][0] == 1){ move = i; } } switch(move) { case 0: printStack.push("UL"); break; case 1: printStack.push("UR"); break; case 2: printStack.push("R"); break; case 3: printStack.push("LR"); break; case 4: printStack.push("LL"); break; case 5: printStack.push("L"); break; default: //System.out.println("Unavailable move: "+move+" @:"+i_curr+j_curr); } return ret_val; } static int explorePath(int n, int i_curr, int j_curr) { if(i_curr < 0 || i_curr >=n || j_curr <0 || j_curr >= n) { // out of bounds return -1; } return paths[i_curr][j_curr]; } static void moveTo(int n, int i_curr, int j_curr, int i_dest, int j_dest, int step) { if(i_curr < 0 || i_curr >= n || j_curr < 0 || j_curr >= n) return; // out of bounds if(i_curr == i_dest && j_curr == j_dest){ if(step < paths[i_curr][j_curr] || paths[i_curr][j_curr] == 0) { paths[i_curr][j_curr] = step; arrive_flag = true; //System.out.println("FOUND "+i_curr+" "+j_curr); return; // reached dest with shorter route or if first to reach } } // hitherto unexplored cell OR 2 replace longer route if(paths[i_curr][j_curr] == 0 || step < paths[i_curr][j_curr]) { //System.out.println("@ "+i_curr+" "+j_curr); paths[i_curr][j_curr] = step; // update step moveTo(n, i_curr - 2, j_curr - 1, i_dest, j_dest, step+1); // UL moveTo(n, i_curr - 2, j_curr + 1, i_dest, j_dest, step+1); // UR moveTo(n ,i_curr, j_curr + 2, i_dest, j_dest, step+1); // R moveTo(n, i_curr + 2, j_curr + 1, i_dest, j_dest, step+1); // LR moveTo(n ,i_curr + 2, j_curr - 1, i_dest, j_dest, step+1); // LL moveTo(n, i_curr, j_curr - 2, i_dest, j_dest, step+1); // L } return; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); printShortestPath(n, i_start, j_start, i_end, j_end); in.close(); } }