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: Runtime Error)

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug cerr << "-- " << __LINE__ << " --" << endl
#define MOD 1000000007
#define ALL(o) (o).begin(), (o).end()
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template <typename T> string to_string(const vector<T> &xs) {string s="["; for(int i=0;i<xs.size();i++) s += (i>0 ? " " : "") + to_string(xs[i]); return s + "]";}
template <typename T> ll argmax(const T &xs) {return distance(xs.begin(), max_element(xs.begin(), xs.end()));}
template <typename T> ll argmin(const T &xs) {return distance(xs.begin(), min_element(xs.begin(), xs.end()));}
ll nextLL(){ll x; scanf("%lld", &x); return x;}
int nextInt(){int x; scanf("%d", &x); return x;}
string nextString(){string s; cin >> s; return s;}



ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y);}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

template<typename T> T comb(ll n, ll k){
	T ret = 1;
	for(ll i=1;i<=k;i++) ret = ret * T(n - k + i) / T(i);
	return ret;
}


ll N;
vector<ll> a;


int main(void){
	cin >> N;
	for(int i=0;i<N;i++) a.pb(nextLL());
	vector<ll> sum(N+1);
	vector<ll> nextZeroIndex(N+1, LLONG_MAX);
	vector<ll> nextSameIndex(N+1, LLONG_MAX);
	vector<ll> firstShown(1048576, -1);
	vector<ll> lastIndex(N+1, -1);

	lastIndex[0] = 0;
	for(int i=0;i<N;i++){
		sum[i+1] = (sum[i] ^ a[i]);
		if (firstShown[sum[i+1]] == -1) firstShown[sum[i+1]] = i+1;
		if (lastIndex[sum[i+1]] != -1){
			nextSameIndex[lastIndex[sum[i+1]]] = i+1;
			if (sum[i+1] == 0){
				for(int j=lastIndex[0];j<=i;j++) nextZeroIndex[j] = i+1;
			}
		}
		lastIndex[sum[i+1]] = i+1;
	}

	llm ans(0);

	// each XOR == i > 0 のケースを数える．
	for(int i=1;i<1048576;i++){
		if (firstShown[i] == -1) continue;
		if (sum[N] != 0 && i != sum[N]) continue;

		ll now = firstShown[i];
		llm cum0(1), cumi(1);
		while(1){
			if (now == LLONG_MAX) break;
			if (nextSameIndex[now]==LLONG_MAX && nextZeroIndex[now]==LLONG_MAX) break;
			if (nextSameIndex[now] > nextZeroIndex[now]){ // i よりも 0 が先に来る場合
				ll zeroCount = 0; // 次の i までに 0 が何個登場するか．
				ll pos = nextZeroIndex[now];
				while(nextSameIndex[now] > pos){
					zeroCount++;
					pos = nextZeroIndex[pos];				
				}
				cum0 += cumi * llm(zeroCount);
				if (nextSameIndex[now] < LLONG_MAX) cumi += cum0;
			}else{ // 0 よりも i が先に来る場合
				cumi += cum0;
			}
			now = nextSameIndex[now];
		}
		if (sum[N] == 0){
			// cerr << i << ":" << cumi << endl;
			ans += cumi;
		}else if (sum[N] == i){
			// cerr << i << ":" << cum0 << endl;
			ans += cum0;
		}
	}
	// each XOR == 0 のケースを数える．
	if (sum[N] == 0){
		llm p(1);
		for(int i=1;i<N;i++) if (sum[i]==0) p *= llm(2);
		ans += p;
	}


	cout << ans << endl;

    return 0;
}