Time limit
2s
Memory limit
128 MB
You are given two binary strings A and B of the same length. One operation r(i, j) reverses the substring from index i through index j in the current string, using 0-based indices.
If several operations are used, their order is restricted. Suppose the operations are performed in the order r(i_1, j_1), r(i_2, j_2), ..., r(i_m, j_m). They must satisfy both conditions below.
In other words, each later operation must be inside the interval of the earlier operations. Find the minimum number of operations needed to transform A into B.
The first line contains the binary string A. The second line contains the binary string B.
The two strings have the same length, and the length is at most 50. Each string consists only of the characters 0 and 1.
Print the minimum number of operations needed to transform A into B. If no valid sequence of operations can do so, print -1.