// yukicoder: No.751 Frac #2 // 2019.5.3 bal4u #include #define gc() getchar() int in() // 整数の入力(負数に対応) { int n = 0, c = gc(); if (c == '-') { c = gc(); do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return -n; } do n = 10*n + (c & 0xf), c = gc(); while (c >= '0'); return n; } long long gcd(long long a, long long b) { long long r; while (b != 0) r = a % b, a = b, b = r; return a; } int main() { int i, n; long long si, bo, g; si = bo = 1; n = in(); si = in(); for (i = 1; i < n; i++) bo *= in(); n = in(); for (i = 0; i < n; i++) { bo *= in(); if (++i < n) si *= in(); } g = gcd(si, bo); if (g < 0) g = -g; si /= g, bo /= g; if (bo < 0) bo = -bo, si = -si; printf("%lld %lld\n", si, bo); return 0; }