cswork / OAOpen practice workspace

MicrosoftOA #18

Count Subarrays with Bitwise OR Present

Estimated MediumJudge-ready

Topics (AI-labelled)Bits & MathHashing

Count the non-empty contiguous subarrays whose bitwise OR of all elements equals some element of the original array (that element does not have to be inside the current subarray). The original site undercounted [1,6,7]; by the definition the answer is 6.

Input

This site's input: the first line contains n (1..100000), and the second line contains n positive integers (1..10⁹).

Output

Output a single integer, the answer.

Example 1

Input:

3
1 6 7

Output:

6

Example 2

Input:

3
2 4 7

Output:

5

Example 3

Input:

1
1

Output:

1

Example notes

Example 1: the ORs of the three single-element segments, the two segments of length 2, and the whole array all lie in {1,6,7}, so there are 6 segments.

Example 2: only [2,4] has OR=6, which is not in the original array; the other 5 segments are valid.

Example 3: the only subarray has OR 1, so the answer is 1.

Editorial

Loading solution…