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) { // Print the distance along with the sequence of moves. int moves = 0; List m_seq = new ArrayList(Arrays.asList("UL", "UR", "R", "LR", "LL", "L")); List m = new ArrayList(); if (((Math.abs(i_end - i_start) % 2) != 0) || ((j_end == j_start) && ((Math.abs(i_start - i_end) % 4) != 0)) || ((i_end == i_start) && ((Math.abs(j_end - j_start) % 2) !=0))) { // vertical distance is not divisible by 2 // in the same column and vertical distance is not divisible by 4 // in the same row but horizontal distance is not divisible by 2 System.out.print("Impossible"); return; } int x = j_start; int y = i_start; // Get the greater distance (vertical or horizontal) if (Math.abs(i_end - i_start) >= Math.abs(j_end - j_start)) { // vertical distance is greater -> move vertically if (i_end > i_start) { // target row is below while (y < i_end && x != j_end) { if (j_end > x) { // target column is on the right side x++; m.add("LR"); } else if (j_end < x) { // target column is on the left side x--; m.add("LL"); } moves++; // if another vertical move will go past the target, exit from the loop if ((y + 2) > i_end || ((j_end > x) && ((x + 1) > j_end)) || ((j_end < x) && ((x - 1) < j_end))) { break; } y += 2; } if (y < i_end && x == j_end) { // target column is reached if ((Math.abs(i_end - y) % 4) != 0) { System.out.println("Impossible"); return; } else { // move vertically in zigzag fashion while (y < i_end) { m.add("LR"); m.add("LL"); moves += 2; y += 4; } } } else if (y == i_end && x != j_end) { // target row is reached so move horizontally if ((Math.abs(j_end - x) % 2) != 0) { System.out.println("Impossible"); return; } else { while (x != j_end) { moves++; if (j_end > x) { // target column is on the right m.add("R"); x += 2; if ((x + 2) > j_end) { // if another horizontal move will go past the target, exit from the loop break; } } else if (j_end < x) { // target column is on the left m.add("L"); x -= 2; if ((x - 2) < j_end) { // if another horizontal move will go past the target, exit from the loop break; } } } if (x != j_end) { System.out.print("Impossible"); return; } } } } else if (i_end < i_start) { // target row is above while (y > i_end && x != j_end) { if (j_end > x) { // target column is on the right side x++; m.add("UR"); } else if (j_end < x) { // target column is on the left side x--; m.add("UL"); } moves++; // if another vertical move will go past the target, exit from the loop if ((y - 2) < i_end || ((j_end > x) && ((x + 1) > j_end)) || ((j_end < x) && ((x - 1) < j_end))) { break; } y -= 2; } if (y > i_end && x == j_end) { // target column is reached if ((Math.abs(i_end - y) % 4) != 0) { System.out.println("Impossible"); return; } else { // move vertically in zigzag fashion while (y > i_end) { m.add("UR"); m.add("UL"); moves += 2; y -= 4; } } } else if (y == i_end && x != j_end) { // target row is reached so move horizontally if ((Math.abs(j_end - x) % 2) != 0) { System.out.println("Impossible"); return; } else { while (x != j_end) { moves++; if (j_end > x) { // target column is on the right m.add("R"); x += 2; if ((x + 2) > j_end) { // if another horizontal move will go past the target, exit from the loop break; } } else if (j_end < x) { // target column is on the left m.add("L"); x -= 2; if ((x - 2) < j_end) { // if another horizontal move will go past the target, exit from the loop break; } } } if (x != j_end) { System.out.print("Impossible"); return; } } } } } else { // horizontal distance is greater -> move horizontally while (x != j_end) { moves++; if (j_end > x) { // target column is on the right m.add("R"); // if another horizontal move will go past the target, exit from the loop if ((x + 2) > i_end) { break; } } else if (j_end < x) { // target column is on the left m.add("L"); // if another horizontal move will go past the target, exit from the loop if ((x - 2) < i_end) { break; } } } if (x == j_end) { // target column is reached if ((Math.abs(i_end - y) % 4) != 0) { System.out.println("Impossible"); return; } else { // move vertically in zigzag fashion while (y < i_end) { m.add("LR"); m.add("LL"); moves += 2; y += 4; } } } else if ((x != j_end) && (y != i_end)) { // if vertical move/s to reach the target is/ are possible if ((Math.abs(i_end - y) % 2) != 0) { System.out.println("Impossible"); return; } else { while (y != i_end) { moves++; if (i_end > y) { // target row is below y += 2; if (j_end > x) { // target column is on the right side m.add("LR"); x++; } else if (j_end < x) { // target column is on the left side m.add("LL"); x--; } } else if (i_end < y) { // target is above y -= 2; if (j_end > x) { // target column is on the right side m.add("UR"); x++; } else if (j_end < x) { // target column is on the left side m.add("UL"); x--; } } if ((y + 2) > i_end || ((x + 1) > j_end)) { // if another vertical move will go past the target, exit break; } } if (x != j_end && y != i_end) { System.out.print("Impossible"); return; } } } else if ((x != j_end) && (y == i_end)) { System.out.println("Impossible"); return; } } Collections.sort(m, Comparator.comparing(s -> m_seq.indexOf(s))); //m.sort(Comparator.comparing(m_seq::indexOf)); System.out.println(moves); for (int i = 0; i < moves; i++) { System.out.print(m.get(i)); if ((i + 1) < moves) { System.out.print(" "); } } 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(); } }