import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.stream.Stream; public class Solution { private static final String UL="UL"; private static final String UR="UR"; private static final String LL="LL"; private static final String LR="LR"; private static final String L="L"; private static final String R="R"; private static final String UP="UP"; private static final String DOWN="DOWN"; private static boolean isPossible(Cordinate start,Cordinate end){ if(start.y==end.y) return true; else if(Math.abs(start.y-end.y)%4!=0 && start.x==end.x) return false; else if(Math.abs(start.y-end.y)%2==0) return true; else return false; } private static int move(Cordinate start,Cordinate end, String toLocation){ if(toLocation.equalsIgnoreCase(UR)){ start.x+=1; start.y-=2; return 1; } else if(toLocation.equalsIgnoreCase(UL)) { start.x -= 1; start.y -= 2; return 1; } else if(toLocation.equalsIgnoreCase(LR)) { start.x += 1; start.y += 2; return 1; } else if(toLocation.equalsIgnoreCase(LL)) { start.x -= 1; start.y += 2; return 1; } else if(toLocation.equalsIgnoreCase(L) || toLocation.equalsIgnoreCase(R)) { start.x = end.x; start.y = end.y; return 1; } else return 0; } private static String getDiretcion(Cordinate start,Cordinate end){ //High Priority up if(start.x==end.x && start.y-end.y>0) return UP; if(start.x==end.x && start.y-end.y<0) return DOWN; //Check for left if(start.y-end.y>0 )//UP { if(start.x-end.x<0)//Right return UR; else return UL; } if(start.y==end.y && start.x-end.x<0) return R; if(start.y-end.y<0 )//Down { if(start.x-end.x<0)//Right return LR; else return LL; } if(start.y==end.y && start.x-end.x>0) return L; return null; } private static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) throws CloneNotSupportedException { Cordinate start = new Cordinate(i_start,j_start); Cordinate end = new Cordinate(i_end,j_end); if(!isPossible(start,end)) System.out.println("Impossible"); else { Cordinate temp = (Cordinate) start.clone(); StringBuilder sb = new StringBuilder(); int count = 0; String direction = ""; while (!temp.equals(end)){ direction = getDiretcion(temp,end); if(direction.equalsIgnoreCase(UP)) { int diff = temp.y-end.y; int finalMove = Math.abs(diff)/2; Stream.iterate(0,val -> val+1) .limit(finalMove/2) .forEach(val -> sb.append("UR UL ")); temp.x = end.x; temp.y = end.y; count += finalMove; } else if( direction.equalsIgnoreCase(DOWN)){ int diff = temp.y-end.y; int finalMove = Math.abs(diff)/2; Stream.iterate(0,val -> val+1) .limit(finalMove/2) .forEach(val -> sb.append("LR LL ")); temp.x = end.x; temp.y = end.y; count += finalMove; } else { sb.append(direction).append(" "); count += move(temp,end,direction); } } System.out.println(count); System.out.println(sb); } } public static void main(String[] args) throws CloneNotSupportedException { 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(); } static class Cordinate implements Cloneable{ @Override protected Object clone() throws CloneNotSupportedException { return super.clone(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Cordinate cordinate = (Cordinate) o; if (x != cordinate.x) return false; return y == cordinate.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } public int x; public int y; public Cordinate(int y, int x) { this.x = x; this.y = y; } } }