import statistics import math def main(): N = int(input()) Y = list(map(int, input().split())) median = statistics.median_low(Y) ans = 0 for i in range(N): ans += abs(Y[i] - median) print(ans) if __name__ == "__main__": main()