#include <algorithm>
#include <iostream>
#include <vector>
void print(const std::vector<int>& v)
{
for (int e : v) {
std::cout << " " << e;
}
std::cout << std::endl;
}
int main()
{
std::vector<int> v = {1,2,3};
// vector should be sorted at the beginning.
do {
print(v);
} while (std::next_permutation(v.begin(), v.end()));
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdm9pZCBwcmludChjb25zdCBzdGQ6OnZlY3RvcjxpbnQ+JiB2KQp7CiAgICBmb3IgKGludCBlIDogdikgewogICAgICAgIHN0ZDo6Y291dCA8PCAiICIgPDwgZTsKICAgIH0KICAgIHN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7Cn0KCmludCBtYWluKCkKewogICAgc3RkOjp2ZWN0b3I8aW50PiB2ID0gezEsMiwzfTsKICAgIC8vIHZlY3RvciBzaG91bGQgYmUgc29ydGVkIGF0IHRoZSBiZWdpbm5pbmcuCgogICAgZG8gewogICAgICAgIHByaW50KHYpOwogICAgfSB3aGlsZSAoc3RkOjpuZXh0X3Blcm11dGF0aW9uKHYuYmVnaW4oKSwgdi5lbmQoKSkpOwp9