#!/bin/python3 import sys import math def is_valid_move(n, move): if move[0] < 0 or move[0] >= n: return False if move[1] < 0 or move[1] >= n: return False return True def distance(c, g): return math.sqrt((c[0] - g[0])**2 + (c[1] - g[1])**2) def get_next_move(n, current, goal): best_move = (-1, -1) best_distance = distance(current, goal) possible_moves = { (current[0] , current[1] - 2) : "L", (current[0] + 2, current[1] - 1) : "LL", (current[0] + 2, current[1] + 1) : "LR", (current[0] , current[1] + 2) : "R", (current[0] - 2, current[1] + 1) : "UR", (current[0] - 2, current[1] - 1) : "UL", } for move in possible_moves.keys(): dist = distance(move, goal) if is_valid_move(n, move) and dist <= best_distance: best_move = move best_distance = dist if best_move == (-1, -1): return "Impossible", best_move else: return possible_moves[best_move], best_move def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. current = (i_start, j_start) goal = (i_end, j_end) moves = [] while current != goal: next_move, next_location = get_next_move(n, current, goal) if next_move == "Impossible": print("Impossible") return else: moves.append(next_move) current = next_location 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)