408533: GYM103182 B Dragons
Description
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?
InputThe 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$$$.
OutputThe output should contain the minimum power coefficient $$$p$$$ that you must start with in order to defeat all dragons.
ExampleInput5 5 1 4 7 2Output
4