#!/usr/bin/env python3 import sys def main(): N = int(input()) A = list(map(int, input().split())) A.sort(reverse=True) ans = 0 for i in range(1, N + 1): ans += (len(bin(i)[2:]) - 1) * A[i - 1] print(ans) return if __name__ == '__main__': main()