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

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Mathematics

Greedy algorithms


Solutions:
n = int(input())
arr = list(map(int, input().split()))
max1 = max(arr)
a = len(bin(max1)) - 2
lis = [0] * a
for i in range(a):
	for j in range(n):
		if arr[j] >= 2 ** i:
			x = bin(arr[j])
			x = x[2:]
			if x[-i - 1] == '1':
				lis[i] += 1
num = []
b = max(lis)
for i in range(b):
	s = 0
	for j in range(a):
		if lis[j] > 0:
			s += 2 ** j
			lis[j] -= 1
	num.append(s)
ans = 0
c = len(num)
for i in range(c):
	ans += num[i] ** 2
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {x: 0 for x in range(20)}
	for num in a:
		if num == 0:
			continue
		b = bin(num)
		for j in range(len(b) - 2):
			if b[-j - 1] == '1':
				d[j] += 1
	for xx in range(20):
		if d[xx] == 0:
			del d[xx]
	l = sorted(d.keys(), reverse=True)
	total = 0
	while l:
		new_num = 0
		z = 0
		while z < len(l):
			new_num += 2 ** l[z]
			d[l[z]] -= 1
			if d[l[z]] == 0:
				l.pop(z)
			else:
				z += 1
		total += new_num ** 2
	print(total)
main()


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 20
for e in a:
	for i in range(20):
		if 1 << i & e:
			cnt[i] += 1
res = 0
while sum(cnt) > 0:
	x = 0
	for i in range(20):
		if cnt[i]:
			cnt[i] -= 1
			x |= 1 << i
	res += x * x
print(res)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
z = []
for i in range(20):
	z.append(2 ** i - 1)
l = inlt()
l.sort()
b = [0] * n
for bit in range(20):
	cnt = 0
	for j in range(n):
		cnt += l[j] >> bit & 1
	for i in range(cnt):
		b[i] |= 1 << bit
res = 0
for x in b:
	res += x ** 2
print(res)


a = [0 for _ in range(20)]
n = int(input())
for m in map(int, input().split()):
	i = 1
	for c in range(20):
		if m & i:
			a[c] += 1
		i *= 2
m = max(a)
s = 0
for _ in range(m):
	ps = 0
	i = 1
	for c in range(20):
		if a[c] > 0:
			a[c] -= 1
			ps += i
		i *= 2
	s += ps * ps
print(s)


def ans(A):
	count = [0] * 25
	for a in A:
		s = '{0:b}'.format(a)
		s = list(s[::-1])
		for (i, e) in enumerate(s):
			if e == '1':
				count[i] += 1
	ret = 0
	while sum(count):
		next = [0] * 25
		for i in range(25):
			if count[i] > 0:
				count[i] -= 1
				next[i] += 1
		next = ''.join((str(x) for x in next))
		next = int(next[::-1], 2)
		ret += next ** 2
	return ret
input()
A = input().split(' ')
A = [int(a) for a in A]
print(ans(A))


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def invr():
	return map(int, input().split())
test_count = 1
for t in range(test_count):
	n = inp()
	a = inlt()
	counts = {}
	max_digit = 0
	for x in a:
		b = bin(x)[:1:-1]
		for i in range(len(b)):
			if b[i] == '1':
				counts[i] = counts.get(i, 0) + 1
				max_digit = max(max_digit, i)
	ans = 0
	i = max_digit
	while i >= 0:
		if i in counts and counts[i] > 0:
			num = ''
			for j in range(i, -1, -1):
				if j in counts and counts[j] > 0:
					num += '1'
					counts[j] = counts[j] - 1
				else:
					num += '0'
			dec_num = int(num, 2)
			ans += dec_num * dec_num
		if i not in counts or counts[i] == 0:
			i -= 1
	print(ans)


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 bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def power2(n):
	while not n & 1:
		n >>= 1
	return n == 1
n = int(input())
arr = list(map(int, input().split()))
a = [0] * 20
for i in range(20):
	for j in range(n):
		if arr[j] & 1 << i:
			a[i] += 1
ans = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		if a[j]:
			tmp |= 1 << j
			a[j] -= 1
	ans += tmp ** 2
print(ans)


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(n,) = rl()
a = rl()
bit_counts = [sum((ai >> i & 1 for ai in a)) for i in range(20)]
r = 0
for i in range(n):
	x = sum((1 << j for (j, count) in enumerate(bit_counts) if count > i))
	r += x * x
print(r)


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, A):
	M = 22
	bits = [0 for _ in range(M)]
	for v in A:
		i = 0
		while v > 0:
			if v & 1:
				bits[i] += 1
			v >>= 1
			i += 1
	ans = 0
	i = M - 1
	while i >= 0:
		while bits[i] > 0:
			v = 0
			for j in range(i, -1, -1):
				if bits[j] > 0:
					bits[j] -= 1
					v |= 1 << j
			ans += v ** 2
		i -= 1
	return ans
N = int(input())
A = [int(x) for x in input().split()]
print(solve(N, A))


import sys
from random import randint
input = sys.stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	f = [0] * 20
	for x in a:
		for b in range(20):
			if x >> b & 1:
				f[b] += 1
	ans = 0
	while True:
		x = 0
		for i in range(len(f)):
			if f[i] > 0:
				f[i] -= 1
				x |= 1 << i
		if not x:
			break
		ans += x * x
	print(ans)
main()


(n, a) = (int(input()), list(map(int, input().split())))
ans = [0] * n
for i in range(20):
	for j in range(sum(list(map(lambda x: x >> i & 1, a)))):
		ans[j] |= 1 << i
print(sum(list(map(lambda x: x ** 2, ans))))


n = int(input())
l = list(map(int, input().split()))
ones_in_position = [0] * 20
for i in l:
	for pos in range(20):
		if i & 1 << pos > 0:
			ones_in_position[pos] += 1
ones_in_position.reverse()
numbers = []
for i in range(n):
	x = ''
	for i in range(20):
		if ones_in_position[i] >= 1:
			x += '1'
			ones_in_position[i] -= 1
		else:
			x += '0'
	numbers.append(int(x, base=2))
sum_of_sq = 0
for i in numbers:
	sum_of_sq += i ** 2
print(sum_of_sq)


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	n = next(ints)
	m = [next(ints) for i in range(n)]
	z = [0] * 20
	for x in m:
		i = 0
		while x:
			z[i] += x & 1
			x >>= 1
			i += 1
	ans = 0
	while 1:
		while z and z[-1] == 0:
			z.pop()
		if not z:
			break
		x = 0
		for i in range(len(z)):
			if z[i]:
				x += 2 ** i
				z[i] -= 1
		ans += x * x
	print(ans)
	return
main()


n = int(input())
l = list(map(int, input().split()))
ans = []
for i in range(20):
	ans.append([])
for i in range(n):
	tmp = bin(l[i])[2:]
	ln = 20 - len(tmp)
	tmp = '0' * ln + tmp
	for j in range(20):
		ans[j].append(tmp[j])
for i in range(20):
	ans[i].sort()
fin = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		tmp += int(ans[j][i]) * 2 ** (20 - j - 1)
	fin += tmp * tmp
print(fin)


from sys import stdin

def catch():
	return [int(v) for v in stdin.readline().split()]
(b,) = catch()
a = catch()
count = [sum((ai >> i & 1 for ai in a)) for i in range(20)]
temp = 0
for i in range(b):
	g = sum((1 << j for (j, val) in enumerate(count) if val > i))
	temp += g * g
print(temp)


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
ara = inara()
bit = [0] * 30
for num in ara:
	for i in range(25):
		if num & 1 << i:
			bit[i] += 1
ans = 0
for i in range(n):
	x = 0
	for j in range(25):
		if bit[j]:
			bit[j] -= 1
			x |= 1 << j
	ans += x * x
print(ans)


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


n = int(input())
a = list(map(int, input().split()))
a.sort()
for bit in range(0, 20):
	ones = 0
	for i in range(0, n):
		if a[i] & 1 << bit > 0:
			ones += 1
	for i in range(n - ones, n):
		a[i] |= 1 << bit
	for i in range(0, n - ones):
		a[i] &= ~(1 << bit)
ans = 0
for i in range(0, n):
	ans += a[i] * a[i]
print(ans)


from collections import defaultdict as dd

def breakpow2(n, dp):
	while n != 0:
		dp[n - (n & n - 1)] += 1
		n = n & n - 1
	return 1
n = int(input())
arr = list(map(int, input().split()))
dp = dd(int)
for i in arr:
	breakpow2(i, dp)
ans = 0
for i in range(n):
	x = 0
	for i in dp:
		if dp[i] > 0:
			x += i
			dp[i] -= 1
	ans += x ** 2
print(ans)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
ss = lambda x: sum((x[i] * x[i] for i in range(len(x))))
(n,) = I()
l = sorted(I())
an = 0
p = list(l)
ct = [0] * 20
for j in range(20):
	for i in range(n):
		ct[j] += l[i] >> j & 1
a = [0] * n
for i in range(len(ct)):
	c = 2 ** i
	for j in range(n - ct[i], n):
		a[j] += c
print(ss(a))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	n = int(input())
	bits = [0] * 20
	a = [int(x) for x in input().split()]
	for i in a:
		for j in range(20):
			if i & 1 << j:
				bits[j] += 1
	ans = 0
	for i in range(n):
		x = 0
		c = 0
		for j in range(20):
			if bits[j] == 0:
				c += 1
			if bits[j] > 0:
				x = x | 1 << j
				bits[j] -= 1
		if c == 20:
			break
		ans += x * x
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def solve(num):
	arr = []
	while num > 0:
		arr.append(num % 2)
		num = num // 2
	if len(arr) < 21:
		arr = arr + [0] * (22 - len(arr))
	return arr
n = int(ri())
a = Ri()
lis = []
for i in a:
	lis.append(solve(i))
cnt = [0] * 22
for i in range(22):
	for j in range(n):
		cnt[i] += lis[j][i]
ans = 0
while True:
	tans = 0
	flag = False
	for i in range(22):
		if cnt[i] >= 1:
			flag = True
	if not flag:
		break
	for i in range(22):
		if cnt[i] >= 1:
			tans += 2 ** i
			cnt[i] -= 1
	ans += tans * tans
print(ans)


def help():
	nos = [0] * 20
	n = int(input())
	arr = list(map(int, input().split(' ')))
	for i in range(n):
		for j in range(20):
			if arr[i] >> j & 1:
				nos[j] += 1
	ans = [0] * n
	for qw in range(20):
		for i in range(n):
			if nos[qw] == 0:
				break
			ans[i] |= 1 << qw
			nos[qw] -= 1
	toret = 0
	for i in range(n):
		toret += ans[i] ** 2
	print(toret)
help()


n = int(input())
u = list(map(int, input().split()))
d = [0] * 20
for i in range(n):
	ind = 0
	while u[i] > 0:
		d[ind] += u[i] % 2
		ind += 1
		u[i] //= 2
for i in range(20):
	d[i] = (d[i], i)
d.sort()
ans = 0
cur = 2 ** 20 - 1
dl = 0
for i in range(20):
	ans += (d[i][0] - dl) * cur ** 2
	dl += d[i][0] - dl
	cur -= 2 ** d[i][1]
print(ans)


import sys
import heapq
import random
import collections
import bisect

def solve(lst):
	c = [0 for _ in range(20)]
	for a in lst:
		for (i, b) in enumerate(format(a, '020b')):
			c[i] += int(b)
	res = []
	for i in range(len(lst)):
		val = ''
		for j in range(20):
			if c[j] > 0:
				val += '1'
				c[j] -= 1
			else:
				val += '0'
		res.append(int(val, 2))
	return sum([val ** 2 for val in res])

def console(*args):
	print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)
_ = int(input())
lst = list(map(int, input().split()))
res = solve(lst)
print(res)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	b = [1 << i for i in range(20)]
	c = [0 for i in range(20)]
	d = [0 for i in range(n)]
	su = 0
	for i in range(n):
		for j in range(20):
			if a[i] & b[j]:
				d[c[j]] += b[j]
				c[j] += 1
	for i in d:
		su += pow(i, 2)
	print(su)
main()


from math import log2
n = int(input())
A = list(map(int, input().split()))
B2 = []
for i in range(22):
	B2.append(0)
for i in range(len(A)):
	if A[i] != 0:
		g = int(log2(A[i])) + 1
		for j in range(g):
			if A[i] % 2 == 1:
				B2[j] += 1
			A[i] //= 2
B = []
for i in range(len(B2)):
	if B2[i] != 0:
		B.append([B2[i], i])
B.sort(key=lambda n: n[0])
Ans = 0
ans = 0
haha = 0
for i in range(len(B)):
	ans += 2 ** B[i][1]
for i in range(len(B)):
	Ans += ans * ans * max(B[i][0] - haha, 0)
	haha += max(B[i][0] - haha, 0)
	ans -= 2 ** B[i][1]
print(Ans)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
has = [0] * 22
for x in a:
	i = 0
	while x > 0:
		if x % 2 == 1:
			has[i] += 1
		x //= 2
		i += 1
sol = 0
for i in range(n):
	n = 0
	for j in range(22):
		if has[j] > 0:
			has[j] -= 1
			n += 2 ** j
	sol += n ** 2
print(sol)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	N = getInt()
	A = getInts()
	bits = [0 for j in range(20)]
	for a in A:
		x = bin(a)[2:]
		for (idx, el) in enumerate(x):
			if el == '1':
				bits[len(x) - idx - 1] += 1
	ans = 0
	while True:
		tmp = ''
		for j in range(19, -1, -1):
			if bits[j]:
				tmp += '1'
				bits[j] -= 1
			else:
				tmp += '0'
		x = int(tmp, 2)
		if not x:
			break
		ans += x * x
	return ans
print(solve())


arr = [0] * 21
n = int(input())
l = list(map(int, input().split()))
for i in l:
	for j in range(21):
		if i & 1 << j:
			arr[j] += 1
ans = 0
for i in range(n):
	su = 0
	for j in range(21):
		if arr[j]:
			su += 1 << j
			arr[j] -= 1
	ans += su ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for u in range(20):
	for i in range(sum((x >> u & 1 for x in a))):
		b[i] |= 1 << u
print(sum((x * x for x in b)))


am = int(input())
arr = list(map(int, input().split()))
bits = [0] * 21
for i in range(am):
	n = list(map(int, reversed(list(bin(arr[i]))[2:])))
	for i in range(len(n)):
		bits[i] += n[i]
b = max(bits)
s = 0
for i in range(b):
	n = 0
	for g in range(21):
		if bits[g]:
			n += 2 ** g
			bits[g] -= 1
	s += n ** 2
print(s)


N = int(input())
A = [int(_) for _ in input().split()]
c = [0] * 20
for el in A:
	for i in range(20):
		if el & 1:
			c[i] += 1
		el = el >> 1
answer = 0
for i in range(N):
	number = 0
	for j in range(20):
		if c[j] > i:
			number |= 1 << j
	answer += number ** 2
print(answer)


n = int(input())
ar = list(map(int, input().split()))
s = [0] * n
for i in range(20):
	v = sum(list(map(lambda v: v >> i & 1, ar)))
	for h in range(v):
		s[h] |= 1 << i
print(sum(list(map(lambda k: k ** 2, s))))


from math import inf as inf
from math import *
from collections import *
import sys
from itertools import permutations
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	c = [0] * 20
	for i in a:
		for j in range(20):
			c[j] += i >> j & 1
	for i in range(n):
		te = 0
		for j in range(20):
			if c[j]:
				c[j] -= 1
				te += 1 << j
		s += te * te
	print(int(s))


