AT_arc227_a [ARC227A] Fermat Point of Binary Strings
Description
A string of length $ 2N $ that contains $ N $ occurrences of each of `0` and `1` is called a good string.
For good strings $ S $ and $ T $ , let $ \operatorname{dist}(S, T) $ denote the minimum number of swaps required to make $ S $ equal to $ T $ by swapping two adjacent characters of $ S $ zero or more times.
You are given good strings $ A $ , $ B $ , and $ C $ . Among all good strings $ X $ , find one that minimizes the value of
$$\operatorname{dist}(A, X)+\operatorname{dist}(B, X)+\operatorname{dist}(C, X),$$
and output it together with the minimum value.
Input Format
The input is given from Standard Input in the following format:
> $ N $ $ A $ $ B $ $ C $
Output Format
Let $ K $ be the minimum value to be found, and let $ X $ be a good string that achieves it. Output $ K $ and $ X $ in the following format:
> $ K $ $ X $
If multiple outputs satisfy the conditions, you may output any of them.
Explanation/Hint
### Sample Explanation 1
If we choose `1010` as the good string $ X $ , then $ \operatorname{dist}(A, X) $ , $ \operatorname{dist}(B, X) $ , and $ \operatorname{dist}(C, X) $ are $ 1 $ , $ 0 $ , $ 3 $ , respectively, and their sum is $ 4 $ . The sum of the distances cannot be made smaller than $ 4 $ .
### Sample Explanation 2
Since the three input strings are all equal, choosing the same string as $ X $ makes the sum of the distances $ 0 $ .
### Constraints
- $ 1 \le N \le 2 \times 10^5 $
- Each of $ A $ , $ B $ , and $ C $ is a good string of length $ 2N $ .
- $ N $ is an integer.