#arc135c. [arc135_c]XOR to All

[arc135_c]XOR to All

Problem Statement

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

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

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

What is bitwise mathrmXOR\\mathrm{XOR}?

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

  • When AoplusBA \\oplus B is written in base two, the digit in the 2k2^k's place (kgeq0k \\geq 0) is 11 if exactly one of AA and BB is 11, and 00 otherwise.

For example, we have 3oplus5=63 \\oplus 5 = 6 (in base two: 011oplus101=110011 \\oplus 101 = 110).

Constraints

  • 1leqNleq3times1051\\leq N \\leq 3\\times 10^{5}
  • 0leqAi<2300\\leq A_i < 2^{30}

Input

Input is given from Standard Input from the following format:

NN A1A_1 ldots\\ldots ANA_N

Output

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


Sample Input 1

5
1 2 3 4 5

Sample Output 1

19

Here is a sequence of operations that achieves sumi=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 sumi=1NAi=5+6+7+0+1=19\\sum_{i=1}^N A_i = 5 + 6 + 7 + 0 + 1 = 19.

Sample Input 2

5
10 10 10 10 10

Sample Output 2

50

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


Sample Input 3

5
3 1 4 1 5

Sample Output 3

18