#!/bin/python3 import sys from collections import deque def isInside(x, y, n): if x >= 0 and x < n and y >= 0 and y < n: return True return False def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. # x and y directions where red knight can move dx = [-1, 1, 2, 1, -1, -2] dy = [-2, -2, 0, 2, 2, 0] moves = ["UL", "UR", "R", "LR", "LL", "L"] # queue for storing states of red knight queue = deque([]) # append starting position of red knight with distance 0 and moves empty queue.append([i_start, j_start, 0, []]) # 2d array for keeping track of which cells we visited visited = [[False for i in range(n)] for j in range(n)] while queue: cell = queue[0] # head queue.popleft() # remove head visited[cell[0]][cell[1]] = True # if current cell is equal to destination cell, return its distance and moves if cell[0] == i_end and cell[1] == j_end: print(cell[2]) # distance print(' '.join(map(str, cell[3]))) # moves made (as space-separated string) return # check all reachable cells from current cell for i in range(6): x = cell[1] + dx[i] y = cell[0] + dy[i] move = cell[3] + [moves[i]] # if [x,y] is not yet visited and inside the board, append to queue if isInside(x, y, n) and not visited[y][x]: queue.append([y, x, cell[2] + 1, move]) 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)] printShortestPath(n, i_start, j_start, i_end, j_end)