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 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

signed main(){
	int M = ((int)1 << 21);
	int N, i, x;
	scanf("%lld", &N);
	int *a = (int *)malloc(sizeof(int) * (N + 1));
	int *s = (int *)malloc(sizeof(int) * (N + 1));
	s[0] = 0;
	int *Onum = (int *)malloc(sizeof(int) * (N + 1));
	Onum[0] = 0;
	for(i = 1; i <= N; i++){
		scanf("%lld", &a[i]);
		s[i] = (s[i - 1] ^ a[i]);
		Onum[i] = Onum[i - 1] + (s[i] == 0 ? 1 : 0);
	}
/*	printf("s:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", s[i]);
	}
	printf("\n");
	printf("Onum:\n");
	for(i = 0; i <= N; i++){
		printf("%lld ", Onum[i]);
	}
	printf("\n");
*/	int *prev = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		prev[i] = -1;
	}
	int *dp = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		dp[i] = 0;
	}
	int *sum = (int *)malloc(sizeof(int) * M);
	for(i = 0; i < M; i++){
		sum[i] = 0;
	}
	for(i = 1; i <= N; i++){
		x = s[i];
		if(prev[x] == -1){
			dp[x] = 1;
			sum[x] = 1;
		}
		else{
			dp[x] = MOD(sum[x] * (Onum[i] - Onum[prev[x]]) + 1);
			sum[x] = MOD(sum[x] +dp[x]);
		}
		prev[x] = i;
//		printf("i = %lld\n", i);
//		printf("dp[%lld] = %lld\n", x, dp[x]);
//		printf("sum[%lld] = %lld\n", x, sum[x]);
	}
	int ans = 0;
	for(i = 1; i < M; i++){
		if(s[N] != 0 && s[N] != i){
			continue;
		}
		else if(s[N] == 0){
			ans = MOD(ans + sum[i]);
		}
		else{
			ans = MOD(ans + dp[i]);
		}
	}
	if(s[N] == 0){
		ans = MOD(ans + power(2, Onum[N] - 1));
	}
	printf("%lld\n", ans);
	return 0;
}