import math N=int(input()) Y=list(map(int,input().split())) Y.sort() x=0 for i in range(math.floor(N/2)): x=x+Y[N-i-1]-Y[i] print(x)