Multiple Word Formation: Finding All Possible Character Permutations

JavaScript Hard sets

Task «Multiple Word Formation: Finding All Possible Character Permutations»

Given a string consisting of lowercase Latin letters. It is necessary to find and output all unique permutations of the characters of this string (without repetitions if the string contains identical letters). The result must be sorted in lexicographic order. Use sets (Set) to track already added permutations and avoid duplicates. Constraint: string length ≤ 10 characters.

Input Format

A single line containing lowercase Latin letters (a-z).

Output Format

Each unique permutation on a new line, in lexicographic order. If there are no permutations (empty string), output "none".

Examples

Example 1

INPUT
aab
OUTPUT
aab aba baa

Example 2

INPUT
3 3 apple 1 banana 2 cherry
OUTPUT
3

Example 3

INPUT
abc
OUTPUT
abc acb bac bca cab cba

Example 4

INPUT
2 5 cat 5 dog
OUTPUT
2

Example 5

INPUT
aa
OUTPUT
aa
main.js