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 Fortran (gfortran v4.8.4) (judge verdict: Accepted)

program xor_partitioning
  implicit none
  integer(8), parameter :: md = 1000000007_8
  integer, parameter :: p = 1048575
  integer :: n, a(500000) = 0, x(0:500000) = 0, m, i, k
  integer(8) :: ans = 0_8, dp0(0:p) = 1_8, dpx(0:p) = 0_8, dpz(0:p) = 0_8
  integer(8) :: prev0, prevx, next0, nextx
  read(*,*) n
  read(*,*) a(1:n)
  do i = 1, n
    x(i) = xor(x(i-1),a(i))
  end do
  if (x(n) == 0) then
    m = 1
    do i = 0, n-1
      if (x(i) == 0) then
        m = m+1
        cycle
      end if
      k = m-dpz(x(i))
      dp0(x(i)) = mod(dp0(x(i))+int(k,8)*dpx(x(i)),md)
      dpx(x(i)) = mod(dpx(x(i))+dp0(x(i)),md)
      dpz(x(i)) = int(m,8)
    end do
    ans = pow(2_8,m-2)
    do i = 0, p
      ans = mod(ans+dpx(i),md)
    end do
    write(*,'(i0)') ans
    stop
  end if
  prev0 = 1_8
  prevx = 0_8
  do i = 1, n
    next0 = prev0
    nextx = prevx
    if (x(i) == 0) next0 = mod(prev0+prevx,md)
    if (x(i) == x(n)) nextx = mod(prev0+prevx,md)
    prev0 = next0
    prevx = nextx
  end do
  write(*,'(i0)') prev0
contains
  integer(8) function pow(x,n)
    integer(8), intent(in) :: x
    integer, intent(in) :: n
    integer :: m
    integer(8) :: p
    pow = 1_8
    p = x
    m = n
    do while (m > 0)
      if (btest(m,0)) pow = mod(pow*p,md)
      p = mod(p*p,md)
      m = rshift(m,1)
    end do
  end
end program xor_partitioning