#!/bin/python3 import sys moves = ["UL", "UR", "R", "LR", "LL", "L"] def step(n, i_start, j_start, move, history): if(move == "UL" and i_start > 0 and j_start > 1): return (i_start-1, j_start-2, move, history) if(move == "UR" and i_start < n-1 and j_start > 1): return (i_start+1, j_start-2, move, history) if(move == "R" and j_start < n-2): return (i_start+2, j_start, move, history) if(move == "LL" and i_start > 0 and j_start < n-2): return (i_start-1, j_start+2, move, history) if(move == "LR" and i_start < n-1 and j_start < n-2): return (i_start+1, j_start+2, move, history) if(move == "L" and i_start > 1): return (i_start-2, j_start, move, history) return None def distance(i_start, j_start, i_end, j_end): return abs(i_end - i_start) + abs(j_end - j_start) def printShortestPath(n, j_start, i_start, j_end, i_end): # Print the distance along with the sequence of moves. #print((i_start, j_start)) #cur_dist = distance(i_start, j_start, i_end, j_end) visited = [(i_start, j_start)] candidates = [(i_start, j_start, None, None)] dist = 9999 found = False while not found: #print("----------------------") new_candidates = [] for candidate in candidates: cur_dist = distance(candidate[0], candidate[1], i_end, j_end) if(cur_dist == 0): found = True #print("Found!!!!") new_candidates.append(candidate) break for move in moves: next = (step(n, candidate[0], candidate[1], move, candidate )) #print("?", (candidate[0], candidate[1], move), "->", next) if(next != None): new_dist = distance(next[0], next[1], i_end, j_end) if new_dist < cur_dist and (next[0], next[1]) not in visited: #print (candidate, "->", next, cur_dist, new_dist) new_candidates.append(next) visited.append((next[0], next[1])) if len(new_candidates) == 0: break candidates = new_candidates #print("=====") found = False for c in candidates: #print(c, i_end, j_end) if c[0] == i_end and c[1] == j_end: found = True l = 0 path = "" x = c while x[2] is not None: #print(x) path = x[2] + " " + path x = x[3] l += 1 print(l) print(path) break if not found: 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)