N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

X=0
for i in range(1,N+1):
    b=i.bit_length()-1
    X+=b*A[i-1]
print(X)