#include<bits/stdc++.h>
#define ull unsigned long long
using namespace std;
int n, m;
ull p = 0, q = 1;
ull gcd(ull a, ull b) {
if(!b) return a;
return gcd(b, a % b);
}
void yuefen(ull &a, ull &b) {
ull d = gcd(a, b);
a /= d;
b /= d;
}
int main() {
freopen("fenshu.in", "r", stdin);
freopen("fenshu.out", "w", stdout);
cin>>n>>m;
for(int i = 0; i < n; i++) {
ull a, b, oq = q, op = p;
cin>>a>>b;
p = b * op + a * oq;
q = b * oq;
yuefen(p, q);
}
for(int i = 0; i < m; i++) {
ull x;
cin >> x;
yuefen(p, x);
q *= x;
}
yuefen(p, q);
cout<<p;
if(q != 1) cout<<" "<<q;
return 0;
}