#P6102. [EER2] 谔运算

[EER2] 谔运算

Description

First, CYJian wrote a sequence aa of length nn.

Then he had a sudden idea and wrote down the following puzzling expression:

$$\sum_{i=1}^{n}\sum_{j=1}^{n}\sum_{k=1}^{n}\sum_{l=1}^{n} (a_i\ {\rm or}\ a_j)\ {\rm xor}\ (a_k\ {\rm and}\ a_l)$$

CYJian thought this was a simple expression of “e-operation”, and it took him 114514s114514{\rm s} with a calculator to compute the answer.

To prove that you can outperform 114514114514 CYJian, please compute the value of this expression within 1s1{\rm s}. You only need to output the value modulo 2322^{32}.

Input Format

The first line contains a positive integer nn, denoting the length of the sequence.

The second line contains nn non-negative integers; the ii-th number is aia_i.

Output Format

Output one non-negative integer, representing the value of the expression given in the description.

2
1 2

30

6
1 1 4 5 1 4

3944

7
1 9 1 9 8 1 0

12892

Hint

Explanation for Sample 1:

(1 or 1) xor (1 and 1)=0(1\ {\rm or}\ 1)\ {\rm xor}\ (1\ {\rm and}\ 1) = 0.

(1 or 1) xor (1 and 2)=1(1\ {\rm or}\ 1)\ {\rm xor}\ (1\ {\rm and}\ 2) = 1.

(1 or 1) xor (2 and 1)=1(1\ {\rm or}\ 1)\ {\rm xor}\ (2\ {\rm and}\ 1) = 1.

(1 or 1) xor (2 and 2)=3(1\ {\rm or}\ 1)\ {\rm xor}\ (2\ {\rm and}\ 2) = 3.

(1 or 2) xor (1 and 1)=2(1\ {\rm or}\ 2)\ {\rm xor}\ (1\ {\rm and}\ 1) = 2.

(1 or 2) xor (1 and 2)=3(1\ {\rm or}\ 2)\ {\rm xor}\ (1\ {\rm and}\ 2) = 3.

(1 or 2) xor (2 and 1)=3(1\ {\rm or}\ 2)\ {\rm xor}\ (2\ {\rm and}\ 1) = 3.

(1 or 2) xor (2 and 2)=1(1\ {\rm or}\ 2)\ {\rm xor}\ (2\ {\rm and}\ 2) = 1.

(2 or 1) xor (1 and 1)=2(2\ {\rm or}\ 1)\ {\rm xor}\ (1\ {\rm and}\ 1) = 2.

(2 or 1) xor (1 and 2)=3(2\ {\rm or}\ 1)\ {\rm xor}\ (1\ {\rm and}\ 2) = 3.

(2 or 1) xor (2 and 1)=3(2\ {\rm or}\ 1)\ {\rm xor}\ (2\ {\rm and}\ 1) = 3.

(2 or 1) xor (2 and 2)=1(2\ {\rm or}\ 1)\ {\rm xor}\ (2\ {\rm and}\ 2) = 1.

(2 or 2) xor (1 and 1)=3(2\ {\rm or}\ 2)\ {\rm xor}\ (1\ {\rm and}\ 1) = 3.

(2 or 2) xor (1 and 2)=2(2\ {\rm or}\ 2)\ {\rm xor}\ (1\ {\rm and}\ 2) = 2.

(2 or 2) xor (2 and 1)=2(2\ {\rm or}\ 2)\ {\rm xor}\ (2\ {\rm and}\ 1) = 2.

(2 or 2) xor (2 and 2)=0(2\ {\rm or}\ 2)\ {\rm xor}\ (2\ {\rm and}\ 2) = 0.

Summing all results, we get the answer 3030.


This problem uses bundled testdata.

Constraints: for 100%100\% of the test points, 1n5×1051 \leq n \leq 5 \times 10^5, 0ai23210 \leq a_i \leq 2^{32}-1.

There are 66 subtasks in total. The score and settings for each subtask are as follows:

Subtask 11 (11 point): Sample 1.

Subtask 22 (1414 points): 1n801 \leq n \leq 80.

Subtask 33 (2525 points): 0ai800 \leq a_i \leq 80.

Subtask 44 (3030 points): 0ai50000 \leq a_i \leq 5000.

Subtask 55 (2525 points): 1n10001 \leq n \leq 1000.

Subtask 66 (55 points): no special constraints.


Friendly Reminder

Please pay attention to the constraints.

If you do not know what the “e-operation” above is, please refer to here.

Translated by ChatGPT 5