Operation XOR
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 subsystems, with values
.
To perform the operation, Leo must choose one of Wesley's subsystem values as a calibration value . That is,
for some
.
The success score of choosing is
where denotes the bitwise XOR operation.
Leo wants to choose a calibration value that maximises the success score, . If several possible values of
give the same maximum success score, he wants to choose the smallest value of
that does so.
Determine the value of 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 (
), the number of Wesley's subsystems.
The second line contains space-separated integers
(
), the value of each subsystem.
Output
Output a single integer : the smallest subsystem value that maximises
.
Example
Input 1
3
1 2 1
Output 1
2
Clearly there are only two distinct subsystem values here that Leo could pick: or
.
- Picking
gives
.
- Picking
gives
.
Thus, picking 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