#include <iostream> #include <map> using namespace std; map<char,int> count; string str; int maxstack; void cp(){ if(str.length()>=maxstack){ cout<<str<<"\n"; return; } for(auto i:count){ if(i.second>0){ str.push_back(i.first); count[i.first]--; cp(); str.pop_back(); count[i.first]++; } } } int main() { // your code goes here string input; cin>>input; maxstack = input.length(); for(int i=0;i<input.length();i++)count[input[i]]++; cp(); return 0; }
abcccde
abcccde abccced abccdce abccdec abccecd abccedc abcdcce abcdcec abcdecc abceccd abcecdc abcedcc abdccce abdccec abdcecc abdeccc abecccd abeccdc abecdcc abedccc acbccde acbcced acbcdce acbcdec acbcecd acbcedc acbdcce acbdcec acbdecc acbeccd acbecdc acbedcc accbcde accbced accbdce accbdec accbecd accbedc acccbde acccbed acccdbe acccdeb acccebd acccedb accdbce accdbec accdcbe accdceb accdebc accdecb accebcd accebdc accecbd accecdb accedbc accedcb acdbcce acdbcec acdbecc acdcbce acdcbec acdccbe acdcceb acdcebc acdcecb acdebcc acdecbc acdeccb acebccd acebcdc acebdcc acecbcd acecbdc aceccbd aceccdb acecdbc acecdcb acedbcc acedcbc acedccb adbccce adbccec adbcecc adbeccc adcbcce adcbcec adcbecc adccbce adccbec adcccbe adccceb adccebc adccecb adcebcc adcecbc adceccb adebccc adecbcc adeccbc adecccb aebcccd aebccdc aebcdcc aebdccc aecbccd aecbcdc aecbdcc aeccbcd aeccbdc aecccbd aecccdb aeccdbc aeccdcb aecdbcc aecdcbc aecdccb aedbccc aedcbcc aedccbc aedcccb bacccde baccced baccdce baccdec baccecd baccedc bacdcce bacdcec bacdecc baceccd bacecdc bacedcc badccce badccec badcecc badeccc baecccd baeccdc baecdcc baedccc bcaccde bcacced bcacdce bcacdec bcacecd bcacedc bcadcce bcadcec bcadecc bcaeccd bcaecdc bcaedcc bccacde bccaced bccadce bccadec bccaecd bccaedc bcccade bcccaed bcccdae bcccdea bcccead bccceda bccdace bccdaec bccdcae bccdcea bccdeac bccdeca bcceacd bcceadc bccecad bccecda bccedac bccedca bcdacce bcdacec bcdaecc bcdcace bcdcaec bcdccae bcdccea bcdceac bcdceca bcdeacc bcdecac bcdecca bceaccd bceacdc bceadcc bcecacd bcecadc bceccad bceccda bcecdac bcecdca bcedacc bcedcac bcedcca bdaccce bdaccec bdacecc bdaeccc bdcacce bdcacec bdcaecc bdccace bdccaec bdcccae bdcccea bdcceac bdcceca bdceacc bdcecac bdcecca bdeaccc bdecacc bdeccac bdeccca beacccd beaccdc beacdcc beadccc becaccd becacdc becadcc beccacd beccadc becccad becccda beccdac beccdca becdacc becdcac becdcca bedaccc bedcacc bedccac bedccca cabccde cabcced cabcdce cabcdec cabcecd cabcedc cabdcce cabdcec cabdecc cabeccd cabecdc cabedcc cacbcde cacbced cacbdce cacbdec cacbecd cacbedc caccbde caccbed caccdbe caccdeb caccebd caccedb cacdbce cacdbec cacdcbe cacdceb cacdebc cacdecb cacebcd cacebdc cacecbd cacecdb cacedbc cacedcb cadbcce cadbcec cadbecc cadcbce cadcbec cadccbe cadcceb cadcebc cadcecb cadebcc cadecbc cadeccb caebccd caebcdc caebdcc caecbcd caecbdc caeccbd caeccdb caecdbc caecdcb caedbcc caedcbc caedccb cbaccde cbacced cbacdce cbacdec cbacecd cbacedc cbadcce cbadcec cbadecc cbaeccd cbaecdc cbaedcc cbcacde cbcaced cbcadce cbcadec cbcaecd cbcaedc cbccade cbccaed cbccdae cbccdea cbccead cbcceda cbcdace cbcdaec cbcdcae cbcdcea cbcdeac cbcdeca cbceacd cbceadc cbcecad cbcecda cbcedac cbcedca cbdacce cbdacec cbdaecc cbdcace cbdcaec cbdccae cbdccea cbdceac cbdceca cbdeacc cbdecac cbdecca cbeaccd cbeacdc cbeadcc cbecacd cbecadc cbeccad cbeccda cbecdac cbecdca cbedacc cbedcac cbedcca ccabcde ccabced ccabdce ccabdec ccabecd ccabedc ccacbde ccacbed ccacdbe ccacdeb ccacebd ccacedb ccadbce ccadbec ccadcbe ccadceb ccadebc ccadecb ccaebcd ccaebdc ccaecbd ccaecdb ccaedbc ccaedcb ccbacde ccbaced ccbadce ccbadec ccbaecd ccbaedc ccbcade ccbcaed ccbcdae ccbcdea ccbcead ccbceda ccbdace ccbdaec ccbdcae ccbdcea ccbdeac ccbdeca ccbeacd ccbeadc ccbecad ccbecda ccbedac ccbedca cccabde cccabed cccadbe cccadeb cccaebd cccaedb cccbade cccbaed cccbdae cccbdea cccbead cccbeda cccdabe cccdaeb cccdbae cccdbea cccdeab cccdeba ccceabd ccceadb cccebad cccebda cccedab cccedba ccdabce ccdabec ccdacbe ccdaceb ccdaebc ccdaecb ccdbace ccdbaec ccdbcae ccdbcea ccdbeac ccdbeca ccdcabe ccdcaeb ccdcbae ccdcbea ccdceab ccdceba ccdeabc ccdeacb ccdebac ccdebca ccdecab ccdecba cceabcd cceabdc cceacbd cceacdb cceadbc cceadcb ccebacd ccebadc ccebcad ccebcda ccebdac ccebdca ccecabd ccecadb ccecbad ccecbda ccecdab ccecdba ccedabc ccedacb ccedbac ccedbca ccedcab ccedcba cdabcce cdabcec cdabecc cdacbce cdacbec cdaccbe cdacceb cdacebc cdacecb cdaebcc cdaecbc cdaeccb cdbacce cdbacec cdbaecc cdbcace cdbcaec cdbccae cdbccea cdbceac cdbceca cdbeacc cdbecac cdbecca cdcabce cdcabec cdcacbe cdcaceb cdcaebc cdcaecb cdcbace cdcbaec cdcbcae cdcbcea cdcbeac cdcbeca cdccabe cdccaeb cdccbae cdccbea cdcceab cdcceba cdceabc cdceacb cdcebac cdcebca cdcecab cdcecba cdeabcc cdeacbc cdeaccb cdebacc cdebcac cdebcca cdecabc cdecacb cdecbac cdecbca cdeccab cdeccba ceabccd ceabcdc ceabdcc ceacbcd ceacbdc ceaccbd ceaccdb ceacdbc ceacdcb ceadbcc ceadcbc ceadccb cebaccd cebacdc cebadcc cebcacd cebcadc cebccad cebccda cebcdac cebcdca cebdacc cebdcac cebdcca cecabcd cecabdc cecacbd cecacdb cecadbc cecadcb cecbacd cecbadc cecbcad cecbcda cecbdac cecbdca ceccabd ceccadb ceccbad ceccbda ceccdab ceccdba cecdabc cecdacb cecdbac cecdbca cecdcab cecdcba cedabcc cedacbc cedaccb cedbacc cedbcac cedbcca cedcabc cedcacb cedcbac cedcbca cedccab cedccba dabccce dabccec dabcecc dabeccc dacbcce dacbcec dacbecc daccbce daccbec dacccbe daccceb daccebc daccecb dacebcc dacecbc daceccb daebccc daecbcc daeccbc daecccb dbaccce dbaccec dbacecc dbaeccc dbcacce dbcacec dbcaecc dbccace dbccaec dbcccae dbcccea dbcceac dbcceca dbceacc dbcecac dbcecca dbeaccc dbecacc dbeccac dbeccca dcabcce dcabcec dcabecc dcacbce dcacbec dcaccbe dcacceb dcacebc dcacecb dcaebcc dcaecbc dcaeccb dcbacce dcbacec dcbaecc dcbcace dcbcaec dcbccae dcbccea dcbceac dcbceca dcbeacc dcbecac dcbecca dccabce dccabec dccacbe dccaceb dccaebc dccaecb dccbace dccbaec dccbcae dccbcea dccbeac dccbeca dcccabe dcccaeb dcccbae dcccbea dccceab dccceba dcceabc dcceacb dccebac dccebca dccecab dccecba dceabcc dceacbc dceaccb dcebacc dcebcac dcebcca dcecabc dcecacb dcecbac dcecbca dceccab dceccba deabccc deacbcc deaccbc deacccb debaccc debcacc debccac debccca decabcc decacbc decaccb decbacc decbcac decbcca deccabc deccacb deccbac deccbca decccab decccba eabcccd eabccdc eabcdcc eabdccc eacbccd eacbcdc eacbdcc eaccbcd eaccbdc eacccbd eacccdb eaccdbc eaccdcb eacdbcc eacdcbc eacdccb eadbccc eadcbcc eadccbc eadcccb ebacccd ebaccdc ebacdcc ebadccc ebcaccd ebcacdc ebcadcc ebccacd ebccadc ebcccad ebcccda ebccdac ebccdca ebcdacc ebcdcac ebcdcca ebdaccc ebdcacc ebdccac ebdccca ecabccd ecabcdc ecabdcc ecacbcd ecacbdc ecaccbd ecaccdb ecacdbc ecacdcb ecadbcc ecadcbc ecadccb ecbaccd ecbacdc ecbadcc ecbcacd ecbcadc ecbccad ecbccda ecbcdac ecbcdca ecbdacc ecbdcac ecbdcca eccabcd eccabdc eccacbd eccacdb eccadbc eccadcb eccbacd eccbadc eccbcad eccbcda eccbdac eccbdca ecccabd ecccadb ecccbad ecccbda ecccdab ecccdba eccdabc eccdacb eccdbac eccdbca eccdcab eccdcba ecdabcc ecdacbc ecdaccb ecdbacc ecdbcac ecdbcca ecdcabc ecdcacb ecdcbac ecdcbca ecdccab ecdccba edabccc edacbcc edaccbc edacccb edbaccc edbcacc edbccac edbccca edcabcc edcacbc edcaccb edcbacc edcbcac edcbcca edccabc edccacb edccbac edccbca edcccab edcccba