
Aircraft carrier Admiral Kuznetsov's deck can hold up to
All aircraft are on deck with their crews. In one unit of time, one of three things can happen:
Four aircraft in consecutive spots simultaneously take off in formation.
Three aircraft in consecutive spots simultaneously take off in formation.
One aircraft lands at an empty spot on deck.
There are an infinite number of land-based aircraft in the air, so the third operation can always be called.
Constraints
Subtask 1 [20%]
Subtask 2 [80%]
Input Specification
The first line contains integer
The next line contains a string of length
The next line contains a string of length
Output Specification
Output the minimum units of time required to reach the final configuration.
If the final configuration can not be reached, print -1
.
Sample Input
7
1100111
0000000
Sample Output
3
Explanation
One aircraft lands at position
Aircraft
Aircraft
Comments
is there no case with -1 as output?
To avoid spoiling the answer for anyone that wants to find out on their own, here it is as an editorial comment.