P27910 [洛谷] [GESP202312 Level 5] Culinary Problem
普及+
题目描述

Problem Description

There are $N$ types of ingredients, numbered from $0$ to $N-1$, where the deliciousness of the $i$-th ingredient is $a_i$.

Combinations of different ingredients can create fascinating chemical reactions. Specifically, if the deliciousness of two ingredients is $x$ and $y$ respectively, their compatibility is $x \ \text{and}\ y$.

Here, $\text{and}$ operation is the bitwise AND operation, which requires converting both operands to binary, padding with leading zeros if necessary, and then performing the AND operation bit by bit. For example, the binary representations of $12$ and $6$ are $1100$ and $0110$ respectively. Performing the AND operation bit by bit results in $0100$, which converts to decimal as $4$. Therefore, $12 \text{and} 6 = 4$. In C++ or Python, the & operator can be used directly for the AND operation.

Now, please find the two ingredients with the highest compatibility and output their compatibility.

Input Format

The first line contains an integer $N$, representing the number of ingredients.

The next line contains $N$ integers separated by spaces, $a_1, \cdots, a_N$, representing the deliciousness of each ingredient.

Output Format

Output a single line containing an integer, representing the highest compatibility.

Sample Input and Output

Sample Input #1

3
1 2 3

Sample Output #1

2

Sample Input #2

5
5 6 2 10 13

Sample Output #2

8

Notes

Sample Explanation 1

The compatibility between ingredients numbered $1$ and $2$ is $2 \ \text{and} \ 3 = 2$, which is the highest compatibility among all pairs of ingredients.

Sample Explanation 2

The compatibility between ingredients numbered $3$ and $4$ is $10 \ \text{and} \ 13 = 8$, which is the highest compatibility among all pairs of ingredients.

Data Range

For $40\%$ of the test cases, $N \le 1,000$.

For all test cases, $N \le 10^6$ and $0 \le a_i \le 2,147,483,647$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 1 2 3
样例输出
2