// A simple C++ Program to count all subarrays having
// XOR of elements as given value m
#include <bits/stdc++.h>
using namespace std;

// Simple function that returns count of subarrays
// of arr with XOR value equals to m
long long subarrayXor(int arr[], int n, int l,int r)
{
	long long ans = 0; // Initialize ans

	// Pick starting point i of subarrays
	for (int i = l-1; i < r; i++) {
		int xorSum = 0; // Store XOR of current subarray

		// Pick ending point j of subarray for each i
		for (int j = i; j < r; j++) {
			// calculate xorSum
			xorSum = xorSum ^ arr[j];

			// If xorSum is equal to given value,
			// increase ans by 1.
			if (xorSum + 1 ==xorSum^1 )
				ans++;
		}
	}
	return ans;
}

// Driver program to test above function
int main()
{
	int arr[] = { 1, 2, 9, 8, 7 };
	int n = sizeof(arr) / sizeof(arr[0]);
	int m = 6;
	
	int l=1;
	int r=5;

	cout << "Number of subarrays having given XOR is "
		<< subarrayXor(arr, n, l,r);
	return 0;
}
