408533: GYM103182 B Dragons

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

Description

B. Dragonstime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

Attention! Original plot! You have $$$N$$$ circularly placed chambers full of dragons which you must get rid of! Each of the dragons, however, has a specific power coefficient $$$x_i$$$ - just like you also have an initial power coefficient, $$$p$$$. Naturally, you can only defeat a dragon if your coefficient is greater than or equal to his.

After you defeat a dragon, your power increases. More specifically, $$$p$$$ will increase to $$$x_i|p$$$, where $$$x_i$$$ is the power of the dragon that you just defeated and $$$p$$$ is the power you had at that moment. Moreover, you can freely move to chambers $$$i-1$$$ or $$$i+1$$$. Since the rooms are circularly placed, it follows that you can move from room $$$1$$$ to $$$N$$$ and from room $$$N$$$ to $$$1$$$. Note that if the room that you move to has a dragon, it is your moral duty to defeat it.

By $$$x_i|p$$$ we refer to the bitwise or operator. In other words, if $$$x_i$$$ is equal to 3 (011 in binary) and $$$p$$$ is equal to 5 (101 in binary), the final result, $$$x_i|p$$$ will be equal to 7 (111 in binary).

Knowing that you must, eventually, defeat all of the dragons, and that you can begin in any room from $$$1$$$ to $$$N$$$, what is the minimum power coefficient that you must start with in order to finish this task of bravery?

Input

The first line of input will contain an integer $$$N$$$ ($$$1 \leq N \leq 10^5$$$), denoting the number of rooms (and dragons). The second line of input will contain $$$N$$$ integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^9$$$), where $$$x_i$$$ represents the power coefficient of the dragon placed in room $$$i$$$.

Output

The output should contain the minimum power coefficient $$$p$$$ that you must start with in order to defeat all dragons.

ExampleInput
5
5 1 4 7 2
Output
4

加入题单

算法标签: