import statistics n = int(input()) Y = list(map(int, input().split())) Y.sort() mid = statistics.median(Y) ans = 0 for y in Y: ans += abs(mid - y) print(ans)