import java.io.*; import java.util.*; import java.util.stream.Collectors; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void printShortestPath(final int n, final int i_start, final int j_start, final int i_end, final int j_end) { // Print the distance along with the sequence of moves. if ((i_end - i_start) % 2 != 0) { impossible(); return; } int vMovs = (i_end - i_start) / 2; if ((j_end - j_start - vMovs) % 2 != 0) { impossible(); return; } List moves = new ArrayList<>(); int i_s = i_start; int j_s = j_start; while (i_end != i_s || j_end != j_s) { int rows = i_end - i_s; int cols = j_end - j_s; DIRECTION d; if (rows > 0) { d = cols > 0 ? DIRECTION.LR : DIRECTION.LL; } else if (rows < 0) { d = cols > 0 ? DIRECTION.UR : DIRECTION.UL; } else { d = cols > 0 ? DIRECTION.R : DIRECTION.L; } moves.add(d); i_s = d.moveI(i_s); j_s = d.moveJ(j_s); } moves.sort(Comparator.naturalOrder()); List result = new ArrayList<>(); i_s = i_start; j_s = j_start; while (!moves.isEmpty()) { for (int i = 0; i < moves.size(); i++) { DIRECTION d = moves.get(i); if (d.canMove(n, i_s, j_s)) { i_s = d.moveI(i_s); j_s = d.moveJ(j_s); result.add(d); moves.remove(i); break; } } } System.out.println(result.size()); System.out.println(result.stream().map(Object::toString).collect(Collectors.joining(" "))); } enum DIRECTION { UL(-2, -1), UR(-2, 1), R(0, 2), LR(2, 1), LL(2, -1), L(0, -2); private int i; private int j; DIRECTION(int i, int j) { this.i = i; this.j = j; } public boolean canMove(int gridSize, int i_start, int j_start) { int i_end = i_start + i; int j_end = j_start + j; return i_end >= 0 && i_end < gridSize && j_end >= 0 && j_end < gridSize; } public int moveI(int i_start) { return i_start + i; } public int moveJ(int j_start) { return j_start + j; } } static void impossible() { 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(); } }