import java.awt.*; import java.util.ArrayList; import java.util.Scanner; public class RedKnight { private Point pos; private int bound; private int length; public RedKnight(Point pos, int bound) { this.pos = pos; this.bound = bound; this.length = 0; } public String moveLeft(){ if (inbound(pos.y - 2)){ pos.y -= 2; length++; return "L"; } return "OUT"; } public String moveRight(){ if(inbound(pos.y + 2)){ pos.y += 2; length++; return "R"; } return "OUT"; } public String moveUL(){ if(inbound(pos.x - 2, pos.y - 1)) { pos.x -= 2; pos.y -= 1; length++; return "UL"; } return "OUT"; } public String moveUR(){ if(inbound(pos.x + 2, pos.y - 1)) { pos.x += 2; pos.y -= 1; length++; return "UR"; } return "OUT"; } public String moveLL(){ if(inbound(pos.x + 2, pos.y - 1)){ pos.x += 2; pos.y -= 1; length++; return "LL"; } return "OUT"; } public String moveLR(){ if(inbound(pos.x + 2, pos.y + 1)) { pos.x += 2; pos.y += 1; length++; return "LR"; } return "OUT"; } private boolean inbound(int a){ return a < bound && a >= 0; } private boolean inbound(int a, int b){ return inbound(a) && inbound(b); } private String moveTo(Point target) { ArrayList seq = new ArrayList(); int dx = target.x - pos.x; int dy = target.y - pos.y; while((dx != 0) || (dy != 0)) { seq.add(move(dx, dy)); dx = target.x - pos.x; dy = target.y - pos.y; } StringBuilder builder = new StringBuilder(); String res = ""; String sp = ""; for (String s : seq){ builder.append(sp).append(s); sp=" "; } return builder.toString(); } private String move(int row, int col){ if(row > 0) { // down if(col < 0) return moveLL(); else return moveLR(); } else if (row < 0) { // up if (col < 0) return moveUL(); else return moveUR(); } else { if (col < 0) return moveLeft(); else return moveRight(); } } public boolean checkPath(Point t){ int dRow = Math.abs(t.x - pos.x); int dCol = Math.abs(t.y - pos.y); if (dRow == 0 && dCol == 0) return true; if(dRow % 2 != 0){ // can only reach even rows return false; } else if(dRow % 4 == 0 || dRow == 0) { // Every fourth row or same row // then column must be even // but not in the same column if(dCol % 2 != 0){ return false; } if(dCol == 0){ return (dRow % 4 == 0); } } else { // Every second row // col must be odd if (dCol % 2 == 0) { return false; } } return true; } public void findPath(Point target){ if(!checkPath(target)) { System.out.println("Impossible"); return; } String seq = moveTo(target); System.out.println(length); System.out.println(seq); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int iStart = in.nextInt(); int jStart = in.nextInt(); int iEnd = in.nextInt(); int jEnd = in.nextInt(); RedKnight r = new RedKnight(new Point(iStart, jStart), size); r.findPath(new Point(iEnd, jEnd)); in.close(); } }