#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
1010
1100
Sample Output 1
3
After the first two steps, a = \[1, 3\] and b = \[1, 2\]. There are possible scenarios after shuffling and :
- a = \[1, 3\], b = \[1, 2\]. Initially, . After swap(, ), . After swap(, ), .
- a = \[1, 3\], b = \[2, 1\]. Initially, . After swap(, ), . After swap(, ), .
- a = \[3, 1\], b = \[1, 2\]. Initially, . After swap(, ), . After swap(, ), .
- a = \[3, 1\], b = \[2, 1\]. Initially, . After swap(, ), . After swap(, ), .
Out of scenarios, of them result in . Therefore, / , and .
Sample Input 2
01001
01001
Sample Output 2
4
No swap ever changes , so we'll always have .
Sample Input 3
101010
010101
Sample Output 3
36
Every possible sequence of three swaps puts the 's in into the right places.
Sample Input 4
1101011011110
0111101011101
Sample Output 4
932171449