# Enter your code here. Read input from STDIN. Print output to STDOUT #!/bin/python import sys def bfs(graph, start, goal): explored = set([]) queue = [[start]] while queue: path = queue.pop(0) node = path[-1][1] if node not in explored: neighbours = graph.get(node, []) if neighbours == None: break else: neighbours = list(neighbours) neighbours.sort(reverse = True) for neighbour in neighbours: new_path = list(path) new_path.append(neighbour) queue.append(new_path) if neighbour[1] == goal[1]: return [len(path), new_path[1:]] explored.add(node) return -1 if __name__ == "__main__": n = int(raw_input().strip()) calc1 = (2 * n) - 1 calc2 = (2 * n) + 1 graph = {} for x in xrange(n*n): xi = x/n xj = x%n UL = x - calc2 ULi = UL/n ULj = UL%n if UL >= 0 and xi - ULi == 2 and xj - ULj == 1: try: temp = graph[x] temp.add(('UL', UL)) graph[x] = temp except KeyError: graph[x] = set([('UL', UL)]) UR = x - calc1 URi = UR/n URj = UR%n if UR >= 0 and xi - URi == 2 and URj - xj == 1: try: temp = graph[x] temp.add(('UR', UR)) graph[x] = temp except KeyError: graph[x] = set([('UR', UR)]) L = x - 2 Li = L/n Lj = L%n if L >= 0 and xi == Li and xj - Lj == 2: try: temp = graph[x] temp.add(('L', L)) graph[x] = temp except KeyError: graph[x] = set([('L', L)]) R = x + 2 Ri = R/n Rj = R%n if R < n*n and xi == Ri and Rj - xj == 2: try: temp = graph[x] temp.add(('R', R)) graph[x] = temp except KeyError: graph[x] = set([('R', R)]) LL = x + calc1 LLi = LL/n LLj = LL%n if LL < n*n and LLi - xi == 2 and xj - LLj == 1: try: temp = graph[x] temp.add(('LL', LL)) graph[x] = temp except KeyError: graph[x] = set([('LL', LL)]) LR = x + calc2 LRi = LR/n LRj = LR%n if LR < n*n and LRi - xi == 2 and LRj - xj == 1: try: temp = graph[x] temp.add(('LR', LR)) graph[x] = temp except KeyError: graph[x] = set([('LR', LR)]) i_start, j_start, i_end, j_end = raw_input().strip().split(' ') i_start, j_start, i_end, j_end = [int(i_start), int(j_start), int(i_end), int(j_end)] start = (i_start * n) + j_start end = (i_end * n) + j_end res = bfs(graph,(None,start), (None,end)) if res == -1: print('Impossible') else: print(res[0]) temp = [i[0] for i in res[1]] print(" ".join(temp))