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