Clay has a binary string of length . By definition, a binary string consists only of s and s.
Clay is able to perform two operations on the string:
- Bitwise XOR () a length substring with (where is a binary string of length )
- Swap two adjacent bits
Both operations have a cost of to perform. Given his starting string and a target string, what is the minimum cost needed to convert from the starting string to the target string?
Input Specification
The first line contains . The second line contains , a binary string of length .
The third line contains . The fourth line contains , a binary string of length .
The final line of input contains the target string.
Output Specification
Output an integer representing the minimum cost needed to convert from the starting string to the target string, or -1
if the target string is impossible to reach.
Sample Input
5
10110
3
111
01001
Sample Output
2
Explanation
The target string can be created if you XOR the substring from index to with and swap indices and .
Comments