~/algor $ cat problems/bit-eng-katta-and
Pair with the largest AND
Medium
1000 ms
128 MB
58%
$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.
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