A research submarine carries n calibration modules mounted in a rack; each module continuously broadcasts one integer signature value. For any chosen non-empty subset of modules, define that subset's "combined signature" as the bitwise XOR of the signature values of exactly the modules in the subset. Compute the sum, taken over every one of the 2^n - 1 non-empty subsets of modules, of that subset's combined signature.
Print a single integer: the sum of the combined signatures of all non-empty subsets of modules.
Example 1
Input
2 1 3
Expected
6
Explanation
The non-empty subsets of modules {1,3} are {1} (signature 1), {3} (signature 3), and {1,3} (signature 1 XOR 3 = 2). Summing 1 + 3 + 2 gives 6.
Example 2
Input
3 5 1 6
Expected
28
Explanation
The non-empty subsets of {5,1,6} give combined signatures 5, 1, 6, 5^1=4, 5^6=3, 1^6=7, and 5^1^6=2. Summing 5+1+6+4+3+7+2 gives 28.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →