import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Solution { static class Coord { int x; int y; Coord(int x, int y) { this.x = x; this.y = y; } boolean inRange(int n) { return 0 <= x && x < n && 0 <= y && y < n; } } static enum Direction { NONE(0, 0), UL(-1, -2), UR(1, -2), R(2, 0), LR(1, 2), LL(-1, 2), L(-2, 0); final int dx; final int dy; Direction(int dx, int dy) { this.dx = dx; this.dy = dy; } Coord apply(Coord coord) { return new Coord(coord.x + this.dx, coord.y + this.dy); } Coord applyRev(Coord coord) { return new Coord(coord.x - this.dx, coord.y - this.dy); } } static void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { Coord initial = new Coord(j_start, i_start); Direction[][] minPath = new Direction[n][n]; for (int i = 0; i < n; i++) { Arrays.fill(minPath[i], null); } List current = new ArrayList<>(); current.add(initial); minPath[initial.x][initial.y] = Direction.NONE; while (current.size() > 0) { List nextCoords = new ArrayList<>(); for (Coord curr : current) { for (Direction dir : Direction.values()) { Coord next = dir.apply(curr); if (next.inRange(n) && minPath[next.x][next.y] == null) { minPath[next.x][next.y] = dir; nextCoords.add(next); } } } current = nextCoords; } if (minPath[j_end][i_end] == null) { System.out.println("Impossible"); } else { Coord curr = new Coord(j_end, i_end); LinkedList path = new LinkedList<>(); while (minPath[curr.x][curr.y] != Direction.NONE) { Direction dir = minPath[curr.x][curr.y]; path.addFirst(dir); curr = dir.applyRev(curr); } System.out.println(path.size()); System.out.println(path.stream().map(Direction::name).collect(Collectors.joining(" "))); } } 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(); } }