from statistics import median N = int(input()) Y = [int(x) for x in input().split()] med = median(Y) ans = 0 for i in Y: ans += abs(med - i) print(ans)