n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) ans=0 for i in range(n): p=bin(i+1)[2:] ans+=a[i]*(len(p)-1) print(ans)