gets a=gets.split.map &:to_i h=(a.inject(:+)**0.5).to_i exp=[*1..h]+[*1..h-1].reverse+[0]*99 p a.zip(exp).map{|ai,e|[ai-e,0].max}.inject(:+)