D. Dangerous Duos
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

There are $$$n$$$ countries arranged in a straight line. Each country has a fighting power $$$p$$$. We skip the definitely very reasonable explanation of why the combined fighting power of two countries is the bitwise XOR of their two fighting powers.

A pair of countries $$$(l, r)$$$, where $$$l \lt r$$$, is called dangerous if their combined fighting power is stronger than every single fighting power of the countries between them and is also stronger than the two countries on their own. Formally, $$$p_l \oplus p_r \gt \max_{i=l}^r p_i$$$.

Count the number of dangerous pairs of countries.

Input

The input consists of:

  • One line with one integer $$$n$$$ ($$$2 \leq n \leq 4 \cdot 10^5$$$), the number of countries.
  • One line with $$$n$$$ integers $$$p$$$ ($$$0 \leq p \leq 10^6$$$), the fighting power of the countries.
Output

Output one integer, the number of dangerous pairs.

Examples
Input
4
3 2 4 1
Output
3
Input
7
6 2 3 1 5 11 0
Output
5