N = int(input()) Y = list(map(int, input().split())) Y.sort() M = Y[N//2] ans = 0 for y in Y: ans += abs(y - M) print(ans)