n = int(input())
arr = list(map(int, input().split(' ')))
count = [0] * 21
for i in range(n):
	s = '{:021b}'.format(arr[i])
	for j in range(21):
		count[j] += int(s[j])
at = [0] * 21
for i in range(21):
	at[i] = 2 ** (20 - i)
ans = 0
for i in range(n):
	temp = 0
	for j in range(21):
		if count[j] > 0:
			temp += at[j]
			count[j] -= 1
	ans += temp * temp
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ff(x):
	if x > 0:
		return '1'
	else:
		return '0'
from math import sqrt
Testcase = 1
for _ in range(Testcase):
	n = inin()
	b = [0 for i in range(21)]
	arr = inar()
	for i in arr:
		temp = i
		index = 0
		while temp > 0:
			b[index] += temp % 2
			temp //= 2
			index += 1
	ss = 0
	b.reverse()
	while any(b):
		aa = ''.join([ff(i) for i in b])
		for i in range(21):
			if b[i] > 0:
				b[i] -= 1
		nm = int(aa, 2)
		ss += nm ** 2
	print(ss)


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


n = int(input())
l = list(map(int, input().split()))
m = max(l)
s = bin(m)
s = s[2:]
o = [0] * len(s)
for i in l:
	s = bin(i)
	s = s[2:]
	d = len(o) - len(s)
	s = '0' * d + s
	j = 0
	while j < len(o):
		x = s[j]
		if x == '1':
			o[j] = o[j] + 1
		j = j + 1
x = sum(o)
som = 0
while x > 0:
	i = 0
	s = ''
	while i < len(o):
		u = o[i]
		if u > 0:
			s = s + '1'
			o[i] = o[i] - 1
			x = x - 1
		else:
			s = s + '0'
		i = i + 1
	f = int(s, 2)
	som = som + f ** 2
print(som)


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


n = int(input())
l = list(map(int, input().split()))
count = [0] * 21
for i in l:
	for j in range(21):
		if i >> j & 1:
			count[j] += 1
ans = 0
for i in range(n):
	c = 0
	for j in range(21):
		if count[j] > 0:
			count[j] -= 1
			c += 2 ** j
	ans += c ** 2
print(ans)


def binify(x):
	l = list(bin(x)[2:])[::-1]
	ans = [int(i) for i in l]
	return ans

def binifys(s, x):
	ans = binify(x)
	return ans + [0] * (s - len(ans))

def transpose(m):
	ans = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))]
	return ans

def fallen(l):
	ans = [0 for i in range(len(l))]
	for i in range(sum(l)):
		ans[i] = 1
	return ans

def makefall(m):
	for i in range(len(m)):
		m[i] = fallen(m[i])
	return m

def debinify(l):
	ans = 0
	c = 1
	for i in l:
		ans += c * i
		c *= 2
	return ans
n = int(input())
a = [int(i) for i in input().split()]
siz = len(binify(max(a)))
matrix = [binifys(siz, i) for i in a]
matrix = transpose(matrix)
matrix = makefall(matrix)
matrix = transpose(matrix)
b = [debinify(i) ** 2 for i in matrix]
print(sum(b))


n = int(input())
a = list(map(int, input().split()))
accu = [0] * 20
for i in a:
	for j in range(20):
		accu[j] += i >> j & 1
ans = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		tmp += (accu[j] > 0) * pow(2, j)
		accu[j] -= 1
	ans += tmp ** 2
print(ans)


(n, arra) = (int(input()), list(map(int, input().split())))
s = [0] * n
for i in range(20):
	x = sum(list(map(lambda x: x >> i & 1, arra)))
	for k in range(x):
		s[k] |= 1 << i
print(sum(list(map(lambda x: x ** 2, s))))


N = int(input())
A = list(map(int, input().split()))
bits = [0 for _ in range(21)]
max_len = 0
for a in A:
	i = 0
	while a > 0:
		if a & 1 == 1:
			bits[i] += 1
		a = a >> 1
		i += 1
	max_len = max(max_len, i)
result = 0
while True:
	r = 0
	for i in range(max_len, -1, -1):
		r = r << 1
		if bits[i] > 0:
			r += 1
			bits[i] -= 1
	result += r * r
	if r == 0:
		break
print(result)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
n = int(input())
a = list(mapi())
mp = [0] * 21
for i in a:
	for j in range(21):
		mp[j] += i >> j & 1
res = 0
for i in range(n):
	num = 0
	for j in range(21):
		if mp[j] > 0:
			num += 1 << j
			mp[j] -= 1
	res += num ** 2
print(res)


t = int(input())
a = list(map(int, input().split()))
z = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(t):
	w = 0
	c = a[i]
	while c:
		z[w] = z[w] + c % 2
		c = c // 2
		w = w + 1
l = 0
for i in range(20):
	if z[19 - i] == 0:
		l = l + 1
	else:
		break
z = z[0:20 - l]
l = 0
for i in range(len(z)):
	if z[i] > l:
		l = z[i]
ans = 0
while l:
	l = l - 1
	q = 0
	p = 1
	for i in range(len(z)):
		if z[i] > 0:
			q = q + p
			z[i] = z[i] - 1
		p = p * 2
	ans = ans + q * q
print(ans)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enum = enumerate
bi = lambda x: '{0:b}'.format(x)

def solve():
	n = input(11)
	a = input(1)
	b = [0] * 22
	for i in a:
		t = bi(i)
		for (j, q) in enum(t[::-1]):
			if q == '1':
				b[j] += 1
	c = 0
	while True:
		r = ''
		for (i, j) in enum(b):
			if j > 0:
				b[i] -= 1
				r += '1'
			else:
				r += '0'
		v = int(r[::-1], 2)
		if not v:
			break
		else:
			c += v ** 2
	log(b)
	out(c)
	return
solve()


from sys import stdin, stdout

def and_or_and_square_sum(n, a):
	bcnt = [0 for i in range(32)]
	for v in a:
		for i in range(32):
			if v & 1 << i > 0:
				bcnt[i] += 1
	res = 0
	cur = -1
	while cur != 0:
		cur = 0
		for i in range(32):
			if bcnt[i] > 0:
				cur += 1 << i
				bcnt[i] -= 1
		res += cur * cur
	return res
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
print(and_or_and_square_sum(n, a))


n = int(input())
arr = list(map(int, input().split()))
binary = [0] * 20
for val in arr:
	temp = 0
	while val:
		if val & 1:
			binary[temp] += 1
		val >>= 1
		temp += 1
ans = 0
for i in range(n):
	temp = 0
	for place in range(20):
		if binary[place]:
			temp += 1 << place
			binary[place] -= 1
	ans += temp ** 2
print(ans)


def getint():
	return int(input())

def getint2():
	return map(int, input().split())

def getintlist():
	return map(int, input().split())

def getstring():
	return input()
n = getint()
ara = list(getintlist())
cnt = [0] * 20
for i in ara:
	for j in range(20):
		if i & 1 << j:
			cnt[j] += 1
ans = 0
for i in range(n):
	x = 0
	for j in range(20):
		if cnt[j]:
			cnt[j] -= 1
			x += 1 << j
	ans += x ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
bit = [0 for i in range(20)]
for i in a:
	x = bin(i)
	x = x[-1:1:-1]
	for j in range(len(x)):
		if x[j] == '1':
			bit[j] += 1
out = 0
num = 0
for i in range(max(bit)):
	num = 0
	for j in range(20):
		if bit[j] != 0:
			bit[j] -= 1
			num += 2 ** j
	out += num * num
print(out)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from sys import stdin, stdout

def sol():
	n = rri()
	v = rrm()
	x = [0 for i in range(25)]
	for i in v:
		z = i
		j = 0
		while z > 0:
			if z & 1 == 1:
				x[j] += 1
			z = z >> 1
			j += 1
	for i in range(n):
		v[i] = 0
		for j in range(25):
			if x[j] > i:
				z = 1 << j
				v[i] += z
	res = 0
	for i in v:
		res += i * i
	print(res)
	return
sol()


from sys import stdin
input = stdin.readline
N = int(input())
arr = list(map(int, input().split()))
cnt = [0] * 20
for x in arr:
	for k in range(0, 20):
		if x & 1 << k != 0:
			cnt[k] += 1
res = 0
while max(cnt) > 0:
	num = 0
	for i in range(0, 20):
		if cnt[i] > 0:
			num ^= 1 << i
			cnt[i] -= 1
	res += num * num
print(res)


from sys import stdin, stdout
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, a):
	bit_bucket = [0] * 20
	for num in a:
		bits = [int(x) for x in reversed(bin(num)[2:])]
		for (i, item) in enumerate(bits):
			if item == 1:
				bit_bucket[i] += 1
	result = 0
	curr = 1
	while curr > 0:
		curr = 0
		for i in range(20):
			if bit_bucket[i] > 0:
				curr += 2 ** i
				bit_bucket[i] -= 1
		result += curr ** 2
	return result
n = int_in()
a = arr_in()
out(solve(n, a))


n = int(input())
a = list(map(int, input().split()))
d = [0 for i in range(20)]
for i in a:
	t = bin(i).replace('0b', '')
	for i in range(len(t) - 1, -1, -1):
		if t[i] == '1':
			d[19 - (len(t) - 1 - i)] += 1
ans = 0
while 1:
	mul = 1
	num = 0
	f = 0
	for i in range(19, -1, -1):
		if d[i]:
			f = 1
			d[i] -= 1
			num += mul
		mul *= 2
	ans += num * num
	if f == 0:
		break
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
d = 20
b = []
x = []
for i in range(d):
	x += [[j >> i & 1 for j in a]]
	b += [sorted(x[-1])]
ans = []
for j in range(n):
	t = 0
	for i in range(d):
		t += b[i][j] << i
	ans += [t]
print(sum([i ** 2 for i in ans]))


n = int(input())
a = [int(i) for i in input().split()]
matrix = [[0 for j in range(20)] for i in range(n)]
for i in range(n):
	now = bin(a[i])[2:]
	for j in range(len(now) - 1, -1, -1):
		matrix[i][len(matrix[i]) - (len(now) - j)] = int(now[j])
cnt = [0] * 20
for i in range(n):
	for j in range(len(matrix[i])):
		cnt[j] += matrix[i][j]
answer = [['0' for j in range(20)] for i in range(n)]
for i in range(n):
	for j in range(20):
		if cnt[j] > 0:
			answer[i][j] = '1'
			cnt[j] -= 1
ans = 0
for i in range(n):
	ans += int(''.join(answer[i]), 2) ** 2
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
M = 20
bit = [0] * M
for a in A:
	for i in range(M):
		if a >> i & 1:
			bit[i] += 1
B = [0] * N
for i in range(N):
	for j in range(M):
		if bit[j]:
			B[i] += 1 << j
			bit[j] -= 1
ans = 0
for b in B:
	ans += b ** 2
print(ans)


from collections import defaultdict as dd
import math
import sys
import heapq
import copy
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
n = nn()
nums = lm()
ans = [0] * n
for j in range(21):
	place = 0
	for i in range(n):
		if nums[i] % 2 == 1:
			ans[place] += 2 ** j
			place += 1
		nums[i] = nums[i] // 2
ans_sq = [num * num for num in ans]
print(sum(ans_sq))


n = int(input())
a = [bin(i)[2:] for i in list(map(int, input().split()))]
a = [list((20 - len(i)) * '0' + i) for i in a]
for i in range(20):
	ones = sum([j[i] == '1' for j in a])
	l = ['0'] * (n - ones) + ['1'] * ones
	for j in range(n):
		a[j][i] = l[j]
s = 0
for i in a:
	s += int(''.join(i), 2) ** 2
print(s)


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


n = int(input())
a = list(map(int, input().split()))
bitCount = [0] * 20
for elem in a:
	binElem = bin(elem)[2:]
	lenBinElem = len(binElem)
	for i in range(lenBinElem):
		if binElem[i] == '1':
			bitCount[lenBinElem - 1 - i] += 1
ans = 0
for i in range(n):
	curElem = 0
	for j in range(20):
		if bitCount[j] > i:
			curElem += 2 ** j
	ans += curElem ** 2
print(ans)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = int(input())
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = inlt()
	counts = {}
	max_digit = 0
	for x in a:
		b = bin(x)[:1:-1]
		for i in range(len(b)):
			if b[i] == '1':
				counts[i] = counts.get(i, 0) + 1
				max_digit = max(max_digit, i)
	ans = 0
	i = max_digit
	while i >= 0:
		if i in counts and counts[i] > 0:
			num = ''
			for j in range(i, -1, -1):
				if j in counts and counts[j] > 0:
					num += '1'
					counts[j] = counts[j] - 1
				else:
					num += '0'
			dec_num = int(num, 2)
			ans += dec_num * dec_num
		if i not in counts or counts[i] == 0:
			i -= 1
	print(ans)


n = int(input())
a = [int(x) for x in input().split()]
from collections import Counter
c = Counter()
for x in a:
	b = 1
	while b < 2 ** 20:
		c[b] += 1 if x & b else 0
		b *= 2
p = 0
while any(c.values()):
	n = 0
	for k in c:
		if c[k] == 0:
			continue
		n += k
		c[k] -= 1
	p += n * n
print(p)


import sys
input = sys.stdin.readline

def dec2bin(n):
	n = int(n)
	a = []
	l = 0
	while n:
		a.append(n % 2)
		n //= 2
		l += 1
	return (a[::-1], l)

def bin2dec(l):
	p = 0
	s = 0
	for i in l[::-1]:
		s += i * 2 ** p
		p += 1
	return s
n = int(input())
a = list(map(dec2bin, input().split()))
v = max((i[1] for i in a))
a = [[0] * (v - l) + i for (i, l) in a]
for i in range(v):
	ones = 0
	for j in a:
		ones += j[i]
	for j in range(n):
		if j < n - ones:
			a[j][i] = 0
		else:
			a[j][i] = 1
s = 0
for i in a:
	s += bin2dec(i) ** 2
print(s)


n = int(input())
a = list(map(int, input().split()))
mp = [0] * 21
for i in a:
	for j in range(21):
		mp[j] += i >> j & 1
res = 0
for i in range(n):
	num = 0
	for j in range(21):
		if mp[j] > 0:
			num += 1 << j
			mp[j] -= 1
	res += num ** 2
print(res)


a = (*map(int, [*open(0)][1].split()),)
l = [0] * len(a)
for i in range(20):
	m = sum([n >> i & 1 for n in a])
	l[:m] = [n | 1 << i for n in l[:m]]
print(sum([n * n for n in l]))


n = int(input())
a_vec = list(map(int, input().split()))
bin_deg_vec = [0] * 21
for i in range(n):
	i_n = a_vec[i]
	index = 0
	while index < 21:
		rem = i_n % 2
		bin_deg_vec[index] += rem
		index += 1
		i_n = i_n // 2
out_sum = 0
while sum(bin_deg_vec) > 0:
	i_num = 0
	index = 20
	while index >= 0:
		if bin_deg_vec[index] > 0:
			i_num += pow(2, index)
			bin_deg_vec[index] -= 1
		index -= 1
	out_sum += pow(i_num, 2)
print(out_sum)


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
ts = [2 ** i for i in range(21)]
ps = [0] * 21
for v in a:
	for i in range(21):
		if v & 1 << i:
			ps[i] += 1
