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: Wrong Answer)

#include <bits/stdc++.h>
using i64 = long long;

long long *fact, *inv;

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

void init_factorial(int n, long long mod) {
    fact = new long long[n + 1];
    inv = new long long[n + 1];
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (long long i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}


int main() {
    int n;
    constexpr i64 mod = 1000000007;
    std::cin >> n;
    std::vector<int> a(n + 1), s(n + 1), prev(n + 1), z(n + 1);
    std::map<int, int> pos;
    init_factorial(n, mod);
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
        s[i] = s[i - 1] ^ a[i];
        z[i] = z[i - 1] + !s[i];
        prev[i] = pos[s[i]];
        pos[s[i]] = i;
    }
    i64 ret = 0;
    
    if (!s[n]) {
        ret = 1;
        for (int i = 1; i < z[n]; i++) ret = ret * 2ll % mod;
    }

    // std::cerr << ret << std::endl;
    // for (int i = 1; i <= n; i++) std::cerr << s[i] << " ";
    // std::cerr << std::endl;

    std::map<int, i64> t, p;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 0) {
            if (s[n]) ret = (ret + p[s[n]]) % mod;
            continue;
        }
        t[s[i]] = p[s[i]] * (z[i] - z[prev[i]]) % mod;
        // t[s[i]] = std::max(t[s[i]], 1ll);
        if (!s[n]) ret = (ret + t[s[i]] + 1) % mod;
        // else if (s[n] == s[i]) ret = (ret + t[s[i]] + 1) % mod;
        // if (!s[n] || s[n] == s[i]) ret = (ret + t[s[i]] + 1) % mod;
        p[s[i]] = (p[s[i]] + t[s[i]] + 1) % mod;
    }
    std::cout << (ret + (s[n] > 0)) << std::endl;

    return 0;
}