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

#PS0000161. Đếm đoạn XOR bằng K (Count 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 bằng K (Count Subarrays With XOR K)

Count 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. 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 (20 points): 1≤n≤5001\le n\le 500; 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 (50 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 3
1 2 3

Output

2

Explanation

Intervals [1,2] and [3,3] have XOR 3; the others have XOR 1, 0, 2, 1.

Example 2

Input

2 0
0 0

Output

3

Explanation

Both singletons and [1,2] have XOR zero.