#include using namespace std; class Frac { public: int a, b, x; Frac() { a = b = x = 0; } }; bool compare(Frac a, Frac b) { return a.x > b.x; } int main() { int n; cin >> n; Frac frac[n]; for (int i = 0; i < n; i++) { cin >> frac[i].a >> frac[i].b; } set memo; for (int i = 0; i < n; i++) { memo.insert(frac[i].b); } int d = 1; for (set::iterator it = memo.begin(); it != memo.end(); it++) { d *= *it; } for (int i = 0; i < n; i++) { frac[i].x = frac[i].a * d / frac[i].b; } sort(frac, frac+n, compare); for (int i = 0; i < n; i++) { cout << frac[i].a << " " << frac[i].b << endl; } return 0; }