#!/bin/python import sys # solution in recursive form def redKnightShortestPath(n, i_start, j_start, i_end, j_end, seqs): v_direction = i_end - i_start h_direction = j_end - j_start # check for base case if (h_direction == 0 and v_direction == 0): return (True, seqs) # check for impossible case mh_direction = abs(h_direction) mv_direction = abs(v_direction) if (mv_direction == 1 and mh_direction == 1): return (False, "Impossible") elif (mv_direction == 0 and mh_direction == 1): return (False, "Impossible") elif (mh_direction == 0 and (mv_direction <= 2)): return (False, "Impossible") # recurse any other case, #move the i_start and j_start to closer position if (v_direction <= -2 and h_direction <= 0): # UL direction seqs.append("UL") return redKnightShortestPath(n, i_start - 2, j_start - 1, i_end, j_end, seqs) elif (v_direction <= -2 and h_direction >= 1): # UR direction seqs.append("UR") return redKnightShortestPath(n, i_start - 2, j_start + 1, i_end, j_end, seqs) elif (v_direction == 0 and h_direction >= 2): # R direction seqs.append("R") return redKnightShortestPath(n, i_start, j_start + 2, i_end, j_end, seqs) elif (v_direction >= 2 and h_direction >= 0): # LR direction seqs.append("LR") return redKnightShortestPath(n, i_start + 2, j_start + 1, i_end, j_end, seqs) elif (v_direction >= 2 and h_direction <= -1): # LL direction seqs.append("LL") return redKnightShortestPath(n, i_start + 2, j_start - 1, i_end, j_end, seqs) elif (v_direction == 0 and h_direction <= -2): # L direction seqs.append("L") return redKnightShortestPath(n, i_start, j_start - 2, i_end, j_end, seqs) # any other case return false return (False, "Impossible") def printShortestPath(n, i_start, j_start, i_end, j_end): seqs = [] (state, seqs) = redKnightShortestPath(n, i_start, j_start, i_end, j_end, seqs) if (state == True): print(len(seqs)) print(reduce(lambda x, y: x + ' ' + y, seqs)) else: print(seqs) if __name__ == "__main__": n = int(raw_input().strip()) 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)] printShortestPath(n, i_start, j_start, i_end, j_end)