n=int(input()) A=list(map(int,input().split())) A.sort(reverse=True) print(sum( [ sum( A[2**i-1:2**(i+1)-1] )*i for i in range(14)]))