import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; public class Solution { static void printShortestPath(int n, int startX, int startY, int endX, int endY) { if (startX >= n || startY >= n || startX >= n || startX >= n) { System.out.println("Impossible"); } else { findAndPrintPath(n, startX, startY, endX, endY); } } private static void findAndPrintPath(int n, int startX, int startY, int endX, int endY) { HashSet visited = new HashSet(); Queue paths = new LinkedList(); paths.add(new Path(startX, startY, 0, "")); while (!paths.isEmpty()) { if (processNext(paths, visited, n, endX, endY)) { return; } } System.out.println("Impossible"); } private static boolean processNext(Queue paths, HashSet visited, int n, int endX, int endY) { Path next = paths.remove(); if (visited.contains(next.x + "-" + next.y)) { return false; } visited.add(next.x + "-" + next.y); if (delegateAndPrintIfFound(next, paths, visited, n, endX, endY)) { return true; } return false; } private static boolean delegateAndPrintIfFound(Path parent, Queue paths, HashSet visited, int n, int endX, int endY) { Path UL = new Path(parent.x - 2, parent.y - 1, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, UL, "UL ")) { return true; } Path UR = new Path(parent.x - 2, parent.y + 1, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, UR, "UR ")) { return true; } Path R = new Path(parent.x, parent.y + 2, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, R, "R ")) { return true; } Path LR = new Path(parent.x + 2, parent.y + 1, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, LR, "LR ")) { return true; } Path LL = new Path(parent.x + 2, parent.y - 1, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, LL, "LL ")) { return true; } Path L = new Path(parent.x, parent.y - 2, parent.depth + 1, parent.steps.toString()); if (addOneMoveAndCheckHit(paths, n, endX, endY, L, "L ")) { return true; } return false; } private static boolean addOneMoveAndCheckHit(Queue paths, int n, int endX, int endY, Path path, String move) { if (path.x >= 0 && path.y >= 0 && path.x < n && path.y < n) { path.steps.append(move); if (path.x == endX && path.y == endY) { System.out.println(path.depth); System.out.println(path.steps.toString().trim()); paths.clear(); return true; } paths.add(path); } return false; } private static class Path { int x, y, depth; StringBuilder steps; public Path(int x, int y, int depth, String stepsSoFar) { this.x = x; this.y = y; this.depth = depth; this.steps = new StringBuilder(stepsSoFar); } } 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(); } }