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>
#define rep(i, n) for(int i=0; i<int(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

vector<int> G[1048576];

int main(){
	int N; cin >> N;
	int A[N];
	rep(i, N) cin >> A[i];
	int rui[N];
	rui[0] = A[0];
	rep(i, N-1){
		rui[i+1] = rui[i] ^ A[i+1];
	}
	int sum[N];
	rep(i, N){
		G[rui[i]].push_back(i);
		if(i == 0){
			if(rui[i] == 0) sum[i] = 1;
			else sum[i] = 0;
		}else{
			if(rui[i] == 0) sum[i] = sum[i-1] + 1;
			else sum[i] = sum[i-1];
		}
	}
	ll ans = 0, s = 1;
	if(rui[N-1] == 0){
		rep(i, sum[N-1] - 1) s = (s * 2) % mod;
		ans = s;
		for(int i=1; i<1048576; i++){
			if(!G[i].size()) continue;
			int p = G[i].size();
			ll dp[p], su = 0;
// dp[k] で、k番目のiで区切るときのそれ以降の通り数
// su で、dpの累積を保存
			dp[p-1] = 1, su = dp[p-1];
			for(int j=p-2; j>=0; j--){
				int nn = sum[G[i][j+1]] - sum[G[i][j]];
				dp[j] = (su * nn + dp[j+1]) % mod;
				su = (su + dp[j]) % mod;
			}
			ans = (ans + su) % mod;
		}
	}else{
		int x = rui[N-1];
		ll dp[G[x].size()], su = 0;
		dp[G[x].size() - 1] = 1, su = 1;
		for(int i=G[x].size() - 2; i>=0; i--){
			int nn = sum[G[x][i+1]] - sum[G[x][i]];
			if(sum[N-1] - sum[G[x][i]] == 0){
				dp[i] = 0; continue;
			}
			dp[i] = (su * nn + dp[i+1]) % mod;
			su = (su + dp[i]) % mod;
		}
		ans = (ans + su) % mod;
	}
	cout << ans << endl;
	return 0;
}