ans = 0
for i in range(n):
	v = 0
	for j in range(21):
		if ps[j]:
			ps[j] -= 1
			v += ts[j]
	ans += v ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
bit = [[0] * 20 for _ in range(n)]
bit1 = [[0] * 20 for _ in range(n)]
for i in range(n):
	c = 19
	for j in reversed(bin(a[i])[2:]):
		if j == '1':
			bit[i][c] = 1
		c -= 1
ct = 0
count = [0] * 20
for j in range(20):
	ct = 0
	for i in range(n):
		ct += bit[i][j]
	count[j] = ct
ans = [[0] * 20 for _ in range(n)]
for j in range(20):
	i = 0
	while count[j] > 0:
		ans[i][j] = 1
		count[j] -= 1
		i += 1
f = 0
for num in ans:
	p = 1
	a = 0
	for i in range(19, -1, -1):
		a += num[i] * p
		p *= 2
	f += a * a
print(f)


import sys
inputr = lambda : sys.stdin.readline().rstrip('\n')
input = sys.stdin.readline
from collections import deque
n = int(input())
A = sorted(map(int, input().split()))
avail = [deque() for _ in range(20)]
for i in range(n):
	v = A[i]
	for j in range(20):
		if v & 1 << j == 0:
			if avail[j]:
				k = avail[j].popleft()
				A[i] |= 1 << j
				A[k] &= ~(1 << j)
				avail[j].append(i)
		else:
			avail[j].append(i)
r = 0
for v in A:
	r += v ** 2
print(r)


n = int(input())
A = list(map(int, input().split()))
D = {}
for i in range(21):
	D[i] = 0
for i in range(n):
	d = bin(A[i])[2:]
	for j in range(len(d) - 1, -1, -1):
		if d[j] == '1':
			D[len(d) - 1 - j] += 1
sum = 0
for i in range(n):
	curr = 0
	for j in range(21):
		if D[j] > 0:
			curr += 2 ** j
			D[j] -= 1
	sum += curr ** 2
print(sum)


n = int(input())
a = list(map(int, input().split()))
deg_count = []
for i in range(n):
	deg = 0
	while a[i] > 0:
		if deg > len(deg_count) - 1:
			deg_count.append(0)
		if a[i] & 1:
			deg_count[deg] += 1
		a[i] >>= 1
		deg += 1
ans = 0
for i in range(n):
	num = 0
	for deg in range(len(deg_count)):
		if deg_count[deg] > 0:
			num += 1 << deg
			deg_count[deg] -= 1
	ans += num * num
print(ans)


n = int(input())
list1 = list(map(int, input().strip().split()))
ans = []
for _ in range(20):
	ans.append(0)
for i in range(n):
	x = list1[i]
	count = 0
	while x:
		if x % 2 != 0:
			ans[count] += 1
		x = x // 2
		count += 1
loop = max(ans)
tot = 0
for _ in range(loop):
	sum = 0
	for i in range(len(ans)):
		if ans[i] > 0:
			ans[i] -= 1
			sum += 2 ** i
	tot += sum ** 2
print(tot)


n = int(input())
a = input().split()
b = []
for i in range(n):
	a[i] = int(a[i])
a.sort()
c = []
for i in range(21):
	c.append(0)
for i in range(n):
	for j in range(21):
		if a[i] >= pow(2, 20 - j):
			c[20 - j] += 1
			a[i] -= pow(2, 20 - j)
t = 0
while c.count(0) < 21:
	r = 0
	for i in range(21):
		if c[i] > 0:
			r += pow(2, i)
			c[i] -= 1
	t += r * r
print(t)


N = int(input())
A = list(map(int, input().split()))
arr = [0] * 20
for a in A:
	for i in range(20):
		if a & 1 << i:
			arr[i] += 1
ans = 0
for i in range(N):
	t = 0
	for (j, a) in enumerate(arr):
		if i < a:
			t += 1 << j
	ans += t * t
print(ans)


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def solve():
	po = []
	for i in range(21):
		po.append(pow(2, i))
	n = I()
	l = IL()
	bit = []
	for i in range(21):
		bit.append(0)
	for ll in l:
		cnt = 0
		while ll > 0:
			if ll & 1 == 1:
				bit[cnt] += 1
			cnt += 1
			ll = ll // 2
	ans = 0
	while True:
		no = 0
		for i in range(21):
			if bit[i] > 0:
				no += po[i]
				bit[i] -= 1
		if no > 0:
			ans += no * no
		else:
			break
	print(ans)
solve()


def main():
	n = int(input())
	l = [int(j) for j in input().split()]
	ans = 0
	mx = 0
	ct = [0] * 20
	for i in range(n):
		for j in range(20):
			if l[i] & 1 << j:
				ct[j] += 1
	f = 0
	for i in range(n):
		ans = 0
		for j in range(20):
			if ct[j] > i:
				ans = ans | 1 << j
		f += ans ** 2
	print(f)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = list(map(int, input().split()))
bit = [0] * 25
for x in s:
	i = 0
	while x != 0:
		bit[i] += x % 2
		x //= 2
		i += 1
ans = 0
while True:
	tmp = 0
	for (i, x) in enumerate(bit):
		if x != 0:
			tmp += 2 ** i
			bit[i] -= 1
	if tmp == 0:
		break
	ans += tmp ** 2
print(ans)


import sys
input = sys.stdin.readline
cnt = [0] * 20
n = int(input())
a = [int(item) for item in input().split()]
for item in a:
	for i in range(20):
		if item & 1 << i:
			cnt[i] += 1
ans = 0
for i in range(n):
	val = 0
	for j in range(20):
		if cnt[j] > 0:
			val |= 1 << j
			cnt[j] -= 1
	if val == 0:
		break
	ans += val * val
print(ans)


n = int(input())
a = list(map(int, input().split()))
x2 = [0] * 30
for i in a:
	x = i
	j = 0
	while x > 0:
		x2[j] += x % 2
		x = x // 2
		j += 1
ans = 0
summ = sum(x2)
while summ > 0:
	x = 0
	p2 = 1
	for i in range(20):
		if x2[i] > 0:
			x = x + p2
			x2[i] -= 1
			summ -= 1
		p2 *= 2
	ans += x ** 2
print(ans)


def squaresum(n, array):
	times = [0 for i in range(20)]
	for m in array:
		i = 0
		while m:
			times[i] += m & 1
			m >>= 1
			i += 1
	max_times = max(times)
	res = 0
	for j in range(max_times):
		cur = 0
		for i in range(20):
			if times[i]:
				cur += 1 << i
				times[i] -= 1
		res += cur * cur
	return res
n = int(input())
array = [int(s) for s in input().split()]
print(squaresum(n, array))


n = int(input())
l = list(map(int, input().split()))
ln = len(bin(max(l))[2:])
l2 = [0] * ln
for i in l:
	x = list(map(int, bin(i)[2:]))
	x = [0] * (ln - len(x)) + x
	l2 = [sum(j) for j in zip(l2, x)]
s = 0
for i in range(max(l2)):
	x = ''
	for j in range(len(l2)):
		if l2[j] > 0:
			l2[j] -= 1
			x += '1'
		else:
			x += '0'
	s += int(x, 2) ** 2
print(s)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import deque

def main():
	n = ri()
	bits = [0] * 20
	a = ria()
	for i in a:
		for j in range(20):
			if i & 1 << j:
				bits[j] += 1
	ans = 0
	c = 0
	while c != 20:
		x = 0
		c = 0
		for j in range(20):
			if bits[j] == 0:
				c += 1
			if bits[j] > 0:
				x = x | 1 << j
				bits[j] -= 1
		ans += x * x
	print(ans)

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from functools import reduce
n = int(input())
a = list(map(int, input().split()))
b = [0] * 32
c = [0] * n
for i in a:
	for j in range(32):
		if i & 1 << j:
			b[j] += 1
for j in range(32):
	for k in range(b[j]):
		c[n - 1 - k] |= 1 << j
s = 0
for i in c:
	s += i ** 2
print(s)


n = int(input())
array = [*map(lambda x: int(x), input().split())]
place = []
for i in range(21):
	digits = []
	x = 2 ** (20 - i)
	count = 0
	for j in range(len(array)):
		if array[j] >= x:
			count += 1
			array[j] -= x
	for i in range(count):
		digits.append(1)
	for i in range(n - count):
		digits.append(0)
	place.append(digits)
final = []
for i in range(len(array)):
	placeholder = 0
	for k in range(21):
		placeholder += 2 ** (20 - k) * place[k][i]
	final.append(placeholder)
total = sum([x * x for x in final])
print(total)


n = int(input())
a = list(map(int, input().split()))
lis = [0] * 22
for i in range(n):
	for j in range(22):
		if a[i] & 2 ** j > 0:
			lis[j] += 1
ans = 0
for i in range(n):
	now = 0
	for j in range(22):
		if lis[j] > 0:
			lis[j] -= 1
			now += 2 ** j
	ans += now ** 2
print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
bit = [0] * 25
for i in R():
	j = 0
	while i:
		if i & 1:
			bit[j] += 1
		i >>= 1
		j += 1
flg = True
ans = 0
while flg:
	val = 1
	sm = 0
	flg = False
	for i in range(22):
		if bit[i]:
			sm += val
			bit[i] -= 1
			flg = True
		val += val
	ans += sm * sm
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split(' ')))
l.sort()
mat = []
m = 20
c = 25
for i in range(n):
	z = bin(l[i])[2:]
	diff = c - len(z)
	z = diff * '0' + z
	mat.append(z)
temp = [['0' for i in range(n)] for j in range(25)]
for i in range(n):
	for j in range(25):
		temp[j][i] = mat[i][j]
for i in range(25):
	temp[i].sort()
a = []
for i in range(n):
	ans = ''
	for j in range(25):
		ans += temp[j][i]
	a.append(ans)
res = 0
for i in range(len(a)):
	res += int(a[i], 2) ** 2
print(res)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	counts = [0] * 21
	for i in range(len(counts)):
		mask = 1 << i
		for x in A:
			if x & mask:
				counts[i] += 1
	B = [0 for i in range(N)]
	for (i, c) in enumerate(counts):
		mask = 1 << i
		for j in range(c):
			B[j] += mask
	return sum((x * x for x in B))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = solve(N, A)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
ps = [0] * 21
ind = {int(2 ** i): i for i in range(21)}
for i in range(n):
	k = a[i]
	while k > 0:
		p = k & -k
		k -= p
		ps[ind[p]] += 1
ss = 0
while max(ps) > 0:
	s = 0
	for i in range(21):
		if ps[i]:
			s += int(2 ** i)
			ps[i] -= 1
	ss += s * s
print(ss)


n = int(input())
a = list(map(int, input().split()))
count = [0] * 20
for e in a:
	for i in range(20):
		if e & 1 << i:
			count[i] += 1
res = 0
for i in range(n):
	x = 0
	for j in range(20):
		if count[j] > i:
			x += 1 << j
	res += x * x
print(res)


n = int(input())
a = list(map(int, input().split()))
bits = [0] * 21
for i in a:
	ct = 0
	while i:
		bits[ct] += i % 2
		i //= 2
		ct += 1
ans = 0
while bits != [0] * 21:
	cur = 0
	for i in range(20, -1, -1):
		if bits[i]:
			bits[i] -= 1
			cur += 2 ** i
	ans += cur ** 2
print(ans)


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])
N = int(input())
A = alele()
if N == 1:
	print(A[0] ** 2)
else:
	mark = [0] * 20
	for i in A:
		for j in range(20):
			x = i >> j
			y = x & 1
			if y:
				mark[j] += 1
	Ans = 0
	for i in range(N):
		temp = 0
		for j in range(20):
			if mark[j] >= 1:
				mark[j] -= 1
				temp += 2 ** j
		Ans += temp ** 2
	print(Ans)


def answer(n, A):
	l = [0] * 21
	for i in range(21):
		count = 1 << i
		for j in A:
			if count & j:
				l[i] += 1
	ans = 0
	for _ in range(max(l)):
		num = 0
		for i in range(len(l)):
			if l[i] > 0:
				num += 2 ** i
				l[i] -= 1
		ans += num ** 2
	return ans
n = int(input())
A = list(map(int, input().split()))
print(answer(n, A))


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	n = ii()
	a = li()
	b = [0] * n
	for i in range(21):
		c = 0
		for j in a:
			if j >> i & 1:
				c += 1
		for j in range(c):
			b[j] |= 1 << i
	ans = 0
	for j in b:
		ans += j * j
	print(ans)
solve()


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1

def bin(n):
	ret = []
	for i in range(21, -1, -1):
		k = n >> i
		if k & 1:
			ret.append(1)
		else:
			ret.append(0)
	return ret
for __ in range(t):
	n = int(input())
	l1 = []
	l = list(map(int, input().split()))
	maxi = 0
	ind = -1
	pos = [0] * 22
	for i in range(n):
		l1.append(bin(l[i]))
		for j in range(len(l1[i])):
			if l1[i][j] == 1:
				pos[j] += 1
	alld = max(pos[:])
	fans = 0
	while alld > 0:
		ans = 0
		power = 0
		for i in range(21, -1, -1):
			if pos[i] > 0:
				pos[i] -= 1
				ans += 2 ** power
			power += 1
		fans += ans ** 2
		alld -= 1
	print(fans)


def main():
	n = int(input())
	nums = [int(x) for x in input().split()]
	bits = {}
	for i in range(20):
		bits[i] = 0
	for num in nums:
		x = 0
		while num > 0:
			if num % 2 == 1:
				bits[x] += 1
				num -= 1
			num /= 2
			x += 1
	mysum = 0
	temp = []
	for x in bits:
		if bits[x] == 0:
			temp.append(x)
	for x in temp:
		bits.pop(x)
	while len(bits) > 0:
		temp = []
		remaining_bits = [x for x in bits]
		y = min((bits[x] for x in bits))
		mysum += sum((2 ** x for x in remaining_bits)) ** 2 * y
		for x in bits:
			bits[x] -= y
			if bits[x] == 0:
				temp.append(x)
		for x in temp:
			bits.pop(x)
	return mysum
output = main()
print('{0}'.format(output))


n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(22)]
for i in a:
	k = 0
	while i > 0:
		if i & 1 == 1:
			b[k] += 1
		k += 1
		i //= 2
ans = 0
while 1:
	k = 0
	for i in range(22):
		if b[i] > 0:
			k |= 1 << i
			b[i] -= 1
	if k == 0:
		break
	ans += k ** 2
print(ans)


import sys
input = sys.stdin.readline
f = lambda : list(map(int, input().split()))
ans = 0
n = int(input())
inp = f()
bits = [0] * 22
for i in inp:
	for j in range(22):
		if i >> j & 1:
			bits[j] += 1
for i in range(n):
	res = 0
	for j in range(22):
		if bits[j]:
			res += 1 << j
			bits[j] -= 1
	ans += res ** 2
print(ans)


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


from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
bitI = [0 for x in range(22)]
for x in a:
	b = 0
	while x > 0:
		if x % 2 == 1:
			bitI[b] += 1
		b += 1
		x = x >> 1
total = 0
for x in range(max(bitI)):
	num = 0
	for y in range(22):
		if bitI[y]:
			num += 2 ** y
			bitI[y] -= 1
	total += num ** 2
