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

#SRD0000129. Yurii có thể làm mọi thứ (Yurii Can Do Everything)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Yurii có thể làm mọi thứ (Yurii Can Do Everything)

Yurii Can Do Everything

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array aa of nn positive integers, call a contiguous subarray al,…,ara_l,\ldots,a_r good if it contains at least three elements and

al⊕ar=∑i=l+1r−1ai. a_l\oplus a_r=\sum_{i=l+1}^{r-1}a_i.

The symbol ⊕\oplus denotes bitwise XOR. Count all good subarrays, distinguishing subarrays by their endpoints.

Input

  • The first line contains nn.
  • The second line contains a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the number of good subarrays.

Subtasks

  • Subtask 1 (10 points): 3≤n≤703\le n\le70, 1≤ai<2301\le a_i<2^{30}.
  • Subtask 2 (20 points): 3≤n≤3 0003\le n\le3\,000, 1≤ai<2301\le a_i<2^{30}.
  • Subtask 3 (30 points): 3≤n≤40 0003\le n\le40\,000, 1≤ai<2301\le a_i<2^{30}.
  • Subtask 4 (40 points): 3≤n≤200 0003\le n\le200\,000, 1≤ai<2301\le a_i<2^{30} (original full constraints).

Examples

Example 1

Input

8
3 1 2 3 1 2 3 15

Output

6

Explanation: The subarrays [3,1,2][3,1,2] and [1,2,3][1,2,3] each appear twice and satisfy the equality; [2,3,1][2,3,1] appears once; and the whole array also satisfies it because 3⊕15=123\oplus15=12 equals the sum of its six interior elements.

Example 2

Input

10
997230370 58052053 240970544 715275815 250707702 156801523 44100666 64791577 43523002 480196854

Output

2

Explanation: Exactly two 1-indexed endpoint pairs work: (1,4)(1,4) with interior sum 299022597299022597, and (5,10)(5,10) with interior sum 309216768309216768. In each case the XOR of the two endpoints equals that sum.