#agc019e. [agc019_e]Shuffle and Swap
[agc019_e]Shuffle and Swap
Problem Statement
You have two strings and of the same length consisting of and . The number of 's in and is equal.
You've decided to transform using the following algorithm:
- Let , , ..., be the indices of 's in .
- Let , , ..., be the indices of 's in .
- Replace and with their random permutations, chosen independently and uniformly.
- For each from to , in order, swap and .
Let be the probability that strings and become equal after the procedure above.
Let . Clearly, is an integer.
Find modulo .
Constraints
- and consist of and .
- and contain the same number of 's.
- and contain at least one .
Partial Score
- points will be awarded for passing the testset satisfying .
Input
Input is given from Standard Input in the following format:
Output
Print the value of modulo .
Sample Input 1
Sample Output 1
After the first two steps, a = and b = . There are possible scenarios after shuffling and :
- a = , b = . Initially, . After swap(, ), . After swap(, ), .
- a = , b = . Initially, . After swap(, ), . After swap(, ), .
- a = , b = . Initially, . After swap(, ), . After swap(, ), .
- a = , b = . Initially, . After swap(, ), . After swap(, ), .
Out of scenarios, of them result in . Therefore, / , and .
Sample Input 2
Sample Output 2
No swap ever changes , so we'll always have .
Sample Input 3
Sample Output 3
Every possible sequence of three swaps puts the 's in into the right places.