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

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

Pair with the largest AND

Medium 1000 ms 128 MB 58%
Share

$n$ non-negative integers are given. Choose two elements $a_{i}$ and $a_{j}$ at different positions ($i \ne j$) so that $a_{i} \mathbin{\&} a_{j}$ (bitwise AND) is as large as possible. Print this largest value.

Binary representations of the numbers; the pair with ones in common starting from the highest bit is chosen

Input

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

Output

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

Note

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

Examples

Input #1
4
12 7 14 9
Output #1
12
Input #2
2
1 2
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.