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)

$mod = 10**9+7

def pow(a,b)
  if b == 1
    a
  elsif b%2 == 0
    (pow(a,b/2)**2)%$mod
  else
    (a*pow(a,b/2)**2)%$mod
  end
end

def create_fact(n)
  for i in 2..n
    $fact[i] = ($fact[i-1]*i)%$mod
  end
end

def create_fact_inv(n)
  $fact_inv[n] = pow($fact[n],$mod-2)
  n.downto(1) do |i|
    $fact_inv[i-1] = ($fact_inv[i]*i)%$mod
  end
end

def create_inv(n)
  for i in 1..n
    $inv[i] = ($fact[i-1]*$fact_inv[i])%$mod
  end
end

def create_table(n)
  $fact = Array.new(n+1,1)
  $fact_inv = Array.new(n+1,1)
  $inv = Array.new(n+1,0)
  create_fact(n)
  create_fact_inv(n)
  create_inv(n)
end

def combi(a,b)
  (($fact[a]*$fact_inv[b])%$mod)*$fact_inv[a-b]%$mod
end
$mod
create_table(500010)
n = gets.to_i
a = gets.split.map(&:to_i)
b = Array.new(n+1,0)
x = Array.new(n+1,0)
y = z = 1
x[0] = x[1] = 1
for i in 2..n
    if i%2 == 0
        x[i] += y
        z += x[i]
    else
        x[i] += z
        y += x[i]
    end
end

n.times do |i|
    b[i+1] = a[i]^b[i]
end
ans = 0
if b[-1] == 0
    cnt = Hash.new(0)
    place = Hash.new(-1)
    z = 0
    y = 0
    for i in 1..n
        if b[i] != 0 && place[b[i]] < z
            cnt[b[i]] += 1
            place[b[i]] = i
        elsif b[i] == 0
            z = i
            y += 1
        end
    end
    cnt.values.each do |i|
        ans += x[i*2]*2
        ans %= $mod
    end
    puts (ans+2**(y-1))%$mod
else
    $mod
    cnt = 0
    c = b[-1]
    place = -1
    z = 0
    y = 0
    for i in 1..n
        if b[i] == c && place < z
            cnt += 1
            place = i
        elsif b[i] == 0
            z = i
        end
    end
    puts x[cnt*2-1]
end