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