#include #include using namespace std; long find_fact(int num) { long num_perms = 1; for (int i = 0; i < num; i++) { num_perms *= num - i; } return num_perms; } int main() { string m; cin >> m; string n = m; sort(n.begin(), n.end()); long num_perms = 1; int current_repetition = 1; for (int i = 0; i < n.length(); i++) { num_perms *= n.length() - i; if (i > 0) { if (n.at(i) == n.at(i - 1)) { current_repetition += 1; } else { if (current_repetition > 1) { num_perms /= find_fact(current_repetition); } current_repetition = 1; } } } if (current_repetition > 1) { num_perms /= find_fact(current_repetition); } cout << num_perms << endl; do { cout << n << endl; } while (next_permutation(n.begin(), n.end())); }