~/algor $ cat problems/bit-juftliklar-xor
Sum of pairwise XORs
Medium
1000 ms
128 MB
56%
$n$ integers $a_{1}, a_{2}, \ldots, a_{n}$ are given. Find the sum of $a_{i} \oplus a_{j}$ over all pairs $i \lt j$. Here $\oplus$ is the bitwise XOR operation.
Input
The first line contains a positive integer $n$. The second line contains $n$ integers $a_{i}$ separated by spaces.
Output
One integer — the sum.
Note
$1 \le n \le 10^{5}$
$0 \le a_{i} \lt 2^{30}$
Examples
Input #1
3 1 2 3
Output #1
6
Input #2
1 7
Output #2
0