import sys input = sys.stdin.readline N = int(input()) a = list(map(int, input().split())) import heapq hpush = heapq.heappush hpop = heapq.heappop h = [] for x in a: hpush(h, -x) res = 0 for k in range(N): c = 1 << k while c > 0 and len(h): res += -hpop(h) * k c -= 1 print(res)