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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using SB = System.Text.StringBuilder;
//using System.Threading.Tasks;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using System.Numerics;
using static System.Math;
using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    readonly int dom = 998244353;
    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanint;

        var sum = new int[N + 1];
        int zerocnt = 0;
        ModInt ans = 0;

        for (int i = 0; i < N; i++)
        {
            sum[i + 1] = sum[i] ^ A[i];
            if (sum[i + 1] == 0) zerocnt++;
        }

        int MAX = 1 << 20;
        if (sum[N] == 0)
        {
            ans += ModInt.Pow(2, zerocnt - 1);

            //sum.join();

            //WriteLine(ans);
            var ONE = new ModInt[MAX];
            var ZERO = new RangeAddFenwickTree(MAX);
            ZERO.Add(1, MAX, 1);

            var lazy = new ModInt[MAX];
            for (int i = 1; i < MAX; i++)
            {
                lazy[i] = 1;
            }

            for (int i = 1; i < N; i++)
            {
                if (sum[i] != 0)
                {
                    int Z = sum[i];
                    //ZEROがX回来ていた.
                    var X = ZERO[Z, Z] % mod;
                    if (X != 0)
                    {
                        lazy[Z] += X * ONE[Z];
                        if (X != 0) ZERO.Add(Z, Z, mod - X);
                    }
                    ONE[Z] += lazy[Z];                  

                }
                else
                {
                    ZERO.Add(1, MAX, 1);
                }
            }


            for (int i = 1; i < MAX; i++)
            {
                ans += ONE[i];
            }


            WriteLine(ans);
        }


        else
        {
            int X = sum[N];
            var dp = new ModInt[2];
            dp[0] = 1;
            for (int i = 1; i < N; i++)
            {
                if (sum[i] == X)
                {
                    dp[1] += dp[0];
                }
                else if (sum[i] == 0)
                {
                    dp[0] += dp[1];
                }
            }
            WriteLine(dp[0]);
        }

    }

}


/// <OriginalAuthor>riantkb</OriginalAuthor>
class LazySegtree<T, U>
{
    readonly int n;
    T[] data;
    U[] lazy;
    readonly bool[] is_lazy;
    readonly Func<T, T, T> calc;
    readonly Func<T, U, int, T> apply;
    readonly Func<U, U, U> merge;
    readonly T ex_data;

    /// <summary>
    /// 遅延セグメントツリーの構築
    /// </summary>
    /// <param name="m">要素数</param>
    /// <param name="calc">要素のマージ</param>
    /// <param name="apply">要素に作用素を作用</param>
    /// <param name="merge">作用素のマージ</param>
    /// <param name="ex_data">単位元</param>
    public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data)
    {
        this.calc = calc;
        this.apply = apply;
        this.merge = merge;
        this.ex_data = ex_data;
        n = 1;
        while (n < m) n <<= 1;
        data = new T[n * 2 - 1];
        lazy = new U[n * 2 - 1];
        is_lazy = new bool[n * 2 - 1];
        for (int i = 0; i < data.Length; i++) data[i] = ex_data;
    }
    public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, T ini) : this(m, calc, apply, merge, ex_data)
    {
        for (int i = 0; i < m; i++) data[i + n - 1] = ini;
        for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]);
    }
    public LazySegtree(int m, Func<T, T, T> calc, Func<T, U, int, T> apply, Func<U, U, U> merge, T ex_data, IList<T> ini) : this(m, calc, apply, merge, ex_data)
    {
        for (int i = 0; i < m; i++) data[i + n - 1] = ini[i];
        for (int i = n - 2; i >= 0; i--) data[i] = calc(data[i * 2 + 1], data[i * 2 + 2]);
    }
    void assign_lazy(int k, U x)
    {
        if (k >= lazy.Length) return;
        if (is_lazy[k]) lazy[k] = merge(lazy[k], x);
        else
        {
            is_lazy[k] = true;
            lazy[k] = x;
        }
    }
    void eval(int k, int len)
    {
        if (!is_lazy[k]) return;
        assign_lazy(k * 2 + 1, lazy[k]);
        assign_lazy(k * 2 + 2, lazy[k]);
        data[k] = apply(data[k], lazy[k], len);
        is_lazy[k] = false;
    }
    T update(int s, int t, U x, int k, int l, int r)
    {
        eval(k, r - l);
        if (r <= s || t <= l) return data[k];
        if (s <= l && r <= t)
        {
            assign_lazy(k, x);
            return apply(data[k], lazy[k], r - l);
        }
        return data[k] = calc(update(s, t, x, k * 2 + 1, l, (l + r) / 2),
                              update(s, t, x, k * 2 + 2, (l + r) / 2, r));
    }
    T run(int s, int t, int k, int l, int r)
    {
        eval(k, r - l);
        if (r <= s || t <= l) return ex_data;
        if (s <= l && r <= t) return data[k];
        return calc(run(s, t, k * 2 + 1, l, (l + r) / 2),
                    run(s, t, k * 2 + 2, (l + r) / 2, r));
    }

    /// <summary>update [s, t]</summary>
    public void Update(int s, int t, U x) { t++; update(s, t, x, 0, 0, n); }
    /// <summary>return node[s, t]</summary>
    public T this[int s, int t] => Run(s, t);
    T Run(int s, int t) { t++; return run(s, t, 0, 0, n); }
}


