#arc132d. [arc132_d]Between Two Binary Strings
[arc132_d]Between Two Binary Strings
Problem Statement
Let us define the beauty of the string as the number of positions where two adjacent characters are the same. For example, the beauty of 00011
is , and the beauty of 10101
is .
Let be the set of all strings of length formed of 0
s and 1
s.
For , let us define the distance of and , , as the minimum number of swaps needed when rearranging the string to by swaps of two adjacent characters.
Additionally, for , is said to be between and when .
Given , print the greatest beauty of a string between and .
Constraints
- Each of and is a string of length formed of
0
s and1
s.
Input
Input is given from Standard Input in the following format:
Output
Print the greatest beauty of a string between and .
Sample Input 1
2 3
10110
01101
Sample Output 1
2
Between 10110
and 01101
, whose distance is , we have the following strings: 10110
, 01110
, 01101
, 10101
. Their beauties are , , , , respectively, so the answer is .
Sample Input 2
4 2
000011
110000
Sample Output 2
4
Between 000011
and 110000
, whose distance is , the strings with the greatest beauty are 000011
and 110000
, so the answer is .
Sample Input 3
12 26
01110111101110111101001101111010110110
10011110111011011001111011111101001110
Sample Output 3
22