atcoder#ABC281F. [ABC281F] Xor Minimization

[ABC281F] Xor Minimization

Score : 500500 points

Problem Statement

You are given a sequence of non-negative integers A=(a1,,aN)A=(a_1,\ldots,a_N).

Let us perform the following operation on AA just once.

  • Choose a non-negative integer xx. Then, for every i=1,,Ni=1, \ldots, N, replace the value of aia_i with the bitwise XOR of aia_i and xx.

Let MM be the maximum value in AA after the operation. Find the minimum possible value of MM.

What is bitwise XOR? The bitwise XOR of non-negative integers A and B, A \oplus B, is defined as follows.
  • When A \oplus B is written in binary, the k-th lowest bit (k \geq 0) is 1 if exactly one of the k-th lowest bits of A and B is 1, and 0 otherwise.
For instance, 3 \oplus 5 = 6 (in binary: 011 \oplus 101 = 110).

Constraints

  • 1N1.5×1051 \leq N \leq 1.5 \times 10^5
  • 0ai<2300 \leq a_i \lt 2^{30}
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

a1a_1 \ldots aNa_N

Output

Print the answer.

3
12 18 11
16

If we do the operation with x=2x=2, the sequence becomes (122,182,112)=(14,16,9)(12 \oplus 2,18 \oplus 2, 11 \oplus 2) = (14,16,9), where the maximum value MM is 1616. We cannot make MM smaller than 1616, so this value is the answer.

10
0 0 0 0 0 0 0 0 0 0
0
5
324097321 555675086 304655177 991244276 9980291
805306368