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 Ruby (2.3.3) (judge verdict: Wrong Answer)

def modpow(x,n)
  ret = 1
  while n > 0
    ret = (ret * x) % MOD if n&1 == 1
    x = (x*x) % MOD
    n >>= 1
  end
  return ret
end

N = gets.to_i
a = gets.split.map(&:to_i)
MOD = 10**9+7
csum = [0]*(N+1)
N.times do |i|
  csum[i+1] = csum[i] ^ a[i]
end

if csum[-1] != 0
  dp = Array.new(N+1){[1,0]}
  N.times do |i|
    if csum[i+1] == 0
      dp[i+1][0] = (dp[i][0] + dp[i][1]) % MOD
      dp[i+1][1] = dp[i][1]
    elsif csum[i+1] == csum[-1]
      dp[i+1][1] = (dp[i][0] + dp[i][1]) % MOD
      dp[i+1][0] = dp[i][0]
    else
      dp[i+1][0] = dp[i][0]
      dp[i+1][1] = dp[i][1]
    end
  end
  p (dp[N][1]-1) % MOD
else
  cnt = 0
  prev = [0]*(2**20)
  rle = Array.new(2**20){[]}
  N.times do |i|
    if csum[i+1] == 0
      cnt += 1
    else
      x = csum[i+1]
      rle[x] << [0,cnt-prev[x]] if cnt > prev[x]
      rle[x] << [x,1]
      prev[x] = cnt
    end
  end

  ans = 0
  rle.each do |cs|
    dp = [[1,0]]
    cs.each do |x,k|
      if x == 0
        a0 = dp[-1][0] + dp[-1][1] * k
        a0 %= MOD
        dp << [a0,dp[-1][1]]
      else
        a1 = dp[-1][0] * k + dp[-1][1]
        a1 %= MOD
        dp << [dp[-1][0],a1]
      end
    end
    ans += (dp[-1][1]) % MOD
  end
  p (ans+modpow(2,cnt-1)) % MOD
end