Program move;
Type
sc=array [1..10000] of longint;
Var
s:sc;
i,j,n:longint;
temp,temp1:longint;
z:longint;
Begin
assign(input,'move.in');
assign(output,'move.out');
reset(input);
rewrite(output);
readln(n);
temp:=0;
for i:=1 to n do begin
read(s[i]);
temp:=temp+s[i];
end;
temp:=temp div n;
z:=0;
for i:=1 to n do
if s[i]<temp then z:=z+(temp-s[i]);
writeln(z);
close(input);
close(output);
End.