#include using namespace std; const int inf = 1e9 + 7 ; int vis[205][205] , dis[205][205] ; pair par[205][205] ; string Move[205][205] ; int x[] = {-2,-2,0,2,2,0} ; int y[] = {-1,+1,2,+1,-1,-2} ; string get(int i) { if(i == 0) return "UL" ; if(i == 1) return "UR" ; if(i == 2) return "R" ; if(i == 3) return "LR" ; if(i == 4) return "LL" ; return "L" ; } bool isvalid(int r , int c , int n) { return r >= 0 && c >= 0 && r < n && c < n ; } 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. // memset(dis,inf,sizeof(dis)) ; queue > Q ; Q.push({i_start,j_start}) ; dis[i_start][j_start] = 0 ; vis[i_start][j_start] = 1 ; while(!Q.empty()) { auto node = Q.front() ; Q.pop() ; if(node.first == i_end && node.second == j_end) break ; for(int i = 0 ; i < 6 ; ++i) { int r = node.first + x[i] ; int c = node.second + y[i] ; if(isvalid(r,c,n) && !vis[r][c]) { dis[r][c] = dis[node.first][node.second] + 1 ; vis[r][c] = 1 ; par[r][c] = node ; Move[r][c] = get(i) ; Q.push({r,c}) ; } } } if(vis[i_end][j_end] == false) { cout << "Impossible\n" ; return ; } cout << dis[i_end][j_end] << endl ; vector moves ; int r = i_end , c = j_end ; for(;;) { if(r == i_start && c == j_start) break ; moves.push_back(Move[r][c]) ; int row = par[r][c].first ; int col = par[r][c].second ; r = row , c = col ; } reverse(moves.begin(),moves.end()) ; for(auto str : moves) { cout << str << " " ; } cout << endl ; 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; }