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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int mod = 1e9+7;

struct DP {
    int prvDp, prvZeroes, odd, even; bool isOdd;
};

int expo(int b, int p) {
    if (p == 0) return 1;
    if (p == 1) return b;

    int x = expo(b, p/2);
    x = (int) (((ll)x*x) % mod);
    if (p&1) x = (int) (((ll)x*b) % mod);
    return x;
}

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    int a[n], all = 0;

    FOR(i,0,n-1){
        cin >> a[i];
        all ^= a[i];
    }

    if (all != 0) {
        int cur = 0;
        map<int, int> cnt;
        cnt[0] = 1;
        int dp = 0;
        FOR(i,0,n-1){
            cur ^= a[i];
            dp = cnt[all^cur];
            cnt[cur] = (cnt[cur] + dp) % mod;
        }
        cout << dp << endl;

        //dp[i] = sum(dp[j < i] st. xor[j,i] = all);
    } else {
        map<int, DP> trk;
        int curZeroes = 0, cur = 0;
        FOR(i,0,n-1){
            cur ^= a[i];
            if (cur == 0) ++curZeroes;
            else {
                if (trk.count(cur)) {
                    int zeroes = curZeroes - trk[cur].prvZeroes;
                    int dp, last = (int) (((ll)trk[cur].prvDp * (zeroes+1)) % mod);
                    if (trk[cur].isOdd) {
                        trk[cur].odd = (trk[cur].odd + last) % mod;
                        dp = trk[cur].odd;
                    } else {
                        trk[cur].even = (trk[cur].even + last) % mod;
                        dp = trk[cur].even;
                    }
                    trk[cur].prvDp = (dp+1) % mod;
                    trk[cur].prvZeroes = curZeroes;
                    trk[cur].isOdd = !trk[cur].isOdd;
                } else {
                    trk[cur] = {1,curZeroes,0,0,true};
                }
            }

            //if (cur == 0) cout << "| ";
            //else cout << cur << ' ';
        }
        //cout << endl;

        int ans = expo(2, curZeroes-1);
        for (auto x : trk) {
            //cout << x.fi << " :: " << x.sc.prvDp << endl;
            ans = (ans + x.sc.prvDp) % mod;
        }
        cout << ans << '\n';

        //dp[i] += dp[x]*(curZeroes - prvZeroes+1);
        //dp[i] += dp[x]*(zeroes+1); for all odd x if last element is odd
        //                           for all even x if last element is even

        //int bleh = 0;
        //map<int, int> counter;
        //FOR(i,0,(1<<(n-1))-1) {
        //    int cur = 0, prv = -1, ok = true;
        //    FOR(j,0,n-1){
        //        cur ^= a[j];
        //        if ((i&(1<<j)) or j == n-1) {
        //            if (prv == -1) prv = cur;
        //            else if (prv != cur) { ok = false; break; }
        //            cur = 0;
        //            //cout << "\tSPLIT " << j << " :: " << cur << endl;
        //        }
        //    }

        //    //cout << i << " :: " << ok << endl;

        //    //if (ok) cout << "BLEH " << i << endl;
        //    //else cout << "NO" << endl;
        //    if (ok) ++bleh, ++counter[prv];
        //}
        //cout << "---DEBUG---" << endl;
        //cout << bleh << endl;
        //for (auto& x : counter) cout << x.fi << " = " << x.sc << endl;
    }
}