import math n = int(input()) scores = list(map(int, input().split())) mean = math.ceil(sum(scores) / n) total = 0 for i in scores: total += abs(mean-i) print(total)