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