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