#!/bin/python3 import sys from collections import namedtuple Cell = namedtuple("Cell", ["x", "y"]) PRIORITY = ["UL", "UR", "R", "LR", "LL", "L"] def convert_to_intlist(line): return [int(item) for item in line.split()] def is_valid(point, gridsize): return 0 <= point.x < gridsize and 0 <= point.y < gridsize def valid_neighbours_in_order(cell, gridsize): x, y = cell neighbours = [Cell(x-1, y-2), Cell(x+1, y-2), Cell(x+2, y), Cell(x+1, y+2), Cell(x-1, y+2), Cell(x-2, y)] return [point if is_valid(point, gridsize) else None for point in neighbours] def neighbours_of_cells(cells, distances, next_level, backtrack, gridsize): unvisited_neighbours = [] for cell in cells: neighbours = valid_neighbours_in_order(cell, gridsize) for neighbour, direction in zip(neighbours, PRIORITY): if neighbour is not None and neighbour not in distances: distances[neighbour] = next_level backtrack[neighbour] = (cell, direction) unvisited_neighbours.append(neighbour) return unvisited_neighbours def get_complete_path(start, end, backtrack): path = [] point = end while point != start: point, direction = backtrack[point] path.append(direction) return " ".join(path[::-1]) def find_shortest_path(start, end, gridsize): distances = {start: 0} backtrack = {} next_level = 1 neighbours = neighbours_of_cells([start], distances, next_level, backtrack, gridsize) while neighbours and end not in neighbours: next_level += 1 neighbours = neighbours_of_cells(neighbours, distances, next_level, backtrack, gridsize) if end not in distances: return None return distances[end], get_complete_path(start, end, backtrack) if __name__ == "__main__": data = sys.stdin.read().splitlines() gridsize = int(data[0]) start_y, start_x, end_y, end_x = convert_to_intlist(data[1]) start = Cell(start_x, start_y) end = Cell(end_x, end_y) path = find_shortest_path(start, end, gridsize) if path is None: print("Impossible") else: print(path[0]) print(path[1])