#include #include // https://www.hackerrank.com/contests/world-codesprint-12/challenges/red-knights-shortest-path using namespace std; void printShortestPath(int n, int i_start, int j_start, int i_end, int j_end) { bool distHeightOdd = (i_start - i_end) % 2 != 0; int nMovesHeight = (i_start - i_end) / 2; if (distHeightOdd || nMovesHeight % 2 != (j_start - j_end) % 2){ cout << "Impossible"; return; } int currentI = i_start; int currentJ = j_start; int nMoves = 0; string orderMoves = ""; while (currentI != i_end || currentJ != j_end){ nMoves++; if (currentI > i_end){ orderMoves += "U"; currentI -= 2; if (currentJ < j_end){ orderMoves += "R "; currentJ++; } else{ orderMoves += "L "; currentJ--; } continue; } if (currentJ < j_end && !(currentI - i_end == (currentJ - j_end) * 2)){ orderMoves += "R "; currentJ += 2; continue; } if (currentI < i_end){ orderMoves += "L"; currentI += 2; if (currentJ > j_end){ orderMoves += "L "; currentJ--; } else{ orderMoves += "R "; currentJ++; } continue; } if (currentJ > j_end){ orderMoves += "L "; currentJ -= 2; } } cout << nMoves << endl << orderMoves << endl; } 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; }