from statistics import median N = int(input()) Y = list(map(int, input().split())) P = median(Y) print(int(sum([abs(y - P) for y in Y])))