<p>Given an array of integers <code>arr</code>.</p>

<p>We want to select three indices <code>i</code>, <code>j</code> and <code>k</code> where <code>(0 &lt;= i &lt; j &lt;= k &lt; arr.length)</code>.</p>

<p>Let&#39;s define <code>a</code> and <code>b</code> as follows:</p>

<ul>
	<li><code>a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]</code></li>
	<li><code>b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]</code></li>
</ul>

<p>Note that <strong>^</strong> denotes the <strong>bitwise-xor</strong> operation.</p>

<p>Return <em>the number of triplets</em> (<code>i</code>, <code>j</code> and <code>k</code>) Where <code>a == b</code>.</p>

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

<pre>
<strong>Input:</strong> arr = [2,3,1,6,7]
<strong>Output:</strong> 4
<strong>Explanation:</strong> The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
</pre>

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

<pre>
<strong>Input:</strong> arr = [1,1,1,1,1]
<strong>Output:</strong> 10
</pre>

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

<ul>
	<li><code>1 &lt;= arr.length &lt;= 300</code></li>
	<li><code>1 &lt;= arr[i] &lt;= 10<sup>8</sup></code></li>
</ul>

class Solution:
    def countTriplets(self, arr: List[int]) -> int:
        n = len(arr)
        pref_xor = [0] * n
        pref_xor[0] = arr[0]
        for i in range(1, n):
            pref_xor[i] = arr[i]^pref_xor[i-1]
        
        print("Prefix XOR array:", pref_xor)  # Debug print
        
        ans = 0
        # for j in range(1, n):
        #     sum1, sum2 = 0, 0
        #     for i in range(j):
        #         sum1 = pref_xor[i]
        #         print(f"i: {i}, sum1: {sum1}")  # Debug print
            
        #     for k in range(j, n):
        #         sum2 = pref_xor[k] ^ sum1
        #         print(f"k: {k}, sum2: {sum2}")  # Debug print
        #         if sum1 == sum2:
        #             print(f"Match found: i={i}, j={j}, k={k}")  # Debug print for match
        #             ans += 1
        #             break

        # for i in range(n-1):
        #     j=-1
        #     while j<i:
        #         sum1,sum2=0,0

        #         sum1 = pref_xor[i]^pref_xor[j] if j != -1 else pref_xor[i]
        #         print(f"j={j},i: {i}, sum1: {sum1}")  # Debug print
        #         for k in range(i+1,n):
        #             sum2 = pref_xor[k]^pref_xor[i] 
        #             print(f"i={i},k: {k}, sum2: {sum2}")  # Debug print

        #             if sum1==sum2:
        #                 print(f"Match found: j={j+1}, i={i+1}, k={k}")  # Debug print for match
        #                 ans += 1

        #         j += 1
        for i in range(n-1):
            sum1, sum2= 0, 0
            for j in range(i+1,n):
                # find the xor between (i,j)
                sum1 = pref_xor[i-1] if i>0 else 0
                sum2 = pref_xor[j]
                if sum1^sum2==0:
                    print(f"Match found: i={i}, j={j}")  # Debug print for match
                    ans += j-i


                    
        return ans

71