N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
L = []
for i in range(20):
    if len(L) < N:
        L.extend([i] * 2 ** i)

ans = 0
for i in range(N):
	ans += A[i] * L[i]
print(ans)