# import sys # input = sys.stdin.readline def mp():return map(int,input().split()) def lmp():return list(map(int,input().split())) import math import bisect from copy import deepcopy as dc from itertools import accumulate from collections import Counter, defaultdict, deque def ceil(U,V):return (U+V-1)//V def modf1(N,MOD):return (N-1)%MOD+1 inf = int(1e30) mod = int(1e9+7) n = int(input()) a = lmp() a.sort(reverse=True) u = [] for i in range(1,17): u.append(2**i-1) ans = 0 cnt = 0 for i in range(17): for j in range(cnt, u[i]): if cnt >= n:break else: ans += i*a[cnt] cnt += 1 if cnt >= n:break print(ans)