MAX-MEX Cut solution codeforces- A binary string is a string that consists of characters 00 and 11. A bi-table is a table that has exactly two rows of equal length, each being a binary string.

  • MAX-MEX Cut solution codeforces

  • For Solution

    Click Here!

A binary string is a string that consists of characters 00 and 11. A bi-table is a table that has exactly two rows of equal length, each being a binary string.

Let MEXMEX of a bi-table be the smallest digit among 0011, or 22 that does not occur in the bi-table. For example, MEXMEX for [00111010][00111010] is 22, because 00 and 11 occur in the bi-table at least once. MEXMEX for [111111][111111] is 00, because 00 and 22 do not occur in the bi-table, and 0<20<2.

You are given a bi-table with nn columns. You should cut it into any number of bi-tables (each consisting of consecutive columns) so that each column is in exactly one bi-table. It is possible to cut the bi-table into a single bi-table — the whole bi-table.

What is the maximal sum of MEXMEX of all resulting bi-tables can be?

MAX-MEX Cut solution codeforces

The input consists of multiple test cases. The first line contains a single integer tt (1t1041≤t≤104) — the number of test cases. Description of the test cases follows.

The first line of the description of each test case contains a single integer nn (1n1051≤n≤105) — the number of columns in the bi-table.

Each of the next two lines contains a binary string of length nn — the rows of the bi-table.

It’s guaranteed that the sum of nn over all test cases does not exceed 105105.

MAX-MEX Cut solution codeforces

For each test case print a single integer — the maximal sum of MEXMEX of all bi-tables that it is possible to get by cutting the given bi-table optimally.

Example

input

Copy
4
7
0101000
1101100
5
01100
10101
2
01
01
6
000000
111111

MAX-MEX Cut solution codeforces

Copy
8
8
2
12
Note

In the first test case you can cut the bi-table as follows:

  • [01][01], its MEXMEX is 22.
  • [1010][1010], its MEXMEX is 22.
  • [11][11], its MEXMEX is 00.
  • [01][01], its MEXMEX is 22.
  • [00][00], its MEXMEX is 11.
  • [00][00], its MEXMEX is 11.

The sum of MEXMEX is 88.

Leave a Comment

Your email address will not be published.