#P1368D. AND, OR and square sum

    ID: 5420 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmasksgreedymath*1700

AND, OR and square sum

No submission language available for this problem.

Description

Gottfried learned about binary number representation. He then came up with this task and presented it to you.

You are given a collection of nn non-negative integers a1,,ana_1, \ldots, a_n. You are allowed to perform the following operation: choose two distinct indices 1i,jn1 \leq i, j \leq n. If before the operation ai=xa_i = x, aj=ya_j = y, then after the operation ai=x AND ya_i = x~\mathsf{AND}~y, aj=x OR ya_j = x~\mathsf{OR}~y, where AND\mathsf{AND} and OR\mathsf{OR} are bitwise AND and OR respectively (refer to the Notes section for formal description). The operation may be performed any number of times (possibly zero).

After all operations are done, compute i=1nai2\sum_{i=1}^n a_i^2 — the sum of squares of all aia_i. What is the largest sum of squares you can achieve?

The first line contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5).

The second line contains nn integers a1,,ana_1, \ldots, a_n (0ai<2200 \leq a_i < 2^{20}).

Print a single integer — the largest possible sum of squares that can be achieved after several (possibly zero) operations.

Input

The first line contains a single integer nn (1n21051 \leq n \leq 2 \cdot 10^5).

The second line contains nn integers a1,,ana_1, \ldots, a_n (0ai<2200 \leq a_i < 2^{20}).

Output

Print a single integer — the largest possible sum of squares that can be achieved after several (possibly zero) operations.

Samples

Sample Input 1

1
123

Sample Output 1

15129

Sample Input 2

3
1 3 5

Sample Output 2

51

Sample Input 3

2
349525 699050

Sample Output 3

1099509530625

Note

In the first sample no operation can be made, thus the answer is 1232123^2.

In the second sample we can obtain the collection 1,1,71, 1, 7, and 12+12+72=511^2 + 1^2 + 7^2 = 51.

If xx and yy are represented in binary with equal number of bits (possibly with leading zeros), then each bit of x AND yx~\mathsf{AND}~y is set to 11 if and only if both corresponding bits of xx and yy are set to 11. Similarly, each bit of x OR yx~\mathsf{OR}~y is set to 11 if and only if at least one of the corresponding bits of xx and yy are set to 11. For example, x=3x = 3 and y=5y = 5 are represented as 0112011_2 and 1012101_2 (highest bit first). Then, x AND y=0012=1x~\mathsf{AND}~y = 001_2 = 1, and x OR y=1112=7x~\mathsf{OR}~y = 111_2 = 7.