#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
#include <iomanip>
int main()
{
using sequence_type = std::vector<std::string> ;
sequence_type seq { "abc", "def", "abc", "ghi", "def", "abc" } ;
std::sort( seq.begin(), seq.end() ) ;
std::set<sequence_type> unique_permutations ;
do unique_permutations.insert( sequence_type( seq.begin(), seq.end() ) ) ;
while( std::next_permutation( seq.begin(), seq.end() ) ) ;
for( const auto& seq : unique_permutations )
{
static int n = 0 ;
std::cout << std::setw(3) << ++n << ". " ;
for( const auto& str : seq ) std::cout << str << ' ' ;
std::cout << '\n' ;
}
}
I2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8aW9tYW5pcD4KCmludCBtYWluKCkKewogICAgdXNpbmcgc2VxdWVuY2VfdHlwZSA9IHN0ZDo6dmVjdG9yPHN0ZDo6c3RyaW5nPiA7CiAgICBzZXF1ZW5jZV90eXBlIHNlcSB7ICJhYmMiLCAiZGVmIiwgImFiYyIsICJnaGkiLCAiZGVmIiwgImFiYyIgfSA7CiAgICBzdGQ6OnNvcnQoIHNlcS5iZWdpbigpLCBzZXEuZW5kKCkgKSA7CgogICAgc3RkOjpzZXQ8c2VxdWVuY2VfdHlwZT4gdW5pcXVlX3Blcm11dGF0aW9ucyA7CgogICAgZG8gdW5pcXVlX3Blcm11dGF0aW9ucy5pbnNlcnQoIHNlcXVlbmNlX3R5cGUoIHNlcS5iZWdpbigpLCBzZXEuZW5kKCkgKSApIDsKICAgIHdoaWxlKCBzdGQ6Om5leHRfcGVybXV0YXRpb24oIHNlcS5iZWdpbigpLCBzZXEuZW5kKCkgKSApIDsKCiAgICBmb3IoIGNvbnN0IGF1dG8mIHNlcSA6IHVuaXF1ZV9wZXJtdXRhdGlvbnMgKQogICAgewogICAgICAgIHN0YXRpYyBpbnQgbiA9IDAgOwogICAgICAgIHN0ZDo6Y291dCA8PCBzdGQ6OnNldHcoMykgPDwgKytuIDw8ICIuICIgOwogICAgICAgIGZvciggY29uc3QgYXV0byYgc3RyIDogc2VxICkgc3RkOjpjb3V0IDw8IHN0ciA8PCAnICcgOwogICAgICAgIHN0ZDo6Y291dCA8PCAnXG4nIDsKICAgIH0KfQo=