import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static String str = "7\n6 6 0 1"; static int sizeOfBoard = 0; static Node root = null; static int i_ende; static int j_ende; static boolean inBounds = true; static List endNodes = new ArrayList<>(); static List> viablePaths = new ArrayList<>(); 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. sizeOfBoard = n; i_ende = i_end; j_ende = j_end; root = new Node("Start", i_start, j_start, null); rec(root); for (Node node : endNodes) { addParents(node); } List> minPaths = new ArrayList<>(); int min = Integer.MAX_VALUE; for (List path : viablePaths) { if (path.size() <= min) { min = path.size(); minPaths.add(path); } } for (List a : minPaths) Collections.reverse(a); int pathSize=minPaths.size()==0?0:minPaths.get(0).size(); List> prioList = new ArrayList<>(); for (int k = 1; k < pathSize; k++) { ArrayList intList = new ArrayList<>(); for (List path : minPaths) { String tmpMove = path.get(k).move; switch (tmpMove) { case "UL": intList.add(5); break; case "UR": intList.add(4); break; case "R": intList.add(3); break; case "LR": intList.add(2); break; case "LL": intList.add(1); break; case "L": intList.add(0); break; default: break; } } List indexList = indicesOf(Collections.max(intList), intList); for (int index : indexList) { prioList.add(minPaths.get(index)); } minPaths.retainAll(prioList); prioList.clear(); } if(minPaths.size()>0) { List path = minPaths.get(0).subList(1, minPaths.get(0).size()); System.out.println(path.size()); for (Node node : path) System.out.print(node.move + " "); }else{ System.out.println("Impossible"); } } static List indicesOf(Integer number, ArrayList list) { List indices = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { if (number == list.get(i)) { indices.add(i); } } return indices; } static void addParents(Node node) { List tmp = new ArrayList<>(); addParentsRec(node, tmp); viablePaths.add(tmp); } static void addParentsRec(Node node, List list) { list.add(node); if (node.parent == null) return; addParentsRec(node.parent, list); } static void rec(Node node) { node.makeMoves(); for (Node child : node.children) { rec(child); } } static class Node { private String move; private int i; private int j; private Node parent; private Set children; private Set possibleChildren; boolean isAncestor(Node node) { if (node == null) { return false; } if (node.equals(this)) return true; if (this.parent == null) return false; if (node.equals(this.parent)) return true; return parent.isAncestor(node); } boolean isInBounds() { return this.i < sizeOfBoard & this.j < sizeOfBoard & this.i >= 0 & this.j >= 0; } public Node(String move, int i, int j, Node parent) { this.move = move; this.i = i; this.j = j; this.children = new HashSet<>(); this.parent = parent; this.possibleChildren = new HashSet<>(6); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Node node = (Node) o; if (i != node.i) return false; return j == node.j; } @Override public int hashCode() { int result = i; result = 31 * result + j; return result; } void makeMoves() { if (this.i == 0 & this.j == 1) { endNodes.add(this); } inBounds = false; possibleChildren.add(new Node("UL", i - 2, j - 1, this)); possibleChildren.add(new Node("UR", i - 2, j + 1, this)); possibleChildren.add(new Node("R", i, j + 2, this)); possibleChildren.add(new Node("LR", i + 2, j + 1, this)); possibleChildren.add(new Node("LL", i + 2, j - 1, this)); possibleChildren.add(new Node("L", i, j - 2, this)); if (!(i == i_ende & j == j_ende)) { for (Node possibleChild : possibleChildren) { if (possibleChild.isInBounds()) { if (!isAncestor(possibleChild)) { inBounds = true; addChild(possibleChild); } } } } } public void addChild(Node child) { children.add(child); } @Override public String toString() { return "Node{" + "move='" + move + '\'' + ", i=" + i + ", j=" + j + '}'; } } 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(); } }