# d = [1,2,3,4,5,10,8,6,2,123,256,379,1014,11,22]
#最小二個合併
d = list(range(1,11))
print(d)
cost = 0
for i in range(len(d)-1):
t = d[0]+d[1]
c = abs(d[0]-d[1])
cost = cost + c
d.append(t)
d.remove(d[0])
d.remove(d[0])
d.sort()
print(d,cost)
# 最大跟最小合併
d = list(range(1,11))
print(d)
cost = 0
for i in range(len(d)-1):
t = d[0]+d[-1]
c = abs(d[0]-d[-1])
cost = cost + c
d.append(t)
d.remove(d[0])
d.remove(d[-2])
d.sort()
print(d,cost)
#最小跟中間以後第1個合併
d = list(range(1,11))
print(d)
cost = 0
for i in range(len(d)-1):
m = len(d)//2
t = d[0]+d[m]
c = abs(d[0]-d[m])
cost = cost + c
d.append(t)
d.remove(d[m])
d.remove(d[0])
d.sort()
print(d,cost)
#最大二個合併
d = list(range(1,11))
print(d)
cost = 0
for i in range(len(d)-1):
t = d[-1]+d[-2]
c = abs(d[-1]-d[-2])
cost = cost + c
d.append(t)
d.remove(d[-3])
d.remove(d[-2])
d.sort()
print(d,cost)