#include #define ll long long using namespace std; int n; int row[] = {-2,-2,0,+2,+2,0 }; int col[] = { -1,1,2,1,-1,-2 }; bool valid(int x, int y){ if (x < 0 || y < 0 || x >= n || y >= n) return false; return true; } struct Node{ int x, y, dist; bool const operator == (const Node& o) const{ return x == o.x && y == o.y; } bool operator<(const Node& o) const{ return x < o.x || (x == o.x && y < o.y); } }; int findmin(int a[]){ int min = a[0]; int ans = 0; for(int i = 1; i < 6; i++){ if(a[i] < min){ min = a[i]; ans = i; } } return ans; } vector path; int BFS(Node src, Node dest){ map visited; queue q; q.push(src); while (!q.empty()){ Node node = q.front(); q.pop(); int x = node.x; int y = node.y; int dist = node.dist; if (x == dest.x && y == dest.y){ return dist; } if (!visited.count(node)){ visited[node] = true; int flag = 0; int ar[6] = { 0 }; for (int i = 0; i < 6; ++i) { int x1 = x + row[i]; int y1 = y + col[i]; ar[i] = (int) sqrt(pow((x1-dest.x),2)+pow((y1-dest.y),2)); } int val = findmin(ar); int a = x + row[val]; int b = y + col[val]; if (valid(a, b)){ q.push({a, b, dist + 1}); path.push_back({a, b, dist + 1}); } } } return -1; } void find(int x1,int y1){ int sx = x1, sy = y1; for(int i = 0; i < path.size(); i++){ Node node = path[i]; int a = node.x; int b = node.y; if(a == sx && b < sy) cout << "L" << " "; if(a == sx && b > sy) cout << "R" << " "; if(a < sx && b < sy) cout << "UL" << " "; if(a < sx && b > sy) cout << "UR" << " "; if(a > sx && b > sy) cout << "LR" << " "; if(a > sx && b < sy) cout << "LL" << " "; sx = node.x; sy = node.y; } } int main(){ cin >> n; int x1,y1,x2, y2; cin >> x1 >> y1 >> x2 >> y2; Node src = {x1,y1}, dest = {x2, y2}; int ans = BFS(src, dest); if(ans == -1) cout << "Impossible"; else { cout << ans << "\n" ; find(x1,y1); } return 0; }