print(total)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['YES', 'NO']
test_case = 1
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	bit = [0] * 21
	for i in a:
		x = i
		j = 0
		while x:
			z = x % 2
			x //= 2
			if z:
				bit[j] += 1
			j += 1
	ans = []
	bit.reverse()
	for _ in range(n):
		x = 0
		for i in range(len(bit)):
			x *= 2
			if bit[i]:
				x += 1
				bit[i] -= 1
		ans.append(x * x)
	print(sum(ans))


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import sys
input = sys.stdin.readline
import bisect
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().strip().split()))
rls = lambda : list(map(str, input().split()))
n = int(input())
a = rl()
b = [0] * 21
for i in a:
	x = bin(i)[2:][::-1]
	for j in range(0, len(x)):
		if x[j] == '1':
			b[j] += 1
ans = 0
for i in range(0, n):
	x = 0
	for j in range(0, 21):
		if b[j] > 0:
			x = x | 1 << j
			b[j] -= 1
	ans = ans + x * x
print(ans)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	cnt = [0] * 20
	ar = inpt()
	for j in ar:
		for i in range(20):
			if j & 1 << i:
				cnt[i] += 1
	ans = 0
	for j in ar:
		x = 0
		for i in range(20):
			if cnt[i]:
				x |= 1 << i
				cnt[i] -= 1
		ans += x * x
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


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


from sys import stdin
n = int(stdin.readline())
arr = list(map(lambda x: bin(int(x))[2:], stdin.readline().split()))
for i in range(n):
	arr[i] = '0' * (30 - len(arr[i])) + arr[i]
i = 0
y = pow(2, 29)
lst = [0] * n
while i < 30:
	cou = 0
	for j in range(n):
		if arr[j][i] == '1':
			cou += 1
	while cou:
		lst[cou - 1] += y
		cou -= 1
	i += 1
	y //= 2
su = 0
for i in lst:
	su += pow(i, 2)
print(su)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
ct = [0] * 30
for x in a:
	for sf in range(30):
		ct[sf] += x >> sf & 1
ans = [0] * n
for i in range(30):
	for j in range(ct[i]):
		ans[j] |= 1 << i
print(sum([x ** 2 for x in ans]))


import io
import os
from math import log, ceil
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	e = max(a)
	e = ceil(log(e + (e == 0), 2)) + 1
	b = [1 << i for i in range(e)]
	c = [0 for i in range(e)]
	d = [0 for i in range(n)]
	su = 0
	for i in a:
		for j in range(e):
			if i & b[j]:
				d[c[j]] += b[j]
				c[j] += 1
	for i in d:
		su += pow(i, 2)
	print(su)
main()


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
t = int(input())
arr = get_array()
freq = [0 for i in range(21)]
for i in range(t):
	for j in range(21):
		if arr[i] & 1 << j:
			freq[j] += 1
ans = 0
for i in range(t):
	tans = 0
	for j in range(21):
		if freq[j] > 0:
			freq[j] -= 1
			tans += 1 << j
	ans += tans * tans
print(ans)


n = int(input())
(*arr,) = map(int, input().split())
bits = [0] * 30
for v in arr:
	idx = 0
	while v:
		if v & 1:
			bits[idx] += 1
		v >>= 1
		idx += 1
bits = bits[::-1]
s = 0
while bits.count(0) != len(bits):
	num = 0
	for (i, v) in enumerate(bits):
		num <<= 1
		if v:
			bits[i] -= 1
			num += 1
	s += num * num
print(s)


n = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(n):
	x = bin(A[i])[2:]
	x = list('0' * (21 - len(x)) + x)
	ans.append(x)
B = []
for i in range(21):
	x = sum((1 if ans[j][i] == '1' else 0 for j in range(n)))
	x = ['0'] * (n - x) + ['1'] * x
	B.append(x)
C = []
for i in range(n):
	num = ''
	for j in range(21):
		num += B[j][i]
	num = '0b' + num
	C.append(int(num, 2) ** 2)
print(sum(C))


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	c = [0] * 20
	for i in mints():
		for j in range(20):
			c[j] += i >> j & 1
	s = 0
	for i in range(n):
		x = 0
		for j in range(20):
			if c[j] > 0:
				c[j] -= 1
				x += 1 << j
		s += x ** 2
	print(s)
solve()


from sys import stdin
input = stdin.readline
n = int(input())
a = [*map(lambda x: bin(int(x))[:1:-1], input().split())]
c1 = len(max(a, key=len))
a = [x + '0' * (c1 - len(x)) for x in a]
b = [sum((c[i] == '1' for c in a)) for i in range(c1)]
c2 = max(b)
ans = 0
for i in range(c2):
	num = ''
	for i in range(c1):
		if b[i] != 0:
			b[i] -= 1
			num += '1'
		else:
			num += '0'
	ans += int(num[::-1], 2) ** 2
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()
t = int(input())
bit_count = [0 for i in range(0, 25)]
powOf2 = [1 for i in range(0, 25)]
for i in range(1, 25):
	powOf2[i] = powOf2[i - 1] * 2
inp_numbers = list(map(int, input().split()))
for i in range(t):
	num_bin = bin(inp_numbers[i])[:1:-1]
	for j in range(0, len(num_bin)):
		if num_bin[j] == '1':
			bit_count[j] += 1
finalAns = 0
while True:
	value = 0
	for i in range(0, 25):
		if bit_count[i] > 0:
			bit_count[i] -= 1
			value += powOf2[i]
	if value > 0:
		finalAns += value * value
	else:
		break
print(finalAns)


import math
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
maxBit = 30
cnt = [0] * maxBit
for i in a:
	for j in range(maxBit):
		if i >> j & 1:
			cnt[j] += 1
b = [0] * n
for i in range(maxBit):
	for j in range(cnt[i]):
		b[j] += 1 << i
ans = 0
for i in b:
	ans += i * i
print(ans)


import sys
pprint = lambda s: print(' '.join(map(str, s)))
input = lambda : sys.stdin.readline().strip()
ipnut = input
n = int(input())
a = list(map(lambda x: list(reversed(list(map(int, bin(int(x))[2:])))), input().split()))
lox = {}
for i in a:
	for j in range(len(i)):
		if i[j]:
			lox[j] = lox.get(j, 0) + 1
ans = [0 for i in range(n)]
for (b, k) in lox.items():
	d = 2 ** b
	for i in range(k):
		ans[i] += d
print(sum(map(lambda x: x ** 2, ans)))


import math
import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
q = [0] * 21
i = 0
ii = 1
mx = max(a)
while ii <= mx:
	for e in a:
		if e & ii:
			q[i] += 1
	ii *= 2
	i += 1
ans = 0
while True:
	ok = True
	s = 0
	for i in range(21):
		if q[i] > 0:
			ok = False
			s += 2 ** i
			q[i] -= 1
	if ok:
		break
	ans += s ** 2
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
b = [0] * 21
for i in a:
	for j in range(20):
		if i & 1:
			b[j] += 1
		i = i >> 1
ans = 0
for _ in range(n):
	x = 0
	for j in range(20):
		if b[j]:
			x += 1 << j
			b[j] -= 1
	ans += x ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
d = {}
for i in range(20):
	d[i] = 0
for i in range(n):
	x = bin(l[i])[2:][::-1]
	for i in range(len(x)):
		if x[i] == '1':
			d[i] += 1
ans = 0
while True:
	a = 0
	for i in d:
		if d[i] > 0:
			a += 2 ** i
			d[i] -= 1
		else:
			a += 0
	ans += a ** 2
	if a == 0:
		break
print(ans)


import sys
inpy = [int(x) for x in sys.stdin.read().split()]
n = inpy[0]
memo = [0] * 21
for i in inpy[1:]:
	num = i
	for j in range(21):
		if num & 1:
			memo[j] += 1
		num = num >> 1
res = 0
for i in range(n):
	(cur, x) = (0, 1)
	for j in range(21):
		if memo[j] > 0:
			memo[j] -= 1
			cur += x
		x = x << 1
	res += cur ** 2
print(res)


n = int(input())
A = list(map(int, input().split()))
nums = [0] * n
for i in range(0, 20):
	ones = sum(list(map(lambda x: x >> i & 1, A)))
	for j in range(0, ones):
		nums[j] += 2 ** i
print(sum(list(map(lambda x: x ** 2, nums))))


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(i) for i in input().split()]
o = 0
cnt = [0] * 22
for i in a:
	j = 0
	while i > 0:
		if i % 2:
			cnt[j] += 1
		i = i >> 1
		j += 1
c = sum(cnt)
ans = 0
while c > 0:
	curr = 0
	for i in range(21):
		if cnt[i] > 0:
			curr += 2 ** i
			cnt[i] -= 1
			c -= 1
	ans += curr ** 2
print(ans)


n = int(input())
a = [int(v) for v in input().split()]
p = 1
b = [0] * n
for j in range(20):
	s = 0
	for v in a:
		if v & p:
			s = s + 1
	for k in range(0, s):
		b[k] = b[k] | p
	p = p << 1
s = 0
for v in b:
	s = s + v * v
print(s)


n = int(input())
a = list(map(int, input().split()))
l = [0] * 20
for i in range(n):
	t = a[i]
	j = 0
	while t:
		if t & 1 == 1:
			l[j] += 1
		t >>= 1
		j += 1
ans = [0] * n
for i in range(20):
	for j in range(l[i]):
		ans[j] |= 1 << i
print(sum([i ** 2 for i in ans]))


from sys import stdin, stdout
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().strip().split(' ')))
count = [0 for i in range(22)]
for i in arr:
	ctr = 0
	while i > 0:
		if i & 1:
			count[ctr] += 1
		ctr += 1
		i = i >> 1
farr = [0 for i in range(n)]
for i in range(len(count)):
	for j in range(count[i]):
		farr[j] = farr[j] | 1 << i
ans = 0
for i in farr:
	ans += i ** 2
stdout.write(str(ans) + '\n')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ff(x):
	if x > 0:
		return '1'
	else:
		return '0'
from math import sqrt
Testcase = 1
for _ in range(Testcase):
	n = inin()
	b = [0 for i in range(21)]
	arr = inar()
	for i in arr:
		temp = i
		index = 0
		while temp > 0:
			b[index] += temp % 2
			temp //= 2
			index += 1
	ss = 0
	b.reverse()
	while any(b):
		aa = ''.join([ff(i) for i in b])
		for i in range(21):
			if b[i] > 0:
				b[i] -= 1
		nm = int(aa, 2)
		ss += nm ** 2
	print(ss)


n = int(input())
arr = list(map(int, input().split()))
bits = [0 for i in range(21)]
ans = [0 for i in range(n)]
for i in range(n):
	for j in range(21):
		if arr[i] >> j & 1:
			bits[j] += 1
for i in range(21):
	for j in range(bits[i]):
		x = pow(2, i)
		ans[j] = ans[j] | x
f = 0
for x in ans:
	f += x * x
print(f)


n = int(input())
f = list(map(int, input().split()))
m = [0 for _ in range(21)]
for i in range(n):
	for b in range(21):
		m[b] += f[i] >> b & 1
res = 0
while 1:
	fg = True
	mask = 0
	for i in range(21):
		if m[i] != 0:
			mask |= 1 << i
			m[i] -= 1
			fg = False
	res += mask ** 2
	if fg:
		break
print(res)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
from math import *
import copy
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def bo(i):
	return ord(i) - ord('a')
from copy import *
from bisect import *

def lol(p):
	h = bin(p)[2:]
	h = '0' * (60 - len(h)) + h
	print(h)
n = fi()
a = li()
ans = 0
c = [0 for i in range(31)]
for i in range(n):
	for j in range(30):
		if a[i] & 1 << j:
			c[j] += 1
for i in range(n):
	x = 0
	for j in range(30):
		if c[j] > 0:
			c[j] -= 1
			x |= 1 << j
	ans += x ** 2
print(ans)


n = int(input())
arr = [x for x in map(int, input().split(' '))]
vals = [0 for x in range(20)]
offsets = [1 << x for x in range(20)]
setbits = 0
for num in arr:
	for i in range(len(vals)):
		if num & offsets[i]:
			vals[i] += 1
			setbits += 1
mysum = 0
while setbits > 0:
	tempnum = 0
	for (i, v) in enumerate(vals):
		if v != 0:
			tempnum += offsets[i]
			vals[i] -= 1
			setbits -= 1
	mysum += tempnum * tempnum
print(mysum)


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


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)


n = int(input())
v = input().split(' ')
c = 30 * [0]
r = 0
for i in range(30):
	for a in v:
		c[i] = c[i] + (int(a) & 2 ** i != 0)
for k in range(n):
	x = 0
	for i in range(30):
		if k < c[i]:
			x = x + 2 ** i
	r = r + x * x
print(r)


from decimal import Decimal as D
num = D(input())
arr = []
l2 = input().split(' ')
for a in l2:
	arr.append(int(a))
if num == 1:
	print(arr[0] ** 2)
else:
	d = {}
	for b in arr:
		conv = list(bin(b)[2:])
		conv.reverse()
		for j in range(len(conv)):
			c = conv[j]
			if c == '1':
				if j not in d:
					d[j] = 1
				else:
					d[j] += 1
	ans = 0
	while d:
		temp = 0
		expo = list(d.keys())
		ma_expo = max(expo)
		number = []
		for l in range(ma_expo + 1):
			number.append(0)
		for k in range(ma_expo + 1):
			if k in d:
				if d[k] > 1:
					d[k] -= 1
					number[k] = 1
				elif d[k] == 1:
					del d[k]
					number[k] = 1
			elif k not in d:
				number[k] = 0
		for (index, r) in enumerate(number):
			temp += 2 ** index * r
		ans += temp ** 2
	print(ans)


from sys import stdin, stdout

class Solve:

	def solve(self):
		r = input
		w = stdout.write
		n = int(input())
		a = [int(x) for x in r().split()]
		a.sort(reverse=True)
		maxbit = len(bin(a[0])) - 2
		for i in range(maxbit):
			op_num = 1 << i
			ones = 0
			for j in range(n):
				b = a[j] & op_num
				if b:
					ones += 1
			reset_bit = 2 ** maxbit - 1 ^ op_num
			for j in range(n):
				if ones:
					a[j] |= op_num
					ones -= 1
				else:
					a[j] &= reset_bit
		ans = 0
		for i in range(n):
			ans += a[i] ** 2
		print(ans)

def main():
	s = Solve()
	s.solve()
main()


bits = 20
n = int(input())
a = list(map(int, input().split()))
counts = [0] * bits
for x in a:
	for i in range(bits):
		counts[i] += x & 1
		x >>= 1
b = [0] * n
for (i, count) in enumerate(counts):
	for j in range(count):
		b[j] |= 1 << i
res = sum((x ** 2 for x in b))
print(res)


n = int(input())
a = map(int, input().split())
l = [0 for _ in range(20)]
for ai in a:
	li = 19
	while ai > 0:
		l[li] += ai % 2
		ai = ai // 2
		li -= 1
sum_sqr = 0
while sum(l) > 0:
	li = 0
	num = 0
	while li < 20:
		if l[li] > 0:
			num = 2 * num + 1
			l[li] -= 1
		else:
			num = 2 * num
		li += 1
	sum_sqr += num * num
print(sum_sqr)


n = int(input())
a = list(map(int, input().split()))
b = [0] * n
for bit in range(20):
	cnt = 0
	for i in range(n):
		if a[i] & 1 << bit:
			cnt += 1
	for i in range(cnt):
		b[i] |= 1 << bit
ans = 0
for i in range(n):
	ans += b[i] ** 2
print(ans)


