#!/bin/python3 import collections from math import sqrt import sys Position = collections.namedtuple('position', 'name,x,y') def get_possible_moves(start): moves = list() moves.append(Position('UL', start.x - 2, start.y - 1)) moves.append(Position('UR', start.x - 2, start.y + 1)) moves.append(Position('R', start.x, start.y + 2)) moves.append(Position('LR', start.x + 2, start.y + 1)) moves.append(Position('LL', start.x + 2, start.y - 1)) moves.append(Position('L', start.x, start.y - 2)) return moves def get_distance(n, start, end): if end.x >= n or end.y >= n or end.x < 0 or end.y < 0: return 999 return sqrt((end.x - start.x)**2 + (end.y - start.y)**2) def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. start = Position('start', x=i_start, y=j_start) end = Position('end', x=i_end, y=j_end) all_moves = list() all_moves = helper(start, end, all_moves) def helper(start, end, all_moves): if start.x == end.x and start.y == end.y: print(len(all_moves)) for move in all_moves: print(move.name, end=' ') print() return if get_distance(n, start, end) < 2: print("Impossible") return if start.x >= n or start.y >=n or start.x < 0 or start.y < 0: print("Impossible") return #calculate all possible moves, some might be outside of the grid but get distance will eliminate those moves = get_possible_moves(start) #moves are in the order of priority, see which if any is closer to the desitnation min_dist = 999 next_move = end for move in moves: dist = get_distance(n, move, end) if min_dist > dist: min_dist = dist next_move = move all_moves.append(next_move) helper(next_move, end, all_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)