//EVIEBOT #include #define inf 0x3f3f3f3f #define INF 1000111000111000111LL #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define fastIO ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL); #define endl '\n' #define pb push_back #define pf push_front #define fi first #define se second #define MP make_pair #define MT make_tuple #define clr(xxx) memset(xxx, 0, sizeof(xxx)); typedef long long int lli; using namespace std; ofstream outfile; ifstream infile; pair s, e; int n; queue > myq; int dir[6][2] = {{-2, -1}, {-2, 1}, {0, 2}, {2, 1}, {2, -1}, {0, -2}}; int backtrace[201][201][2]; bool vis[201][201]; bool checker(int r, int c){ if(r < 0 || c < 0 || r >= n || c >= n) return 0; return !vis[r][c]; } void bfs(){ clr(vis); myq.push(s); vis[s.fi][s.se] = 1; int r, c; while(!myq.empty()){ pair temp = myq.front(); myq.pop(); //cout << temp.fi << ' '<< temp.se << "\n"; for(int i = 0; i < 6; ++i){ r = temp.fi+dir[i][0]; c = temp.se+dir[i][1]; if(checker(r, c)){ vis[r][c] = 1; backtrace[r][c][0] = temp.fi; backtrace[r][c][1] = temp.se; myq.push(MP(r, c)); } } } } int main() { infile.open("input.txt"); outfile.open("output.txt"); fastIO; int r, c, i, j; cin >> n; cin >> r >> c; s = MP(r, c); cin >> r >> c; e = MP(r, c); if(s == e){ cout << 0 << "\n"; return 0; } for(i = 0; i < n; ++i){ for(j= 0; j < n; ++j){ backtrace[i][j][0] = backtrace[i][j][1] = -1; } } bfs(); if(backtrace[e.fi][e.se][0] == -1){ cout << "Impossible\n"; }else{ vector moves; int n_moves = 0; r = e.fi; c = e.se; while(r != s.fi || c != s.se){ n_moves++; for(i = 0; i < 6; ++i){ if(backtrace[r][c][0]+dir[i][0] == r && backtrace[r][c][1]+dir[i][1] == c){ //cout << i << "\n"; if(i == 0){ moves.pb("UL"); }else if(i == 1){ moves.pb("UR"); }else if(i == 2){ moves.pb("R"); }else if(i == 3){ moves.pb("LR"); }else if(i == 4){ moves.pb("LL"); }else{ moves.pb("L"); } int r1 = backtrace[r][c][0], c1 = backtrace[r][c][1]; r = r1; c = c1; break; } } } cout << n_moves << "\n"; for(i = n_moves-1; i >= 0; --i) cout << moves[i] << ' '; cout << "\n"; } }