E. Maximum Subsequence Value

194 篇文章 1 订阅
4 篇文章 0 订阅

链接:https://codeforces.ml/contest/1365/problem/E

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∑2i over all integers i≥0i≥0 such that at least max(1,k−2)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 ⌊x2i⌋mod2⌊x2i⌋mod2 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.

Input

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

The next line consists of nn space-separated integers — the elements of the array (1≤ai≤1018)(1≤ai≤1018).

Output

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

Examples

input

Copy

3
2 1 3

output

Copy

3

input

Copy

3
3 1 4

output

Copy

7

input

Copy

1
1

output

Copy

1

input

Copy

4
7 7 1 1

output

Copy

7

Note

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(k−2,1)max(k−2,1) is equal to 11, the value of the subsequence is 20+2120+21 (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.

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,n,flag;
ll a[501],k,s;
ll b[501][20],c[501];
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll max1=0;
    if(n>=3)
    {
        for(int i=i;i<=n-2;i++)
        {
            for(int j=i+1;j<=n-1;j++)
            {
                for(int l=j+1;l<=n;l++)
                {
                    max1=max(max1,a[i]|a[j]|a[l]);
                }
            }
        }
    }
    else if(n==2)
    {
        max1=a[1]|a[2];
    }
    else
    {
        max1=a[1];
    }
    printf("%lld\n",max1);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值