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: Accepted)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int MAXN = 5e5 + 5, MAXM = 2e5 + 5, BOUND = 1e7, MOD = 1e9 + 7, INF = 0x3f3f3f3f, base = 10000;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0), eps = 1e-9;
#define mid l + ((r-l)>>1)
#define lson o<<1,l,m
#define rson o<<1|1,m+1,r
#define lc(x) ch[x][0]
#define pii pair<int,int>
#define vi vector<int>
#define RR register int
#define rc(x) ch[x][1]
#define rep(i,a,b) for(RR i=(a);i<=(b);++i)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
int n, a[MAXN], sum[MAXN], b[MAXN];
vi pos[MAXN];
inline void add(int &x, int y) {
	x += y;
	if (x >= MOD)x -= MOD;
}
inline int get_v(int x, int y) {
	if (x > y)swap(x, y);
	return sum[y] - sum[x - 1];
}
int main() {
	cin >> n;
	int k = 0;
	rep(i, 1, n)cin >> a[i], k ^= a[i], a[i] = k, b[i] = a[i];
	b[k = n + 1] = 0;
	sort(b + 1, b + 1 + k);
	k = unique(b + 1, b + 1 + k) - b - 1;
	rep(i, 1, n) {
		a[i] = lower_bound(b + 1, b + 1 + k, a[i]) - b;
		pos[a[i]].push_back(i);
		sum[i] = sum[i - 1] + (a[i] == 1);
	}
	int ans = 0;
	if (a[n] == 1) {
		ans = 1;
		rep(j, 2, pos[1].size())ans = ans * 2 % MOD;
	}
	rep(i, 2, k) {
		if (a[n] != i && a[n] != 1)continue;
		int pre = 0, odd = 0, even = 1;
		for (int j = 0; j < pos[i].size(); j++) {
			int x = get_v(pre, pos[i][j]);
			add(even, (ll)odd * x%MOD);
			add(odd, even);
			pre = pos[i][j] + 1;
		}
		if (a[n] == 1) {
			add(ans, odd);
		}
		else {
			add(ans, even);
		}
	}
	cout << ans << '\n';
	return 0;
}