N=int(input()) A=list(map(int,input().split())) A.sort() ans=0 for i in range(N): c=-1 x=i+1 while x!=0: x//=2 c+=1 ans+=c*A[N-1-i] print(ans)