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# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		long[]A = new long[N];
		long[]S = new long[N+1];
      	long[]S0 = new long[N+1];
      	long mod = 1000000007;
		string[]str = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = long.Parse(str[i]);
		}
		for(var i=0;i<N;i++){
			long c = 1;
			for(var j=0;j<21;j++){
				if(A[i]/c%2 + S[i]/c%2==1){
					S[i+1] += c;
                }
                S0[i+1] = S0[i];
                if(S[i+1] == 0){
                	S0[i+1]++;
                }
				c *= 2;
			}
		}
		long ans = 0;
		if(S[N]==0){
			long[]D0 = new long[2000000];
			long[]DX = new long[2000000];
			long[]DL = new long[2000000];
			D0[0] = 1;
			for(var i=1;i<N;i++){
				if(S[i]>0){
					if(DX[S[i]]==0){
						DX[S[i]] = 1;
					} else {
						D0[S[i]] += 1 + DX[S[i]] * (S0[i] - DL[S[i]]);
						DX[S[i]] += 1 + DX[S[i]] * (S0[i] - DL[S[i]]);
						D0[S[i]] %= mod;
						DX[S[i]] %= mod;
					}
					DL[S[i]] = S0[i];
				} else {
					D0[0] = D0[0] * 2 % mod;
				}
			}
			for(var i=1;i<2000000;i++){
              	D0[i] = DX[i];
            }
			for(var i=0;i<2000000;i++){
				ans = (ans + D0[i]) % mod;
			}
		} else {
			long D0 = 1;
			long DX = 0;
			for(var i=1;i<N;i++){
				if(S[i]==S[N]){
					DX = (D0+DX) % mod;
				} else if(S[i]==0){
					D0 = (D0+DX) % mod;
				}
			}
          	DX = D0;
			ans = DX;
		}
      	Console.WriteLine(ans);
        //for(var i=0;i<=30;i++){
        //  Console.Write(D0[i]+" ");
        //}
      	//Console.WriteLine();
        //for(var i=0;i<=30;i++){
        //  Console.Write(DX[i]+" ");
        //}
      	//Console.WriteLine();
      	//for(var i=0;i<=N;i++){
        //  Console.Write(S0[i]);
        //}
      	//Console.WriteLine();
      	//for(var i=0;i<=N;i++){
        //  Console.Write(S[i]);
        //}
    }
}