Operation XOR


Submit solution

Points: 1
Time limit: 1.5s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python, Rust

Wesley the robot has been in a car accident and needs surgery. Unfortunately, ordinary surgical tools are not much use on a robot, so his surgeon Leo must work with Wesley's internal subsystem values instead.

Wesley has n subsystems, with values a_1,a_2,\dots,a_n.

To perform the operation, Leo must choose one of Wesley's subsystem values as a calibration value x. That is, x=a_j for some 1\le j\le n.

The success score of choosing x is

\displaystyle 
S(x)=\sum_{i=1}^{n}(a_i\oplus x),

where \oplus denotes the bitwise XOR operation.

Leo wants to choose a calibration value that maximises the success score, S(x). If several possible values of x give the same maximum success score, he wants to choose the smallest value of x that does so.

Determine the value of x that Leo should use.

Bitwise XOR compares two integers bit by bit. A bit in the result is (1) exactly when the corresponding bits of the two integers are different.

Input

The first line contains a single integer n (1\le n\le 10^5), the number of Wesley's subsystems.

The second line contains n space-separated integers a_1,a_2,\dots,a_n (0\le a_i\le 10^9), the value of each subsystem.

Output

Output a single integer x: the smallest subsystem value that maximises S(x).

Example

Input 1
3
1 2 1
Output 1
2

Clearly there are only two distinct subsystem values here that Leo could pick: 1 or 2.

  • Picking 1 gives S(1)=1\oplus1+2\oplus1+1\oplus1=0+3+0=3.
  • Picking 2 gives S(2)=1\oplus2+2\oplus2+1\oplus2=3+0+3=6.

Thus, picking 2 maximises the success score of Leo's surgery.

Input 2
4
3 1 2 0
Output 2
0
Input 3
5
5 5 5 5 5
Output 3
5

Comments

There are no comments at the moment.