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++ (GCC 9.2.1) (judge verdict: Wrong Answer)

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9 + 7;
const int maxn = 1e6 + 5;

void add(ll& x, ll y) {
    if (x>=mod) x%=mod;
    if (y>=mod) y%=mod;
    x += y;
    if (x>=mod) x%=mod;
}

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}


int n;
int a[maxn];
int acc[maxn];


vector<int> inds[maxn];




ll solve(vector<int> a) {
    // count odd length subsequences that alternate: 101..0101, must start and end with 1
    vector<ll> dp(2, 0);
    dp[0] = 1;
    for (int x: a) {
	if (x==0) {
	    dp[0]=(dp[0]+dp[1])%mod;
	} else {
	    dp[1]=(dp[1]+dp[0])%mod;
	}
    }
    return dp[1];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }

    
    for (int i=0; i<n; i++) {
	acc[i+1]=acc[i]^a[i];
    }

    //watch(acc[n]);

    if (acc[n] != 0) {
	// even # of dividers
	// alternating parity of indices
	vector<int> v;
	for (int i=1; i<n; i++) {
	    if (acc[i]==0) {
		v.push_back(0);
	    }
	    if (acc[i]==acc[n]) {
		v.push_back(1);
	    }
	}

	//101010
	//even length, alternate
	vector<ll> dp(2, 0);
	dp[0] = 1;
	for (int x: v) {
	    if (x==0) {
		dp[0]=(dp[0]+dp[1])%mod;
	    } else {
		dp[1]=(dp[1]+dp[0])%mod;
	    }
	}
	
	out(dp[0]);
    } else {
	out("-1");

	
	for (int i=1; i<n; i++) {
	    inds[acc[i]].push_back(i);
	}


	ll res = 0;
	add(res, pw(2, inds[0].size()));
    

	for (int x=1; x<maxn; x++) {
	    if (inds[x].empty()) {
		continue;
	    }
	
	    vector<int> v;
	    int len0 = inds[0].size();
	    int lenx = inds[x].size();

	    for (int i=0,j=0; i<len0 || j<lenx; ) {
		if (i==len0) {
		    v.push_back(1);
		    j++;
		    continue;
		}
		if (j==lenx) {
		    v.push_back(0);
		    i++;
		    continue;
		}
		if (inds[0][i]<inds[x][j]) {
		    v.push_back(0);
		    i++;
		} else {
		    v.push_back(1);
		    j++;
		}
	    }
	    add(res, solve(v));
	}


	cout<<res<<endl;
    }
    return 0;
}