题库练习 AND, OR and square sum
← 上一题 下一题 →

A13493 | AND, OR and square sum

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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

You are given a collection of $n$ non-negative integers $a_1, \ldots, a_n$ . You are allowed to perform the following operation: choose two distinct indices $1 \leq i, j \leq n$ . If before the operation $a_i = x$ , $a_j = y$ , then after the operation $a_i = x~\mathsf{AND}~y$ , $a_j = x~\mathsf{OR}~y$ , where $\mathsf{AND}$ and $\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 $\sum_{i=1}^n a_i^2$ — the sum of squares of all $a_i$ . What is the largest sum of squares you can achieve?

输入格式

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

The second line contains $n$ integers $a_1, \ldots, a_n$ ( $0 \leq a_i < 2^{20}$ ).

输出格式

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

输入输出样例

输入 #1
1
123
输出 #1
15129
输入 #2
3
1 3 5
输出 #2
51
输入 #3
2
349525 699050
输出 #3
1099509530625
C++ 编辑器
输入
输出