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

#PS0000167. Đếm đoạn XOR K có độ dài chẵn (Count Even-Length Subarrays With XOR K)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn XOR K có độ dài chẵn (Count Even-Length Subarrays With XOR K)

Count Even-Length Subarrays With XOR K

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, numbered from 1. A nonempty contiguous interval [l,r][l,r] contains all elements from ll through rr and has length r−l+1r-l+1. Count intervals whose bitwise XOR of all elements is equal to KK and whose length is even. Bitwise XOR has a 1 at a bit position exactly when an odd number of operands have a 1 there. Intervals with different endpoints are counted separately.

Input

The first line contains two integers n,Kn,K. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of qualifying intervals.

Subtasks

  • Subtask 1 (30 points): 1≤n≤2001\le n\le 200; 0≤aj<2300\le a_j<2^{30} for all 1≤j≤n1\le j\le n; 0≤K<2300\le K<2^{30}.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 0≤aj<2300\le a_j<2^{30} for all 1≤j≤n1\le j\le n; K=0K=0.
  • Subtask 3 (40 points): 1≤n≤2000001\le n\le 200000; 0≤aj<2300\le a_j<2^{30} for all 1≤j≤n1\le j\le n; 0≤K<2300\le K<2^{30}.

Example 1

Input

3 0
1 1 1

Output

2

Explanation

The two intervals [1,2] and [2,3] have length 2 and XOR zero; no other even-length interval exists.

Example 2

Input

4 0
0 0 0 0

Output

4

Explanation

Three length-2 intervals and one length-4 interval all have XOR zero.