n, *A = map(int, open(0).read().split()) A.sort(reverse=True) result = 0 for i in range(n): result += ((i + 1).bit_length() - 1) * A[i] print(result)