n = int(input())
lis = sorted(map(int, input().split()))
bit = [0] * 21
for i in range(21):
	k = 2 ** i
	for j in range(n):
		if k & lis[j]:
			bit[i] += 1
ans = 0
while sum(bit) != 0:
	no = 0
	for i in range(21):
		if bit[i]:
			no += 2 ** i
			bit[i] -= 1
	ans += no * no
print(ans)


n = int(input())
a = list(map(int, input().split()))
arr = [0] * n
for i in range(22):
	bit = 1 << i
	ind = 0
	for j in a:
		if bit & j:
			arr[ind] += bit
			ind += 1
ans = 0
for i in arr:
	ans += i ** 2
print(ans)


n = int(input())
l = list(map(int, input().split()))
bits = [0 for _ in range(22)]
for i in l:
	for j in range(22):
		if i >> j & 1 == 1:
			bits[j] += 1
total = 0
for i in range(n):
	current = 0
	for j in range(22):
		if bits[j] > 0:
			current |= 1 << j
			bits[j] -= 1
	total += current * current
print(total)


n = int(input())
A = list(map(int, input().split()))
Arr = [0 for i in range(21)]
for val in A:
	a = bin(val).replace('0b', '')
	for i in range(len(a)):
		Arr[20 - i] = Arr[20 - i] + int(a[len(a) - 1 - i])
a = sum(Arr)
ans = 0
while a > 0:
	s = ''
	for i in range(21):
		if Arr[i] > 0:
			s = s + '1'
			a = a - 1
			Arr[i] = Arr[i] - 1
		else:
			s = s + '0'
	v = int(s, 2)
	ans = ans + v * v
print(ans)


def getmini(arr):
	maxi = 1000000000000
	for i in arr:
		if i > 0:
			maxi = min(maxi, i)
	return maxi
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(arr[0] * arr[0])
	exit()
else:
	freq = [0 for i in range(21)]
	for i in arr:
		b = bin(i)[2:]
		if len(b) < 21:
			b = '0' * (21 - len(b)) + b
		for z in range(21):
			if b[z] == '1':
				freq[z] += 1
	ans = 0
	while freq.count(0) != 21:
		cnt = getmini(freq)
		st = ['0' for i in range(21)]
		for i in range(21):
			if freq[i] == 0:
				pass
			else:
				freq[i] -= cnt
				st[i] = '1'
		el = int(''.join(st), 2)
		ans += cnt * pow(el, 2)
	print(ans)


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


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys

def count(A, d):
	cnt = 0
	for a in A:
		cnt += a >> d & 1
	return cnt

def solve(n, A):
	if n == 1:
		return A[0] ** 2
	digit = 0
	for a in A:
		l = a.bit_length()
		digit = max(digit, l)
	Cnt = [0] * digit
	for d in range(digit):
		Cnt[d] = count(A, d)
	Ans = [0] * n
	for (d, cnt) in enumerate(Cnt):
		tmp = 1 << d
		for i in range(cnt):
			Ans[i] += tmp
	ans = 0
	for a in Ans:
		ans += a ** 2
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = solve(n, A)
	sys.stdout.write(str(ans) + '\n')
main()


n = int(input())
arr = list(map(int, input().split()))
bits = [0] * 30
for val in arr:
	for i in range(30):
		if val & 1 << i:
			bits[i] += 1
pows = [2 ** i for i in range(30)]
tmps = []
for i in range(max(bits)):
	tmp = 0
	for j in range(30):
		if bits[j] == 0:
			continue
		tmp += pows[j]
		bits[j] -= 1
	tmps.append(tmp)
ans = 0
for val in tmps:
	ans += val ** 2
print(ans)


def solve():
	nm = [0 for i in range(21)]
	step = [1]
	for i in range(20):
		step.append(step[-1] * 2)
	n = int(input())
	lst = list(map(int, input().split()))
	for i in range(n):
		num = lst[i]
		st = 0
		while num:
			ar = num % 2
			nm[st] += ar
			num //= 2
			st += 1
	ans = 0
	for i in range(n):
		rnum = 0
		for j in range(21):
			if nm[j] > 0:
				nm[j] -= 1
				rnum += step[j]
		ans += rnum * rnum
	print(ans)
for i in range(1):
	solve()


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def dec2bin(n):
	n = int(n)
	a = []
	l = 0
	while n:
		a.append(n % 2)
		n //= 2
		l += 1
	return (a[::-1], l)

def bin2dec(l):
	p = 0
	s = 0
	for i in l[::-1]:
		s += i * 2 ** p
		p += 1
	return s
n = int(input())
a = list(map(dec2bin, input().split()))
v = max((i[1] for i in a))
a = [[0] * (v - l) + i for (i, l) in a]
for i in range(v):
	ones = 0
	for j in a:
		ones += j[i]
	for j in range(n):
		if j < n - ones:
			a[j][i] = 0
		else:
			a[j][i] = 1
s = 0
for i in a:
	s += bin2dec(i) ** 2
print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2
from math import *
for _ in range(1):
	n = int(input())
	li = list(map(int, input().split()))
	check = [0] * 20
	for i in range(n):
		for b in range(20):
			if li[i] & 1 << b:
				check[b] += 1
	ans = 0
	for i in range(n):
		temp = 0
		for b in range(20):
			if check[b]:
				temp ^= 1 << b
				check[b] -= 1
		ans += temp ** 2
	print(ans)


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)


n = input()
import math

def isKthBitSet(i, k):
	if i & 1 << k - 1:
		return 1
	else:
		return 0
li = list(map(int, input().split()))
bits = [0 for i in range(21)]
for k in range(1, 21):
	for i in li:
		bits[k] += isKthBitSet(i, k)
numbers = []
while True:
	num = '0b'
	for i in range(len(bits) - 1, 0, -1):
		if bits[i] > 0:
			num += str(1)
			bits[i] -= 1
		else:
			num += str(0)
	numbers.append(int(num, 2))
	if int(num, 2) == 0:
		break
sum_ = 0
for i in numbers:
	sum_ += i ** 2
print(sum_)


BITS = 32
n = int(input())
a = list(map(int, input().split()))
bits = [0 for i in range(BITS)]
for x in a:
	for i in range(BITS):
		if x % 2 == 1:
			bits[i] += 1
		x //= 2
M = max(bits)
ret = 0
while M > 0:
	b = 0
	for i in range(BITS):
		if bits[i] > 0:
			b += 2 ** i
			bits[i] -= 1
	M -= 1
	ret += b * b
print(ret)


import math
n = int(input())
lis = list(map(int, input().split()))
cnt = [0 for i in range(20)]
for i in lis:
	for j in range(20):
		cnt[j] += (i & 1 << j) >> j
ans = 0
r = max(cnt)
while r:
	val = 0
	for i in range(20):
		if cnt[i]:
			val += 2 ** i
			cnt[i] -= 1
	ans += val ** 2
	r -= 1
print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
n = inputnum()
a = inputlist()
ones = [0] * 20
for i in range(n):
	for j in range(20):
		if a[i] >> j & 1:
			ones[j] += 1
ans = 0
for i in range(n):
	cur = 0
	for j in range(20):
		if ones[j] > 0:
			cur += 1 << j
			ones[j] -= 1
	ans += cur ** 2
print(ans)


import sys, os, io
from math import log, gcd
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
for _ in range(t):
	n = ii()
	l = li()
	b = [0] * 21
	for i in l:
		x = bin(i)[2:][::-1]
		for j in range(len(x)):
			b[j] += int(x[j])
	ans = 0
	while 1:
		f = 0
		s = ''
		for i in range(20, -1, -1):
			if b[i] > 0:
				s += '1'
				b[i] -= 1
			else:
				s += '0'
		s = int(s, 2)
		ans += s * s
		if s == 0:
			break
	print(ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor
from collections import Counter
from math import gcd
mod = 998244353

def main():
	for _ in range(1):
		n = int(input())
		arr = list(map(int, input().split()))
		cnt = [0] * 20
		for i in range(n):
			for shi in range(20):
				if arr[i] & 1 << shi:
					cnt[shi] += 1
		res = 0
		while sum(cnt):
			t = 0
			for i in range(20):
				if cnt[i] > 0:
					cnt[i] -= 1
					t += 1 << i
			res += t ** 2
		print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
arr = list(map(int, input().split()))
bits = [0 for i in range(21)]
for i in range(n):
	binary = str(bin(arr[i]))[2:]
	binary = binary[::-1]
	for j in range(len(binary) - 1, -1, -1):
		if binary[j] == '1':
			bits[j] += 1
res = []
bits = bits[::-1]
if sum(bits) > 0:
	while 1:
		num = ''
		for i in range(20, -1, -1):
			if bits[i] > 0:
				num = '1' + num
				bits[i] -= 1
			else:
				num = '0' + num
		res.append(int(num, 2))
		if sum(bits) == 0:
			break
	s = 0
	for ele in res:
		s += ele ** 2
	print(s)
else:
	print(0)


N = int(input())
A = list(map(int, input().split()))
llist = [0] * 21
for i in range(N):
	r = list(map(int, list(bin(A[i])[2:])))
	t = 20
	for j in range(len(r) - 1, -1, -1):
		if r[j] == 1:
			llist[t] += 1
		t -= 1
c = llist.count(0)
ans = 0
while c != 21:
	r = ''
	for i in range(len(llist)):
		if llist[i] >= 1:
			r += '1'
			llist[i] -= 1
		else:
			r += '0'
	t = int(r, 2)
	ans += t * t
	c = llist.count(0)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ct = [0] * 30
for x in a:
	for sf in range(30):
		ct[sf] += x >> sf & 1
ans = [0] * n
for i in range(30):
	for j in range(ct[i]):
		ans[j] |= 1 << i
print(sum([x ** 2 for x in ans]))


from collections import defaultdict

def read_list():
	return list(map(int, input().strip().split(' ')))

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
a = read_list()
dic = defaultdict(int)
for n in a:
	i = 0
	while n:
		if n & 1:
			dic[i] += 1
		i += 1
		n >>= 1
res = 0
while dic:
	tmp = 0
	mi = min(dic.values())
	dd = []
	for i in dic:
		tmp += 1 << i
		dic[i] -= mi
		if dic[i] == 0:
			dd.append(i)
	for aa in dd:
		del dic[aa]
	res += tmp ** 2 * mi
print(res)


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
bits = [0] * 21
for i in arr:
	for bit in range(21):
		if i & 1 << bit:
			bits[bit] += 1
ans = 0
for i in range(n):
	temp = 0
	for bit in range(21):
		if bits[bit]:
			temp = temp ^ 1 << bit
			bits[bit] -= 1
	ans += temp * temp
print(ans)


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 998244353

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k))))
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def solution(a, n):
	d = defaultdict(int)
	a = [list(reversed(bi(x).zfill(20))) for x in a]
	for i in range(20):
		for x in a:
			if x[i] == '1':
				d[i] += 1
	sol = [['0'] * 20 for _ in range(n)]
	for i in range(20):
		j = 0
		while d[i] > 0:
			sol[j][i] = '1'
			j += 1
			d[i] -= 1
	sol = [int(''.join(reversed(x)), 2) for x in sol]
	return sum((x ** 2 for x in sol))

def main():
	T = 1
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
dp = [0] * 20
for i in range(n):
	j = 20
	while j >= 0:
		if arr[i] & 1 << j:
			dp[j] += 1
		j -= 1
answer = 0
while True:
	temp = 0
	for i in range(20):
		if dp[i]:
			temp += 1 << i
			dp[i] -= 1
	if temp == 0:
		break
	answer += temp ** 2
out(answer)


n = int(input())
a = [int(C) for C in input().split()]
mat = [['0' for i in range(20)] for j in range(n)]
for i in range(20):
	q = 0
	for j in a:
		if j & 1 << i:
			mat[q][i] = '1'
			q += 1
x = 0
for i in mat:
	x += int(''.join(i[::-1]), 2) ** 2
print(x)


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(i) for i in input().split()]
bit = [0] * 20
for i in range(n):
	for j in range(20):
		if a[i] & 1 << j:
			bit[j] += 1
ans = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		if bit[j] > 0:
			tmp += 1 << j
		bit[j] -= 1
	ans += tmp * tmp
sys.stdout.write(str(ans))


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 20
for (i, num) in enumerate(a):
	for j in range(20):
		if num & 1 << j:
			cnt[j] += 1
ans = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		if cnt[j] > 0:
			tmp += 1 << j
			cnt[j] -= 1
	ans += tmp ** 2
print(ans)


n = int(input())

def binary(n):
	return str(bin(n))[2:]
ai = list(map(int, input().split()))
ai = list(map(binary, ai))
bits = [0 for _ in range(22)]
number = []
for i in ai:
	for ii in range(len(i)):
		if i[ii] == '1':
			bits[len(i) - int(ii) - 1] += 1
gg = max(bits)
while gg >= 0:
	num = 0
	for i in range(len(bits)):
		if bits[i] > 0:
			num += 2 ** i
			bits[i] -= 1
	number.append(num)
	gg -= 1
ans = 0
for i in number:
	ans += i ** 2
print(ans)


(n, arr) = (int(input()), list(map(int, input().split())))
s = [0] * n
for i in range(20):
	x = sum(list(map(lambda x: x >> i & 1, arr)))
	for k in range(x):
		s[k] |= 1 << i
print(sum(list(map(lambda x: x ** 2, s))))
num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()


from sys import stdin
input = stdin.readline
n = int(input())
arr = list(map(int, input().rstrip().split(' ')))
counts = [0] * 20
for i in range(n):
	for j in range(20):
		if arr[i] & 1 << j:
			counts[j] += 1
answer = 0
while True:
	temp = 0
	for i in range(20):
		if counts[i] > 0:
			temp += 1 << i
			counts[i] -= 1
	if temp == 0:
		break
	else:
		answer += temp ** 2
print(answer)


N = int(input())
A = list(map(int, input().split()))
BIT = [0] * 22
for a in A:
	for i in range(21):
		BIT[i] += a & 1
		a >>= 1
ANS = 0
while any(BIT):
	k = 1
	c = 0
	for i in range(21):
		if BIT[i]:
			c += k
			BIT[i] -= 1
		k <<= 1
	ANS += c * c
print(ANS)


n = int(input())
ar = list(map(int, input().split()))
li = [0] * 20
count = 0
st = 1
for i in range(20):
	for j in ar:
		if st & j:
			li[i] += 1
			count += 1
	st <<= 1
ans = 0
while count:
	st = 1
	tem = 0
	for i in range(20):
		if li[i] != 0:
			li[i] -= 1
			count -= 1
			tem += st
		st <<= 1
	ans += tem ** 2
print(ans)


from sys import stdin, stdout
from bisect import bisect, bisect_left, bisect_right

def gt():
	return map(int, stdin.readline().split())

def gi():
	return int(stdin.readline())

def gl():
	return list(map(int, stdin.readline().split()))

def gs():
	return stdin.readline()
power = []
i = 0
temp = 1
while i <= 21:
	i += 1
	power.append(temp)
	temp = temp * 2
t = gi()
bits = [0] * 21
a = gl()
for i in a:
	for j in range(20):
		if i & 1 << j:
			bits[j] += 1
ans = 0
while any(bits):
	temp = 0
	for j in range(21):
		if bits[j] > 0:
			bits[j] -= 1
			temp = temp + power[j]
	ans = ans + temp * temp
print(ans)


K = 20
ans = [0] * K
for n in map(int, [*open(0)][1].split()):
	for i in range(K):
		ans[i] += (n & 1 << i) >> i
M = max(ans)
s = 0
for i in range(M):
	n = 0
	for j in range(K):
		n += (ans[j] > i) << j
	s += n * n
print(s)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():
	n = II()
	aa = LI()
	cnt = [0] * 20
	for a in aa:
		for i in range(20):
			if a & 1:
				cnt[i] += 1
			a >>= 1
	ans = 0
	for _ in range(n):
		cur = 0
		for i in range(20):
			if cnt[i] == 0:
				continue
			cnt[i] -= 1
			cur += 1 << i
		ans += cur ** 2
	print(ans)
main()


import sys
import random
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def YESNO(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def main(n):
	(q, res) = ({}, [0 for i in range(n)])
	for i in list(map(lambda f: list(reversed(list(map(int, bin(int(f))[2:])))), tinput())):
		for o in range(len(i)):
			if i[o]:
				q[o] = q.get(o, 0) + 1
	for (i, v) in q.items():
		g = 2 ** i
		for i in range(v):
			res[i] += g
	print(sum([i * i for i in res]))
for inytd in range(1):
	main(iinput())


n = int(input())
g = [0] * 21
c = a = 0
for i in map(int, input().split()):
	b = bin(i)[2:].zfill(21)
	for j in range(21):
		if b[j] == '1':
			c += 1
			g[j] += 1
while c:
	t = ''
	for i in range(20, -1, -1):
		if g[i]:
			t = '1' + t
			c -= 1
			g[i] -= 1
		else:
			t = '0' + t
	a += int(t, 2) ** 2
print(a)


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = 1
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		a = inlt()
		bits = [[0 for i in range(21)] for j in range(n)]
		ones = [0 for i in range(21)]
		curr = 2
		for i in range(21):
			for j in range(len(a)):
				if a[j] % curr == 1:
					ones[i] = ones[i] + 1
				a[j] = a[j] // 2
		ans = 0
		for i in range(n):
			no = 0
			curr = 1
			for j in range(21):
				if ones[j] > 0:
					no = no + curr
					ones[j] = ones[j] - 1
				curr = curr * 2
			ans = ans + no * no
		print(ans)
main()


def gns():
	return list(map(int, input().split()))
n = int(input())
ns = gns()
l = 22
ls = [0] * l

def addd(x):
	for i in range(l):
		if x & 1 << i != 0:
			ls[i] += 1
for ni in ns:
	addd(ni)
ans = 0

def get_min():
	global ls, ans
	lls = [x for x in ls if x > 0]
	if len(lls) == 0:
		return False
	num = min(lls)
	t = 0
	for i in range(l):
		if ls[i] == 0:
			continue
		t += 2 ** i
		ls[i] = max(ls[i] - num, 0)
	ans += t * t * num
	return True
while get_min():
	pass
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	arr = [0] * 20
	for i in range(0, n):
		s = bin(a[i])[2:]
		while len(s) != 20:
			s = '0' + s
		for j in range(20):
			if s[j] == '1':
				arr[j] += 1
	udp = []
	for i in range(n):
		num = 0
		for j in range(20):
			if arr[j] > 0:
				num += 2 ** (19 - j)
				arr[j] -= 1
		udp.append(num)
	ans = 0
	for i in range(0, n):
		ans += udp[i] ** 2
	print(ans)
testcase(1)


import sys

def inp():
	return sys.stdin.readline().strip()
n = int(inp())
a = list(map(int, inp().split()))
freq = {}
for i in range(32):
	freq[i] = 0
	mask = 1 << i
	for j in a:
		if j & mask > 0:
			freq[i] += 1
ans = [0] * n
for i in range(31, -1, -1):
	if freq[i] <= 0:
		continue
	mask = 1 << i
	for j in range(n - 1, -1, -1):
		if freq[i] > 0:
			ans[j] |= mask
			freq[i] -= 1
sm = 0
for i in ans:
	sm += i * i
print(sm)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(20)]
for i in a:
	j = bin(i)[2:]
	for kek in range(1, len(j) + 1):
		b[-kek] += int(j[-kek])
ans = 0
flag = True
while flag:
	x = 0
	flag = False
	for i in range(20):
		if b[i] > 0:
			flag = True
			x += 2 ** (19 - i)
			b[i] -= 1
	ans += x ** 2
print(ans)


n = int(input())
a = list(map(int, input().split()))
bit = [0] * 20
for i in range(n):
	for j in range(20):
		bit[j] += a[i] >> j & 1 == 1
ans = 0
while True:
	m = min(bit)
	if m == float('inf'):
		break
	s = 0
	for i in range(20):
		if bit[i] == m:
			bit[i] = float('inf')
			s += 2 ** i
		elif bit[i] != float('inf'):
			s += 2 ** i
			bit[i] -= m
	ans += m * s ** 2
print(ans)


n = int(input())
l = [0] * 20
a = map(int, input().split())
for i in a:
	x = i
	y = 0
	while x > 0:
		if x % 2 == 1:
			l[y] += 1
			x -= 1
		y += 1
		x /= 2
sol = 0
for _ in range(n):
	x = 0
	for i in range(20):
		if l[i] > 0:
			x += pow(2, i)
			l[i] -= 1
	sol += x * x
print(sol)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
bits = []
for i in range(20):
	cur = 0
	masq = 1 << i
	for x in a:
		if x & masq:
			cur += 1
	bits.append(cur)
for i in range(n):
	num = 0
	for j in range(20):
		if i < bits[j]:
			num += 1 << j
	ans += num ** 2
print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
n = int(input())
arr = [int(x) for x in input().split()]
LOG = 20
bits = [0 for x in range(LOG)]
for item in arr:
	for i in range(LOG):
		if 1 << i & item:
			bits[i] += 1
ans = []
while sum(bits):
	num = 0
	for i in range(LOG):
		if bits[i]:
			num |= 1 << i
			bits[i] -= 1
	ans.append(num)
print(sum([item ** 2 for item in ans]))


def dec2bin(n):
	n = int(n)
	a = []
	l = 0
	while n:
		a.append(n % 2)
		n //= 2
		l += 1
	return (a[::-1], l)

def bin2dec(l):
	p = 0
	s = 0
	for i in l[::-1]:
		s += i * 2 ** p
		p += 1
	return s
n = int(input())
a = []
v = -1
for i in input().split():
	(val, l) = dec2bin(i)
	a.append((val, l))
	v = max(v, l)
a = [[0] * (v - l) + i for (i, l) in a]
for i in range(v):
	ones = 0
	for j in a:
		ones += j[i]
	for j in range(n):
		if j < n - ones:
			a[j][i] = 0
		else:
			a[j][i] = 1
s = 0
for i in a:
	s += bin2dec(i) ** 2
print(s)


n = int(input())
a = input().split()
b = [0] * 30
for i in a:
	x = 0
	while x <= 20:
		if int(i) & 1 << x != 0:
			b[x] += 1
		x += 1
res = 0
while n > 0:
	n -= 1
	temp = 0
	index = 0
	while index <= 20:
		if b[index] > 0:
			b[index] -= 1
			temp |= 1 << index
		index += 1
	res += temp * temp
print(res)


import sys
from collections import Counter
from typing import List

def solve(n: int, a: List[int]) -> int:
	base = [2 ** x for x in range(20)]
	c = Counter()
	for e in a:
		for (i, b) in enumerate(base):
			if e & b > 0:
				c[i] += 1
	r = [0] * n
	for (i, b) in enumerate(base):
		for j in range(c[i]):
			r[j] |= b
	return sum((x ** 2 for x in r))
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a))


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def main():
	n = int(input())
	a = list(map(lambda x: bin(int(x))[2:], input().split()))
	b = [['0' for i in range(20)] for j in range(n)]
	c = [0 for i in range(20)]
	for i in range(n):
		for j in range(len(a[i])):
			if a[i][-(j + 1)] == '1':
				b[c[j]][-(j + 1)] = '1'
				c[j] += 1
	su = 0
	for i in range(n):
		su += pow(int(''.join(b[i]), 2), 2)
	print(su)
main()


n = int(input())
arr = [int(i) for i in input().split()]
binary = []
num = [0 for i in range(21)]
for i in range(n):
	b = bin(arr[i]).replace('0b', '')
	if len(b) < 21:
		for k in range(21 - len(b)):
			b = '0' + b
	binary.append(b)
for i in range(21):
	for j in range(n):
		if binary[j][i] == '1':
			num[i] += 1
m = max(num)
f = 0
ans = 0
while f <= m:
	f += 1
	a = ''
	for i in range(21):
		if num[i] > 0:
			num[i] -= 1
			a = a + '1'
		else:
			a = a + '0'
	ans = ans + int(a, 2) ** 2
print(ans)


def game(n):
	pow2 = [2 ** i for i in range(20)]
	t = [0 for i in range(20)]
	for i in n:
		for j in range(20):
			t[j] += 1 if pow2[j] & i > 0 else 0
	for i in range(len(t) - 1, -1, -1):
		if t[i] == 0:
			t = t[:i]
		else:
			break
	if t == []:
		return 0
	g = [0 for i in range(max(t))]
	for i in range(len(t) - 1, -1, -1):
		c = 2 ** i
		for j in range(t[i]):
			g[j] += c
	return sum([i ** 2 for i in g])
t = input().strip()
n = [int(i) for i in input().strip().split()]
print(game(n))


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
N = int(input())
A = list(map(int, input().split()))
B = [0] * 20
for a in A:
	for i in range(20):
		if a >> i & 1:
			B[i] += 1
ans = 0
for a in A:
	a = 0
	for i in range(20):
		if B[i]:
			a |= 1 << i
			B[i] -= 1
	ans += a * a
print(ans)


from sys import stdin
from collections import Counter
n = int(stdin.readline().strip())
alist = list(map(int, stdin.readline().split()))
(c, m) = (Counter(), 0)
for a in alist:
	i = 0
	while a:
		if a % 2:
			c[i] += 1
		a //= 2
		i += 1
	m = max(m, i)
p = {}
e = 1
for i in range(m):
	p[i] = e
	e *= 2
ans = 0
while True:
	b = 0
	for i in c:
		if c[i] > 0:
			b += p[i]
			c[i] -= 1
	if b:
		ans += b * b
	else:
		break
print(ans)


def correct(s, k):
	return (k - len(s)) * '0' + s
n = int(input())
ls = list(map(int, input().split()))
ar = [0] * 20
for i in range(n):
	s = correct(bin(ls[i])[2:], 20)
	for j in range(20):
		ar[j] += int(s[j])
ans = 0
for i in range(n):
	s = ''
	for j in range(20):
		if ar[j] > 0:
			s += '1'
			ar[j] -= 1
		else:
			s += '0'
	ans += int(s, 2) ** 2
print(ans)


n = int(input())
l = [[0] * 20 for i in range(n)]
am = list(map(int, input().split()))
for i in range(n):
	for s in range(20):
		l[i][s] = am[i] % 2
		am[i] //= 2
k = [0] * 20
for i in range(20):
	for j in range(n):
		if l[j][i] == 1:
			k[i] += 1
sumsquare = 0
for i in range(max(k)):
	t = 0
	for j in range(20):
		t += min(k[j], 1) * 2 ** j
	sumsquare += t ** 2
	for j in range(20):
		if k[j] == 0:
			k[j] = 0
		else:
			k[j] -= 1
print(sumsquare)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
n = INT()
l = mp()
l.sort()
ans = [0 for i in range(20)]
for i in range(n):
	k = bin(l[i])[2:][::-1]
	for j in range(len(k)):
		ans[j] += int(k[j])
res = 0
for i1 in range(max(ans)):
	v = 0
	for j1 in range(20):
		if ans[j1] != 0:
			v += pow(2, j1)
			ans[j1] -= 1
	res += v * v
print(res)


def prog():
	n = int(input())
	nums = list(map(int, input().split()))
	amounts = [0] * 20
	for num in nums:
		num = bin(num)[:1:-1]
		for i in range(len(num)):
			amounts[i] += '1' == num[i]
	totals = []
	while True:
		left = False
		for amount in amounts:
			if amount:
				left = True
				break
		if not left:
			break
		curr = 0
		for i in range(20):
			if amounts[i]:
				amounts[i] -= 1
				curr += 1 << i
		totals.append(curr)
	ans = 0
	for total in totals:
		ans += total ** 2
	print(ans)
prog()


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = [int(c) for c in input().split()]
if n == 1:
	print(arr[0] ** 2)
else:
	arr.sort()
	for i in range(20, -1, -1):
		els = []
		for ind in range(len(arr)):
			if arr[ind] & 1 << i > 0:
				els.append(ind)
		if len(els) == 0:
			continue
		p = 0
		for ind in range(len(arr) - 1, -1, -1):
			if arr[ind] & 1 << i == 0:
				if p < len(els):
					k = els[p]
					p += 1
					if k < ind:
						(arr[ind], arr[k]) = (arr[ind] | arr[k], arr[ind] & arr[k])
					else:
						break
				else:
					break
	ans = sum([x ** 2 for x in arr])
	print(ans)


n = int(input())
A = list(map(int, input().split(' ')))
count = [0 for i in range(20)]
exp = [1 for i in range(21)]
exp[1] = 2
for i in range(2, 21):
	exp[i] = 2 * exp[i - 1]

def COUNT(x):
	c = 0
	while x != 0:
		if x & 1 == 1:
			count[c] += 1
		x >>= 1
		c += 1
for i in A:
	COUNT(i)
ans = 0
for i in range(n):
	temp = 0
	for i in range(19, -1, -1):
		if count[i] > 0:
			temp += exp[i]
			count[i] -= 1
	ans += temp * temp
print(ans)


(q, arr) = (int(input()), list(map(int, input().split())))
s = [0] * q
for i in range(20):
	u = sum(list(map(lambda u: u >> i & 1, arr)))
	for y in range(u):
		s[y] |= 1 << i
print(sum(list(map(lambda u: u ** 2, s))))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
nums = list(map(int, input().split()))
maxy = max(nums)
maxlength = len(bin(maxy)[2:])
binrep = [0] * maxlength
for s in range(n):
	binny = bin(nums[s])[2:]
	for b in range(len(binny)):
		if binny[-1 - b] == '1':
			binrep[-1 - b] += 1
total = 0
for s in range(n):
	binnum = ''
	for b in range(len(binrep)):
		if binrep[b] >= 1:
			binnum += '1'
			binrep[b] -= 1
		else:
			binnum += '0'
	total += int(binnum, 2) ** 2
print(total)


inf = float('inf')
n = int(input())
lst = list(map(int, input().split(' ')))
bit = [0] * 30
for j in range(n):
	x = lst[j]
	for i in range(30):
		if x & 1:
			bit[i] += 1
		x = x >> 1
cnt = 0
while True:
	mn = inf
	for i in range(30):
		if bit[i] > 0:
			if bit[i] < mn:
				mn = bit[i]
	if mn == inf:
		break
	no = 0
	for i in range(30):
		if bit[i] > 0:
			bit[i] -= mn
			no += 2 ** i
	cnt += no * no * mn
print(cnt)


from sys import stdin

def get():
	return [int(w) for w in stdin.readline().split()]
(n,) = get()
ara = get()
cnt = [sum((ai >> i & 1 for ai in ara)) for i in range(20)]
ans = 0
for i in range(n):
	x = sum((1 << j for (j, val) in enumerate(cnt) if val > i))
	ans += x * x
print(ans)


n = int(input())
arr = list(map(int, input().split()))
s = [0] * 20
for i in arr:
	num = i
	t = 0
	while num > 1:
		s[t] += num % 2
		num = num // 2
		t += 1
	s[t] += num % 2
total = 0
while s != [0] * 20:
	ans = ''
	for i in range(20):
		if s[i] > 0:
			ans += '1'
			s[i] -= 1
		else:
			ans += '0'
	total += pow(int(ans[::-1], 2), 2)
print(total)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0] ** 2)
	exit()
a.sort(reverse=True)
x = len(bin(a[0])[2:])
b = []
for i in range(n):
	y = bin(a[i])[2:]
	y = '0' * (x - len(y)) + y
	b.append(list(y))
for i in range(x):
	count = 0
	for j in range(n):
		if b[j][i] == '1':
			count += 1
	for j in range(count):
		b[j][i] = '1'
	for j in range(count, n):
		b[j][i] = '0'
ans = 0
for i in range(n):
	y = ''
	for j in range(x):
		y += b[i][j]
	ans += int(y, 2) ** 2
print(ans)


n = int(input())
A = list(map(int, input().split()))
bitcount = [0] * 20
for a in A:
	b = bin(a + 2 ** 20)
	for i in range(20):
		if b[22 - i] == '1':
			bitcount[i] += 1
summa = 0
while max(bitcount) > 0:
	res = list(filter(lambda i: bitcount[i] > 0, range(20)))
	el = 0
	for i in range(20):
		if i in res:
			el += 2 ** i
			bitcount[i] -= 1
	summa += el ** 2
print(summa)


n = int(input())
a = ['{0:b}'.format(int(x)) for x in input().split()]
longueur = 0
for x in a:
	longueur = max(longueur, len(x))
for x in range(len(a)):
	a[x] = '0' * (longueur - len(a[x])) + a[x]
count_1 = [0] * longueur
for x in a:
	for y in range(longueur):
		count_1[y] += int(x[y])
nouveaux_nombres = []
for i in range(len(a)):
	nouveau_nombre = ['0'] * longueur
	for y in range(longueur):
		if count_1[y] > i:
			nouveau_nombre[y] = str(1)
	nouveaux_nombres.append(int(''.join(nouveau_nombre), 2) ** 2)
print(sum(nouveaux_nombres))


from sys import stdin, stdout
from collections import deque
R = lambda : stdin.readline().strip()
RL = lambda : list(map(int, R().split(' ')))
output = lambda x: stdout.write(str(x) + '\n')
n = int(R())
a = RL()
arr = []
for i in range(20):
	l = []
	arr.append(l)
for i in range(n):
	b = bin(a[i])[2:]
	b = (20 - len(b)) * '0' + b
	l = list(map(int, list(b)))
	l.reverse()
	for j in range(20):
		arr[j].append(l[j])
for i in arr:
	i.sort()
ans = []
for i in range(n):
	s = ''
	for j in range(19, -1, -1):
		s += str(arr[j][i])
	ans.append(s)
for i in range(n):
	ans[i] = int(ans[i], 2)
ANS = 0
for i in ans:
	ANS += i ** 2
output(ANS)


n = int(input())
a = list(map(int, input().split()))
arr = [int(0) for _ in range(20)]
for i in range(n):
	for j in range(20):
		arr[19 - j] += a[i] >> j & 1
total = 0
for i in range(n):
	tmp = 0
	for j in range(20):
		if arr[j] > 0:
			arr[j] -= 1
			tmp += 1 << 19 - j
	total += tmp * tmp
print(total)


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)


import math
import sys
from itertools import permutations
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
ind = [0] * 20
for i in range(n):
	xbin = '{0:20b}'.format(arr[i])
	for i in range(20):
		if xbin[i] == '1':
			ind[i] += 1
ans = 0
for i in range(n):
	flag = True
	cur = 0
	for j in range(20):
		if ind[j] > 0:
			cur += 2 ** (20 - j - 1)
			flag = False
			ind[j] -= 1
	ans += cur ** 2
	if flag:
		break
print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def score(a):
	return sum([ai * ai for ai in a])

def solve(n, a):
	bn = 22
	cnt = [0] * bn
	for i in range(n):
		for j in range(bn):
			if a[i] & 1 << j:
				cnt[j] += 1
	b = [0] * n
	for i in range(n):
		for j in range(bn):
			if cnt[j] > 0:
				b[i] += 1 << j
				cnt[j] -= 1
	return score(b)

def main():
	n = ri()
	a = ria()
	wi(solve(n, a))
main()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
inlt()
array = inlt()

def bina(n, a):
	i = 0
	while n > 0:
		if i + 1 > len(a):
			a = a + [0]
		if n % 2 == 1:
			a[i] = a[i] + 1
		n = n // 2
		i = i + 1
	return a
a = [0]
for i in range(len(array)):
	a = bina(array[i], a)
ans = 0
while sum(a) > 0:
	t = 0
	for i in range(len(a)):
		if a[i] > 0:
			a[i] = a[i] - 1
			t = t + 2 ** i
	ans = ans + t ** 2
print(ans)


import sys
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = 10 ** 20
MOD = 1000000007

def solve():
	n = getN()
	nums = getList()
	bits = [0 for i in range(20)]
	for num in nums:
		cur = num
		for i in range(20):
			if cur % 2 == 1:
				bits[i] += 1
			cur //= 2
			if cur == 0:
				break
	ans = 0
	for i in range(n):
		tmp = 0
		for b in range(20):
			if bits[b]:
				tmp += 2 ** b
				bits[b] -= 1
		ans += tmp ** 2
	print(ans)

def main():
	n = getN()
	for _ in range(n):
		solve()
solve()


from collections import defaultdict
import sys
sys.setrecursionlimit(10000)
n = int(input())
a = list(map(int, input().split()))
one_pos = {}
maxval = 0
for ano in a:
	theno = '0' * (20 - len(bin(ano)[2:])) + bin(ano)[2:]
	for (ind, val) in enumerate(list(theno)):
		if val == '1':
			if ind not in one_pos:
				one_pos[ind] = 1
			else:
				one_pos[ind] += 1
			maxval = max(maxval, one_pos[ind])
allnos = []
for _ in range(maxval):
	newno = ''
	for x in range(20):
		if x in one_pos and one_pos[x] > 0:
			newno += '1'
			one_pos[x] -= 1
		else:
			newno += '0'
	allnos.append(int(newno, 2))
theans = 0
for ano in allnos:
	theans += ano ** 2
print(theans)


n = int(input())
arr = list(map(int, input().split()))
narr = [0 for _ in range(20)]
for x in arr:
	for (i, b) in enumerate(f'{x:20b}'):
		if b == '1':
			narr[i] += 1
s = 0
while sum(narr):
	o = min(filter(lambda o: o, narr))
	r = ''
	for (i, x) in enumerate(narr):
		if x:
			r += '1'
			narr[i] -= o
		else:
			r += '0'
	s += o * int(r, 2) ** 2
print(s)


n = int(input())
arr = [int(x) for x in input().split()]
setBitCounts = [0 for _ in range(20)]
for x in arr:
	for i in range(20):
		if x & 1 << i > 0:
			setBitCounts[i] += 1
t = 0
while sum(setBitCounts) > 0:
	minNonZero = 2 * 10 ** 5
	for c in setBitCounts:
		if 0 < c < minNonZero:
			minNonZero = c
	b = 0
	for i in range(20):
		if setBitCounts[i] > 0:
			b = b | 1 << i
			setBitCounts[i] -= minNonZero
	t += b * b * minNonZero
print(t)


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
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)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass

def get(arr, target):
	n = len(arr)
	left = 0
	right = n - 1
	mid = 0
	if target >= arr[n - 1]:
		return n - 1
	if target <= arr[0]:
		return 0
	while left < right:
		mid = (left + right) // 2
		if target < arr[mid]:
			right = mid
		elif target > arr[mid]:
			left = mid + 1
		else:
			return mid
	if target < arr[mid]:
		return mid - 1
	else:
		return mid
q = int(input())
a = sorted(list(map(int, input().split())))
b = [0] * 20
s = 0
for i in a:
	for j in range(20):
		b[j] += i >> j & 1
b = b[::-1]
for i in range(max(b)):
	a = ''
	for j in range(20):
		if b[j] > 0:
			b[j] -= 1
			a += '1'
		else:
			a += '0'
	s += int(a, 2) ** 2
print(s)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
s = [0] * n
for i in range(20):
	x = 0
	for j in range(n):
		x += a[j] >> i & 1
	for k in range(x):
		s[k] |= 1 << i
ans = sum([i * i for i in s])
print(ans)


n = int(input())
lis = list(map(int, input().split()))
bits = [0] * 20
for num in lis:
	for i in range(20):
		bits[i] += num >> i & 1
sq = 0
for i in range(n):
	cur = 0
	for j in range(20):
		if bits[j] > 0:
			cur += 1 << j
			bits[j] -= 1
	if cur > 0:
		sq += cur ** 2
print(sq)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
n = int(input())
a = list(map(int, input().split()))
l = [0] * 20
for i in a:
	if i != 0:
		b = bin(i).lstrip('0b')
		for j in range(len(b) - 1, -1, -1):
			l[len(b) - j - 1] += int(b[j])
s = 0
for i in range(n):
	a1 = 0
	for j in range(20):
		if l[j] > 0:
			a1 += 1 << j
			l[j] -= 1
	s += a1 * a1
print(s)


import sys, math, itertools, collections, copy
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]
cnt = [0] * 32
for i in range(N):
	s = bin(A[i])
	s = s[2:]
	s = s[::-1]
	for j in range(len(s)):
		if s[j] == '1':
			cnt[j] += 1
nums = []
for i in range(32):
	num = '1' * cnt[i]
	if cnt[i] < N:
		num += '0' * (N - cnt[i])
	nums.append(num)
ans = 0
for i in range(N):
	cur = 0
	for j in range(32):
		if nums[j][i] == '1':
			cur += 2 ** j
	ans += cur ** 2
print(ans)


import sys
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
n = int(input())
l = RI()
pre = [[0] * 20 for i in range(n)]
for i in range(n):
	for j in range(20):
		pre[i][j] = l[i] % 2
		l[i] //= 2
ones = [0] * 20
for i in range(20):
	for j in range(n):
		if pre[j][i] == 1:
			ones[i] += 1
ans = 0
for i in range(n):
	temp = 0
	for j in range(19, -1, -1):
		if ones[j] >= i + 1:
			temp = temp * 2 + 1
		else:
			temp = temp * 2
	ans += temp ** 2
print(ans)


n = int(input())
arr = list(map(int, input().split()))
bit = list((0 for i in range(21)))
for i in arr:
	k = i
	s = list()
	while k != 0:
		s.append(k % 2)
		k //= 2
	for j in range(0, len(s)):
		bit[j] += s[j]
ans = 0
for i in range(n):
	k = 0
	for j in range(len(bit)):
		if bit[j] > 0:
			k += 2 ** j
			bit[j] -= 1
	ans += k ** 2
print(ans)


from collections import Counter
n = int(input())
nums = ['{:020b}'.format(int(x)) for x in input().split()]
counter = Counter()
for num in nums:
	for (i, x) in enumerate(num):
		if x == '1':
			counter[i] += 1
ans = 0
for _ in range(n):
	num = []
	for i in range(20):
		if counter[i] > 0:
			counter[i] -= 1
			num.append('1')
		else:
			num.append('0')
	ans += int(''.join(num), 2) ** 2
print(ans)


from collections import Counter
n = int(input().strip())
a = list(map(int, input().strip().split()))[:n]
sts = Counter()
for i in a:
	pow = 0
	j = i
	while j:
		if j % 2:
			sts[pow] += 1
		pow += 1
		j //= 2
res = 0
while sts:
	cur = 0
	for pow in sts:
		cur += 2 ** pow
	res += cur * cur
	lst = list(sts)
	for pow in lst:
		sts[pow] -= 1
		if sts[pow] == 0:
			sts.pop(pow)
print(res)


N = int(input())
array = [int(x) for x in input().split()]
bits = [0] * 32
for i in range(N):
	for j in range(32):
		if array[i] >> j & 1 == 1:
			bits[j] += 1
highest = max(bits)
tobeprinted = []
total = 0
for i in range(highest):
	total = 0
	for j in range(32):
		if bits[j] > 0:
			total += 2 ** j
			bits[j] -= 1
	tobeprinted.append(total ** 2)
print(sum(tobeprinted))


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree1:

	def __init__(self, data, default=9999999, func=lambda a, b: a | b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a * a + b * b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(l[0] ** 2)
	sys.exit()
else:
	d = defaultdict(int)
	a = [0] * n
	for i in range(n):
		e = bin(l[i])[2:][::-1]
		for j in range(len(e)):
			d[j] += int(e[j])
	for i in range(20):
		for j in range(d[i]):
			a[-j - 1] += pow(2, i)
	p = 0
	for i in a:
		p += i * i
	print(p)


n = int(input())
aa = [int(i) for i in input().split()]
bits = [0] * 21
for i in range(0, n):
	b = bin(aa[i])[2:][::-1]
	for j in range(0, len(b)):
		bits[j] += int(b[j])
ans = 0
for i in range(0, n):
	ss = 0
	for j in range(0, 21):
		if bits[j]:
			ss += pow(2, j)
			bits[j] -= 1
	ans += pow(ss, 2)
print(ans)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.buffer.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = 998244353
n = int(data())
a = mdata()
d = [[0] * 20 for i in range(n + 1)]
a.sort()
for i in range(n - 1, -1, -1):
	d[i] = d[i + 1][:]
	b = bin(a[i])[2:][::-1]
	for j in range(len(b)):
		if b[j] == '0':
			d[i][j] += 1
ans = 0
d1 = [0] * 20
for i in range(n):
	b = list(bin(a[i])[2:][::-1])
	for j in range(len(b)):
		if b[j] == '1' and d[i][j] + d1[j] > 0:
			b[j] = '0'
			d1[j] -= 1
		elif d[i][j] + d1[j] <= 0:
			b[j] = '1'
	ans += int(''.join(b[::-1]), 2) ** 2
out(ans)


from sys import stdout
n = int(input())
ls = list(map(int, input().split()))
ar = [0] * 20
for i in range(n):
	s = bin(ls[i])[2:]
	k = len(s)
	j = 0
	while ls[i]:
		ar[19 - j] += ls[i] & 1
		ls[i] >>= 1
		j += 1
ans = 0
for i in range(n):
	s = ''
	cnt = 0
	for j in range(20):
		if ar[j] > 0:
			cnt += 1 << 19 - j
			ar[j] -= 1
	ans += cnt ** 2
stdout.write(str(ans))


n = int(input())
A = list(map(int, input().split()))
bits = [0 for i in range(21)]
for i in range(n):
	x = A[i]
	for j in range(20):
		if x & 1 << j:
			bits[j] += 1
ans = 0
while True:
	flag = 0
	num = 0
	for i in range(20):
		if bits[i] != 0:
			flag = 1
			bits[i] -= 1
			num += 2 ** i
	ans += num * num
	if flag == 0:
		break
print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
it = [0] * 20
l = [[] for i in range(20)]
b = [[0 for j in range(20)] for i in range(n)]
for i in range(n):
	x = bin(a[i])[2:]
	for j in range(-1, (len(x) + 1) * -1, -1):
		b[i][j] = int(x[j])
for i in range(n - 1, -1, -1):
	for j in range(20):
		if b[i][j] == 0:
			l[j].append(i)
for i in range(n):
	for j in range(20):
		if b[i][j] == 1:
			if it[j] < len(l[j]):
				if i < l[j][it[j]]:
					b[l[j][it[j]]][j] = 1
					it[j] += 1
					b[i][j] = 0
ans = 0
for i in range(n):
	x = 0
	y = 1
	for j in range(19, -1, -1):
		if b[i][j] == 1:
			x += y
		y *= 2
	ans += x * x
print(ans)


from math import floor, log
n = int(input())
l = list(map(int, input().split()))
l.sort()
if l[-1] == 0:
	print(0)
else:
	nbit = floor(log(l[-1], 2)) + 1
	bits = [0] * nbit
	for i in l:
		for j in range(nbit):
			if i & 1 << j != 0:
				bits[j] += 1
	ans = 0
	for i in range(n):
		temp = 0
		for j in range(nbit):
			if bits[j] == 0:
				continue
			bits[j] -= 1
			temp = temp | 1 << j
		ans += temp ** 2
	print(ans)


def solution(A, n):
	C = [int(0) for _ in range(20)]
	for i in range(n):
		for j in range(20):
			C[19 - j] += A[i] >> j & 1
	total = 0
	for i in range(n):
		curr = 0
		for j in range(20):
			if C[j] > 0:
				C[j] -= 1
				curr += 1 << 19 - j
		total += curr ** 2
	return total
n = int(input())
A = list(map(int, input().split(' ')))
print(solution(A, n))


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())
n = oint()
a = list(rint())
b = [0] * 20
for i in range(n):
	for j in range(20):
		if a[i] & 2 ** j:
			b[j] += 1
ans = 0
for i in range(n):
	ans += sum([2 ** j for j in range(20) if b[j]]) ** 2
	for j in range(20):
		if b[j]:
			b[j] -= 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
arr = [bin(i)[2:].zfill(20) for i in l]
ans = [str() for i in range(n)]
for i in range(20):
	cnt = 0
	for j in arr:
		cnt += j[-(i + 1)] == '1'
	for j in range(n - 1, -1, -1):
		char = '0' if cnt <= 0 else '1'
		ans[j] = char + ans[j]
		cnt -= 1
narr = [int(i, 2) for i in ans]
s = 0
for i in narr:
	s += i * i
print(s)


import sys
import collections
input = sys.stdin.readline

def main():
	N = int(input())
	A = [int(x) for x in input().split()]
	c = collections.Counter()
	for a in A:
		for i in range(a.bit_length()):
			c[i] += a >> i & 1
	ans = 0
	for i in range(N):
		tmp = 0
		for j in range(22):
			if c[j] >= 1:
				c[j] -= 1
				tmp += 2 ** j
		ans += tmp ** 2
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	n = N()
	arr = RLL()
	rec = [0] * 20
	for i in range(n):
		for j in range(20):
			if arr[i] & 1 << j:
				rec[j] += 1
	res = 0
	while True:
		tag = False
		now = 0
		for i in range(20):
			if rec[i] != 0:
				tag = True
				now += 1 << i
				rec[i] -= 1
		res += now ** 2
		if tag == False:
			break
	print(res)
main()


n = int(input())
a = list(map(int, input().split()))
bits = [0] * 20
for i in range(n):
	for j in range(20):
		if a[i] >> j & 1:
			bits[j] += 1
b = [0] * n
for i in range(n):
	updated = False
	for j in range(20):
		if bits[j] > 0:
			b[i] |= 1 << j
			bits[j] -= 1
			updated = True
	if not updated:
		break
print(sum((b[i] * b[i] for i in range(n))))


n = int(input())
l = list(map(int, input().split()))
b = [0] * 21
ans = 0
for i in l:
	x = bin(i)[2:][::-1]
	for j in range(len(x)):
		b[j] += int(x[j])
while 1:
	f = 0
	s = ''
	for i in range(20, -1, -1):
		if b[i] > 0:
			s += '1'
			b[i] -= 1
		else:
			s += '0'
	ans += int(s, 2) * int(s, 2)
	if int(s, 2) == 0:
		break
print(ans)


t = 1
while t != 0:
	t -= 1
	n = int(input())
	lt = [int(x) for x in input().split()]
	if n == 1:
		print(lt[0] ** 2)
	else:
		bits = [0 for _ in range(20)]
		for i in range(n):
			k = lt[i]
			for j in range(20):
				if k % 2 != 0:
					bits[j] += 1
				k //= 2
		ans = ['' for _ in range(n)]
		for i in range(20):
			for j in range(bits[i]):
				ans[j] += '1'
			for j in range(bits[i], n):
				ans[j] += '0'
		sm = 0
		for i in ans:
			p = int(i[::-1], 2)
			sm += p ** 2
		print(sm)


n = int(input())
arr = list(map(int, input().split()))
numOnes = [0] * 22
for i in range(n):
	for j in range(1, 21):
		if arr[i] & 1 << j - 1 > 0:
			numOnes[j] += 1
sum = 0
for i in range(n):
	curr = 0
	for j in range(1, 21):
		if numOnes[j] > 0:
			numOnes[j] -= 1
			curr += 2 ** (j - 1)
	sum += curr ** 2
print(sum)


a = int(input())
z = list(map(int, input().split()))
from bisect import *
z.sort()
from collections import *
al = defaultdict(int)
for i in range(len(z)):
	m = bin(z[i])[2:]
	for i in range(len(m)):
		if m[i] == '0':
			continue
		al[len(m) - i - 1] += 1
ans = 0
while 1:
	flag = 0
	total = 0
	for i in range(21):
		if al[i] >= 1:
			total += pow(2, i)
			al[i] -= 1
			flag = 1
	ans += pow(total, 2)
	if flag == 0:
		break
print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def instr():
	return str(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
from collections import Counter

def main():
	n = inp()
	nums = inlt()
	bits = [0] * 21
	for num in nums:
		bits_i = 0
		while num > 0:
			bits[bits_i] += num % 2
			num //= 2
			bits_i += 1
	result = 0
	while sum(bits) > 0:
		res = 0
		p = 1
		for bits_i in range(len(bits)):
			if bits[bits_i] > 0:
				res += p
				bits[bits_i] -= 1
			p *= 2
		result += res ** 2
	print(result)
main()


t = 1
for test in range(1, t + 1):
	n = int(input())
	a = list(map(int, input().split()))
	arr = [[0 for i in range(n)] for j in range(20)]
	ind = 0
	pows = {}
	for i in range(20):
		pows[i] = pow(2, i)
	for i in range(n):
		for j in range(20):
			if pows[j] & a[i] > 0:
				arr[j][i] = 1
			else:
				arr[j][i] = 0
	for i in range(20):
		arr[i].sort()
	ans = 0
	for i in range(n):
		cur = 0
		for j in range(20):
			if arr[j][i] == 1:
				cur += pows[j]
		ans += cur * cur
	print(ans)


size = int(input())
arr = list(map(int, input().split()))
l = [0] * 20
for i in arr:
	count = 0
	while i:
		if i & 1:
			l[count] += 1
		count += 1
		i = i >> 1
product = 0
while True:
	dig = 0
	for i in range(len(l)):
		if l[i]:
			dig += 2 ** i
			l[i] -= 1
	if dig == 0:
		break
	else:
		product += dig ** 2
print(product)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	bc = [0] * 20
	bct = 0
	for a in aa:
		b = 1
		for i in range(20):
			if a % (b * 2) >= b:
				bc[i] += 1
				bct += 1
			b *= 2
	res = 0
	while bct > 0:
		b = 1
		v = 0
		for i in range(20):
			if bc[i] > 0:
				v += b
				bc[i] -= 1
				bct -= 1
			b *= 2
		res += v * v
	print(res)
main()


n = int(input())
a = list(map(int, input().strip().split()))
b = [0] * 20
for x in a:
	for bb in range(20):
		b[bb] += x >> bb & 1
ans = 0
for t in range(n):
	x = 0
	for bb in range(20):
		if b[bb] > 0:
			x += 1 << bb
			b[bb] -= 1
	ans += x * x
print(ans)


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
C = [0] * 20
for i in range(0, n):
	for j in range(0, 20):
		if a[i] % 2 == 1:
			C[j] = C[j] + 1
		a[i] = a[i] // 2
for j in range(0, 20):
	for i in range(0, C[j]):
		a[i] = a[i] + 2 ** j
ans = 0
for i in range(0, n):
	ans = ans + a[i] ** 2
print(ans)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
a = LI()
d = [0] * 21
for i in range(t):
	a[i] = bin(a[i])[2:]
	for j in range(len(a[i])):
		d[len(a[i]) - j - 1] += int(a[i][j])
ans = 0
for i in range(max(d)):
	temp = 0
	for j in range(21):
		if d[j] > 0:
			temp += 2 ** j
			d[j] -= 1
	ans += temp ** 2
print(ans)


n = int(input())
a = sorted(list(map(int, input().split(' '))))

def f(x):
	xd = int(x)
	a = [0] * 20
	i = 19
	while i >= 0:
		if xd >= round(2 ** i):
			a[i] = 1
			xd -= round(2 ** i)
			i -= 1
		else:
			i -= 1
			continue
	return a
ag = []
for i in range(n):
	ag.append(f(a[i]))
num_ones = [0] * 20
for i in range(20):
	for j in range(n):
		num_ones[i] += ag[j][i]
ag_new = []
for i in range(n):
	ag_new.append([0] * 20)
for i in range(20):
	for j in range(num_ones[i]):
		ag_new[j][i] = 1
final_numbers = [0] * n

def rev(a):
	x = 0
	for i in range(20):
		x += a[i] * round(2 ** i)
	return round(x)
for i in range(n):
	final_numbers[i] = rev(ag_new[i])
answer = 0
for i in range(n):
	answer += round(final_numbers[i] ** 2)
print(answer)


n = input()
a = [int(m) for m in input().split()]
bits_cnt = [0] * 20
for i in a:
	for j in range(20):
		if i <= 0:
			break
		bits_cnt[j] += i % 2
		i //= 2
m = max(bits_cnt)
s = 0
for i in range(m):
	num = 0
	for j in range(19, -1, -1):
		num *= 2
		if bits_cnt[j] > 0:
			num += 1
			bits_cnt[j] -= 1
	s += num ** 2
print(s)


n = int(input())
arr = [bin(i)[2:][::-1] for i in map(int, input().split())]
bits = [0] * 20
for i in arr:
	for j in range(len(i)):
		if i[j] == '1':
			bits[j] += 1
newarr = []
while bits.count(0) != len(bits):
	num = 0
	for i in range(len(bits)):
		if bits[i] != 0:
			bits[i] -= 1
			num += 2 ** i
	newarr.append(num)
summ = 0
for i in newarr:
	summ += i * i
print(summ)


import atexit
import io
import sys
import math
from collections import defaultdict, Counter
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
n = int(input())
a = list(map(int, input().split()))
l = [0] * 20
for i in a:
	if i != 0:
		b = bin(i).lstrip('0b')
		for j in range(len(b) - 1, -1, -1):
			l[len(b) - j - 1] += int(b[j])
s = 0
for i in range(n):
	a1 = 0
	for j in range(20):
		if l[j] > 0:
			a1 += 1 << j
			l[j] -= 1
	s += a1 * a1
print(s)


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)


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)


from sys import stdin
input = lambda : stdin.readline().strip()
char = [chr(i) for i in range(97, 123)]
CHAR = [chr(i) for i in range(65, 91)]
mp = lambda : list(map(int, input().split()))
INT = lambda : int(input())
rn = lambda : range(INT())
from math import ceil, sqrt, factorial, gcd
n = INT()
l = mp()
h = [0 for i in range(20)]
for i in l:
	for j in range(20):
		if i & 1 << j:
			h[j] += 1
ans = 0
for i in range(max(h)):
	v = 0
	for j in range(20):
		if h[j]:
			v += 1 << j
			h[j] -= 1
	ans += v * v
print(ans)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
cnt = [0] * 21
for i in range(n):
	for j in range(21):
		cnt[j] += a[i] >> j & 1
total = sum(cnt)
ans = 0
while total:
	x = 0
	for i in range(21):
		if cnt[i]:
			x += 2 ** i
			cnt[i] -= 1
			total -= 1
	ans += x ** 2
print(ans)


import sys
from fractions import gcd
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _t in range(1):
	n = cin()
	a = li()
	d = {pow(2, i): 0 for i in range(21)}
	for el in a:
		s = bin(el)[2:]
		prd = 1
		for ell in s[::-1]:
			if ell == '1':
				d[prd] += 1
			prd *= 2
	ans = 0
	for i in range(n):
		nm = 0
		prd = 1
		for j in range(21):
			if d[prd] > 0:
				nm += prd
				d[prd] -= 1
			prd *= 2
		ans += pow(nm, 2)
	print(ans)


from sys import stdin
input = stdin.buffer.readline
n = int(input())
(cnt, ans) = ([0] * 20, 0)
for i in map(int, input().split()):
	for b in range(20):
		cnt[b] += i >> b & 1
for i in range(n):
	x = 0
	for b in range(20):
		if cnt[b]:
			x += 1 << b
			cnt[b] -= 1
	ans += x * x
print(ans)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def yield_ones(n):
	place = 0
	while n:
		(n, r) = divmod(n, 2)
		if r:
			yield place
		place += 1

def solve():
	n = ri()
	A = rl()
	bits = dd(int)
	for a in A:
		for one in yield_ones(a):
			bits[one] += 1
	answer = 0
	while bits:
		new_bits = {}
		m = min(bits.values())
		partial = 0
		for (power, count) in bits.items():
			partial += pow(2, power)
			if count > m:
				new_bits[power] = count - m
		answer += m * partial ** 2
		bits = new_bits
	print(answer)
mode = 's'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
L = 21
ans = [0] * N
for i in range(L):
	k = 0
	for a in A:
		if a & 1 << i:
			k += 1
	for j in range(k):
		ans[j] += 1 << i
q = 0
for a in ans:
	q += a ** 2
print(q)


n = int(input())
a = list(map(int, input().split()))
cnt = [0 for i in range(32)]
for i in range(n):
	for j in range(32):
		if a[i] % 2:
			cnt[j] += 1
		a[i] //= 2
pows = [2 ** i for i in range(35)]
for j in range(32):
	for i in range(cnt[j]):
		a[i] += pows[j]
sum1 = 0
for i in range(n):
	sum1 += a[i] * a[i]
print(sum1)


import sys
import math
from math import factorial, inf, gcd, sqrt
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10 ** 5)

def rarray():
	return [int(i) for i in input().split()]

def f(c, n):
	i = 0
	while n > 0:
		if n % 2 == 1:
			c[i] += 1
		n //= 2
		i += 1

def g(c):
	ans = 0
	for i in range(32):
		if c[i] > 0:
			c[i] -= 1
			ans += 1 << i
	return ans * ans
t = 1
for ii in range(t):
	n = int(input())
	a = rarray()
	a.sort()
	c = [0] * 32
	for i in a:
		f(c, i)
	ans = 0
	for i in range(n):
		ans += g(c)
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
l = [0] * 20
for i in arr:
	for j in range(20):
		k = 2 ** j
		if i & k == k:
			l[j] += 1
ans = 0
while True:
	c = 0
	co = 0
	for i in range(20):
		if l[i] > 0:
			c += 2 ** i
			l[i] -= 1
		else:
			co += 1
	ans += c ** 2
	if co == 20:
		break
print(ans)