#include <bits/stdc++.h>
using namespace std;
int n,m,fenshu[3][55]={0};//1分子,2分母
unsigned long long fz;
unsigned long long gcd(unsigned long long x,unsigned long long y)
{
while(x!=y)
{
if(x<y)swap(x,y);
x-=y;
}
return x;
}
int main()
{
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>fenshu[1][i]>>fenshu[2][i];
}
for(int i=1;i<=m;i++)
{
cin>>fenshu[1][n+i];
fenshu[2][n+i]=1;
}
unsigned long long Gcd=fenshu[2][1];
for(int i=2;i<=n;i++)
{
Gcd=gcd(Gcd,fenshu[2][i]);
}
unsigned long long gbs=Gcd;
for(int i=1;i<=n;i++)gbs*=fenshu[2][i]/Gcd;
for(int i=1;i<=n;i++)
{
fz+=fenshu[1][i]*(gbs/fenshu[2][i]);
}
for(int i=1;i<=m;i++)gbs*=fenshu[1][n+i];
unsigned long long g=gcd(fz,gbs);
if(fz%gbs==0)cout<<fz/gbs<<endl;
else
{
cout<<fz/g<<" "<<gbs/g<<endl;
}
return 0;
}