n=int(input()) y=list(map(int,input().split())) m=sum(y)//n s=list(set(y+[m-1,m,m+1])) l=[sum([abs(x-i) for x in y]) for i in s] print(min(l))