#!/bin/python3 import sys import math from collections import namedtuple sys.setrecursionlimit(10000) P = namedtuple('Pos', 'r c') # UL, UR, R, LR, LL, L moves = [ P(-2, -1), P(-2, 1), P(0, 2), P(2, 1), P(2, -1), P(0, -2), ] names = { P(-2, -1): "UL", P(-2, 1): "UR", P(0, 2): "R", P(2, 1): "LR", P(2, -1): "LL", P(0, -2): "L", } def shortest(start, end, N, mem): if start == end: return 0 if mem[start.r][start.c] is not None: return mem[start.r][start.c][0] mn = math.inf mem[start.r][start.c] = (math.inf, None) bst = None for move in moves: n = P(start.r + move.r, start.c + move.c) d1 = abs(n.c - end.c) - abs(start.c - end.c) d2 = abs(n.r - end.r) - abs(start.r - end.r) if n.r >= 0 and n.r < N and n.c >= 0 and n.c < N and d1 <= 1 and d2 <= 1: ans = 1 + shortest(n, end, N, mem) if ans < mn: mn = ans bst = move mem[start.r][start.c] = (mn, bst) return mn def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. start = P(i_start, j_start) end = P(i_end, j_end) mem = [[None for i in range(n)] for u in range(n)] s = shortest(start, end, n, mem=mem) # for r, row in enumerate(mem): # for c, col in enumerate(row): # if P(r, c) == start: # print("s", end="") # elif P(r, c) == end: # print("e", end="") # else: # print(col[0] if col is not None else ".", end="") # print("") # print("") if s == math.inf: print("Impossible") return print(s) m = [] p = start while p != end: _, b = mem[p.r][p.c] assert b in names m.append(names[b]) p = P(p.r + b.r, p.c + b.c) print(" ".join(m)) 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)