Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bit-juftliklar-xor

Sum of pairwise XORs

Medium 1000 ms 128 MB 56%
Share

$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.

Three numbers and the XOR of each pair of them; the sum of the results is highlighted

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

Sign in to submit a solution

Signing up is free and takes a minute.