#!/bin/python3 import sys # check if new row and column coordinates are safe to move. def isSafe(r,c,n): return (r >= 0 and c >= 0 and r < n and c < n) def tracking(result, start, end, prev, path = []): ans = "" while start != end: #current = path.append(start) if start in prev.keys(): start = (prev[start][0], prev[start][1], prev[start][2]) path.reverse() for j in range(len(path)): for i in range(6): if i == 0: direction = "UL" elif i == 1: direction = "UR" elif i == 2: direction = "R" elif i == 3: direction = "LR" elif i == 4: direction = "LL" else: direction = "L" if end[0] + u[i] == path[j][0] and end[1] + d[i] == path[j][1]: ans += direction + " " end = (path[j][0], path[j][1]) return len(path), ans def find(pointInfo, i_end, j_end,prev = {}): queue = [] queue.append(pointInfo) source = (pointInfo[0],pointInfo[1],0) while(queue): size = len(queue) for q in range(size): position = queue.pop(0) r,c,cnt = position checker[r][c] = True # if r == i_end and c == j_end: # #return cnt # return tracking(cnt,dest,source, prev) for i in range(6): newRow = r + u[i] newCol = c + d[i] # if newRow == i_end and newCol == j_end: # print('prevous node ', r, c) # prev[newRow,newCol] = (r,c,cnt) # return tracking(cnt,dest,source, prev) # else: if isSafe(newRow, newCol, n): if checker[newRow][newCol] == False: if newRow == i_end and newCol == j_end: prev[newRow,newCol,cnt+1] = (r,c,cnt) dest = (newRow,newCol,cnt+1) return tracking(cnt,dest,source, prev) queue.append((newRow,newCol,cnt+1)) prev[newRow,newCol,cnt+1] = (r,c,cnt) return -1 def printShortestPath(n, i_start, j_start, i_end, j_end): # mark start position as 1 board[i_start][j_start] = 1; # mark end position as 2 board[i_end][j_end] = 2; result = find([i_start,j_start,0], i_end, j_end) if result != -1: print(result[0]) print(result[1].strip()) else: print("Impossible") if __name__ == "__main__": n = int(input().strip()) i_start, j_start, i_end, j_end = input().strip().split(' ') i_start, j_start, i_end, j_end = [int(i_start), int(j_start), int(i_end), int(j_end)] board = [[0 for j in range(n)]for i in range(n)] checker= [[False for j in range(len(board))]for i in range(len(board[0]))] u = [-2,-2,0,2,2,0] d = [-1,1,2,1,-1,-2] printShortestPath(n, i_start, j_start, i_end, j_end)