Given a sequence of $n$ non-negative integers $[a_1, \dots, a_n]$, find a subsequence $[a_{i_1}, a_{i_2}, \dots, a_{i_k}]$ ($1 \le i_1 < i_2 < \dots < i_k \le n$) such that $\sum_{j=1}^{k-1}(a_{i_j} \operatorname{and} a_{i_{j+1}})$ is maximized. You only need to output this maximum value.
Here, $\operatorname{and}$ denotes the bitwise AND operation.
A subsequence is defined as a sequence obtained by deleting zero or more elements from the original sequence while maintaining the relative order of the remaining elements.
Input
The first line contains a positive integer $n$. The next line contains $n$ integers $a_1 \sim a_n$.
Output
Output a single integer representing the maximum value of $\sum_{j=1}^{k-1}(a_{i_j} \operatorname{and} a_{i_{j+1}})$.
Examples
Input 1
5 1 2 3 1 3
Output 1
5
Note 1
One optimal solution is to choose the subsequence $[a_2, a_3, a_5]$.
Input 2
2 1000000000000 987654321234
Output 2
965637836800
Examples 3, 4
See the provided files.
Constraints
All data satisfy: $1 \le n \le 10^{6}$, $0 \le a_i \le 10^{12}$.
- Subtask 1 (20 points): $n \le 20$.
- Subtask 2 (25 points): $n \le 5000$.
- Subtask 3 (20 points): $n \le 10^5, a_i < 512$.
- Subtask 4 (15 points): $n \le 2 \times 10^5$, each $a_i$ is generated independently and uniformly at random in $[0, 10^{12}]$.
- Subtask 5 (20 points): No additional constraints.