#C7369. Unique Permutations of Distinct Characters

    ID: 51232 Type: Default 1000ms 256MiB

Unique Permutations of Distinct Characters

Unique Permutations of Distinct Characters

You are given a string s. Your task is to determine the number of unique permutations that can be formed using only the distinct characters in the string. In other words, you should first extract the set of distinct characters from s, count them let this be n, and then compute n! modulo \(10^9+7\).

For example:

  • If s = "abc", the distinct characters are {a, b, c}. Since n = 3, the answer is \(3! = 6\).
  • If s = "aabc", the distinct characters are still {a, b, c} and the answer is \(3! = 6\).
  • If s = "abbccc", the distinct characters are {a, b, c} and the answer is \(3! = 6\).
  • If s = "a", there is only one distinct character, so the answer is \(1! = 1\).
  • If s = "aaaa", there is only one distinct character, so the answer is \(1! = 1\).

You need to handle large inputs as well, though note that the maximum distinct characters possible is limited by the character set in use. All calculations should be done under modulo \(10^9+7\).

inputFormat

The input consists of a single line containing a string s. The string may contain any characters.

outputFormat

Output a single integer that is the factorial of the number of distinct characters in s, computed modulo \(10^9+7\).

## sample
abc
6

</p>