fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define endl '\n'
  6. ll N = 1e9+7;
  7. ll oo =1e13;
  8. const ll maxx = 1000000 + 3;
  9. ll n,m,k,q,x,y,z,l,r,mid,ans;
  10. string s;
  11. map<char,ll>mp;
  12. unordered_set<string>ss;
  13. void go(string s1) {
  14. if (s1.size()>s.size())return;
  15. if (s1.size() == s.size()) {
  16. map<char,ll>mp1;
  17. for (char c:s1){mp1[c]++;}
  18.  
  19. for(auto &it:mp1) {
  20. if (it.second != mp[it.first]) return;
  21. }
  22. ss.insert(s1);
  23. }
  24.  
  25. for (ll i=0;i<s.size();i++) {
  26. go(s1+s[i]);
  27. }
  28.  
  29. }
  30. void solve() {
  31. cin>>s;
  32. for (char c:s){mp[c]++;}
  33. go("");
  34.  
  35. ll size=ss.size();
  36. cout<<size<<endl;
  37. vector<string>v(ss.begin(),ss.end());
  38. sort(v.begin(),v.end());
  39. for (auto &it:v)cout<<it<<endl;
  40. }
  41. int main() {
  42. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  43. ll t=1 ;
  44. // cin >>t;
  45. while (t--) {
  46. ans=0;
  47. solve();
  48. }
  49. }
Success #stdin #stdout 0.01s 5320KB
stdin
abc
stdout
6
abc
acb
bac
bca
cab
cba