#ABC291G. [ABC291G] OR Sum
[ABC291G] OR Sum
Score : points
Problem Statement
There are length- sequences and . Takahashi may perform the following operation on any number of times (possibly zero):
- apply a left cyclic shift to the sequence . In other words, replace with defined by , where denotes the remainder when is divided by .
Takahashi's objective is to maximize , where denotes the bitwise logical sum (bitwise OR) of and .
Find the maximum possible .
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
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the maximum possible .
If Takahashi does not perform the operation, remains , and we have ; if he performs the operation once, making , we have ; and if he performs the operation twice, making , we have . If he performs the operation three or more times, becomes one of the sequences above, so the maximum possible is , which should be printed.
The value is maximized if he performs the operation three times, making , where .