#!/bin/python3 import sys def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. def my_path(n, i_start, j_start, i_end, j_end, path, steps): #print(i_end, j_end) #print(steps) #print(path) if i_end > n-1 or j_end > n-1 or i_end <0 or j_end <0: #steps[i_end][j_end] = n return "", 201, path, steps if steps[i_end][j_end] != 202: return path[i_end][j_end], steps[i_end][j_end],path, steps if i_start == i_end and j_start == j_end: return "", 0, path, steps #steps[i_end][j_end] =1 path1, steps1, path, steps = my_path(n,i_start,j_start,i_end+2,j_end+1,path, steps) #print("Here1........") path2, steps2, path, steps = my_path(n, i_start, j_start, i_end+2, j_end-1, path, steps) #print("Here2........") #path3, steps3, path, steps = my_path(n, i_start, j_start, i_end, j_end-2, path, steps) #print("Here3........") #path4, steps4, path, steps = my_path(n, i_start, j_start, i_end-2, j_end-1, path, steps) #print("Here4........") #path5, steps5, path, steps = my_path(n, i_start, j_start, i_end-2, j_end+1, path, steps) #print("Here5........") path6, steps6, path, steps = my_path(n, i_start, j_start, i_end, j_end+2, path, steps) #print("Here6........") curr_path = path1 curr_steps = steps1 curr_action = "UL" if steps2 < curr_steps: curr_path = path2 curr_steps = steps2 curr_action = "UR" #if steps3 < curr_steps: # curr_path = path3 # curr_steps = steps3 # curr_action = "R" #if steps4 < curr_steps: # curr_path = path4 # curr_steps = steps4 # curr_action = "LR" #if steps5 < curr_steps: # curr_path = path5 # curr_steps = steps5 # curr_action = "LL" if steps6 < curr_steps: curr_path = path6 curr_steps = steps6 curr_action = "L" steps[i_end][j_end] = curr_steps + 1 for i in range(0,len(curr_path)): path[i_end][j_end].append(curr_path[i]) #path[i_end][j_end].append(curr_path) path[i_end][j_end].append(curr_action) return path[i_end][j_end], steps[i_end][j_end], path, steps path = [] steps = [] for i in range(0,n): path.append([]) steps.append([]) for j in range(0,n): path[i].append([]) steps[i].append(202) curr_path, curr_steps, path, steps = my_path(n, i_start, j_start, i_end, j_end, path, steps) if curr_steps >= 201: print("Impossible") else: print(steps[i_end][j_end]) #print(path[i_end][j_end]) temp = "" j = len(path[i_end][j_end])-1 for i in range(0,len(path[i_end][j_end])): #if steps[i_end][j_end][j] == #temp.append(path[i_end][j_end][j]) temp = temp + path[i_end][j_end][j] temp = temp + " " j = j - 1 print(temp) 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)