Gats and the Tangled Tags
Gats has tied lettered tags along a piece of yarn. Reading from left to right, their letters form a string .
Gats performs the following random experiment exactly once:
- He chooses a set with , uniformly among all such sets.
- He chooses a bijection uniformly among the possible bijections.
- A resulting string is formed as follows:
The tags are treated as distinct when choosing the bijection, even when some of them carry the same letter.
The score of the resulting string is the number of adjacent pairs with equal letters:
Find the expected value of modulo .
Input
The first line contains two integers and (, ), the number of tags and the number of selected positions.
Output
Let the expected score be the rational number in lowest terms. Print
where is the multiplicative inverse of modulo . The constraints guarantee that this inverse exists.
Samples
Sample 1
Input
3 2 aba
Output
332748118
There are six equally likely pairs of a selected set and a bijection. Their scores sum to , so the expected score is . Its required residue is .
Sample 2
Input
4 4 aabc
Output
499122177
All four positions are selected. The expected score after the random bijection is , whose required residue is .