Binary String Randomizer
Problem Code: BINSTRRAND
Chef JJ is a fan of random events and calculating probabilities.
He designed a machine called the binary string randomizer (BSRand). BSRand takes a binary string (say, of length ) as input and then generates a binary string (of the same length ) as output using the following algorithm:
For each from to ,
- Uniformly randomly choose an integer between and .
- Uniformly randomly choose an integer between and .
- Set (where represents the bitwise XOR operation)
Given a binary string , Chef JJ passes it through BSRand times (i.e, first he passes the binary string through the BSRand, then he passes the resultant binary string through BSRand again, and so on. This is done times in total). Calculate the probability that the final binary string obtained is .
You need to print the probability of getting binary string modulo . Formally, let . It can be shown that the answer can be expressed as an irreducible fraction , where and are integers and . Output . In other words, output the (unique) integer which satisfies and .
Input Format
- The first line of the input contains two integers and - the length of the binary strings and and the number of times chef JJ passes the binary string through BSRand, respectively.
- The second line contains the binary string .
- The third line contains the binary string .
Output Format
Output the probability of getting binary string from binary string after passing it through BSRand times, modulo .
Constraints
Sample Input 1
2 1
01
11
Sample Output 1
748683265
Sample Input 2
2 1
00
11
Sample Output 2
0
Sample Input 3
2 2
11
00
Sample Output 3
1
Explanation
Test Case : For , we notice that the BSRand can select the following combinations of : . Out of these combinations, we see that only of them give as result. Therefore, the probability that becomes is .
For , similarly the the probability that becomes is .
Therefore the probability that the final string is is .
Test Case : It can be proved that there is no way to get string from .
where is code
ReplyDelete