#!/bin/python3 import sys import math moveset_dict = {(-2, -1): 'UL', (-2, 1): 'UR', (0, 2): 'R', (2, 1): 'LR', (2, -1): 'LL', (0, -2): 'L'} moveset = [(-2, -1), (-2, 1), (0, 2), (2, 1), (2, -1), (0, -2)] def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. matrix = [[() for c in range(n)] for r in range(n)] queue = [(i_start, j_start)] while queue: r_pos, c_pos = queue.pop(0) moves = get_moves(r_pos, c_pos) for move in moves: add_r, add_c = move new_r, new_c = r_pos + add_r, c_pos + add_c if not matrix[new_r][new_c]: queue.append((new_r, new_c)) matrix[new_r][new_c] = move # postprocess to_prev = matrix[i_end][j_end] if not to_prev: print('Impossible') else: num_moves = 0 path = '' r = i_end c = j_end while r != i_start or c != j_start: move = moveset_dict[to_prev] path = move + ' ' + path r -= to_prev[0] c -= to_prev[1] to_prev = matrix[r][c] num_moves += 1 print(num_moves) print(path[:-1]) def get_moves(r_pos, c_pos): moves = [] for move in moveset: if 0 <= r_pos + move[0] < n and 0 <= c_pos + move[1] < n: moves.append(move) return 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)