A nice approach O(n*32)


#1

#define MOD 1000000007
#define ll long long
int Solution::hammingDistance(const vector &A) {
int n=A.size();
int x=0,y=0;
long long ans=0;
for(int i=0;i<32;i++){
x=0;
for(int j=0;j<n;j++){
if(A[j] & (1<<i)){
x+=1;
}
}
y=n-x;
ans=(ans%MOD+((ll)(x%MOD)(ll)(y%MOD))%MOD)%MOD;
}
return (int)(ans
2)%MOD;
}