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)

/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 500005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
const int magic = 350;

int n;
int a[N];

int DP[N][3];
int dp[3];
vector <int> g;

unordered_map <int,int> ind;

int nxt[N] , id[N];
int pref[N];

pair <int,int> mas[N];

int main() {
    mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n;
    int z = 0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        a[i] ^= a[i - 1];
        pref[i] = pref[i - 1] + (a[i] == 0);
        if(a[i]) g.push_back(a[i]);
    }
    ///
    sort(g.begin() , g.end());
    g.resize( unique(g.begin() , g.end()) - g.begin() );
    for(int i=0;i<(int)g.size();i++){
        ind[ g[i] ] = i + 1;
    }
    for(int i=1;i<=n;i++){
        if(a[i]){
            a[i] = ind[ a[i] ];
        }
    }
    ///
    for(int i=1;i<=(int)g.size();i++){
        id[i] = n + 1;
    }
    for(int i=n;i>=1;i--){
        int x = a[i];
        if(x == 0)continue;
        nxt[i] = id[x];
        id[x] = i;
    }
    ///
    if(a[n] == 0){
        int answ = 1;
        for(int i=1;i<pref[n];i++){
            answ *= 2;
            answ %= mod;
        }
        if((int)g.size() < magic){
            for(int i=1;i<=(int)g.size();i++){
                DP[i][0] = 1;
                DP[i][1] = 0;
            }
            for(int i=1;i<n;i++){
                if(a[i] == 0){
                    for(int j=1;j<=(int)g.size();j++){
                        DP[j][0] += DP[j][1];
                        DP[j][0] %= mod;
                    }
                }
                else{
                    int x = a[i];
                    DP[x][1] += DP[x][0];
                    DP[x][1] %= mod;
                }
            }
            for(int i=1;i<=(int)g.size();i++){
                answ += DP[i][1];
                answ %= mod;
            }
            cout << answ << endl;
        }
        else{
            for(int i=1;i<=(int)g.size();i++){
                int v = id[i];
                int z = 0;
                while(v != n + 1){
                    mas[++z] = (make_pair(i , 1));
                    int s = pref[ nxt[v] - 1 ] - pref[v];
                    if(nxt[v] != n + 1) mas[++z] = (make_pair(0 , s));
                    v = nxt[v];
                }
                dp[0] = 1;
                dp[1] = 0;
                for(int j=1;j<=z;j++){
                    int q = mas[j].second;
                    if(mas[j].first == 0){
                        dp[0] += q * 1ll * dp[1] % mod;
                    }
                    else{
                        dp[1] += q * 1ll * dp[0] % mod;
                    }
                }
                answ += dp[1];
                answ %= mod;
            }
            cout << answ << endl;
        }
    }
    else{
        dp[0] = 1;
        dp[1] = 0;
        for(int i=1;i<n;i++){
            if(a[i] == 0){
                dp[0] += dp[1];
                dp[0] %= mod;
            }
            if(a[i] == a[n]){
                dp[1] += dp[0];
                dp[1] %= mod;
            }
        }
        cout << dp[0] << endl;
    }
	return 0;
}