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?


-----Input-----

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}$).


-----Output-----

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


-----Examples-----
Input
1
123

Output
15129

Input
3
1 3 5

Output
51

Input
2
349525 699050

Output
1099509530625



-----Note-----

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

In the second sample we can obtain the collection $1, 1, 7$, and $1^2 + 1^2 + 7^2 = 51$.

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

Difficulty: interview

Starter code:

Solutions:
import sys
from copy import copy

input = sys.stdin.readline

n = int(input())
l = [int(a) for a in input().split()]
x = []
for i in range(0, 20):
    res = 0
    for a in l:
        if a & (1 << i):
            res += 1
    x.append(res)

res = 0
for i in range(n):
    a = 0
    for j in range(20):
        if i < x[j]:
            a += (1 << j)
    res += a ** 2
print(res)

import sys
input = sys.stdin.readline

n=int(input())
A=list(map(int,input().split()))

ANS=[0]*21

for a in A:
    for i in range(21):
        if a & (1<<i) !=0:
            ANS[i]+=1

S=0
for i in range(n):
    K=0
    for j in range(21):
        if ANS[j]>0:
            ANS[j]-=1
            K+=1<<j

    S+=K*K

print(S)


import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
arr = list(map(int, lines[1].strip().split(" ")))

digits = [0 for _ in range(21)]
for a in arr:
    b = bin(a)[2:]
    for i in range(1, len(b)+1):
        if b[-i] == '1': digits[i-1] += 1
final = []
for i in range(n):
    tmp = 0
    for j in range(21):
        if digits[j] != 0: 
            tmp += 2 ** j
            digits[j] -= 1
    final.append(tmp)
res = 0
for num in final:
    res += num ** 2
print(res)

import sys
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
B = 20
table = [0]*B
for a in A:
    for i in range(B):
        if (1<<i) & a:
            table[i] += 1

ans = 0

for _ in range(N):
    res = 0
    for i in range(B):
        if table[i]:
            table[i] -= 1
            res |= (1<<i)
    ans += res**2

print(ans)

from sys import stdin
input = stdin.readline
n = int(input())
l = list(map(int,input().split()))
ile = [0] * 21
for i in l:
    ind = 0
    while i > 0:
        if i%2 == 1:
            ile[ind] += 1
        ind += 1
        i//=2
pot = [1] * 22
for i in range(1,22):
    pot[i] = pot[i-1] * 2
wyn = 0
for j in range(n):
    liczba = 0
    for i in range(21):
        if ile[i] > 0:
            liczba += pot[i]
            ile[i] -= 1
    wyn += liczba**2
print(wyn)

N = int(input())
A = [int(a) for a in input().split()]
X = [0] * 20
for a in A:
    for i in range(20):
        if a >> i & 1:
            X[i] += 1
# print("X =", X)
m = (1 << 20) - 1
s = m
ans = 0
for i in range(N):
    for j in range(20):
        if X[j] == i:
            s ^= 1 << j
    ans += s * s
print(ans)


n = int(input())
a = list(map(int,input().split()))
ls = [0]*20
for i in a:
  for j in range(20):
    if i&1<<j:
      ls[j] += 1
ans = 0
for i in range(n):
  x = 0
  for j in range(20):
    if ls[j]:
      x += 1<<j
      ls[j] -= 1
  ans += x**2
print(ans)

n=int(input())
a=list(map(int,input().split()))
x=[0]*20
for i in range(n):
  s="{0:b}".format(a[i])
  b=[]
  for j in range(len(s)):
    b.append(s[j])
  b.reverse()
  for j in range(20-len(s)):
    b.append('0')
  b.reverse()
  for j in range(20):
    if b[j]=='1':
      x[j]+=1
ans=0
for i in range(n):
  s=[]
  for j in range(20):
    if x[j]>0:
      s.append('1')
      x[j]-=1
    else:
      s.append('0')
  ans+=int(''.join(s), 2)**2
print(ans)