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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)


import java.util.*;

public class Main {

    long MOD = (long) 1e9 + 7;

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n + 1];
        int[] c0 = new int[n + 1];
        c0[0] = 1;

        HashMap<Integer, ArrayList<Integer>> map = new HashMap<>();

        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            b[i] ^= b[i - 1] ^ a[i];
            c0[i] = c0[i - 1] + (b[i] == 0 ? 1 : 0);
            if (b[i] != 0) {
                ArrayList<Integer> l = map.getOrDefault(b[i], new ArrayList<>());
                l.add(i);
                map.put(b[i], l);
            }
        }

//        debug(a);
//        debug(b);
//        debug(c0);
//        debug(map);

        if (b[n] != 0) {
            long[] z = new long[2];
            long[] x = new long[2];

            int f = 0;
            z[0] = 1;

            for (int i = 1; i <= n; i++) {
                f = 1 - f;
                z[f] = (z[1 - f] + (b[f] == b[n] ? x[1 - f] : 0)) % MOD;
                x[f] = (x[1 - f] + (b[f] == 0 ? z[1 - f] : 0)) % MOD;
//                debug(x[f], z[f]);
            }

            System.out.println(x[f]);
        } else {
            long ans = 1;
            for (int i = 1; i <= c0[n] - 2; i++) ans = (ans * 2) % MOD;
            for (Map.Entry<Integer, ArrayList<Integer>> entry: map.entrySet()) {
                long[] z = new long[2];
                long[] x = new long[2];

                int f = 0;
                z[0] = 1;

                ArrayList<Integer> ps = entry.getValue();
                int len = ps.size();
                for (int i = 1; i < len; i++) {
                    f = 1 - f;
                    z[f] = (z[1 - f] + x[1 - f] * (c0[ps.get(i)] - c0[ps.get(i - 1) - 1]) + 1) % MOD;
                    x[f] = (x[1 - f] + z[1 - f] * (c0[ps.get(i)] - c0[ps.get(i - 1) - 1]) + 1) % MOD;
//                    debug(entry.getKey(), z[f], x[f]);
                }
//                debug(entry.getKey(), x[f], z[f]);
                ans = (ans + x[f] + 1) % MOD;
            }
            System.out.println(ans);
        }

    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}