import statistics as st N = int(input()) Y = list(map(int,input().split())) #中央値の算出~距離を算出 median = 0. distance = 0 median = st.median(Y) for i in range(N): distance = distance + abs(median-Y[i]) print(int(distance))