import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void res(int x, String a, int z, String b) { String[] way = new String[x]; String[] way1 = new String[z]; Arrays.fill(way, a); Arrays.fill(way1, b); String shortString = Arrays.toString(way) .replace(",", "") //remove the commas .replace("[", "") //remove the right bracket .replace("]", "") //remove the left bracket .trim(); String short1String = Arrays.toString(way1) .replace(",", "") //remove the commas .replace("[", "") //remove the right bracket .replace("]", "") //remove the left bracket .trim(); System.out.println(x+z); System.out.println(shortString + " " + short1String); } public 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. if (Math.abs(i_end - i_start) % 2 != 0 || Math.abs(i_end - i_start)==2 || i_end >= n || j_end >= n || i_start>=n || j_start>=n || i_start<0 || j_start<0 || i_end < 0 || j_end < 0) { System.out.println("Impossible"); return; } if (i_end < i_start) { if (j_end < j_start) { int x = (Math.abs(i_end - i_start)) / 2; int y = Math.abs(j_start - x - j_end); int z = y / 2; if (y % 2 != 0) { System.out.println("Impossible"); } else if(j_end>(j_start-x)) { int i_new=i_start-(Math.abs(i_end-i_start)/x); int q = Math.abs(i_end - i_start) / 4; z=(Math.abs(i_end-i_start)/x)/2; if((Math.abs(i_end - i_new))%4!=0) { System.out.println("Impossible"); return; } int s=q+z; if (j_start > x) { res(s, "UL", q, "UR"); } else { res(s, "UR", q, "UL"); } return; } else if ((j_start - x) > j_end) { res(x, "UL", z, "L"); } else { res(x, "UL", z, "R"); } } if (j_end > j_start) { int x = (Math.abs(i_end - i_start)) / 2; int y = Math.abs(j_start + x - j_end); int z = y / 2; if (y % 2 != 0) { System.out.println("Impossible"); } else if(j_end<(j_start+x)) { int i_new=i_start-(Math.abs(i_end-i_start)/x); int q = Math.abs(i_end - i_start) / 4; z=(Math.abs(i_end-i_start)/x)/2; if((Math.abs(i_end - i_new))%4!=0) { System.out.println("Impossible"); return; } int s=q+z; res(s, "UR", q, "UL"); return; } else if ((j_start + x) > j_end) { res(x, "UR", z, "L"); } else { res(x, "UR", z, "R"); } } if (j_end == j_start) { int x = Math.abs(i_end - i_start) / 4; if((Math.abs(i_end - i_start))%4!=0) { System.out.println("Impossible"); return; } if (j_start > x) { res(x, "UL", x, "UR"); } else { res(x, "UR", x, "UL"); } } } // down if (i_end > i_start) { if (j_end < j_start) { int x = (Math.abs(i_end - i_start)) / 2; int y = Math.abs(j_start - x - j_end); int z = y / 2; if (y % 2 != 0) { System.out.println("Impossible"); } else if(j_end>(j_start-x)) { int i_new=i_start-(Math.abs(i_end-i_start)/x); int q = Math.abs(i_end - i_start) / 4; z=(Math.abs(i_end-i_start)/x)/2; if((Math.abs(i_end - i_new))%4!=0) { System.out.println("Impossible"); return; } int s=q+z; res(s, "LL", q, "LR"); return; } else if ((j_start - x) > j_end) { res(x, "LL", z, "L"); } else { res(z, "R", z, "LL"); } } if (j_end > j_start) { int x = (Math.abs(i_end - i_start)) / 2; int y = Math.abs(j_start + x - j_end); int z = y / 2; if (y % 2 != 0) { System.out.println("Impossible"); } else if(j_end<(j_start+x)) { int i_new=i_start-(Math.abs(i_end-i_start)/x); int q = Math.abs(i_end - i_start) / 4; z=(Math.abs(i_end-i_start)/x)/2; if((Math.abs(i_end - i_new))%4!=0) { System.out.println("Impossible"); return; } int s=q+z; res(s, "LR", q, "LL"); return; } else if ((j_start + x) > j_end) { res(x, "LR", z, "L"); } else { res(z, "R", x, "LR"); } } if (j_end == j_start) { int x = Math.abs(i_end - i_start)/4; if(Math.abs(i_end - i_start)%4!=0) { System.out.println("Impossible"); return; } if (n>(j_start+x)) { res(x, "LR", x, "LL"); } else { res(x, "LL", x, "LR"); } } } //equal if(i_end==i_start) { int x = Math.abs(j_end-j_start); if(x%2!=0) { System.out.println("Impossible"); return; } int y=x/2; if((j_end-j_start)>0) { res(y, "R", 0, ""); } if((j_end-j_start)<0) { res(y, "L", 0, ""); } } } 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(); } }