#include using namespace std; void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { // Print the distance along with the sequence of moves. if( (abs(i_start - i_end) % 2 != 0) // Every move up |v| will be 1 || ((abs(i_start - i_end) / 2) % 2 == 1 && abs(j_start - j_end) % 2 != 1) // Every 2 moves up |v| will be 0 like starting position || ((abs(i_start - i_end) / 2) % 2 == 0 && abs(j_start - j_end) % 2 != 0) ) { cout << "Impossible" << endl; return; } int r = i_start, c = j_start; int yMoves = abs(i_start - i_end) / 2; int xMoves = abs(j_start - j_end); if(xMoves <= yMoves) { xMoves = 0; } else { xMoves = (xMoves - yMoves) / 2; } cout << yMoves + xMoves << endl; while(!(r == i_end && c == j_end)) { if(yMoves > 0) { if(r < i_end) { if(xMoves > 0) { // Move right before LR if(c < j_end) { cout << "R "; c += 2; xMoves--; continue; } } if(abs(j_end - (c + 1)) <= yMoves - 1 && c + 1 <= n - 1) { cout << "LR "; r += 2; c += 1; yMoves--; continue; } else { if(c <= j_end && c + 1 <= n - 1) { cout << "LR "; r += 2; c += 1; yMoves--; continue; } else { cout << "LL "; r += 2; c -= 1; yMoves--; continue; } } } else { if(abs(j_end - (c - 1)) <= yMoves - 1 && c - 1 >= 0) { cout << "UL "; r -= 2; c -= 1; yMoves--; continue; } else { if(c >= j_end && c - 1 >= 0) { cout << "UL "; r -= 2; c -= 1; yMoves--; continue; } else { cout << "UR "; r -= 2; c += 1; yMoves--; continue; } } } } else { if(c < j_end) { cout << "R "; c += 2; xMoves--; continue; } else { cout << "L "; c -= 2; xMoves--; continue; } } } return; } 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; }