#P4144. Sock Sequence Dirty Value

    ID: 17392 Type: Default 1000ms 256MiB

Sock Sequence Dirty Value

Sock Sequence Dirty Value

There is a sequence of socks, each with an integer dirty value. The dirty value of a contiguous subsegment (from index (l) to (r)) is defined as [ \left( \bigwedge_{i=l}^{r} \text{dirty}i \right) + \left( \bigvee{i=l}^{r} \text{dirty}_i \right) ] where (\bigwedge) denotes the bitwise AND operation and (\bigvee) denotes the bitwise OR operation. In other words, you need to choose a contiguous subsequence such that the sum of the bitwise AND and the bitwise OR of all its elements is maximized.

If the sock sequence's dirty value reaches a certain threshold, it will cause trouble. Help determine the maximum dirty value of the sock sequence.

inputFormat

The first line contains an integer (n) representing the number of socks. The second line contains (n) space-separated integers representing the dirty values of the socks.

outputFormat

Output a single integer, which is the maximum dirty value obtainable by any contiguous subsequence.

sample

3
1 2 3
6