A factory conveyor belt is divided into n consecutive load-bearing segments; the i-th segment currently carries a load of weight w_i. For quality auditing, the plant's monitoring system looks at every contiguous run of one or more segments — there are n(n+1)/2 such runs in total, including every single segment on its own and the run spanning the entire belt — and computes the total weight carried across that run. The plant's audit signature is obtained by taking the bitwise OR of the totals of every one of these runs. Given the segment weights, compute the audit signature.
Print a single integer: the bitwise OR, taken over every contiguous run of one or more segments, of that run's total weight.
Example 1
Input
3 1 2 4
Expected
7
Explanation
The six run totals are: [1]=1, [2]=2, [4]=4, [1,2]=3, [2,4]=6, [1,2,4]=7. Their bitwise OR is 1|2|4|3|6|7 = 7 (the run covering everything already sets every bit that appears). Output: 7.
Example 2
Input
2 5 5
Expected
15
Explanation
The three run totals are: [5]=5, [5]=5, [5,5]=10. In binary 5=0101 and 10=1010, so 5|5|10 = 0101|1010 = 1111 = 15. Output: 15.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →