use std::io::{Read,stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); macro_rules! get { ($t:ty) => (get().parse::<$t>().unwrap()); () => (get!(i64)); } let n = get!(); let mut x1 = 1; let mut x2 = 1; for i in 0..n { let x = get!(); if i == 0 { x1 *= x; } else { x2 *= x; } } let m = get!(); let mut y1 = 1; let mut y2 = 1; for i in 0..m { let y = get!(); if i > 0 { y1 *= y; } else { y2 *= y; } } let g = gcd(x1 * y1, x2 * y2); let z1 = x1 * y1 / g; let z2 = x2 * y2 / g; let s = (z1 * z2).signum(); let z1 = z1.abs() * s; let z2 = z2.abs(); println!("{} {}", z1, z2); } fn gcd(a: i64, b: i64) -> i64 { fn _gcd(a: i64, b: i64) -> i64 { if a == 0 { b } else { _gcd(b % a, a) } } let a = a.abs(); let b = b.abs(); if a < b { _gcd(a, b) } else { _gcd(b, a) } }