# Here your code ! B = gets.to_i N = gets.to_i cs = [] N.times{ c = gets.to_i cs.push(c) } total = cs.inject(&:+) avg = total / cs.length if(avg-avg.to_i>0.5 && (total-avg.to_i*cs.length)<=B) avg = avg.to_i + 1 else avg = avg.to_i end totaldiff = 0 cs.each{|c| diff = (c - avg).abs totaldiff += diff } puts totaldiff