#include <iostream>
#include <vector>
#include <algorithm>
void generatePermutationsWithConstraints(const std::vector<int>& fixedPart, const std::vector<int>& restOfElements, std::vector<int>& current, std::vector<bool>& used, int fixedIndex) {
if (current.size() == fixedPart.size() + restOfElements.size()) {
for (int num : current) {
std::cout << num << " ";
}
std::cout << std::endl;
return;
}
// Add the fixed part in order if we are at the correct index
if (current.size() == fixedIndex) {
current.insert(current.end(), fixedPart.begin(), fixedPart.end());
generatePermutationsWithConstraints(fixedPart, restOfElements, current, used, fixedIndex + fixedPart.size());
current.erase(current.end() - fixedPart.size(), current.end());
}
// Generate permutations for remaining elements
for (int i = 0; i < restOfElements.size(); ++i) {
if (used[i]) continue;
used[i] = true;
current.push_back(restOfElements[i]);
generatePermutationsWithConstraints(fixedPart, restOfElements, current, used, fixedIndex);
current.pop_back();
used[i] = false;
}
}
int main() {
std::vector<int> fixedPart = {1, 2}; // Fixed part that must appear together in order
std::vector<int> restOfElements = {3}; // Elements available for permutation
std::vector<int> current;
std::vector<bool> used(restOfElements.size(), false);
generatePermutationsWithConstraints(fixedPart, restOfElements, current, used, 0);
return 0;
}