n = int(input()) Y = list(map(int, input().split())) Y.sort() if n % 2 == 1: mid = Y[n//2] else: mid = (Y[n//2] + Y[n//2-1]) // 2 ans = 0 for y in Y: ans += abs(mid - y) print(ans)