<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. In one operation, you can:</p>

<ul>
	<li>Choose two different indices <code>i</code> and <code>j</code> such that <code>0 &lt;= i, j &lt; nums.length</code>.</li>
	<li>Choose a non-negative integer <code>k</code> such that the <code>k<sup>th</sup></code> bit (<strong>0-indexed</strong>) in the binary representation of <code>nums[i]</code> and <code>nums[j]</code> is <code>1</code>.</li>
	<li>Subtract <code>2<sup>k</sup></code> from <code>nums[i]</code> and <code>nums[j]</code>.</li>
</ul>

<p>A subarray is <strong>beautiful</strong> if it is possible to make all of its elements equal to <code>0</code> after applying the above operation any number of times.</p>

<p>Return <em>the number of <strong>beautiful subarrays</strong> in the array</em> <code>nums</code>.</p>

<p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [4,3,1,2,4]
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are 2 beautiful subarrays in nums: [4,<u>3,1,2</u>,4] and [<u>4,3,1,2,4</u>].
- We can make all elements in the subarray [3,1,2] equal to 0 in the following way:
  - Choose [<u>3</u>, 1, <u>2</u>] and k = 1. Subtract 2<sup>1</sup> from both numbers. The subarray becomes [1, 1, 0].
  - Choose [<u>1</u>, <u>1</u>, 0] and k = 0. Subtract 2<sup>0</sup> from both numbers. The subarray becomes [0, 0, 0].
- We can make all elements in the subarray [4,3,1,2,4] equal to 0 in the following way:
  - Choose [<u>4</u>, 3, 1, 2, <u>4</u>] and k = 2. Subtract 2<sup>2</sup> from both numbers. The subarray becomes [0, 3, 1, 2, 0].
  - Choose [0, <u>3</u>, <u>1</u>, 2, 0] and k = 0. Subtract 2<sup>0</sup> from both numbers. The subarray becomes [0, 2, 0, 2, 0].
  - Choose [0, <u>2</u>, 0, <u>2</u>, 0] and k = 1. Subtract 2<sup>1</sup> from both numbers. The subarray becomes [0, 0, 0, 0, 0].
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,10,4]
<strong>Output:</strong> 0
<strong>Explanation:</strong> There are no beautiful subarrays in nums.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
</ul>

from typing import List
from collections import Counter
from itertools import accumulate
import operator

class Solution:
    def beautifulSubarrays(self, nums: List[int]) -> int:
        # Initialize a counter with a base case: XOR of 0 has been seen once.
        cnt = Counter({0: 1})
        
        # Calculate the prefix XOR for each element in the array.
        # The accumulate function will compute the running XOR of the array.
        for val in accumulate(nums, operator.xor):
            # Increment the count of the current prefix XOR value.
            cnt[val] += 1
        
        # Calculate the number of beautiful subarrays.
        # For each unique prefix XOR value, if it appears v times,
        # we can choose any two of these occurrences to form a subarray
        # with XOR 0, which is a beautiful subarray.
        return sum(v * (v - 1) // 2 for v in cnt.values())

# Explanation of the solution:

# 1. **Prefix XOR Calculation**: 
#    - We use the `accumulate` function with `operator.xor` to compute the prefix XOR for each element in the array.
#    - The prefix XOR up to an index `i` is the XOR of all elements from the start of the array to `i`.

# 2. **Counting Prefix XORs**:
#    - We maintain a counter `cnt` to keep track of how many times each prefix XOR value has been seen.
#    - We initialize the counter with `{0: 1}` because a prefix XOR of 0 means the subarray from the start to the current index can be a beautiful subarray.

# 3. **Finding Beautiful Subarrays**:
#    - A subarray is beautiful if its XOR is 0. This means the prefix XOR at the end of the subarray is the same as the prefix XOR just before the start of the subarray.
#    - For each unique prefix XOR value that appears `v` times, we can form `v * (v - 1) // 2` beautiful subarrays. This is because we can choose any two occurrences of the same prefix XOR to form a subarray with XOR 0.

# 4. **Return the Result**:
#    - We sum up the counts of all possible beautiful subarrays calculated in the previous step to get the total number of beautiful subarrays in the array.
834