Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bit-eng-katta-xor

Pair with the largest XOR

Medium 1000 ms 128 MB 60%
Share

$n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ are given. Choose two numbers at different positions ($i \ne j$) so that $a_{i} \oplus a_{j}$ is as large as possible. Find this largest value. Here $\oplus$ is the bitwise XOR operation.

Binary representations of the numbers; the pair with the largest XOR and the result are highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$ separated by spaces.

Output

One integer — the largest $a_{i} \oplus a_{j}$.

Note

$2 \le n \le 10^{5}$
$0 \le a_{i} \lt 2^{30}$

Examples

Input #1
6
3 10 5 25 2 8
Output #1
28
Input #2
2
7 7
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.