n = int(input()) l = sorted(map(int,input().split())) x = l[n//2] y = 0 for i in l: y += abs(x-i) print(y)