/// <OriginalAuthor>camypaper</OriginalAuthor>
class FenwickTree
{
    readonly int n;
    readonly long[] bit;
    readonly int max = 1;
    public FenwickTree(int size)
    {
        n = size; bit = new long[n + 1];
        while ((max << 1) <= n) max <<= 1;
    }
    /// <summary>sum[a, b] 0-indexed</summary>
    public long this[int i, int j] { get { i++; j++; return i <= j ? this[j] - this[i - 1] : 0; } }
    /// <summary>sum[1, i] 1-indexed</summary>
    public long this[int i] { get { long s = 0; for (; i > 0; i -= i & -i) s += bit[i]; return s; } }
    public int LowerBound(long w)
    {
        if (w <= 0) return 0;
        int x = 0;
        for (int k = max; k > 0; k >>= 1)
            if (x + k <= n && bit[x + k] < w)
            {
                w -= bit[x + k];
                x += k;
            }
        return x + 1;
    }
    /// <summary>add v to bit[i] 0-indexed</summary>
    public void Add(int i, long v)
    {
        i++;
        //if (i == 0) System.Diagnostics.Debug.Fail("BIT is 1 indexed");
        for (; i <= n; i += i & -i) bit[i] += v;
    }
    public long[] Items
    {
        get
        {
            var ret = new long[n + 1];
            for (int i = 0; i < ret.Length; i++)
                ret[i] = this[i, i];
            return ret;
        }
    }
}

class RangeAddFenwickTree
{
    readonly int n;
    FenwickTree a, b;
    public RangeAddFenwickTree(int n)
    {
        this.n = n;
        a = new FenwickTree(n);
        b = new FenwickTree(n);
    }
    /// <summary>Add V to[i, j] 0-indexed</summary>
    public void Add(int i, int j, long v)
    {
        //a.Add(i, -(i - 1) * v); a.Add(j + 1, j * v);
        //b.Add(i, v); b.Add(j + 1, -v);
        a.Add(i, -i * v); a.Add(j + 1, (j + 1) * v);
        b.Add(i, v); b.Add(j + 1, -v);
    }
    /// <summary>Sum [1, i] 1-indexed</summary>
    public long this[int i] => a[i] + b[i] * i;
    /// <summary>Sum [i, j] 0-indexed</summary>
    public long this[int i, int j] { get { i++; j++; return i <= j ? this[j] - this[i - 1] : 0; } }
    public long[] Items
    {
        get
        {
            var ret = new long[n + 1];
            for (int i = 0; i < ret.Length; i++)
                ret[i] = this[i, i];
            return ret;
        }
    }
}


/// <summary>
/// [0,<see cref="Mod"/>) までの値を取るような数
/// </summary>
/// <OriginalAuthor>camypaper</OriginalAuthor>
struct ModInt
{
    /// <summary>
    /// 剰余を取る値．
    /// </summary>
    public const long Mod = (int)1e9 + 7;

