CF1365E.Maximum Subsequence Value

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Ridhiman challenged Ashish to find the maximum valued subsequence of an array aa of size nn consisting of positive integers.

The value of a non-empty subsequence of kk elements of aa is defined as 2i\sum 2^i over all integers i0i \ge 0 such that at least max(1,k2)\max(1, k - 2) elements of the subsequence have the ii -th bit set in their binary representation (value xx has the ii -th bit set in its binary representation if x2imod2\lfloor \frac{x}{2^i} \rfloor \mod 2 is equal to 11 ).

Recall that bb is a subsequence of aa , if bb can be obtained by deleting some(possibly zero) elements from aa .

Help Ashish find the maximum value he can get by choosing some subsequence of aa .

输入格式

The first line of the input consists of a single integer nn (1n500)(1 \le n \le 500) — the size of aa .

The next line consists of nn space-separated integers — the elements of the array (1ai1018)(1 \le a_i \le 10^{18}) .

输出格式

Print a single integer — the maximum value Ashish can get by choosing some subsequence of aa .

输入输出样例

  • 输入#1

    3
    2 1 3

    输出#1

    3
  • 输入#2

    3
    3 1 4

    输出#2

    7
  • 输入#3

    1
    1

    输出#3

    1
  • 输入#4

    4
    7 7 1 1

    输出#4

    7

说明/提示

For the first test case, Ashish can pick the subsequence {2,3}\{{2, 3}\} of size 22 . The binary representation of 22 is 10 and that of 33 is 11. Since max(k2,1)\max(k - 2, 1) is equal to 11 , the value of the subsequence is 20+212^0 + 2^1 (both 22 and 33 have 11 -st bit set in their binary representation and 33 has 00 -th bit set in its binary representation). Note that he could also pick the subsequence {3}\{{3\}} or {2,1,3}\{{2, 1, 3\}} .

For the second test case, Ashish can pick the subsequence {3,4}\{{3, 4\}} with value 77 .

For the third test case, Ashish can pick the subsequence {1}\{{1\}} with value 11 .

For the fourth test case, Ashish can pick the subsequence {7,7}\{{7, 7\}} with value 77 .

首页