AND choice

2.9

14 votes
Algorithms, Bit Manipulation, Data Structures, Math, Priority queue, Trees
Problem

M is alone and he has an array a1,a2,...,an. M wants to choose two integers i,j such that ij,1i,jn and the value ai&aj(bitwise AND) is maximum.

What is the maximum value M can get?

Input

First line contains only n, legnth of array.

Second line contains the array elements a1,a2,...,anseparated by space.

1n3×105

1ai109

Output

The only line of output contains an integer, maximum value value that M can get.

Sample Input
4
3 4 2 3
Sample Output
3
Time Limit: 2.5
Memory Limit: 256
Source Limit:
Explanation

M can choose a1=3 and a4=3 with bitwise AND 3 which is maximum.

Editor Image

?