import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { Queue queue = new ArrayDeque<>(); Location start = new Location(null, 0, i_start, j_start, ""); queue.add(start); int[][] visited = new int[n][n]; visited[i_start][ j_start] = 0; for(int i = 0; i < n; ++i){ for(int j = 0; j< n; ++j){ visited[i][j] = -1; } } while(true){ if(queue.size() ==0){ System.out.println("Impossible"); return; } Location cur = queue.poll(); int x = cur.x; int y = cur.y; //System.out.println("on " + x + " " + y + " " + cur.movesToHere); if( x == i_end && y == j_end){ System.out.println(cur.movesToHere); ArrayList result = new ArrayList<>(); while(cur != null){ result.add(cur.moveToGetHere ); cur = cur.parent; } Collections.reverse(result); for(int i = 1; i < result.size(); ++i){ System.out.print(result.get(i) + " " ); } return; } tryMove(cur, x-2, y-1, visited, queue, "UL"); tryMove(cur, x-2, y+1, visited, queue, "UR"); tryMove(cur, x, y+2, visited, queue, "R"); tryMove(cur, x+2, y+1, visited, queue, "LR"); tryMove(cur, x+2, y-1, visited, queue, "LL"); tryMove(cur, x, y-2, visited, queue, "L"); } } static void tryMove(Location cur, int destX, int destY, int[][] visited, Queue queue, String move){ if(destX>=visited.length || destX<0 || destY>=visited.length || destY< 0){ return; } if(visited[destX][destY]>=0){ return; } Location next = new Location(cur, cur.movesToHere+1, destX, destY, move); visited[destX][destY] = next.movesToHere; queue.add(next); } 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(); } } class Location{ Location parent; int movesToHere; int x; int y; String moveToGetHere; public Location(Location p, int m, int x, int y, String move){ parent = p; movesToHere = m; this.x=x; this.y = y; moveToGetHere = move; } }