def ascan; gets.split.map(&:to_i); end gets aa = ascan gets bb = ascan r = Rational(aa.reduce{|s,e| Rational(s, e)}, bb.reduce{|s,e| Rational(s, e)}) puts "#{r.numerator} #{r.denominator}"