#P4098. Gem Fusion XOR
Gem Fusion XOR
Gem Fusion XOR
Welcome to ALO (Arithmetic and Logistic Online)! In this VR MMORPG, you are presented with mathematical puzzles. You are given n gems, where each gem has a distinct energy density denoted by \(a_i\). You can select a contiguous segment of gems (with at least 2 gems) for fusion. Let the chosen segment be \(a_i, a_{i+1}, \ldots, a_j\). Let the second highest energy density in this segment be \(k\). The energy density of the fused gem is defined as:
\[ \max\{ k \oplus a_p \mid i \le p \le j,\; a_p \ne k \}\ \]
Here, \(\oplus\) denotes the bitwise XOR operation. Your task is to choose a contiguous segment of gems such that the resulting fused gem has the maximum possible energy density.
inputFormat
The first line contains an integer n (\(2 \le n \le 10^5\)), the number of gems. The second line contains n space-separated integers \(a_1, a_2, \ldots, a_n\) representing the energy densities of the gems. It is guaranteed that all \(a_i\) are distinct.
outputFormat
Output a single integer which is the maximum possible energy density of the fused gem.
sample
2
3 5
6