#P10114. Witch's Binary Summation

    ID: 12100 Type: Default 1000ms 256MiB

Witch's Binary Summation

Witch's Binary Summation

The witch is given a sequence \(d\) of length \(n\). She wants to calculate:

\[ \sum_{i=1}^{n}\sum_{j=1}^{n}\Bigl( (d_i \oplus d_j) + (d_i \otimes d_j) \Bigr) \]

Here, \(\oplus\) is defined as the number of 1s in the binary representation of \(d_i+d_j\), and \(\otimes\) is defined as the number of 1s in the binary representation of \(|d_i-d_j|\) (i.e. the difference between the larger and the smaller number).

inputFormat

The first line contains an integer \(n\) — the length of the sequence. The second line contains \(n\) space-separated integers \(d_1,d_2,\dots,d_n\).

outputFormat

Output a single integer, which is the computed summation.

sample

2
1 2
8