Caterpillar3

Time limit: 1s Memory limit: 256MB Input: Output:

- Sorry, it was a typo. We didn't mean to hurt your feelings like that.
- More often than not, we are stuck rationalizing whatever disreputable deeds we engage in for the sake of moving on. But, it is important in this process that we do not stray away from the one truth we have, which is the present moment.
In the quest of simplifying historical data for the sake of potential clarity, we can find ourselves destroying relationships and communities. What could be holier than the present, we ask of you? What is the point when mere abstention becomes problematic revisionism, and why shouldn't we believe you have crossed this threshold already?

- The Author with the Very Hungarian Catterpilar

Task

Consider the bitwise AND\texttt{AND} operation (hereby noted as &\texttt{\&}). The bitwise AND\texttt{AND} operation (denoted by &\texttt{\&}) is a binary operation that compares each bit of two operands and returns a new value where each bit is set to 11 only if the corresponding bits of both operands are 11. In other words, it performs a logical AND on every pair of corresponding bits. For example, given two 4-bit binary numbers A=1100(2)A = 1100_{(2)} and B=1010(2)B = 1010_{(2)}, their bitwise AND is A&B=1000(2)A\,\texttt{\&}\,B = 1000_{(2)}. This operation is defined in C++\texttt{C++} as &\texttt{\&}, which works similarly to any other operator (e.g. +,-,\texttt{+}, \texttt{-}, etc.).

We call a sequence bb of numbers b1,b2,,bkb_1, b_2, \dots, b_k self-describing\textit{self-describing} if there exists an index pp with 1pk1 \leq p \leq k such that b1&b2&&bk=bpb_1\,\texttt{\&}\, b_2\,\texttt{\&}\,\dots\,\texttt{\&}\,b_k = b_p.

Given a sequence vv of NN natural numbers v1,v2,,vNv_1, v_2, \dots, v_N, determine how many pairs of indexes (l,r)(l, r) bound a self-describing\textit{self-describing} subarray. That is, count the number of pairs of numbers (l,r)(l, r) with with 1lrN1 \leq l \leq r \leq N such that vl,vl+1,vrv_l, v_{l+1}, \dots v_r is a self-describing\textit{self-describing} sequence.

Input data

The first line contains a natural number NN.
The second line contains NN natural numbers, representing the elements of the sequence vv.

Output data

Print a single number: the sought number of pairs of indexes l,rl, r that satisfy the property described in the statement.

Restrictions

  • 1N2 000 0001 \leq N \leq 2 \ 000 \ 000.
  • 0vi<2600 \leq v_i < 2^{60}.
# Points Restrictions
1 10 1N2001 \leq N \leq 200, vi<230v_i < 2^{30}
2 3 1N21061 \leq N \leq 2 \cdot 10^6, all values viv_i are equal
3 13 1N21031 \leq N \leq 2 \cdot 10^3, vi<230v_i < 2^{30}
4 11 1N41041 \leq N \leq 4 \cdot 10^4, vi<230v_i < 2^{30}
5 6 1N21051 \leq N \leq 2 \cdot 10^5, vi=2kv_i = 2^k
6 11 1N21051 \leq N \leq 2 \cdot 10^5, vi<8v_i < 8
7 14 1N21051 \leq N \leq 2 \cdot 10^5, vi=2j2kv_i = 2^j - 2^k, for 0kj600 \le k \le j \le 60
8 13 1N21051 \leq N \leq 2 \cdot 10^5
9 19 No additional restrictions

Example

stdin

5
1 1 4 0 2

stdout

13

Explanation

For the given example, the intervals that satisfy the property are: (1,1)(1, 1), (1,2)(1, 2), (1,4)(1, 4), (1,5)(1, 5), (2,2)(2, 2), (2,4)(2, 4), (2,5)(2, 5), (3,3)(3, 3), (3,4)(3, 4), (3,5)(3, 5), (4,4)(4, 4), (4,5)(4, 5), (5,5)(5, 5).

Log in or sign up to be able to send submissions!