#K38902. Unique Letter Sequences

    ID: 26301 Type: Default 1000ms 256MiB

Unique Letter Sequences

Unique Letter Sequences

You are given a string s consisting of letters. Your task is to compute the number of unique sequences (permutations) that can be formed using every character of s exactly once. If the string is empty, then the answer is defined to be 0.

This is essentially calculating the number of distinct arrangements of characters. For a string of length n with characters having counts \(c_1, c_2, \dots, c_k\), the answer is given by the formula:

[ \text{Answer} = \frac{n!}{c_1! \times c_2! \times \dots \times c_k!} ]

For example, if s = "aab", then the answer is \(\frac{3!}{2! \times 1!} = 3\). Solve the problem by reading input from stdin and writing the result to stdout.

inputFormat

The input consists of a single line containing a non-empty string s (if the input is empty, output should be 0). The string may contain duplicate characters.

outputFormat

Output a single integer: the number of unique sequences (permutations) that can be formed using all characters of the input string exactly once.## sample

abc
6