Two vending machines contain queues of tokens. Each token is gold (worth one point) or silver (worth zero points).
On each turn, choose a nonempty machine and take its front token. Receive points according to that token’s current color. Then every token still inside the other machine changes color: gold becomes silver and silver becomes gold. The chosen machine does not change its remaining tokens. Flipping an empty machine has no effect.
You must eventually take every token from both machines. What is the maximum total score?
The first line contains and : the numbers of tokens in the two machines.
The second line is a binary string of length describing the first queue, front to back.
The third line is a binary string of length describing the second queue, front to back.
Here 1 means gold and 0 means silver.
Print the maximum achievable score.
In Sample 1, take all four tokens from the second machine first, earning points. Four flips restore the first machine’s token to gold, so taking it earns one more point.
In Sample 2, whichever gold token you take first flips the remaining token to silver.
| Sample Input 1 | Sample Output 1 |
|---|---|
1 4 1 0111 |
4 |
| Sample Input 2 | Sample Output 2 |
|---|---|
1 1 1 1 |
1 |