Question
The Perfumer's Scent Blend Orders
A perfumer has a string
Find every distinct order in which the vials could have been poured, given that pouring vials of the same scent in different orders relative to each other produces an indistinguishable result.
The resulting list of distinct pouring orders must be sorted in lexicographically increasing order.
Input
A single line containing the string KaTeX can only parse string typed expression.
Output
Print a single integer on the first line — the number of distinct pouring orders. Then print that many lines, each containing one distinct order, sorted lexicographically.
Example
Example 1:
Input
The vials "aab" can be poured in 3 distinguishable orders (out of 3! = 6 total orderings, since the two 'a' vials are indistinguishable from each other): aab, aba, and baa, listed in sorted order.
Example 2:
Input
A single vial has only one possible pouring order.
Input
aabOutput3
aab
aba
baaExplanationThe vials "aab" can be poured in 3 distinguishable orders (out of 3! = 6 total orderings, since the two 'a' vials are indistinguishable from each other): aab, aba, and baa, listed in sorted order.
Example 2:
Input
aOutput1
aExplanationA single vial has only one possible pouring order.