#C728. Find All Anagrams

    ID: 51133 Type: Default 1000ms 256MiB

Find All Anagrams

Find All Anagrams

Given a string \(s\), your task is to generate all unique anagrams (permutations) of the string and output them in lexicographical order. Two anagrams are considered the same if they are identical strings. Note that if the string contains repeated characters, some arrangements may be identical.

You can recall that the number of distinct anagrams of a string with character frequencies \(n_1, n_2, \ldots, n_k\) is given by the formula: \[ \frac{n!}{n_1!\, n_2!\, \cdots\, n_k!} \] where \(n\) is the length of the string.

The input will be provided from standard input (stdin) and the result must be printed to standard output (stdout) with each anagram separated by a single space.

inputFormat

The input is a single line containing a string \(s\). The string may be empty and can contain repeated characters.

outputFormat

Output all unique anagrams of the given string sorted in lexicographical order, separated by a single space. If the string is empty, output an empty line.

## sample
abc
abc acb bac bca cab cba