#P10114. [LMXOI Round 1] Size

[LMXOI Round 1] Size

Background

On a pitch-dark night, the witch took LMX away. HQZ, in order to save LMX, must complete the task given by the witch.

Problem Description

The witch gives a sequence dd of length nn. The witch wants to compute:

$$\sum\limits_{i=1}^{ n}\sum\limits_{j=1}^{n}{((d_i\oplus d_j)+(d_i \otimes d_j))}$$

Here, \oplus is defined as the number of 11 bits in the binary representation of the sum of two numbers in binary addition, and \otimes is defined as the number of 11 bits in the binary representation of the difference between the larger number and the smaller number.

Input Format

The first line contains an integer nn, the length of the sequence.

The second line contains nn non-negative integers, representing the sequence dd.

Output Format

Output one integer in one line, representing the answer.

2
1 3 
7
10
114514 19 19 810 1477 44151 15260 369 2010 222
1396

Hint

Sample Explanation #1

As shown in the table below, the answer is 1+2+2+2=71 + 2 + 2 + 2 = 7.

ii jj ansans
11 11
22 22
22 11
22

For 100%100\% of the testdata, it is guaranteed that $1 \le n\le 2\times 10^6,\sum\limits d_i\le5\times10^7$。

Constraints

Subtask ID nn Special Property Score
Subtask #1 2×106\le 2\times10^6 di=1d_i =1 1010
Subtask #2 5000\le 5000 None 2020
Subtask #3 2×106\le 2\times 10^6 did_i is a power of 22 3030
Subtask #4 None 4040

Translated by ChatGPT 5