#K11601. Unique Permutations Count

    ID: 23505 Type: Default 1000ms 256MiB

Unique Permutations Count

Unique Permutations Count

Given a string s consisting of lowercase characters, compute the number of unique permutations of its characters. In other words, if the string contains repeated characters, the total number of unique arrangements is given by:

\( \displaystyle \frac{n!}{n_1! \times n_2! \times \cdots \times n_k!} \)

where \( n \) is the length of the string and \( n_i \) is the frequency of the \( i\)-th distinct character.

For example, for the string "aab", the answer is:

\( \frac{3!}{2!\times1!} = 3 \)

inputFormat

The input begins with an integer \( T \) representing the number of test cases. Following this are \( T \) lines, each containing a single string \( s \) consisting of lowercase alphabet characters.

Example:

2
abc
aab

outputFormat

For each test case, output a single line containing the number of unique permutations of the given string.

Example output for the above input:

6
3
## sample
2
abc
aab
6

3

</p>