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. (python)leetcode刷题笔记 01 TWO SUM

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  2. 数据库Mysql的学习(四)-表的记录操作

    ,);//指定插入的顺序 ,);//按照默认的插入 ,),(,)(,);//同时插入多条数据 //将查询结果插入表中 CREATE TABLE TEXT( category_id INT PRIMAR ...

  3. 【shell 练习5】编写简单的多级菜单

    一.简单的多级菜单 [root@web129 ~]# cat menu.sh #!/bin/bash #shell菜单演示 function menu() { echo -e `date` cat & ...

  4. Appium基础环境搭建(windows)---基于python

    1  JDK安装 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 安装注意:安装 ...

  5. Thunder团队第五周 - Scrum会议4

    Scrum会议4 小组名称:Thunder 项目名称:i阅app Scrum Master:李传康 工作照片: 邹双黛同学在拍照,所以不在照片内. 参会成员: 王航:http://www.cnblog ...

  6. 【APS.NET Core】- Razor Page 使用jqgrid实现分页功能

    本文将使用jqgrid在Razor Page中实现分页功能. 前台 List.cshtml代码如下: @page @model ListModel @{ Layout = "~/Pages/ ...

  7. WEB安全测试要点总结

    一.大类检查点: 二.测试项详细说明 上传功能 绕过文件上传检查功能 上传文件大小和次数限制 注册功能 注册请求是否安全传输 注册时密码复杂度是否后台校验 激活链接测试 重复注册 批量注册问题  登录 ...

  8. 面试:谈谈你对Spring框架的理解

    Spring是一个优秀的轻量级框架,大大的提高了项目的开发管理与维护.Spring有两个核心模块.一个是IOC,一个是AOP. IOC: 就是控制反转的意思,指的是我们将对象的控制权从应用代码本身转移 ...

  9. Ubuntu 删除多余内核

    Ubuntu 删除多余内核 转载▼ 首先查询当前我们使用的是内核是那个版本别删错了. uname -a 第二: 查询系统中装了多少内核 dpkg --get-selections|grep linux ...

  10. 完全理解Python的 '==' 和 'is'

    '==' 比较的是两个对象的值 'is' 比较的是两个对象的内存地址(id) 下面我们着重理解 'is'.对于这个,我们需要知道:小整数对象池,大整数对象池,以及intern机制 小整数池:Pytho ...