import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) Y=[int(i) for i in input().split()] def f(x): ret=0 for y in Y: ret+=abs(y-x) return ret Y.sort() print(f(Y[n//2]))