#K73647. Maximum XOR Sum of Any Subarray

    ID: 34022 Type: Default 1000ms 256MiB

Maximum XOR Sum of Any Subarray

Maximum XOR Sum of Any Subarray

You are given an array of n non-negative integers. Your task is to find the maximum XOR sum among all possible contiguous subarrays. In other words, if we denote a subarray by A[i...j], you need to compute:

\( \max_{1 \le i \le j \le n} \{ A[i] \oplus A[i+1] \oplus \cdots \oplus A[j] \} \)

where \( \oplus \) denotes the bitwise XOR operation.

Example: For the array [3, 8, 2, 6, 4], one optimal subarray is the entire array, whose XOR sum is 15.

inputFormat

The input is given from standard input and consists of two lines:

  • The first line contains an integer n (1 ≤ n ≤ 105), representing the number of elements in the array.
  • The second line contains n non-negative integers separated by spaces, where each integer is at most 109.

outputFormat

Print a single integer representing the maximum XOR sum over all subarrays of the given array. The output should be written to standard output.

## sample
5
3 8 2 6 4
15

</p>