Codeforces Round 807 (Div. 2) |
---|
Finished |
Mark has just purchased a rack of $$$n$$$ lightbulbs. The state of the lightbulbs can be described with binary string $$$s = s_1s_2\dots s_n$$$, where $$$s_i=\texttt{1}$$$ means that the $$$i$$$-th lightbulb is turned on, while $$$s_i=\texttt{0}$$$ means that the $$$i$$$-th lightbulb is turned off.
Unfortunately, the lightbulbs are broken, and the only operation he can perform to change the state of the lightbulbs is the following:
Mark wants the state of the lightbulbs to be another binary string $$$t$$$. Help Mark determine the minimum number of operations to do so.
The first line of the input contains a single integer $$$q$$$ ($$$1\leq q\leq 10^4$$$) — the number of test cases.
The first line of each test case contains a single integer $$$n$$$ ($$$3\leq n\leq 2\cdot 10^5$$$) — the number of lightbulbs.
The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — the initial state of the lightbulbs.
The third line of each test case contains a binary string $$$t$$$ of length $$$n$$$ — the final state of the lightbulbs.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.
For each test case, print a line containing the minimum number of operations Mark needs to perform to transform $$$s$$$ to $$$t$$$. If there is no such sequence of operations, print $$$-1$$$.
4401000010410100100501001000116000101010011
2 -1 -1 5
In the first test case, one sequence of operations that achieves the minimum number of operations is the following.
In the third test case, even though the first digits of $$$s$$$ and $$$t$$$ are the same and the last digits of $$$s$$$ and $$$t$$$ are the same, it can be shown that there is no sequence of operations that satisfies the condition.
In the fourth test case, one sequence that achieves the minimum number of operations is the following:
Name |
---|