#include using namespace std; void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { vector dir_prior = {"UL", "UR", "R", "LR", "LL", "L"}; map step_count; for(int i = 0; i < dir_prior.size(); i++){ step_count[dir_prior[i]] = 0; } int total_steps = 0; int y_diff = j_end - j_start, x_diff = i_end - i_start; int diag_steps = min(abs(y_diff), abs(x_diff/2)); string step = ""; step += (x_diff > 0 ? "L" : "U"); step += (y_diff > 0 ? "R" : "L"); step_count[step] += diag_steps; total_steps += diag_steps; y_diff = y_diff - (diag_steps*(y_diff/abs(y_diff))); x_diff = x_diff - (2*diag_steps*(x_diff/abs(x_diff))); if(!(abs(y_diff)%2 == 0 && abs(x_diff)%4 == 0)){ cout << "Impossible" << endl; return; } if(y_diff == 0 && x_diff != 0){ int vert_steps = abs(x_diff/2); string dir = (x_diff > 0 ? "L" : "U"); step_count[dir+"L"] += vert_steps/2; step_count[dir+"R"] += vert_steps/2; total_steps += vert_steps; } if(y_diff != 0 && x_diff == 0){ int horz_steps = abs(y_diff/2); string step = (y_diff > 0 ? "R" : "L"); step_count[step] += horz_steps; total_steps += horz_steps; } //printing step_count in possible order cout << total_steps << endl; for(int i = 0; i < dir_prior.size(); i++){ string dir = dir_prior[i]; if(dir == "UL" || dir == "LR"){ int continous_steps; if(dir == "UL"){ continous_steps = min(step_count[dir], j_start); } else { continous_steps = min(step_count[dir], n-1-j_start); } for(int j = 0; j < continous_steps; j++){ cout << dir << " "; } string inverse_dir = dir_prior[i+1]; int alternate_steps = step_count[dir] - continous_steps; for(int j = 0; j < alternate_steps; j++){ cout << inverse_dir << " " << dir << " "; } step_count[dir] -= continous_steps + alternate_steps; step_count[inverse_dir] -= alternate_steps; } else { for(int j = 0; j < step_count[dir]; j++){ cout << dir << " "; } step_count[dir] = 0; } } } int main() { int n; cin >> n; int i_start; int j_start; int i_end; int j_end; cin >> i_start >> j_start >> i_end >> j_end; printShortestPath(n, i_start, j_start, i_end, j_end); return 0; }