n1 = gets.to_i a = gets.split.map(&:to_r) n2 = gets.to_i b = gets.split.map(&:to_r) numer = a[0] denom = b[0] (1...n1).each{|i| numer /= a[i]} (1...n2).each{|i| denom /= b[i]} ans = numer / denom puts "#{ans.numerator} #{ans.denominator}"