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: Accepted)

// https://atcoder.jp/contests/diverta2019/tasks/diverta2019_e
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MAX: usize = 1<<20;
const MOD: i64 = 1e9 as i64 + 7;

fn make(a: &Vec<usize>, want: usize) -> i64 {
    let n = a.len();
    let mut xorsum = vec![0; n+1];
    for i in 0..n {
        xorsum[i+1] = xorsum[i] ^ a[i];
    }
    let mut dp = vec![0i64; n+1];
    dp[0] = 1;
    for t in 1..n+1 {
        for f in 0..t {
            let xor = xorsum[t] ^ xorsum[f];
            if xor == want {
                dp[t] += dp[f];
                dp[t] %= MOD;
            }
        }
    }
    dp[n]
}

fn main() {
    input! {
        n: usize,
        a: [usize; n]
    };

    // {
    //     let mut tt = 0;
    //     for i in 0..16  {
    //         let w = make(&a, i);
    //         debug!(i, w);
    //         tt += w;
    //     }
    //     tt %= MOD;
    //     debug!(tt);
    // }

    let mut xorsum = vec![0; n+1];
    for i in 0..n {
        xorsum[i+1] = xorsum[i] ^ a[i];
    }


    let mut dp = vec![0; MAX];
    let mut dp_zero = vec![0; MAX];
    let mut last_zero = vec![0; MAX];

    let mut idx = n;
    let mut mode = xorsum[n];
    let mut zero_count = 0;
    if mode == 0 {
        for i in 1..MAX {
            dp_zero[i] = 1;
        }
    } else {
        dp[mode] = 1;
    }

    loop {
        let mut histories = vec![];
        while idx >= 0 && xorsum[idx] != 0 {
            histories.push(xorsum[idx]);
            idx -= 1;
        }

        histories.sort();
        let hn = histories.len();
        let mut fr = 0;
        while fr < hn {
            let mut to = fr;
            while to < hn && histories[to] == histories[fr] {
                to += 1;
            }
            let count = (to - fr) as i64;
            let num = histories[fr];

            let add_zero = zero_count - last_zero[num];
            last_zero[num] = zero_count;
            dp_zero[num] += add_zero * dp[num] % MOD;
            dp_zero[num] %= MOD;

            dp[num] += count * dp_zero[num] % MOD;
            dp[num] %= MOD;

            // debug!(num, last_zero[num], zero_count, dp_zero[num], dp[num]);

            fr = to;
        }

        while idx >= 1 && xorsum[idx] == 0 {
            idx -= 1;
            zero_count += 1;
        }

        if idx == 0 {
            break;
        }
    }

    let mut ans = 0;
    if mode == 0 {
        for w in 1..MAX {
            ans += dp[w];
            ans %= MOD;
        }
        let mut count = 1;
        for i in 1..n {
            if xorsum[i] == 0 {
                count *= 2;
                count %= MOD;
            }
        }
        ans += count;
        ans %= MOD;
    } else {
        ans = dp[mode];
    }
    println!("{}", ans);
}