AtCoder Regular Contest 135
C
XOR to All
AtCoder
⌀ 1512
原题
← BD →
翻译中…

Problem Statement

翻译中…

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

翻译中…
  • Choose an integer $x\in \{A_1,\ldots,A_N\}$.
  • Replace $A_i$ with $A_i\oplus x$ for every $i$ ($\oplus$ denotes the bitwise $\mathrm{XOR}$ operation).
翻译中…

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

翻译中…

What is bitwise $\mathrm{XOR}$? The bitwise $\mathrm{XOR}$ of non-negative integers $A$ and $B$, $A \oplus B$, is defined as follows: When $A \oplus B$ is written in base two, the digit in the $2^k$'s place ($k \geq 0$) is $1$ if exactly one of $A$ and $B$ is $1$, and $0$ otherwise. For example, we have $3 \oplus 5 = 6$ (in base two: $011 \oplus 101 = 110$).

翻译中…

Constraints

翻译中…
  • $1\leq N \leq 3\times 10^{5}$
  • $0\leq A_i < 2^{30}$
翻译中…

Input

翻译中…

Input is given from Standard Input from the following format:

翻译中…

N
A_1 \ldots A_N

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
5
1 2 3 4 5
Output #1
19
Here is a sequence of operations that achieves $\sum_{i=1}^N A_i = 19$. - Initially, the sequence $A$ is $(1,2,3,4,5)$. - An operation with $x = 1$ changes it to $(0,3,2,5,4)$. - An operation with $x = 5$ changes it to $(5,6,7,0,1)$, where $\sum_{i=1}^N A_i = 5 + 6 + 7 + 0 + 1 = 19$.
Input #2
5
10 10 10 10 10
Output #2
50
Doing zero operations achieves $\sum_{i=1}^N A_i = 50$.
Input #3
5
3 1 4 1 5
Output #3
18
题目信息
题号
arc135_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。