######################################## PROG # UL i-2, # UR, # R, # LR, # LL, # L. def get_valid_points(n, r,c): out = [] if r-2 >= 0 and c-1 >= 0: out.append((r-2,c-1,'UL')) if r-2 >= 0 and c+1 < n: out.append((r-2,c+1,'UR')) if c+2 < n: out.append((r,c+2,'R')) if r+2 < n and c+1 < n: out.append((r+2,c+1,'LR')) if r+2 < n and c-1 >= 0: out.append((r+2,c-1,'LL')) if c-2 >= 0: out.append((r,c-2,'L')) return out def get_padding(dir): if dir == 'UL': return 1 elif dir == 'UR': return 2 elif dir == 'R': return 3 elif dir == 'LR': return 4 elif dir == 'LL': return 5 elif dir == 'L': return 6 def printShortestPath(n, i_start, j_start, i_end, j_end): # Print the distance along with the sequence of moves. mtx = [ [False for _ in range(n)] for _ in range(n) ] arr = [ ( 0, i_start,j_start,[] ) ] cur_min_path = None while len(arr) > 0: tmp = [] if cur_min_path is not None: break for each_arr_path_item in arr: _, r,c,paths = each_arr_path_item if r == i_end and c == j_end: #print cur_min_path, paths if cur_min_path is None: cur_min_path = paths else: if len(cur_min_path) == len(paths): # do equal logic change = True for each_path_item_i in range(len(cur_min_path)): cur_which = get_padding(cur_min_path[each_path_item_i]) other_which = get_padding(paths[each_path_item_i]) if other_which == cur_which: continue elif other_which > cur_which: change = False break if change: cur_min_path = paths elif len(paths) > len(cur_min_path): break continue elif mtx[r][c]: continue else: mtx[r][c] = True for next_r, next_c, next_dir in get_valid_points(n, r, c): d = list(paths) d.append(next_dir) pt = (len(d), next_r, next_c, d) tmp.append(pt) arr = tmp if cur_min_path is None: print 'Impossible' else: print len(cur_min_path) print ' '.join(cur_min_path) 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)