from sys import stdin def main(): input = lambda: stdin.readline()[:-1] N = int(input()) A = list(map(int, input().split())) A.sort(reverse=1) prev = 0 f = [] for k in range(20): i = 2 ** k if prev + i > N: break f.append(A[prev : prev + i]) prev = i ans = 0 for k, a in enumerate(f): ans += sum(map(lambda x: x * k, a)) print(ans) main()