#include<bits/stdc++.h>
using namespace std;
int n,m;
long long a,b,u;
long long ansz;
long long ansm;
int main(){
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a>>b;
if(i==1){
ansz=a;
ansm=b;
}
else{
int t=ansm;
ansm=ansm*b;
ansz=t*a+ansz*b;
}
}
for(int i=1;i<=m;i++){
cin>>u;
ansm=ansm*u;
}
long long o=__gcd(ansz,ansm);
ansz/=o;
ansm/=o;
if(ansm==1){
cout<<ansz;
}
else cout<<ansz<<" "<<ansm;
return 0;
}