#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd (unsigned long long a,unsigned long long b)
{
if (a==0)
{
return b;
}
return gcd(b%a,a);
}
int main()
{
freopen ("fenshu.in","r",stdin);
freopen ("fenshu.out","w",stdout);
long long n,m,fenzi,fenmu,fenzi1,fenmu1,zhengshu;
cin >> n >> m;
cin >> fenzi >> fenmu;
for (int i=2;i<=n;i++)
{
cin >> fenzi1 >> fenmu1;
long long xianfenmu=fenmu*fenmu1,xianfenzi=fenzi*fenmu1+fenzi1*fenmu;
fenzi=xianfenzi/gcd(xianfenzi,xianfenmu);
fenmu=xianfenmu/gcd(xianfenzi,xianfenmu);
}
for (int i=1;i<=m;i++)
{
cin >> zhengshu;
long long xianfenzi=fenzi,xianfenmu=fenmu*zhengshu;
fenzi=xianfenzi/gcd(xianfenzi,xianfenmu);
fenmu=xianfenmu/gcd(xianfenzi,xianfenmu);
}
if (fenmu==1)
{
cout << fenzi;
}
else
{
cout << fenzi << " " << fenmu;
}
return 0;
}