N = int(input()) A = list(map(int,input().split())) S = [2**k for k in range(N+1)] A.sort(reverse=True) i,j,ans = 0,0,0 for s in S: cnt = 0 while cnt < s and j < N: ans += i*A[j] j += 1 cnt += 1 i += 1 print(ans)