#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 s1,s2,…,sns_1,s_2,\ldots,s_n 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 nn. The second line contains nn pairwise distinct integers s1,s2,…,sns_1,s_2,\ldots,s_n.

Output

Print one integer: the maximum possible XOR value.

Subtasks

  • Subtask 1 (30 points): n≤2000n\le2000; all other conditions are unchanged.
  • Subtask 2 (70 points): 2≤n≤1052\le n\le10^5, 1≤si≤1091\le s_i\le10^9, các sis_i đôi một khác nhau.

Examples

Input

5
5 2 1 4 3

Output

7

Explanation

The sequence is [5,2,1,4,3][5,2,1,4,3]. 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:

  • [1..2]=[5,2][1..2]=[5,2]: the two largest values are 55 and 22, so 5⊕2=75\oplus2=7.
  • [2..4]=[2,1,4][2..4]=[2,1,4]: the two largest values are 44 and 22, so 4⊕2=64\oplus2=6.
  • [3..4]=[1,4][3..4]=[1,4]: 4⊕1=54\oplus1=5.
  • [4..5]=[4,3][4..5]=[4,3]: 4⊕3=74\oplus3=7.
  • Longer subarrays containing both 55 and 44 have largest values 55 and 44, giving 5⊕4=15\oplus4=1.

No subarray produces a value greater than 77, while [1..2][1..2] and [4..5][4..5] both attain 77. Therefore the program prints 7.