#!/bin/python3 class Move(object): def __init__(self, i, j, move, prior): self.i = i self.j = j self.move = move self.prior = prior def on_board(n, i, j): if i < 0 or i > n-1: return False if j < 0 or j > n-1: return False return True def get_path(final_move): move_list = [] last_move = final_move while last_move.prior: move_list.append(last_move.move) last_move = last_move.prior move_list.reverse() return move_list def get_moves(previously_occupied, queue, i_end, j_end): moves = [] while queue: move = queue.pop(0) i = move.i j = move.j if i == i_end and j == j_end: moves = get_path(move) break if on_board(n, i-2, j-1): if not previously_occupied[i-2][j-1]: queue.append(Move(i-2, j-1, 'UL', move)) previously_occupied[i-2][j-1] = True if on_board(n, i-2, j+1): if not previously_occupied[i-2][j+1]: queue.append(Move(i-2, j+1, 'UR', move)) previously_occupied[i-2][j+1] = True if on_board(n, i, j+2): if not previously_occupied[i][j+2]: queue.append(Move(i, j+2, 'R', move)) previously_occupied[i][j+2] = True if on_board(n, i+2, j+1): if not previously_occupied[i+2][j+1]: queue.append(Move(i+2, j+1, 'LR', move)) previously_occupied[i+2][j+1] = True if on_board(n, i+2, j-1): if not previously_occupied[i+2][j-1]: queue.append(Move(i+2, j-1, 'LL', move)) previously_occupied[i+2][j-1] = True if on_board(n, i, j-2): if not previously_occupied[i][j-2]: queue.append(Move(i, j-2, 'L', move)) previously_occupied[i][j-2] = True return moves def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. move_queue = [Move(i_start, j_start, None, None)] board = [[False]*n for _ in range(n)] moves = get_moves(board, move_queue, i_end, j_end) if not moves: print("Impossible") else: print(len(moves)) print(' '.join(moves)) 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)