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 Rust (1.15.1) (judge verdict: Runtime Error)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut ac: Vec<usize> = vec![0; n + 1];
    for i in 0..n {
        ac[i + 1] = ac[i] ^ v[i];
    }
    let mut ans;
    let d = 1000000007;
    if ac[n] != 0 {
        let mut ls: Vec<usize> = Vec::new();
        let mut prev = 0;
        let mut c = 1;
        for i in 0..n {
            if ac[i + 1] == ac[n] || ac[i + 1] == 0 {
                if ac[i + 1] == prev {
                    c += 1;
                } else {
                    ls.push(c);
                    c = 0;
                    prev = ac[i + 1];
                }
            }
        }
        if c > 0 {
            ls.push(c);
        }
        ans = solve(&ls, d);
    } else {
        let mut zs: Vec<usize> = vec![0; n + 1];
        zs[0] = 1;
        for i in 0..n {
            zs[i + 1] = zs[i];
            if ac[i + 1] == 0 {
                zs[i + 1] += 1;
            }
        }
        ans = pow_m(2, zs[n] - 2, d);
        let mut map: HashMap<usize, Vec<usize>> = HashMap::new();
        for (i, x) in ac.iter().enumerate().filter(|x| *x.1 != 0) {
            map.entry(*x).or_insert(vec![0]).push(i);
        }
        for locs in map.values() {
            let mut ls: Vec<usize> = vec![zs[locs[1]]];
            let mut c = 1;
            for i in 1..locs.len() - 1 {
                let z = zs[locs[i + 1]] - zs[locs[i]];
                if z > 0 {
                    ls.push(c);
                    ls.push(z);
                    c = 1;
                } else {
                    c += 1;
                }
            }
            ls.push(c);
            let z = zs[n] - zs[locs[locs.len() - 1]];
            if z > 0 {
                ls.push(z);
            }
            ans = (ans + solve(&ls, d)) % d;
        }
    }
    println!("{}", ans);
}

fn solve(ls: &Vec<usize>, d: usize) -> usize {
    let n = ls.len();
    let mut dp: Vec<Vec<usize>> = vec![vec![0; 2]; n - 1];
    dp[0][0] = 1;
    for i in 1..n - 1 {
        if i % 2 == 0 {
            dp[i][0] = (dp[i - 1][0] + dp[i - 1][1] * ls[i]) % d;
            dp[i][1] = dp[i - 1][1];
        } else {
            dp[i][0] = dp[i - 1][0];
            dp[i][1] = (dp[i - 1][0] * ls[i] + dp[i - 1][1]) % d;
        }
    }
    if n % 2 == 1 {
        dp[n - 2][1]
    } else {
        dp[n - 2][0]
    }
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut ret = 1;
    let mut r = n;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}