import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*Y = map(int,read().split()) Y.sort() med = Y[N//2] answer = sum(abs(x - med) for x in Y) print(answer)