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