#!/bin/python3 import sys def printShortestPath(n, i_start, j_start, i_end, j_end): j_diff = abs(j_end - j_start) i_diff = abs(i_end - i_start) done = False if i_diff % 2 == 1: print("Impossible") done = True if (i_diff %4) == 0: if(j_diff %2 ==1): print("Impossible") done = True if (abs(i_end - (i_start+2)) % 4 ==0): if(j_diff %2 ==0): print("Impossible") done = True directionString = "" numberOfMoves = 0 while not ((i_start == i_end) and (j_start == j_end)) and not done: i, j, direction = findClosesSpot(n, i_start, j_start, i_end, j_end) numberOfMoves +=1 #i_old = i_start #j_old = j_start i_start = i j_start = j #print("i is " + str(i) + " j is " + str(j) + " and the direction is " + str(direction)) directionString = directionString + direction + " " #if i_old == i and j_old == j: # print("Impossible") # done = True if not done: print(numberOfMoves) print(directionString) def findClosesSpot(n, i_start, j_start, i_end, j_end): closest = 100 movesList = [("UL",-2,-1),("UR",-2,1),("R",0,2),("LR",2,1),("LL",2,-1), ("L",0,-2)] for moves in movesList: d_i = moves[1] d_j = moves[2] n_i = i_start + d_i n_j = j_start + d_j if n_i >= 0 and n_i < n and n_j >= 0 and n_j = 0: # if j_start - 2 >= 0: # # print(i_start-1, j_start-2, i_end, j_end) # d = distance(i_start - 1, j_start - 2, i_end, j_end) # if d < closest: # # print ("dist is "+str(d)+" for UL") # closest = d # direction = "UL" # i_new, j_new = i_start - 1, j_start - 2 # # print("UL set") # # if i_start + 1 > n: # if j_start - 2 >= 0: # d = distance(i_start + 1, j_start - 2, i_end, j_end) # if d < closest: # closest = d # direction = "UR" # i_new, j_new = i_start + 1, j_start - 2, # # if i_start + 2 < 8: # d = distance(i_start + 2, j_start, i_end, j_end) # if d < closest: # closest = d # direction = "R" # i_new, j_new = i_start + 2, j_start # # if i_start + 1 > 8: # if j_start + 2 < 8: # d = distance(i_start + 1, j_start + 2, i_end, j_end) # if d < closest: # closest = d # direction = "LR" # i_new, j_new = i_start + 1, j_start + 2 # # if i_start - 1 >= 0: # if j_start + 2 < 8: # d = distance(i_start - 1, j_start + 2, i_end, j_end) # if d < closest: # closest = d # direction = "LL" # i_new, j_new = i_start - 1, j_start + 2 # # if i_start - 2 >= 0: # d = distance(i_start - 2, j_start, i_end, j_end) # if d < closest: # # print ("dist is "+str(closest)+" for L") # closest = d # direction = "L" # i_new, j_new = i_start - 2, j_start # # print("L set") #return i_new, j_new, direction def distance(i_start, j_start, i_end, j_end): return abs(i_start - i_end) + abs(j_start - j_end) 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)