// #define _GLIBCXX_DEBUG // for STL debug (optional) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template void chmax(T &a, T b) {a = max(a, b);} template void chmin(T &a, T b) {a = min(a, b);} template void chadd(T &a, T b) {a = a + b;} typedef pair pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); } pair make_fraction(vector &vec, int l, int r, int mode) { if(l == r) return make_pair(1, 1); int A = 1, B = 1; int nl = -1, nr = -1; if(mode == 1) { nl = l, nr = r - 1; B *= vec[r-1]; } if(mode == 2) { nl = l+1, nr = r; A *= vec[l]; } int la, lb; tie(la, lb) = make_fraction(vec, nl, nr, mode); if(mode == 1) { A *= la, B *= lb; } else { A *= lb, B *= la; } return make_pair(A, B); } signed main() { int N, M; int cntN = 0; vector vec1, vec2; cin >> N; for(int i=0; i> val; cntN += (val < 0); val = abs(val); vec1.push_back(val); } cin >> M; for(int i=0; i> val; cntN += (val < 0); val = abs(val); vec2.push_back(val); } auto fa = make_fraction(vec1, 0, N, 1); auto fb = make_fraction(vec2, 0, M, 2); int A = 1, B = 1; A = fa.first * fb.second; B = fa.second * fb.first; int g = gcd(A, B); A /= g, B /= g; if(cntN % 2) A *= -1; printf("%lld %lld\n", A, B); return 0; }