def div(a, b) if b.zero? nil elsif a.positive? a / b else - (-a / b) end end n = gets.to_i xs = gets.chomp.split.map(&:to_i) mn = xs[0] mx = xs[0] (1...n).each do |i| x = xs[i] ys = [] ys << mn + x ys << mn - x ys << mn * x ys << mx + x ys << mx - x ys << mx * x r = div(mx, x) ys << r if r r = div(mn, x) ys << r if r mn = ys.min mx = ys.max end p mx