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 namespace std;

using lint = long long;
const lint MOD = 1e9 + 7;

lint power(lint n, lint p) {
    lint res = 1;
    while (p > 0) {
        if (p % 2 == 1) {
            res = res * n % MOD;
        }
        n = n * n % MOD;
        p /= 2;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1), zero(n + 1); // zero[i]: [0, i] での 0 の出現回数
    map<int, vector<int>> num;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] ^= a[i - 1];
        zero[i] = zero[i - 1];
        if (a[i] == 0) {
            zero[i]++;
        } else {
            num[a[i]].push_back(i);
        }
    }

    lint ans = 0;
    if (a[n] == 0) {
        ans = power(2, zero[n] - 1);
    }

    for (auto p: num) {
        int val = p.first;
        if (a[n] == val or a[n] == 0) {
            auto vec = p.second;
            int m = vec.size();

            vector<lint> dp(m), dp_cum(m);
            // dp[i]: 最後 vec[i] を踏んで終わっている
            // dp_cum[i]: 最後 vec[i] までのどこかを踏んで終わっている
            dp[0] = 1;
            dp_cum[0] = 1;
            for (int i = 1; i < m; i++) {
                int z = zero[vec[i]] - zero[vec[i - 1] - 1];
                if (z > 0) {
                    dp[i] = (dp_cum[i - 1] * lint(z) + lint(1)) % MOD;
                } else {
                    dp[i] = dp[i - 1];
                }
                dp_cum[i] = (dp[i] + dp_cum[i - 1]) % MOD;
            }
            if (a[n] == 0) {
                ans = (ans + dp_cum[m - 1]) % MOD;
            } else {
                ans = (ans + dp[m - 1]) % MOD;
            }
        }
    }

    cout << ans << endl;
    return 0;
}