N=int(input()) Y=sorted(list(map(int,input().split()))) alpha=Y[N//2] print(sum([abs(alpha-y) for y in Y]))