#!/bin/python3 import sys from collections import deque def next_possible_positions(n, row, col): possible_positions = [] for (move, r, c) in [('UL', row-2, col-1), ('UR', row-2, col+1), ('R', row, col+2), ('LR', row+2, col+1), ('LL', row+2, col-1), ('L', row, col-2)]: if r >= 0 and r < n and c >= 0 and c < n: possible_positions.append((move, r, c)) return possible_positions def backtrack_cell(r, c, move): if move == 'UL': return r+2, c+1 if move == 'UR': return r+2, c-1 if move == 'R': return r, c-2 if move == 'LR': return r-2, c-1 if move == 'LL': return r-2, c+1 if move == 'L': return r, c+2 return None def backtracked_path(matrix, r_start, c_start, r_end, c_end): moves = deque() r, c = r_end, c_end while not (r == r_start and c == c_start): move = matrix[r][c] moves.appendleft(move) r, c = backtrack_cell(r, c, move) return moves def printShortestPath(n, r_start, c_start, r_end, c_end): # Print the distance along with the sequence of moves. next_to_visit = deque() next_to_visit.append((r_start, c_start)) matrix = [[None for _ in range(n)] for _ in range(n)] while len(next_to_visit) > 0: c_r, c_c = next_to_visit.popleft() for (move, n_r, n_c) in next_possible_positions(n, c_r, c_c): if matrix[n_r][n_c] is not None: continue # already visited matrix[n_r][n_c] = move if (n_r, n_c) == (r_end, c_end): moves = backtracked_path(matrix, r_start, c_start, r_end, c_end) print(len(moves)) print(' '.join(moves)) return next_to_visit.append((n_r, n_c)) print('Impossible') 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)