atcoder#DWACON5THPRELIMSB. Sum AND Subarrays
Sum AND Subarrays
Score : points
Problem Statement
One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence of length . He is interested in properties of the sequence .
For a nonempty contiguous subsequence of the sequence , its beauty is defined as . Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of nonempty contiguous subsequences among all nonempty contiguous subsequences. (Subsequences may share elements.)
Find the maximum possible value for him.
Constraints
- All numbers given in input are integers
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4 2
2 5 2 5
12
There are nonempty contiguous subsequences of . Let us enumerate them:
- contiguous subsequences starting from the first element:
- contiguous subsequences starting from the second element:
- contiguous subsequences starting from the third element:
- contiguous subsequences starting from the fourth element:
(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)
The maximum possible bitwise AND of the beauties of two different contiguous subsequences is . This can be achieved by choosing (with beauty ) and (with beauty ).
8 4
9 1 8 2 7 5 6 4
32