#include<iostream>
using namespace std;
long long n, m, na = 0, nb = 1;
long long aaa(long long a, long long b) {
if (a % b == 0)
return b;
else
return aaa(b, a % b);
}
int main() {
freopen("fenshu.in", "r", stdin);
freopen("fenshu.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
long long x, y;
cin >> x >> y;
na = na * y + nb * x;
nb = y * nb;
long long t = aaa(na, nb);
na /= t, nb /= t;
// cout << na << " " << nb << "\n";
}
for (int i = 1; i <= m; i ++) {
long long x;
cin >> x;
nb *= x;
long long t = aaa(na, nb);
na /= t, nb /= t;
}
if (na % nb == 0)
cout << na / nb;
else
cout << na << " " << nb;
return 0;
}