#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif using S = pair; S div(S a, S b) { S res{a.first * b.second, a.second * b.first}; int64_t g = std::gcd(res.first, res.second); res.first /= g; res.second /= g; return res; } void solve() { int N; cin >> N; S nu; cin >> nu.first; nu.second = 1; for (int i = 1; i < N; i++) { S cur; cin >> cur.first; cur.second = 1; nu = div(nu, cur); } int M; cin >> M; vector B(M - 1); for (int i = 0; i < M - 1; i++) cin >> B[i]; S de; cin >> de.first; de.second = 1; for (int i = M - 1; i--;) { S cur; cur.first = B[i]; cur.second = 1; de = div(cur, de); } S ans = div(nu, de); if(ans.second < 0) { ans.first *= -1; ans.second = -ans.second; } cout << ans.first << " " << ans.second << "\n"; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }