#include #include using lint = long long; void solve() { lint x = 1, y = 1; auto reduce = [&]() { if (y < 0) { x = -x; y = -y; } auto g = std::gcd(x, y); x /= g, y /= g; }; { int n; std::cin >> n; for (int i = 0; i < n; ++i) { lint a; std::cin >> a; if (i == 0) { x *= a; } else { y *= a; } reduce(); } } { int n; std::cin >> n; for (int i = 0; i < n; ++i) { lint b; std::cin >> b; if (i % 2 == 0) { y *= b; } else { x *= b; } reduce(); } } std::cout << x << " " << y << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }