#include #include #include #include using namespace std; struct node{ int cost; int i; int j; }; int main(){ cin.sync_with_stdio(false); int n, x1, y1, x2, y2; cin >> n >> x1 >> y1 >> x2 >> y2; queue< node > Q; Q.push({0, x1, y1}); int dis[n][n]; int parent[2][n][n]; for(int i = 0 ; i < n ; ++i) for(int j = 0 ; j < n ; ++j) dis[i][j] = 1e9, parent[0][i][j] = -1, parent[1][i][j] = -1; dis[x1][y1] = 0; while(Q.size()){ node pt = Q.front(); Q.pop(); int cost = pt.cost; int i = pt.i; int j = pt.j; if(i >= 2 && j >= 1){ int ii = i - 2; int jj = j - 1; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } if(i >= 2 && j + 1 < n){ int ii = i - 2; int jj = j + 1; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } if(i >= 0 && j + 2 < n){ int ii = i; int jj = j + 2; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } if(i + 2 < n && j + 1 < n){ int ii = i + 2; int jj = j + 1; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } if(i + 2 < n && j >= 1){ int ii = i + 2; int jj = j - 1; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } if(i >= 0 && j >= 2){ int ii = i; int jj = j - 2; if(dis[ii][jj] > 1 + cost){ dis[ii][jj] = 1 + cost; parent[0][ii][jj] = i; parent[1][ii][jj] = j; Q.push({1 + cost, ii, jj}); } } } int d = dis[x2][y2]; if(d >= 1e9){ cout << "Impossible" << endl; return 0; } cout << d << endl; vector< string > Pos; while( !(x1 == x2 && y1 == y2) ){ int x = parent[0][x2][y2]; int y = parent[1][x2][y2]; if(x + 2 == x2 && y + 1 == y2) Pos.push_back("LR"); if(x + 2 == x2 && y - 1 == y2) Pos.push_back("LL"); if(x == x2 && y + 2 == y2) Pos.push_back("R"); if(x == x2 && y - 2 == y2) Pos.push_back("L"); if(x - 2 == x2 && y - 1 == y2) Pos.push_back("UL"); if(x - 2 == x2 && y + 1 == y2) Pos.push_back("UR"); x2 = x; y2 = y; } for(int i = d - 1 ; i >= 0 ; --i ) cout << Pos[i] << " "; }