Problem Statement
There are length-$N$ sequences $A=(A_0,A_1,\ldots,A_{N-1})$ and $B=(B_0,B_1,\ldots,B_{N-1})$.
Takahashi may perform the following operation on $A$ any number of times (possibly zero):
- apply a left cyclic shift to the sequence
$A$. In other words, replace$A$with$A'$defined by$A'_i=A_{(i+1)\% N}$, where$x\% N$denotes the remainder when$x$is divided by$N$.
Takahashi's objective is to maximize $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)$, where $x|y$ denotes the bitwise logical sum (bitwise OR) of $x$ and $y$.
Find the maximum possible $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)$.
What is the bitwise logical sum (bitwise OR)? The logical sum (or the OR operation) is an operation on two one-bit integers ($0$ or $1$) defined by the table below. The bitwise logical sum (bitwise OR) is an operation of applying the logical sum bitwise. $x$ $y$ $x|y$ $0$ $0$ $0$ $0$ $1$ $1$ $1$ $0$ $1$ $1$ $1$ $1$ The logical sum yields $1$ if at least one of the bits $x$ and $y$ is $1$. Conversely, it yields $0$ only if both of them are $0$. Example 0110 | 0101 = 0111
Constraints
$2 \leq N \leq 5\times 10^5$$0\leq A_i,B_i \leq 31$- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
N
A_0 A_1 \ldots A_{N-1}
B_0 B_1 \ldots B_{N-1}
Output
Print the maximum possible $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)$.
样例
3
0 1 3
0 2 3
8
5
1 6 1 4 3
0 6 4 0 1
23
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。