#K57527. Unique String Rearrangements
Unique String Rearrangements
Unique String Rearrangements
You are given a string s
consisting of lowercase English letters. Your task is to calculate the number of unique rearrangements (permutations) of the characters in s
. Two rearrangements are considered different if the order of the letters is different.
Mathematically, if the length of the string is \(n\) and each distinct letter \(i\) appears \(k_i\) times, the number of unique rearrangements is given by:
[ \frac{n!}{\prod_i (k_i)!} ]
For example, for the string "aabb", the result is \(\frac{4!}{2!\times2!} = 6\).
inputFormat
The input consists of a single line containing the string s
(only lowercase English letters).
outputFormat
Output a single integer which represents the number of unique rearrangements of the string s
.
abc
6