The XOR sum of a list is the bitwise XOR of all its elements. If the list only contains one element, then its XOR sum will be equal to this element.


	For example, the XOR sum of [1,2,3,4] is equal to 1 XOR 2 XOR 3 XOR 4 = 4, and the XOR sum of [3] is equal to 3.


You are given two 0-indexed arrays arr1 and arr2 that consist only of non-negative integers.

Consider the list containing the result of arr1[i] AND arr2[j] (bitwise AND) for every (i, j) pair where 0 &lt;= i &lt; arr1.length and 0 &lt;= j &lt; arr2.length.

Return the XOR sum of the aforementioned list.

&nbsp;
Example 1:

Input: arr1 = [1,2,3], arr2 = [6,5]
Output: 0
Explanation: The list = [1 AND 6, 1 AND 5, 2 AND 6, 2 AND 5, 3 AND 6, 3 AND 5] = [0,1,2,0,2,1].
The XOR sum = 0 XOR 1 XOR 2 XOR 0 XOR 2 XOR 1 = 0.


Example 2:

Input: arr1 = [12], arr2 = [4]
Output: 4
Explanation: The list = [12 AND 4] = [4]. The XOR sum = 4.


&nbsp;
Constraints:


	1 &lt;= arr1.length, arr2.length &lt;= 105
	0 &lt;= arr1[i], arr2[j] &lt;= 109


class Solution:
    def getXORSum(self, arr1: List[int], arr2: List[int]) -> int:
        def xor_lis(lis): return functools.reduce(lambda a,b : a^b,lis)
        return xor_lis(arr1) & xor_lis(arr2)
class Solution {

    public int getXORSum(int[] arr1, int[] arr2) {
        int[] x = (arr1.length < arr2.length ? arr2 : arr1);
        int[] y = (arr1.length < arr2.length ? arr1 : arr2);
        int xorSumX = 0;
        for (int xi : x) {
            xorSumX ^= xi;
        }
        int answer = 0;
        for (int yj : y) {
            answer ^= (yj & xorSumX);
        }
        return answer;
    }

}
class Solution {
public:
    // this code is basically pure mathematics, mainly distributive property with AND and XOR
    
    int getXORSum(vector<int>& arr1, vector<int>& arr2) {
        int m=arr1.size();
        int n=arr2.size();
        long int ans1=0,ans2=0;
        for(int i=0;i<m;i++)  // this loop stores the XOR between every element of arr1
        {
            ans1=ans1 ^ arr1[i];
        }
        for(int j=0;j<n;j++)   // this loop stores the XOR between every element of arr2
        {
            ans2=ans2 ^ arr2[j];
        }
        return ans1 & ans2;  // AND operation of both XOR's is the answer.
        
    }
};
var getXORSum = function(arr1, arr2) {
    // (x & 2) xor (x & 3) =[ !(x&2) & (x&3) ] OR  [ (x&2) & !(x&3) ]
	// = [ (!x || !2 ) & (x&3) ] OR [ (x&2) & (!x || !3) ]
    // = [ (!x || !2) & x & 3 ]   OR  [ x & 2 & (!x || !3) ]
    // = (!2 & x & 3 ) || (x & 2 & !3)
    // = x & [ (!2 & 3) || (!3 & 2) ]
    // = x & (2 XOR 3)
    // const ans = (2 XOR 3 XOR....) in arr2
    // The same principle: x, y,z... in arr1
    // res = (x & ans) XOR (y & ans) XOR .....
    //  = ans & (x XOR y XOR z .......)
    // Finally: res = (XOR: arr1) AND (XOR: arr2);
    var xor1 = arr1.reduce((acc,cur)=>acc^cur);
    var xor2 = arr2.reduce((acc,cur)=>acc^cur);
    return xor1 & xor2;
};
Find XOR Sum of All Pairs Bitwise AND