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