import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static List moves = new ArrayList<>(Arrays.asList("UL", "UR", "R", "LR", "LL", "L")); private static class Coord implements Comparable { int i; int j; List path; public Coord(int i, int j) { this.i = i; this.j = j; this.path = new ArrayList<>(); } public Coord(int i, int j, List path) { this.i = i; this.j = j; this.path = path; } public Coord makeMove(Coord delta, String move) { List newPath = new ArrayList<>(); for (String s : this.path) { newPath.add(s); } newPath.add(move); return new Coord(this.i + delta.i, this.j + delta.j, newPath); } @Override public int compareTo(Object other) throws ClassCastException { if (!(other instanceof Coord)) throw new ClassCastException(); Coord otherCoord = (Coord) other; int c = Integer.compare(this.path.size(), otherCoord.path.size()); if (c == 0) { return -1 * Integer.compare(moves.indexOf(this.path.get(this.path.size() - 1)), moves.indexOf(otherCoord.path.get(otherCoord.path.size() - 1))); } else return c; } @Override public boolean equals(Object other) { if (!(other instanceof Coord)) return false; Coord otherCoord = (Coord) other; return otherCoord.i == this.i && otherCoord.j == this.j; } @Override public int hashCode() { return Integer.hashCode(this.i * this.j); } } private static boolean isInBoard(Coord c, int n) { return c.i >= 0 && c.i < n && c.j >= 0 && c.j < n; } 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. Map moveDeltas = new HashMap<>(); moveDeltas.put("UL", new Coord(-2, -1)); moveDeltas.put("UR", new Coord(-2, 1)); moveDeltas.put("R", new Coord(0, 2)); moveDeltas.put("LR", new Coord(2, 1)); moveDeltas.put("LL", new Coord(2, -1)); moveDeltas.put("L", new Coord(0, -2)); Coord currCoord = new Coord(i_start, j_start); Coord endCoord = new Coord(i_end, j_end); PriorityQueue frontier = new PriorityQueue<>(); Set visited = new HashSet<>(); do { for (String move : moves) { Coord nextCoord = currCoord.makeMove(moveDeltas.get(move), move); if (isInBoard(nextCoord, n) && !visited.contains(nextCoord)) { frontier.add(nextCoord); visited.add(currCoord); } } currCoord = frontier.poll(); if (currCoord.equals(endCoord)) { System.out.println(currCoord.path.size()); for (String s : currCoord.path) { System.out.print(s + " "); } return; } } while (!frontier.isEmpty()); System.out.println("Impossible"); } 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(); } }