while True:
try:
IP = input()
a,b = IP.split(" ",1)
a=int(a)
B = b.split(" ")
x = int(a/2)
sss = 0
B.sort()
for i in range(a):
sss = sss + abs(int(B[x])-int(B[i]))
print(int(sss),"\n")
except:
break
輸入第一行是測資數量,排序前要先轉int