#include using namespace std; int a[10]; int b[10]; int afact[11];//0番目の要素は符号判定 int bfact[11]; void dcmp(int n, int* list){ if (n < 0){ list[0]++; n *= -1; } for (int i = 2; i < 10; i++){ while (n % i == 0){ n /= i; list[i]++; } } } int main() { for (int i = 0; i < 11; i++){ afact[i] = 0; bfact[i] = 0; } int n1, n2; int tmp; cin >> n1; for (int i = 0; i < n1; i++) cin >> a[i]; cin >> n2; for (int i = 0; i < n2; i++) cin >> b[i]; dcmp(a[0],afact); for (int i = 1; i < n1; i++) dcmp(a[i],bfact); for (int i = 0; i < n2; i++) if (i % 2 == 0) dcmp(b[i],bfact); else dcmp(b[i],afact); long child = 1; long mother = 1; if ((afact[0] - bfact[0]) % 2 != 0) child *= -1; for (int i = 2; i < 11; i++){ if (afact[i] > bfact[i]){ for (int j = 0; j < afact[i]-bfact[i]; j++){ child *= i; } } else if (afact[i] < bfact[i]){ for (int j = 0; j < bfact[i]-afact[i]; j++){ mother *= i; } } } cout << child << " " << mother << "\n"; }