#K42762. Max Affinity Value
Max Affinity Value
Max Affinity Value
You are given a forest of trees, each with an initial affinity rating. You can join trees together, and the operation of joining two trees results in a new tree whose affinity is the bitwise OR of the two individual affinities. In other words, if you join trees with affinities \(a\) and \(b\), the resulting tree will have an affinity of \(a \; | \; b\). This operation is both associative and commutative, meaning that the maximum achievable affinity can always be determined by computing the bitwise OR of all the trees' affinity values.
Mathematically, if the trees have affinities \(a_1, a_2, \dots, a_n\), then the maximum affinity value after all possible joining operations is given by:
[ a_1 ; | ; a_2 ; | ; \cdots ; | ; a_n ]
Your task is to compute this maximum affinity value.
inputFormat
The first line of input contains a single integer (n) representing the number of trees. The second line contains (n) space-separated integers, each representing the affinity rating of a tree. You can assume (1 \leq n \leq 10^5) and each affinity rating is in the range (0) to (10^9).
outputFormat
Output a single integer, which is the maximum achievable affinity value after optimally joining the trees.## sample
5
5 7 12 8 3
15
</p>