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<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}

vector<ll> cnt[1200005];
ll ar[500005]={0},rxor[500005]={0};
int main(){
  ll n;
  cin>>n;
  for(int i=1;i<=n;i++) {
    cin>>ar[i];
    rxor[i]=rxor[i-1]^ar[i];
  }
  if(rxor[n]==0){
    ll las=0,num=0;
    ll ans=0;
    vector<ll> comp;
    for(int i=1;i<=n;i++){
      if(rxor[i]==0){
        for(int j=las+1;j<i;j++){
          ll val=rxor[j]^rxor[las];
          cnt[val].push_back(num);
          comp.push_back(val);
        }
        las=i;
        num++;
      }
    }
    ans+=pow(2,num-1);
    ans%=mod;
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());
    for(int k=0;k<comp.size();k++){
      ll val=comp[k];
      vector<ll> dp,rsum;
      dp.push_back(1);
      rsum.push_back(1);
      for(int i=1;i<cnt[val].size();i++){
        dp.push_back(dp[i-1]+rsum[i-1]*(cnt[val][i]-cnt[val][i-1]));
        rsum.push_back(rsum[i-1]+dp[i]);
      }
      for(int i=0;i<cnt[val].size();i++){
        ans+=dp[i];
        ans%=mod;
      }
    }
    cout<<ans<<endl;
  }
  else{
    ll all_xor=rxor[n];
    ll las=0,num=0;
    for(int i=1;i<=n;i++){
      if((rxor[i]^rxor[las])==all_xor){
        num++;
        las=i;
      }
    }
    cout<<pow(2,(num-1)/2)<<endl;
  }
}