import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.InputMismatchException; import java.util.List; public class Solution { private static int N; static class Pos { public Step step; public Pos previous; @Override public String toString() { return "Pos{" + "step=" + step + ", x=" + x + ", y=" + y + '}'; } public Pos(int x, int y) { this.x = x; this.y = y; } int x; int y; public Pos forward(Step step) { int x = this.x + step.dx; int y = this.y + step.dy; if (x < N && y < N && x >= 0 && y >= 0) { return new Pos(x, y); } return null; } public Pos backward(Step step) { int x = this.x - step.dx; int y = this.y - step.dy; if (x < N && y < N && x >= 0 && y >= 0) { return new Pos(x, y); } return null; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } Pos pos = (Pos) o; if (x != pos.x) { return false; } return y == pos.y; } @Override public int hashCode() { int result = x; result = 31 * result + y; return result; } } enum Step { UL(-1, -2), UR(1, -2), R(2, 0), LR(1, 2), LL(-1, 2), L(-2, 0); Step(int dx, int dy) { this.dx = dx; this.dy = dy; } int dx; int dy; } public static void main(String[] args) throws FileNotFoundException { // long l = System.currentTimeMillis(); InputStream in1 = System.in; InputReader in = new InputReader(in1); N = in.readInt(); Pos start = new Pos(in.readInt(), in.readInt()); start = new Pos(start.y, start.x); Pos end = new Pos(in.readInt(), in.readInt()); end = new Pos(end.y, end.x); // UL, UR, R, LR, LL, L boolean[][] box = new boolean[N][N]; ArrayList front = new ArrayList<>(); front.add(start); box[start.x][ start.y] = true; List path = bfs(box, front, end); if (path == null) { prn("Impossible"); return; } int size = path.size(); prn(size-1); path.remove(path.size() - 1); Collections.reverse(path); for (Pos pos : path) { System.out.print(pos.step + " "); } } private static void prn(Object o) { System.out.println(o); } private static List bfs(boolean[][] box, ArrayList front, Pos end) { ArrayList newfront = new ArrayList<>(); for (Pos pos : front) { for (Step step : Step.values()) { Pos next = pos.forward(step); if (next != null && !box[next.x][next.y]) { box[next.x][next.y] = true; newfront.add(next); next.step = step; next.previous = pos; // System.out.println("next " + next); if (next.equals(end)) { ArrayList path = new ArrayList(); path.add(next); while (next.previous != null) { path.add(next.previous); next = next.previous; } return path; } } } } if (newfront.isEmpty()) { return null; } // prnFront(newfront); List path = bfs(box, newfront, end); // if (path == null) { // return null; // } // Pos pos = path.get(path.size() - 1); // Pos pos0 = pos.backward(pos.step); // path.add(pos0); return path; } private static void prnFront(ArrayList newfront) { for (Pos pos : newfront) { System.out.print(pos.step + " "); } System.out.println(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }