#STK0000087. XOR cực đại thứ cấp (Maximum Xor Secondary)
XOR cực đại thứ cấp (Maximum Xor Secondary)
Maximum Xor Secondary
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sequence of pairwise distinct positive integers. For every contiguous subarray of length at least two, take its largest and second largest values and compute their bitwise XOR. Find the maximum XOR over all valid subarrays.
Input
The first line contains . The second line contains pairwise distinct integers .
Output
Print one integer: the maximum possible XOR value.
Subtasks
- Subtask 1 (30 points): ; all other conditions are unchanged.
- Subtask 2 (70 points): , , các đôi một khác nhau.
Examples
Input
5
5 2 1 4 3
Output
7
Explanation
The sequence is . For each subarray of length at least two, take its largest and second-largest values and compute their XOR.
Some subarrays that determine the maximum are:
- : the two largest values are and , so .
- : the two largest values are and , so .
- : .
- : .
- Longer subarrays containing both and have largest values and , giving .
No subarray produces a value greater than , while and both attain . Therefore the program prints 7.