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