n=int(input()) y=sorted(map(int,input().split())) print(sum([abs(y[i]-y[-(i+1)]) for i in range(n//2)]))