atcoder#ARC135C. [ARC135C] XOR to All

[ARC135C] XOR to All

Score : 500500 points

Problem Statement

You are given a sequence of non-negative integers A=(A1,,AN)A = (A_1, \ldots, A_N). You can do the operation below any number of times (possibly zero).

  • Choose an integer x{A1,,AN}x\in \{A_1,\ldots,A_N\}.
  • Replace AiA_i with AixA_i\oplus x for every ii (\oplus denotes the bitwise XOR\mathrm{XOR} operation).

Find the maximum possible value of i=1NAi\sum_{i=1}^N A_i after your operations.

What is bitwise $\mathrm{XOR}$?

The bitwise XOR\mathrm{XOR} of non-negative integers AA and BB, ABA \oplus B, is defined as follows:

  • When ABA \oplus B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if exactly one of AA and BB is 11, and 00 otherwise.
3 \oplus 5 = 6$$$$011 \oplus 101 = 110

Constraints

  • 1N3×1051\leq N \leq 3\times 10^{5}
  • 0Ai<2300\leq A_i < 2^{30}

Input

Input is given from Standard Input from the following format:

NN

A1A_1 \ldots ANA_N

Output

Print the maximum possible value of i=1NAi\sum_{i=1}^N A_i after your operations.

5
1 2 3 4 5
19

Here is a sequence of operations that achieves i=1NAi=19\sum_{i=1}^N A_i = 19.

  • Initially, the sequence AA is (1,2,3,4,5)(1,2,3,4,5).
  • An operation with x=1x = 1 changes it to (0,3,2,5,4)(0,3,2,5,4).
  • An operation with x=5x = 5 changes it to (5,6,7,0,1)(5,6,7,0,1), where i=1NAi=5+6+7+0+1=19\sum_{i=1}^N A_i = 5 + 6 + 7 + 0 + 1 = 19.
5
10 10 10 10 10
50

Doing zero operations achieves i=1NAi=50\sum_{i=1}^N A_i = 50.

5
3 1 4 1 5
18