Minimum XOR Sum of SubarraysMedium

Minimum XOR Sum of Subarrays

MediumPractice library · +20 XPbit manipulationprefix sumshash map

Given an array of N integers A, partition it into two non-empty contiguous subarrays. The first subarray will be A[0...i] and the second subarray will be A[i+1...N-1] for some 0 <= i < N-1. Calculate the XOR sum of elements in the first subarray and the XOR sum of elements in the second subarray. Find the minimum possible absolute difference between these two XOR sums over all possible partitions.

Input

The first line contains an integer N. The second line contains N space-separated integers A_1, A_2, ..., A_N.

Output

Print a single integer representing the minimum absolute difference.

Constraints

1 <= N <= 200000 0 <= A_i <= 10^9

Time limit 1 s (native code; slower languages get more)Memory 256 MB14 hidden tests

Example 1

Input
5
8 1 2 12 7
Output
0

The array can be split after index 3: [8, 1, 2, 12] (XOR sum 7) and [7] (XOR sum 7). The difference is |7-7| = 0.

Example 2

Input
3
1 2 3
Output
0

Split after index 0: [1] (XOR sum 1) and [2, 3] (XOR sum 1). Difference |1-1|=0. Split after index 1: [1, 2] (XOR sum 3) and [3] (XOR sum 3). Difference |3-3|=0.

Hints