n = int(input()) a = sorted(list(map(int, input().split())), reverse=True) k = 0 ans = 0 for i in range(n): if i + 1 >= (1 << (k + 1)): k += 1 ans += k * a[i] print(ans)