N=int(input()) A=list(map(int, input().split())) A=sorted(A)[::-1] now=-1 ans=0 g=0 r=0 cost=0 for i in range(N): ans+=A[i]*cost if i==g: r+=1 g+=pow(2,r) cost+=1 print(ans)