#!/bin/python3 import sys from collections import deque def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. assert 5 <= n <= 200 assert (i_start,j_start) != (i_end, j_end) is_reachable, directions = find_path(n, i_start, j_start, i_end, j_end) if is_reachable: print(len(directions)) print(*directions, sep=' ') else: print('Impossible') def find_path(n, i_s, j_s, i_e, j_e): ''' return (is_reachable, directions in order) ''' is_reachable = False ci, cj = i_s, j_s parent = [[None for _ in range(n)] for _ in range(n)] parent[ci][cj] = (ci, cj) # parent is double for discovered q = deque() # to_visit q.append((ci, cj)) while q: ci, cj = q.popleft() if (ci,cj) == (i_e, j_e): is_reachable = True break for ni, nj in next_moves(n, ci, cj): if parent[ni][nj]: continue #not visited. parent[ni][nj] = (ci, cj) #todo: change maybe...? q.append((ni, nj)) if is_reachable: return (True, conf_path(parent, n, i_s, j_s, i_e, j_e)) else: return (False, []) def next_moves(n, i, j): didjs = [(-2,-1),(-2,1),(0,2),(2,1),(2,-1),(0,-2)] for di,dj in didjs: ni, nj = i + di, j + dj if (0 <= ni < n) and (0 <= nj < n): yield (ni, nj) def conf_path(parent, n, i_s, j_s, i_e, j_e): assert parent[i_s][j_s] == (i_s, j_s) assert parent[i_e][j_e] != None i,j = i_e,j_e stack = [] while (i,j) != (i_s,j_s): stack.append((i,j)) i,j = parent[i][j] assert (i,j) == (i_s,j_s) stack.append((i_s, j_s)) didjs = {(-2,1):'UR', (0,2):'R', (2,1):'LR', (2,-1):'LL', (0,-2):'L', (-2,-1):'UL'} directions = [] nodes = stack[::-1] for x in range(len(nodes)-1): (ai,aj), (bi,bj) = nodes[x], nodes[x+1] direction = didjs[(bi-ai,bj-aj)] directions.append(direction) return directions 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)