import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static class Node implements Comparable { String move; Node parent; double cost; Pair p; int priority; Node(Pair p, double cost, int priority, String move, Node parent) { this.priority = priority; this.parent = parent; this.move = move; this.p = p; this.cost = cost; } @Override public int compareTo(Node o) { if (cost < o.cost) return -1; else if (cost > o.cost) return 1; else { return o.priority - priority; } } } static class Pair { int r; int c; Pair(int r, int c) { this.r = r; this.c = c; } Pair add(Pair other) { Pair newP = new Pair(r, c); newP.r += other.r; newP.c += other.c; return newP; } @Override public boolean equals(Object o) { if (o == this) return true; Pair oth = (Pair)o; return r == oth.r && c == oth.c; } @Override public int hashCode() { return Objects.hash(r, c); } } static Pair[] moveset = new Pair[6]; static int N; static void printShortestPath(int i_start, int j_start, int i_end, int j_end) { Pair UL = new Pair(-2, -1); Pair UR = new Pair(-2, 1); Pair R = new Pair(0, 2); Pair LR = new Pair(2, 1); Pair LL = new Pair(2, -1); Pair L = new Pair(0, -2); moveset[0] = UL; moveset[1] = UR; moveset[2] = R; moveset[3] = LR; moveset[4] = LL; moveset[5] = L; String [] moveNames = new String[6]; moveNames[0] = "UL"; moveNames[1] = "UR"; moveNames[2] = "R"; moveNames[3] = "LR"; moveNames[4] = "LL"; moveNames[5] = "L"; Pair start = new Pair(i_start, j_start); Pair goal = new Pair(i_end, j_end); HashSet visitedSet = new HashSet(); Queue q = new PriorityQueue<>(); Node startNode = new Node(start, 0, 0, "", null); q.add(startNode); while (q.size() > 0) { Node curr = q.poll(); Pair currP = curr.p; if (visitedSet.contains(currP)) continue; visitedSet.add(currP); if (currP.equals(goal)) { ArrayList path = new ArrayList(); //backtrack while (curr.parent != null) { path.add(curr.move); curr = curr.parent; } Collections.reverse(path); StringBuilder str = new StringBuilder(); for (int i=0; i= N) continue; if (newPos.c < 0 || newPos.c >= N) continue; if (visitedSet.contains(newPos)) continue; double diffR = goal.r - newPos.r; double diffC = goal.c - newPos.c; Node newNode = new Node(newPos, 1 + curr.cost, i, moveNames[i], curr); q.add(newNode); } } System.out.println("Impossible"); } public static void main(String[] args) { Scanner in = new Scanner(System.in); N = in.nextInt(); int i_start = in.nextInt(); int j_start = in.nextInt(); int i_end = in.nextInt(); int j_end = in.nextInt(); printShortestPath(i_start, j_start, i_end, j_end); in.close(); } }