#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. int i, j; i = i_start-i_end; j = j_start-j_end; string direction[6] = {"UL", "UR", "R", "LR", "LL", "L"}; string answer = ""; int moves = 0; if(i<0) { i = -i; } if(j<0) { j = -j; } if(i==0) { if(j%2 == 0) { //Possible moves = j%2; if(j_start > j_end) { int temp = 0; while(temp < j%2) { answer += direction[5] + " "; temp++; } } else { int temp = 0; while(temp < j%2) { answer += direction[2] + " "; temp++; } } } else { cout<<"Impossible\n"; return; } } else if(i%2==0) { //Can be Possible! //Cases if(j==0) { //Can be Possible! if((i/2)%2 == 0) { //Possible! moves = i/2; if(i_start > i_end) { //Check for Outer Boundaries! //Boundary value of J //only for j_start near j = 0 if(j_start < i/4) { int temp = 0; while(temp < i/4) { answer += direction[1] + " " + direction[0] + " "; temp++; } } else { int temp = 0; while(temp < i/4) { answer += direction[0] + " "; temp++; } temp = 0; while(temp < i/4) { answer += direction[1] + " "; temp++; } } } else { //Check for Outer Boundaries! //Boundary value of J //only for j_start near j=n-1 if(j_start < n-(i/4)) { int temp = 0; while(temp < i/4) { answer += direction[3] + " "; temp++; } temp = 0; while(temp < i/4) { answer += direction[4] + " "; temp++; } } else { int temp = 0; while(temp < i/4) { answer += direction[1] + " " + direction[0] + " "; temp++; } } } } else { cout<<"Impossible\n"; return; } } else if(j*2==i || (j-2)*2==i) { //Possible moves = i/2; if(i_start > i_end) { if(j_start > j_end) { int temp = 0; for(; temp<(i/2); temp++) { answer += direction[0] + " "; } while(j > temp) { answer += direction[5] + " "; temp+=2; moves++; } } else { int temp = 0; for(; temp<(i/2); temp++) { answer += direction[1] + " "; } while(j > temp) { answer += direction[2] + " "; temp+=2; moves++; } } } else { if(j_start > j_end) { int temp = 0; for(; temp<(i/2); temp++) { answer += direction[4] + " "; } while(j > temp) { answer += direction[5] + " "; temp+=2; moves++; } } else { int temp = 0; for(; temp<(i/2); temp++) { answer += direction[3] + " "; } while(j > temp) { answer += direction[2] + " "; temp+=2; moves++; } } } } else { cout<<"Impossible\n"; return; } } else { cout<<"Impossible\n"; return; } answer.pop_back(); cout<> 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; }