Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
F
Bits And Pieces
Codeforces
2600
原题
← EG →
翻译中…

You are given an array $a$ of $n$ integers.

翻译中…

You need to find the maximum value of $a_{i} | ( a_{j} \& a_{k} )$ over all triplets $(i,j,k)$ such that $i \lt j \lt k$.

翻译中…

Here $\&$ denotes the bitwise AND operation, and $|$ denotes the bitwise OR operation.

翻译中…

Input

翻译中…

The first line of input contains the integer $n$ ($3 \le n \le 10^{6}$), the size of the array $a$.

翻译中…

Next line contains $n$ space separated integers $a_1$, $a_2$, ..., $a_n$ ($0 \le a_{i} \le 2 \cdot 10^{6}$), representing the elements of the array $a$.

翻译中…

Output

翻译中…

Output a single integer, the maximum value of the expression given in the statement.

翻译中…

Note

翻译中…

In the first example, the only possible triplet is $(1, 2, 3)$. Hence, the answer is $2 | (4 \& 6) = 6$.

翻译中…

In the second example, there are $4$ possible triplets:

翻译中…
  1. $(1, 2, 3)$, value of which is $2|(8\&4) = 2$.
  2. $(1, 2, 4)$, value of which is $2|(8\&7) = 2$.
  3. $(1, 3, 4)$, value of which is $2|(4\&7) = 6$.
  4. $(2, 3, 4)$, value of which is $8|(4\&7) = 12$.
翻译中…

The maximum value hence is $12$.

翻译中…

样例

Input #1
3
2 4 6
Output #1
6
InputCopy OutputCopy
Input #2
4
2 8 4 7
Output #2
12
InputCopy OutputCopy
题目信息
题号
1208F
时间限制
2 s
内存限制
256 MB
标签
位运算
DFS 及类似
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。