text: k; if (a == 0 && b == 0) { if (c) puts("-1"), exit(0); continue; } long long g = gcd(a, gcd(-b, mabs(c))); a /= g, b /= g, c /= g; if (!b) { if (c % a) puts("-1"), exit(0); if (-c / a < 0) puts("-1"), exit(0); } if (!A && !B) { A = a, B = b, C = c; continue; } if (!B) { if (b) { inter(A, B, C, a, b, c, x1, x2); flg1 = 1; break; } if (C / A != c / a) puts("-1"), exit(0); continue; } if (A * b == a * B) { if (c * A == C * a) continue; puts("-1"), exit(0); } inter(A, B, C, a, b, c, x1, x2), flg1 = 1; break; } if (flg1) { for (long long i = 0; i < num; ++i) { long long a = B1[i].k, b = -B2[i].k, c = A1[i].k - A2[i].k; if (a * x1 + b * x2 + c) puts("-1"), exit(0); } for (long long i = 0; i < num; ++i) { A1[i].k = A1[i].k + B1[i].k * x1; B1[i].k = 0; } for (long long i = 0; i < num; ++i) { a1.p[i] = A1[i], b1.p[i] = B1[i]; } a1.num = b1.num = num; return; } long long g = exgcd(A, B, x1, x2); if (C % g) puts("-1"), exit(0); x1 *= -C / g, x2 *= -C / g; long long tx = mabs(-B / g), ty = mabs(A / g); if (C > 0 || !ty) { x1 = (x1 % tx + tx) % tx; if (B) x2 = -(A * x1 + C) / B; else x2 = 0; } else { x2 = (x2 % ty + ty) % ty; if (A) x1 = (-B * x2 - C) / A; else x1 = 0; } for (long long i = 0; i < num; ++i) { A1[i].k = A1[i].k + B1[i].k * x1; B1[i].k = tx * B1[i].k; } for (long long i = 0; i < num; ++i) { a1.p[i] = A1[i], b1.p[i] = B1[i]; } a1.num = b1.num = num; } const long long P = 1e9 + 7; inline long long ksm(long long x, long long y) { long long ans = 1; while (y) { if (y & 1) ans = ans * x % P; x = x * x % P; y >>= 1; } return ans; } signed main() { n = read(); for (long long i = 1, a, b; i <= n; ++i) { a = read(); b = read(); A[i].init(a); B[i].init(b); } for (long long i = 2; i <= n; ++i) { UN(A[1], B[1], A[i], B[i]); } long long ans = 1; for (long long i = 0; i < A[1].num; ++i) { ans = ans * 1ll * ksm(A[1].p[i].p, A[1].p[i].k) % P; } printf("%lld\n", ans); return 0; }