n = int(input()) A = list(map(int,input().split())) A.sort(reverse=True) ans = 0 now = 0 k = 0 while now < n: for i in range(2**k): if i+now >= n: break ans += A[i+now]*k now += 2**k k += 1 print(ans)