N = int(input()) Y = list(map(int,input().split())) #平均値の算出~距離を算出 ave = 0 distance = 0 ave = round(sum(Y)/len(Y)) for i in range(N): distance = distance + abs(ave-Y[i]) print(disance)