PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000152. Đếm đoạn có tổng bằng XOR (Xor Sum 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm đoạn có tổng bằng XOR (Xor Sum 2)

Xor Sum 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given nonnegative integers a1,a2,…,ana_1,a_2,\ldots,a_n, count the nonempty intervals [l,r][l,r] (1≤l≤r≤n1\le l\le r\le n) satisfying al⊕⋯⊕ar=al+⋯+ara_l\oplus\cdots\oplus a_r=a_l+\cdots+a_r. Here ⊕\oplus is bitwise XOR: a result bit is set precisely when an odd number of operands have that bit set. For instance, 3⊕5=63\oplus5=6.

Input

  • Line 1: integer nn, the number of elements.
  • Line 2: nn integers a1,…,ana_1,\ldots,a_n in order.

Output

Print the number of qualifying intervals as one integer.

Subtasks

  • Subtask 1 (20 points): 1≤n≤10001\le n\le 1000; 0≤aj≤10485750\le a_j\le 1048575 for every 1≤j≤n1\le j\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 0≤aj≤10\le a_j\le 1 for every 1≤j≤n1\le j\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 0≤aj≤10485750\le a_j\le 1048575 for every 1≤j≤n1\le j\le n.

Example 1

Input

4
2 5 4 6

Output

5

Explanation

All four singletons qualify. For [1,2], the sum and XOR both equal 7. Every other interval has a repeated set bit, so its sum differs from its XOR.

Example 2

Input

9
0 0 0 0 0 0 0 0 0

Output

45

Explanation

Every interval has sum and XOR zero. There are 9⋅10/2=459\cdot10/2=45 intervals.

Example 3

Input

19
885 8 1 128 83 32 256 206 639 16 4 128 689 32 8 64 885 969 1

Output

37

Explanation

The counts of qualifying intervals ending at positions 1 through 19 are 1, 2, 2, 3, 2, 3, 4, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 1. They sum to 37.