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: Wrong Answer)

const N: usize = 1 << 20;
const MOD: usize = 1e9 as usize + 7;
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a: Vec<usize> = sc.vec(n);
    let mut pos = vec![vec![]; N];

    let mut sum = 0;
    for i in 0..n {
        sum ^= a[i];
        pos[sum].push(i);
    }

    if sum == 0 {
        let mut ans = 0;
        for x in 1..N {
            ans += calc(&pos, x, n, 0);
            ans += MOD - 1;
            ans %= MOD;
        }

        let zero_count = pos[0].len();
        let mut pow = 1;
        for _ in 0..(zero_count - 1) {
            pow *= 2;
            pow %= MOD;
        }
        ans += pow;
        ans %= MOD;
        println!("{}", ans);
    } else {
        let ans = calc(&pos, sum, n, 1);
        println!("{}", ans);
    }
}

fn calc(pos: &[Vec<usize>], x: usize, n: usize, last: usize) -> usize {
    let mut cur_pos = 0;
    let mut zeros = vec![];
    while cur_pos < n {
        let next = pos[x].lower_bound(cur_pos);
        if next == pos[x].len() {
            let zero = pos[0].len() - pos[0].lower_bound(cur_pos);
            zeros.push(zero);
            break;
        } else {
            let next_pos = pos[x][next];
            let zero = pos[0].lower_bound(next_pos) - pos[0].lower_bound(cur_pos);
            cur_pos = next_pos + 1;
            zeros.push(zero);
        }
    }

    let n = zeros.len();
    let mut dp = vec![1, 0];
    for i in 0..(n - 1) {
        let count = zeros[i];
        dp = vec![(dp[0] + count * dp[1]) % MOD, dp[1]];
        dp = vec![dp[0], (dp[0] + dp[1]) % MOD];
    }

    let count = zeros[n - 1];
    dp = vec![(dp[0] + count * dp[1]) % MOD, dp[1]];
    dp[last]
}

trait LowerBound {
    fn lower_bound(&self, i: usize) -> usize;
}

impl LowerBound for Vec<usize> {
    fn lower_bound(&self, i: usize) -> usize {
        self.binary_search_by_key(&(i * 2 + 1), |&a| a * 2 + 2)
            .err()
            .unwrap()
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}