N = int(input()) pow2 = 1 ans = 0 A = list(map(int, input().split())) A.sort(reverse = True) x = 0 f = 0 while x < N: for i in range(pow2): ans += f * A[x] x += 1 f += 1 pow2 *= 2 print(ans)