I am Fluttershy, a plain and ordinary Pegasus pony of Equestria—well, after going through countless experiences with Twilight Sparkle and other friends, maybe I'm not that ordinary.
Like today, when I returned home, what caught my eye was countless versions of myself.
Luckily, I'm not Pinkie Pie; so instead of bouncing around chattering endlessly, they just quietly looked at me and gave me a question:
Given an array of non-negative integers $$$a_i$$$ with length $$$n$$$, I may perform the following operation no more than $$$n$$$ times:
I must ensure that all $$$a_i$$$ remain non-negative integers after each operation, reminded by one of us.
My goal is to minimize the value of $$$a_1 \ | \ a_2 \ | \ \ldots \ | \ a_n$$$ after the operations. Here, $$$|$$$ denotes the bitwise OR operator, and $$$x \ | \ y$$$ represents the bitwise OR of two non-negative integers $$$x$$$ and $$$y$$$.
The bitwise OR operation compares two binary numbers bit by bit. In each bit position, if at least one of the bits is $$$1$$$, then the result is $$$1$$$; otherwise, it is $$$0$$$. For example, the bitwise OR result of the binary numbers $$$10 = 1010_2$$$ and $$$12 = 1100_2$$$ is $$$14 = 1110_2$$$, and the result of $$$3 = 0011_2$$$ and $$$5 = 0101_2$$$ is $$$7 = 0111_2$$$.
The first line contains a single integer $$$n$$$ ($$$1\le n\le 2\times 10^5$$$), representing the length of the array.
The second line contains $$$n$$$ non-negative integers $$$a_i$$$ ($$$0\le a_i\le 10^9$$$).
A single line containing one integer representing the answer, the minimized $$$a_1 \ | \ a_2 \ | \ \ldots \ | \ a_n$$$ value.
71 9 1 9 8 1 0
5
In the example, one feasible final result is $$$[5,5,5,5,5,4,0]$$$, which has a minimal result equal to $$$5$$$. It can be proven that there is no better result.
One feasible method to achieve this result is $$$[1,9,1,9,8,1,0] \rightarrow [5,5,1,9,8,1,0] \rightarrow [5,5,5,5,8,1,0]$$$ $$$\rightarrow [5,5,5,5,5,4,0]$$$, requiring a total of $$$3$$$ steps.