#include <iostream>
#include <fstream>
int gcd(int a, int b) {
return (b == 0) ? a : gcd(b, a % b);
}
void printToFile(int tu, int mau) {
std::ofstream outFile("cong.out");
outFile << tu << " " << mau << std::endl;
outFile.close();
}
int main() {
std::ifstream inFile("cong.inp");
int tu, mau, c, d;
inFile >> tu >> mau;
while (inFile >> c >> d) {
int tuMoi = (mau == d) ? (tu + c) : (tu * d + c * mau);
int mauMoi = mau * d;
int ucln = gcd(tuMoi, mauMoi);
tu = tuMoi / ucln;
mau = mauMoi / ucln;
}
inFile.close();
printToFile(tu, mau);
return 0;
}