ご回答を受けて冗長な部分があったため修正
import heapq
import math
a = [6, 3, 2, 4, 5, 7, 1, 8]
heapq.heapify(a)
num = int(math.log2(len(a)))
depth_list = []
for i in range(num+1):
depth_list.append(i)
print('depth_list')
print(depth_list)
element= [2**x for x in range(num)] + [len(a) - (2**num - 1)]
print('element')
print(element)
total = 0
for j in range (len(depth_list)):
total += depth_list[j]*element[j]
print('tolal')
print(total)