#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
std::string myStr = "abc";
std::stable_sort(std::begin(myStr), std::end(myStr));
do {
for(auto&& element : myStr)
std::cout << element << " ";
std::cout << std::endl;
} while (std::next_permutation(std::begin(myStr), std::end(myStr)));
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglzdGQ6OnN0cmluZyBteVN0ciA9ICJhYmMiOwoJc3RkOjpzdGFibGVfc29ydChzdGQ6OmJlZ2luKG15U3RyKSwgc3RkOjplbmQobXlTdHIpKTsKCWRvIHsKCQlmb3IoYXV0byYmIGVsZW1lbnQgOiBteVN0cikKCQkgICAgc3RkOjpjb3V0IDw8IGVsZW1lbnQgPDwgIiAiOwoJCXN0ZDo6Y291dCA8PCBzdGQ6OmVuZGw7CiAgfSB3aGlsZSAoc3RkOjpuZXh0X3Blcm11dGF0aW9uKHN0ZDo6YmVnaW4obXlTdHIpLCBzdGQ6OmVuZChteVN0cikpKTsKCXJldHVybiAwOwp9