N = int(input()) Y = list(map(int, input().split())) Y.sort() sum = 0 if N % 2 != 0: center = Y[int(N / 2)] else: center = int((Y[int(N / 2) - 1] + Y[int(N / 2)]) / 2) for i in Y: sum += abs(i - center) print(sum)