A. Interview
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ..., xr, where xi is the i-th element of the array x. You are given two arrays a and b of length n. You need to determine the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers ai (0 ≤ ai ≤ 109).

The third line contains n integers bi (0 ≤ bi ≤ 109).

Output

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.

Examples
Input
5
1 2 4 3 2
2 3 3 12 1
Output
22
Input
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
Output
46
Note

Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation.

In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose l = 1 and r = 4, l = 1 and r = 5, l = 2 and r = 4, l = 2 and r = 5, l = 3 and r = 4, or l = 3 and r = 5.

In the second sample, the maximum value is obtained for l = 1 and r = 9.

题解: max(f(a,l,r)+f((b,l,r))  f() 为求 l-->r的按位或的值

马上codeforces  上分

 #include<bits/stdc++.h>
using namespace std;
int a[][];
int b[][];
int exm1[],exm2[];
int main()
{
int n;
int sum1=,sum2=,maxn=;;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&exm1[i]);
}
for(int i=; i<=n; i++)
{
scanf("%d",&exm2[i]);
}
for(int i=; i<=n; i++)
{
sum1=exm1[i];
a[i][i]=sum1;
for(int j=i+; j<=n; j++)
{
a[i][j]=sum1|exm1[j];
sum1=a[i][j];
}
}
for(int i=; i<=n; i++)
{
sum2=exm2[i];
b[i][i]=sum2;
if(b[i][i]+a[i][i]>maxn)
maxn=b[i][i]+a[i][i];
for(int j=i+; j<=n; j++)
{
b[i][j]=sum2|exm2[j];
sum2=b[i][j];
if(b[i][j]+a[i][j]>maxn)
maxn=b[i][j]+a[i][j];
}
}
printf("%d\n",maxn);
return ;
}

Codeforces Round #344 (Div. 2) A的更多相关文章

  1. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

  2. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  3. Codeforces Round #344 (Div. 2) D. Messenger kmp

    D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...

  4. Codeforces Round #344 (Div. 2) C. Report 其他

    C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...

  5. Codeforces Round #344 (Div. 2) B. Print Check 水题

    B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...

  6. Codeforces Round #344 (Div. 2) A. Interview 水题

    A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...

  7. Codeforces Round #344 (Div. 2) B. Print Check

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #344 (Div. 2)(按位或运算)

    Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...

  9. Codeforces Round #344 (Div. 2)

    水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...

随机推荐

  1. Angular6项目搭建

    参照 草根专栏- ASP.NET Core + Ng6 实战:https://v.qq.com/x/page/b076702elvw.html 安装工具: Nodejs, npm     最新版, h ...

  2. Python全栈 Web(HTML基础语法)

    原文地址:           https://yq.aliyun.com/articles/632672 .............................................. ...

  3. lintcode50 数组剔除元素后的乘积

    数组剔除元素后的乘积 给定一个整数数组A. 定义B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], 计算B的时候请不要使用除法. 您在真实的面试中是 ...

  4. 服务器返回中文乱码的情况(UTF8编码 -> 转化为 SYSTEM_LOCALE 编码)

    服务器乱码 转换使用如下方法 入惨{“msg”} -> utf8编码 -> 转化为 SYSTEM_LOCALE 编码 -> 接受转换后的参数 "sEncoding" ...

  5. 统计单词数:string函数使用

    题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...

  6. 第一周 Welcome

    什么是机器学习 您也许一天用它几十次都不知道,每次你用google或者bing搜索网页感觉很厉害,因为他们用机器学习软件来设计网页排名,当你用Facebook或Apple的照片软件而它们知道照片里面哪 ...

  7. Python3.5 Keras-Theano(含其他库)windows 安装环境

    https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.2.0-Windows-x86.execonda --version ...

  8. 深入理解eos账户体系 active和action

    在eos中,账户是一个非常重要的概念. 账户分为两部分组成 一种是active 一种是action. 智能合约本质上来讲就是一个action加上一个回馈脚本程序.任何智能合约都有这俩个部分组成. 那么 ...

  9. es6从零学习(四):Class的继承

    es6从零学习(四):Class的继承 一:继承的方式 1.Class 可以通过extends关键字实现继承 class Point { } class ColorPoint extends Poin ...

  10. 团队第一次作业 ——404 Note Found 团队

    如果记忆是一个罐头的话,我希望这一罐罐头不会过期----<重庆森林> 404 Note Found Team 如果记忆是一个备忘录的话,别说了,它不会过期----<404 Note ...