# 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.to_f / cs.length.to_f if(avg-avg.to_i>0.5 && (avg.to_i+1)*cs.length-total<=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