Given an array A of n integers, the task is to count the number of ways to split given array elements into two disjoint groups such that XOR of elements of each group is equal.
Note: The answer could be very large so print it by doing modulos with 10^{9} + 7. 
Example 1:
Input : a[] = {1, 2, 3}
Output : 3
Explanation:
{(1),(2, 3)},{(2),(1, 3)},{(3),(1, 2)}
are three ways with equal XOR
value of two groups.
Example 2:
Input : a[] = {5, 2, 3, 2}
Output : 0
Your Task:
The input is already taken care of by the driver code. You only need to complete the function countgroup() that takes an array (a), sizeOfArray (n), and return the number of ways to split an array. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
Constraints:
1<=N<=10^{5}
1<=a<=10^{8}

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Starter code: #User function Template for python3
class Solution:
	def countgroup(self,a, n): 
		#Complete the function


Solutions:
class Solution:

	def countgroup(self, a, n):
		xor = 0
		for i in a:
			xor ^= i
		if xor != 0:
			return 0
		return pow(2, n - 1, 1000000007) - 1


class Solution:

	def countgroup(self, a, n):
		xr = 0
		for i in range(n):
			xr = xr ^ a[i]
		if xr == 0:
			return ((1 << n - 1) - 1) % 1000000007
		return 0


class Solution:

	def power(self, x, y, p):
		res = 1
		x = x % p
		if x == 0:
			return 0
		while y > 0:
			if y & 1 == 1:
				res = res * x % p
			y = y >> 1
			x = x * x % p
		return res

	def countgroup(self, a, n):
		xs = 0
		for i in range(n):
			xs = xs ^ a[i]
		if xs == 0:
			ans = self.power(2, n - 1, 1000000007) - 1
			return ans
		return 0


import math

class Solution:

	def countgroup(self, a, n):
		xor = 0
		for i in range(n):
			xor = xor ^ a[i]
		if xor != 0:
			return 0
		modulo = 10 ** 9 + 7
		mod_inverse = 500000004
		groups = (int(pow(2, n, modulo)) - 2 + modulo) % modulo * mod_inverse % modulo
		return groups


class Solution:

	def countgroup(self, a, n):
		MOD = 10 ** 9 + 7
		ans = 0
		for i in range(n):
			ans ^= a[i]
		val = 1
		for i in range(n - 1):
			val *= 2
			val %= MOD
		return val - 1 if ans == 0 else 0