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 Haskell (GHC 7.10.3) (judge verdict: Wrong Answer)

{-# LANGUAGE BangPatterns #-}
import Data.Int
import Data.Char
import Data.Bits
import Data.Monoid
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntMap.Strict as IntMap

modulo = 10^9+7 :: Int64
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y = (x + y) `rem` modulo
subMod !x !y = (x - y) `mod` modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  N x + N y = N ((x + y) `rem` modulo)
  N x - N y = N ((x - y) `mod` modulo)
  N x * N y = N ((x * y) `rem` modulo)
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

powMod :: Int64 -> Int64 -> Int64 -> Int64
powMod !_ 0 !_ = 1
powMod !a b !modulo = loop a a (b - 1)
  where
    loop :: Int64 -> Int64 -> Int64 -> Int64
    loop !acc !a 0 = acc
    loop !acc !a 1 = (acc * a) `rem` modulo
    loop !acc !a i = case i `quotRem` 2 of
                       (j,0) -> loop acc ((a * a) `rem` modulo) j
                       (j,_) -> loop ((acc * a) `rem` modulo) ((a * a) `rem` modulo) j

main = do
  n <- readLn
  xs <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let ys = U.scanl xor 0 xs
  let z = U.last ys
  if z /= 0
    then let f ys = let (ys0, ys1) = U.span (== 0) ys
                        (ys', ys'') = U.span (/= 0) ys1
                        l = U.length ys0
                        k = U.length $ U.filter (== z) ys'
                    in if U.null ys''
                       then fromIntegral l
                       else (fromIntegral l * fromIntegral k) * f ys'' + 1
         in print (f ys :: N)
    else let f :: U.Vector Int -> (Int, IntMap.IntMap N, IntMap.IntMap N)
             f ys = let (ys0, ys1) = U.span (== 0) ys
                        (ys', ys'') = U.span (/= 0) ys1
                        l = U.length ys0
                    in if U.null ys1
                       then (l, IntMap.empty, IntMap.empty)
                       else let (l0, s, t) = f ys''
                                tx = IntMap.fromListWith (+) [(a, IntMap.findWithDefault 1 a t) | a <- U.toList ys']
                                s' = IntMap.unionWith (+) s tx
                                t' = IntMap.unionWith (+) (fmap (fromIntegral l *) s') $ IntMap.union t tx
                                !l' = l0 + l
                            in (l', s', t')
             !(ll, ss, tt) = f ys
         in print (2 ^ (ll - 2) + getSum (IntMap.foldMapWithKey (\k v -> Sum v) ss) :: N)