n = gets.to_i a = gets.split.map(&:to_i) x = a[0] y = a[0] 1.upto(n - 1) do |i| b = [x * a[i], x + a[i], x - a[i], y * a[i], y + a[i], y - a[i]] tmp, tmp2 = b.minmax x = tmp2 y = tmp end p x