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 <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <unordered_map>
#include <set>
#include <limits>

typedef long long ll;
int N;
std::vector<int> A;
std::vector<int> B;

class MyPow {
  private:
  typedef long long ll;
  std::unordered_map<ll, ll> memo;
  ll a;

  public:
  ll MOD = std::numeric_limits<long long>::max();

  MyPow ( ll a_ ) : a(a_) {
    memo[0] = 1 % MOD;
    memo[1] = a % MOD;
  }

  ll power ( ll p ) {
    if ( memo.count(p) != 0 ) return memo[p];
    return memo[p] = ((power(p/2)%MOD) * (power(p-p/2)%MOD)) % MOD;
  }
};


ll do_dp ( int X ) {
  std::vector<std::unordered_map<int,ll>> dp(N+1);
  for(int i=0; i<N+1; i++) {
    dp[i][0] = 0;
    dp[i][X] = 0;
  }

  dp[0][0] = 1;
  dp[0][X] = 0;
  for(int i=1; i<=N; i++){
    if ( i == N ) {
      if ( B[i] == 0 ) {
        dp[i][0] = dp[i-1][X];
        dp[i][X] = dp[i-1][X];
      }
      else if ( B[i] == X ) {
        dp[i][X] = dp[i-1][0];
        dp[i][0] = dp[i-1][0];
      }
      continue;
    }
    if ( B[i] == 0 ) {
      dp[i][0] = dp[i-1][0] + dp[i-1][X];
      dp[i][X] = dp[i-1][X];
    }
    else if ( B[i] == X ) {
      dp[i][X] = dp[i-1][0] + dp[i-1][X];
      dp[i][0] = dp[i-1][0];
    }
    else {
      dp[i][X] = dp[i-1][X];
      dp[i][0] = dp[i-1][0];
    }
  }

  return dp[N][B[N]];
}

constexpr ll mod = 1000000007;

int main (void) {
  std::cin >> N;

  A.resize(N);
  for(int i=0; i<N; i++) std::cin >> A[i];

  B.resize(N+1);
  B[0] = 0; B[1] = A[0];
  for(int i=1; i<N; i++) B[i+1] = (B[i]^A[i]);

  std::set<int> S;
  for(int i=0; i<=N; i++) S.insert(B[i]);

  if ( B[N] != 0 ) std::cout << do_dp(B[N]) << std::endl;
  else {
    ll ans = 0;
    for(auto itr = S.begin(); itr != S.end(); ++itr){
      if ( *itr != 0 ) {
        ans += (do_dp(*itr) % mod) ;
        ans %= mod;
      }
      else {
        int count = 0;
        for(int i=0; i<=N; i++) if ( B[i] == 0 ) count++;
        MyPow p(2); p.MOD = mod;
        ans += p.power(count-2);
        ans %= mod;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}