#P1368D. AND, OR and square sum
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 non-negative integers . You are allowed to perform the following operation: choose two distinct indices . If before the operation , , then after the operation , , where and 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 — the sum of squares of all . What is the largest sum of squares you can achieve?
The first line contains a single integer ().
The second line contains integers ().
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 ().
The second line contains integers ().
Output
Print a single integer — the largest possible sum of squares that can be achieved after several (possibly zero) operations.
Samples
Note
In the first sample no operation can be made, thus the answer is .
In the second sample we can obtain the collection , and .
If and are represented in binary with equal number of bits (possibly with leading zeros), then each bit of is set to if and only if both corresponding bits of and are set to . Similarly, each bit of is set to if and only if at least one of the corresponding bits of and are set to . For example, and are represented as and (highest bit first). Then, , and .