A, B = 2.times.map{ gets; gets.split.map(&:to_i) } c = A.inject{|s,a| s.to_r / a } / B.inject{|s,b| s.to_r / b } puts "#{c.numerator} #{c.denominator}"