// Red Knight by Herbert Meiler #include int main() { constexpr int MaxDirection = 6; const char* direction[MaxDirection]{ "UL", "UR", "R", "LR", "LL", "L" }; const int deltaR[MaxDirection]{ -2, -2, 0, 2, 2, 0 }; const int deltaC[MaxDirection]{ -1, 1, 2, 1,-1, -2 }; constexpr int MaxN = 200; constexpr int MaxSize = MaxN * MaxN; int board[MaxSize]; for (int index = 0; index != MaxSize; ++index) { board[index] = -1; } int n; std::cin >> n; auto makeIndex = [n](int row, int col) { const auto index = row * n + col; return index; }; auto isInside = [n](int row, int col) { return ((row >= 0) && (row < n) && (col >= 0) && (col < n)); }; int startRow; std::cin >> startRow; int startCol; std::cin >> startCol; int endRow; std::cin >> endRow; int endCol; std::cin >> endCol; const int startIndex = makeIndex(startRow, startCol); const int endIndex = makeIndex(endRow, endCol); if (startIndex == endIndex) { std::cout << "0" << std::endl; return 0; } int distance = 0; board[endIndex] = distance; for (;;) { int count = 0; for (int row = 0; row != n; ++row) { for (int col = 0; col != n; ++col) { const auto index = makeIndex(row, col); if (board[index] == distance) { for (int direction = 0; direction != MaxDirection; ++direction) { const auto destRow = row + deltaR[direction]; const auto destCol = col + deltaC[direction]; if (isInside(destRow, destCol)) { const auto destIndex = makeIndex(destRow, destCol); if (-1 == board[destIndex]) { board[destIndex] = distance + 1; ++count; } } } } } } if (count == 0) { std::cout << "Impossible" << std::endl; return 0; } ++distance; if (board[startIndex] != -1) { break; } } std::cout << distance << std::endl; int posRow = startRow; int posCol = startCol; bool first = true; while (distance--) { for (int dir = 0; dir != MaxDirection; ++dir) { const int nextRow = posRow + deltaR[dir]; const int nextCol = posCol + deltaC[dir]; if (isInside(nextRow, nextCol)) { const auto index = makeIndex(nextRow, nextCol); if (board[index] == distance) { if (!first) { std::cout << " "; } std::cout << direction[dir]; posRow = nextRow; posCol = nextCol; first = false; break; } } } } return 0; }