function main()
  
  N = parse(Float64, readline())
  a = map(x -> parse(Int, x), split(readline()))
  
  sum = 0
  n = zeros(N)
  
  for i in 1:N
    
    sum += a[i]
    
  end
  
  sum = sum / N
  
  parse(Float64, a)
  
  for i in 1:N
    
    a[i] = abs(sum - a[i])
    
  end
  
  (c, ans) = findmin(a)
  
  println(ans-1)
  
end

main()