Problem:
Score : 800 points

Problem Statement

The beauty of a sequence a of length n is defined as a_1 \oplus \cdots \oplus a_n, where \oplus denotes the bitwise exclusive or (XOR).

You are given a sequence A of length N.
Snuke will insert zero or more partitions in A to divide it into some number of non-empty contiguous subsequences.

There are 2^{N-1} possible ways to insert partitions.
How many of them divide A into sequences whose beauties are all equal? Find this count modulo 10^{9}+7.

Constraints

All values in input are integers.

1 \leq N \leq 5 \times 10^5

0 \leq A_i < 2^{20}

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

3

Four ways of dividing A shown below satisfy the condition. The condition is not satisfied only if A is divided into (1),(2),(3).

(1,2,3)

(1),(2,3)

(1,2),(3)

Sample Input 2

3
1 2 2

Sample Output 2

1

Sample Input 3

32
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Sample Output 3

147483634

Find the count modulo 10^{9}+7.

Sample Input 4

24
1 2 5 3 3 6 1 1 8 8 0 3 3 4 6 6 4 0 7 2 5 4 6 2

Sample Output 4

292

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int Maxn = 500005;
const int Maxm = 1 << 20;
const int mod = 1000000007;

int n;
int a[Maxn];
int add1[Maxn], add2[Maxn];
vector <int> V[Maxm];
int my[Maxn];
int res;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        a[i] ^= a[i - 1];
        V[a[i]].push_back(i);
    }
    for (int i = 1; i < Maxm; i++) if (!V[i].empty())
        add2[V[i][0]]++;
    int zers = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] == 0) zers++;
        else {
            my[i] = (ll(zers) * add1[i] % mod + ll(add2[i])) % mod;
            int ind = upper_bound(V[a[i]].begin(), V[a[i]].end(), i) - V[a[i]].begin();
            if (ind < V[a[i]].size()) {
                int nxt = V[a[i]][ind];
                add1[nxt] = (ll(add1[nxt]) + ll(add1[i]) + ll(my[i])) % mod;
                add2[nxt] = (ll(add2[nxt]) + ll(add2[i]) - ll(my[i]) * zers % mod + ll(mod)) % mod;
            }
        }
    if (a[n] == 0) {
        int pw = 1;
        for (int i = 1; i < n; i++)
            if (a[i] == 0) pw = pw * 2 % mod;
            else res = (res + my[i]) % mod;
        res = (res + pw) % mod;
    } else res = my[n];
    printf("%d\n", res);
    return 0;
}