import java.util.*; public class Solution { public static String[] knightMovesStr = {"UL","UR","R","LR","LL","L"}; public static int[][] knightMoves = {{-2, -2, 0, 2, 2, 0}, {-1, 1, 2, 1, -1 ,-2}}; public static class BoardState{ public int i; public int j; public int moves; public String moveHistory; public BoardState(int I, int J, int Moves, String Hist){ i = I; j = J; moves = Moves; moveHistory = Hist; } public BoardState move(int k, int n){ int nextI = i + knightMoves[0][k]; int nextJ = j + knightMoves[1][k]; String nextHistory = ""; if (nextI >= 0 && nextI < n && nextJ >= 0 && nextJ < n){ if (moveHistory == ""){ nextHistory = knightMovesStr[k]; } else{ nextHistory = moveHistory + " " + knightMovesStr[k]; } return new BoardState(nextI, nextJ, moves+1, nextHistory); } else{ return null; } } public boolean isAtLoc(int i1, int j1){ return i == i1 && j == j1; } public boolean equals(Object o){ if (o instanceof BoardState){ BoardState s = (BoardState)o; if (i == s.i && j == s.j){ return true; } } return false; } public int hashCode(){ return ("{" + i + "," + j + "}").hashCode(); } public String toString(){ return moves + "\n" + moveHistory; } } 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. boolean answerFound = false; Queue queue = new LinkedList(); HashSet seen = new HashSet(); BoardState state; BoardState next; state = new BoardState(i_start, j_start, 0, ""); queue.add(state); seen.add(state); while (!queue.isEmpty()){ state = queue.poll(); if (state.isAtLoc(i_end, j_end)){ answerFound = true; break; } for (int k = 0; k < knightMoves[0].length; k++){ next = state.move(k, n); if (next != null && !seen.contains(next)){ queue.add(next); seen.add(next); } } } if (answerFound) System.out.println(state.toString()); else 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(); } }