N = int(input()) Y = list(map(int,input().split())) Y.sort() u = Y[(N+1) // 2 - 1] S = 0 for i in Y: S += abs(u-i) print(S)