CF2084E Blossom
Description
Input Format
Output Format
Explanation/Hint
So the answer is $ 3 $ .
In the second test case, there are two valid permutations: $ \[0, 1\] $ and $ \[1, 0\] $ . The value of $ \[0, 1\] $ and the value of $ \[1, 0\] $ is $ 3 $ , so the answer is $ 3 + 3 = 6 $ .
In the fourth test case, there are two valid permutations: $ \[0, 2, 1\] $ and $ \[1, 2, 0\] $ . The value of $ \[0, 2, 1\] $ is $ 5 $ since:
$ $ \operatorname{mex}([0]) + \operatorname{mex}([2]) + \operatorname{mex}([1]) + \operatorname{mex}([0, 2]) + \operatorname{mex}([2, 1]) + \operatorname{mex}([0, 2, 1]) = 1 + 0 + 0 + 1 + 0 + 3 = 5 $ $
And the value of $ \[1, 2, 0\] $ is $ 5 $ since:
$ $ \operatorname{mex}([1]) + \operatorname{mex}([2]) + \operatorname{mex}([0]) + \operatorname{mex}([1, 2]) + \operatorname{mex}([2, 0]) + \operatorname{mex}([1, 2, 0]) = 0 + 0 + 1 + 0 + 1 + 3 = 5 $ $
So the answer is $ 5 + 5 = 10$$$.