cho.sh
Notes
Loading...

Bulbs and Switches

Time limit

2s

Memory limit

128 MB

Problem

There are N switches and N bulbs arranged in a row. Each bulb is either on or off.

For 2 <= i <= N - 1, pressing switch i flips the states of bulbs i - 1, i, and i + 1. An on bulb becomes off, and an off bulb becomes on. Pressing switch 1 flips bulbs 1 and 2. Pressing switch N flips bulbs N - 1 and N.

Given the current states of all bulbs and the target states, write a program that finds the minimum number of switch presses needed to reach the target.

Input

The first line contains an integer N (2 <= N <= 100,000).

The second line contains a length-N string representing the current bulb states. The third line contains a length-N string representing the target bulb states. In both strings, 0 means on and 1 means off.

Output

Print the minimum number of switch presses. If the target state cannot be made, print -1.