시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 13 8 8 61.538%

문제

The Bytelandian government has issued the Bank Security Unification law (or, shortly, the BSU law). The recent law regulates the usage of Wi-Fi routers in banks and other financial institutions.

According to the BSU law, all the $n$ Wi-Fi routers in a bank must be located in a straight line. Suppose that the $i$-th router operates at the frequency $f_i$. Denote the security of a connection between two adjacent routers as $f_{i}\,\, \&\,\, f_{i+1}$, where $\&$ is the bitwise AND operation.

A set of at least two routers numbered $1 \le i_1 < i_2 < \dots < i_k \le n$ must be chosen as active.  All other routers will be kept inactive so that they can replace the active ones if any of them would break. Denote the security of the network as the sum of the securities of all connections between adjacent active routers. In other words, the security of the network is calculated as $\sum\limits_{j=1}^{k-1} f_{i_j}\,\,\&\,\,f_{i_{j+1}}$.

You are an employee of a large Bytelandian bank. Surely, the bank is obliged to comply with the BSU law. The routers are already placed in a line, and their placement cannot be changed. Now you want to choose some of the routers as active to maximize the security of the network.

입력

The first line contains an integer $n$, denoting the number of Wi-Fi routers in the bank ($2 \le n \le 10^6$).

The second line contains $n$ integers $f_1, f_2, \ldots, f_n$, where $f_i$ is the frequency of the $i$-th router in the line ($0 \le f_i \le 10^{12}$).

출력

Print the maximum possible security of the network.

예제 입력 1

5
1 2 3 1 3

예제 출력 1

5

예제 입력 2

4
1 2 4 0

예제 출력 2

0