atcoder#AGC049B. [AGC049B] Flip Digits

[AGC049B] Flip Digits

Score : 600600 points

Problem Statement

Given are length-NN strings SS and TT consisting of 0 and 1. You can do the following operation on SS any number of times:

  • Choose ii (2iN2 \leq i \leq N) such that Si=S_i=1, and replace SiS_i with 0. Additionally, invert Si1S_{i-1}, that is, change it to 1 if it is 0 now and vice versa.

Is it possible to make SS exactly match TT? If it is possible, how many operations does it take at least?

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • SS is a string of length NN consisting of 0 and 1.
  • TT is a string of length NN consisting of 0 and 1.

Input

Input is given from Standard Input in the following format:

NN

SS

TT

Output

If it is possible to make SS exactly match TT, print the minimum number of operations it takes. Otherwise, print 1-1.

3
001
100
2

We can do as follows: 001 → (choose i=3i=3) → 010 → (choose i=2i=2) → 100.

3
001
110
-1
5
10111
01010
5