def solve(l, d): d = [int(k) for k in d] ave = int(sum(d) / l) min1 = sum(abs(v - ave) for v in d) min2 = sum(abs(v - (ave + 1)) for v in d) return min(min1, min2) if __name__ == '__main__': l = map(int, input().split()) print(solve(l, input().split()))