import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int n; scan(n); auto a = readln.split.to!(int[]); int m; scan(m); auto b = readln.split.to!(int[]); long num, den; num = den = 1; num = a[0]; foreach (i ; 0 .. m) { if (i & 1) { num *= b[i]; } else { den *= b[i]; } } foreach (i ; 0 .. n) { if (i > 0) { den *= a[i]; } } if (sgn(den) == sgn(num)) { den = abs(den); num = abs(num); } else { den = abs(den); num = -abs(num); } long g = gcd(abs(num), abs(den)); num /= g; den /= g; writefln("%d %d", num, den); } int sgn(long x) { return x > 0 ? 1 : -1; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }