407976: GYM102956 D Bank Security Unification

Memory Limit:0 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Bank Security Unificationtime limit per test2 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

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.

Input

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}$$$).

Output

Print the maximum possible security of the network.

ExamplesInput
5
1 2 3 1 3
Output
5
Input
4
1 2 4 0
Output
0

加入题单

上一题 下一题 算法标签: