n = int(input())
a = [int(_) for _ in input().split()]
b = []
ans = 0
for i in range(1,n):
    q = a[0] ^ a[i]
    b.append(q)
    ans += q
b = sorted(b)
s_b = [0] * n
for i in range(n-1):
    s_b[i+1] = b[i] + s_b[i]
for i in range(n-2):
    ans += s_b[n] - s_b[i+1] * (n-i)
print(ans)