m = int(input()) num_list = list(map(int,input().split())) num_list.sort() dot = num_list[m//2] print(sum([abs(num-dot) for num in num_list]))