import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { private static class Position { public int i; public int j; public Position(int i, int j) { this.i = i; this.j = j; } @Override public String toString() { return "Position{" + "i=" + i + ", j=" + j + '}'; } } private static class Move extends Position { public String name; public Move(int i, int j, String name) { super(i,j); this.name = name; } public Position next(int i, int j){ return new Position(this.i +i,this.j +j); } } static Move UPLEFT = new Move(-2,-1,"UL"); static Move UPRIGHT = new Move(-2,1,"UR"); static Move LOWERLEFT = new Move(2,-1,"LL"); static Move LOWERRIGHT = new Move(2,1,"LR"); static Move LEFT = new Move(0,-2,"L"); static Move RIGHT = new Move(0,2,"R"); static Move ZERO = new Move(0,0,"Zero"); static Move IMPOSSIBLE = new Move(0,0,"Impossible"); static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // System.out.println(n + " " + i_start + " " + j_start + " " +i_end + " " + j_end); List moves=new ArrayList(); moves= tryReach(n, i_start, j_start, i_end, j_end, new ArrayList()); if(moves.isEmpty()) System.out.print(IMPOSSIBLE.name); else { int index=0; System.out.println(moves.size()-1); for (Move move : moves) { if(index++>0) System.out.print(" "); if(move!=ZERO) { System.out.print(move.name); } } } } private static List tryReach(int n, int i_start, int j_start, int i_end, int j_end, List positions) { List moves=new ArrayList(); if(i_start>=n||i_start<0 || j_start>=n||j_start<0){ //System.out.println("Stop trying this branch"); return moves; } if(i_start==i_end && j_start==j_end){ //System.out.println("Found one path"); moves.add(ZERO); return moves; } if(j_start>j_end) { reach(n, i_start, j_start, i_end, j_end, moves, LEFT, positions); reach(n, i_start, j_start, i_end, j_end, moves, UPLEFT, positions); reach(n, i_start, j_start, i_end, j_end, moves, LOWERLEFT, positions); }else { reach(n, i_start, j_start, i_end, j_end, moves, RIGHT, positions); reach(n, i_start, j_start, i_end, j_end, moves, UPRIGHT, positions); reach(n, i_start, j_start, i_end, j_end, moves, LOWERRIGHT, positions); } return moves; } static void reach(int n, int i_start, int j_start, int i_end, int j_end, List moves, Move move, List positions) { Position pos=move.next(i_start,j_start); if(!positions.contains(pos.toString())) { /*System.out.println("Move: "+move.name+" to "+pos.toString()); System.out.print("positions:"); for(String position: positions){ System.out.print(position+" "); } System.out.println(""); */ positions.add(pos.toString()); List movesPossible = tryReach(n, pos.i, pos.j, i_end, j_end, positions); if (!movesPossible.isEmpty() && (moves.isEmpty() || moves.size() > movesPossible.size())) { moves.clear(); moves.add(move); moves.addAll(movesPossible); } positions.remove(pos.toString()); } } 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(); } }