import math from statistics import mean N = int(input()) Y = list(map(int, input().split())) P = round(mean(Y)) print(sum([abs(y - P) for y in Y]))