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