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 Kotlin (1.0.0) (judge verdict: Wrong Answer)

const val P = 1000000007L

fun solveCase(): Long {
  val n = readLine()!!.toInt()
  val xs = readLine()!!.map { it.toInt() }
  val xorArray = IntArray(n + 1)
  for (i in 1..n) {
    xorArray[i] = xorArray[i - 1] xor xs[i - 1]
  }
  val zeroCountArray = IntArray(n + 1)
  zeroCountArray[0] = 1
  for (i in 1..n) {
    zeroCountArray[i] = zeroCountArray[i - 1] + (if (xorArray[i] == 0) 1 else 0)
  }

  val indexLists = Array(1 shl 20, { mutableListOf<Int>() })
  for (i in 1..n) {
    if (xorArray[i] != 0) {
      indexLists[xorArray[i]].add(i)
    }
  }

  if (xorArray[n] != 0) {
    val x = xorArray[n]
    // println(indexLists[x])
    val xIndexArray = indexLists[x].toIntArray()
    if (xIndexArray.size == 1) return 1L

    val dp1 = LongArray(xIndexArray.size)
    val dp2 = LongArray(xIndexArray.size)
    dp1[0] = 1
    dp2[0] = 1
    for (i in 1 until dp1.size) {
      val zeroCountDiff = zeroCountArray[xIndexArray[i]] - zeroCountArray[xIndexArray[i - 1]]
      dp1[i] = dp2[i - 1] * zeroCountDiff  + dp1[i - 1]
      dp1[i] %= P
      dp2[i] = dp2[i - 1] + dp1[i]
      dp2[i] %= P
    }

    return dp1.last()
  }

//  println(xorArray.asList())
//  println(zeroCountArray.asList())
  var count = pow2(zeroCountArray.last() - 2)
  for (x in 1 until (1 shl 20)) {
    if (indexLists[x].isEmpty()) continue
//    println("x: $x")
//    println(indexLists[x])
    if (indexLists[x].size == 1) {
      count += 1
      count %= P
      // println("count: $count")
      continue
    }

    val xIndexArray = indexLists[x].toIntArray()
    val dp1 = LongArray(xIndexArray.size)
    val dp2 = LongArray(xIndexArray.size)
    dp1[0] = 1
    dp2[0] = 1
    for (i in 1 until dp1.size) {
      val zeroCountDiff = zeroCountArray[xIndexArray[i]] - zeroCountArray[xIndexArray[i - 1]]
      dp1[i] = dp2[i - 1] * zeroCountDiff  + dp1[i - 1]
      dp1[i] %= P
      dp2[i] = dp2[i - 1] + dp1[i]
      dp2[i] %= P
    }

    count += dp2.last()
    count %= P
    // println("count: $count")
  }
  return count
}

fun pow2(p: Int): Long {
  var ret = 1L
  repeat(p) {
    ret *= 2L
    ret %= P
  }
  return ret
}

fun main(args: Array<String>) {
  println(solveCase())
}