#agc049b. [agc049_b]Flip Digits
[agc049_b]Flip Digits
Problem Statement
Given are length- strings and consisting of 0
and 1
. You can do the following operation on any number of times:
- Choose () such that
1
, and replace with0
. Additionally, invert , that is, change it to1
if it is0
now and vice versa.
Is it possible to make exactly match ? If it is possible, how many operations does it take at least?
Constraints
- is a string of length consisting of
0
and1
. - is a string of length consisting of
0
and1
.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to make exactly match , print the minimum number of operations it takes. Otherwise, print .
Sample Input 1
3
001
100
Sample Output 1
2
We can do as follows: 001
→ (choose ) → 010
→ (choose ) → 100
.
Sample Input 2
3
001
110
Sample Output 2
-1
Sample Input 3
5
10111
01010
Sample Output 3
5