    /// <summary>
    /// 実際の数値．
    /// </summary>
    public long num;
    /// <summary>
    /// 値が <paramref name="n"/> であるようなインスタンスを構築します．
    /// </summary>
    /// <param name="n">インスタンスが持つ値</param>
    /// <remarks>パフォーマンスの問題上，コンストラクタ内では剰余を取りません．そのため，<paramref name="n"/> ∈ [0,<see cref="Mod"/>) を満たすような <paramref name="n"/> を渡してください．このコンストラクタは O(1) で実行されます．</remarks>
    public ModInt(long n) { num = n; }
    /// <summary>
    /// このインスタンスの数値を文字列に変換します．
    /// </summary>
    /// <returns>[0,<see cref="Mod"/>) の範囲内の整数を 10 進表記したもの．</returns>
    public override string ToString() { return num.ToString(); }
    public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
    public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
    public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
    public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

    /// <summary>
    /// 与えられた 2 つの数値からべき剰余を計算します．
    /// </summary>
    /// <param name="v">べき乗の底</param>
    /// <param name="k">べき指数</param>
    /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
    public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

    /// <summary>
    /// 与えられた 2 つの数値からべき剰余を計算します．
    /// </summary>
    /// <param name="v">べき乗の底</param>
    /// <param name="k">べき指数</param>
    /// <returns>繰り返し二乗法により O(N log N) で実行されます．</returns>
    public static ModInt Pow(long v, long k)
    {
        long ret = 1;
        for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
            if ((k & 1) == 1) ret = ret * v % Mod;
        return new ModInt(ret);
    }
    /// <summary>
    /// 与えられた数の逆元を計算します．
    /// </summary>
    /// <param name="v">逆元を取る対象となる数</param>
    /// <returns>逆元となるような値</returns>
    /// <remarks>法が素数であることを仮定して，フェルマーの小定理に従って逆元を O(log N) で計算します．</remarks>
    public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
}

class BinomialCoefficient
{
    public ModInt[] fact, ifact;
    public BinomialCoefficient(int n)
    {
        fact = new ModInt[n + 1];
        ifact = new ModInt[n + 1];
        fact[0] = 1;
        for (int i = 1; i <= n; i++)
            fact[i] = fact[i - 1] * i;
        ifact[n] = ModInt.Inverse(fact[n]);
        for (int i = n - 1; i >= 0; i--)
            ifact[i] = ifact[i + 1] * (i + 1);
        ifact[0] = ifact[1];
    }
    public ModInt this[int n, int r]
    {
        get
        {
            if (n < 0 || n >= fact.Length || r < 0 || r > n) return 0;
            return fact[n] * ifact[n - r] * ifact[r];
        }
    }
    public ModInt RepeatedCombination(int n, int k)
    {
        if (k == 0) return 1;
        return this[n + k - 1, k];
    }
}

static class Ex
{
    public static void join<T>(this IEnumerable<T> values, string sep = " ") => WriteLine(string.Join(sep, values));
    public static string concat<T>(this IEnumerable<T> values) => string.Concat(values);
    public static string reverse(this string s) { var t = s.ToCharArray(); Array.Reverse(t); return t.concat(); }

    public static int lower_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) < 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
    public static int upper_bound<T>(this IList<T> arr, T val) where T : IComparable<T>
    {
        int low = 0, high = arr.Count;
        int mid;
        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid].CompareTo(val) <= 0) low = mid + 1;
            else high = mid;
        }
        return low;
    }
}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f; public U s;
    public Pair(T f, U s) { this.f = f; this.s = s; }
    public int CompareTo(Pair<T, U> a) => f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    public override string ToString() => $"{f} {s}";
}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan => ReadLine().Split();
    public int[] scanint => Array.ConvertAll(scan, int.Parse);
    public long[] scanlong => Array.ConvertAll(scan, long.Parse);
    public double[] scandouble => Array.ConvertAll(scan, double.Parse);
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint => int.Parse(next);
    public long nextlong => long.Parse(next);
    public double nextdouble => double.Parse(next);
}