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