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