n = gets.to_i
digits = gets.split.map(&:to_i)
sum = digits.inject(:+)
average = sum / digits.size
left = []
right = []
digits.each do |d|
  left << d if d < average
  right << d if d >= average
end

p right.length == left.length ? right.min - left.max : 0