n = int(input()) y = sorted(list(map(int, input().split()))) ans = 0 for i in y: ans += abs(y[n // 2] - i) print(ans)