#include #include #include using namespace std; const int MAX_N = 200; const int MOD = 1e9 + 7; struct mint { int n; mint(int n_ = 0) : n(n_) {} }; mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; } mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; } mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } mint dp[MAX_N+1][MAX_N*2][MAX_N+1]; mint I[1000]; mint modpow(mint a, int b) { mint res = 1; while (b > 0) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } mint modinv(mint a) { return modpow(a, MOD - 2); } mint f(mint *a, mint l, mint r) { mint res = 0; mint L = 1; mint R = 1; for (int i = 0; i <= MAX_N; i++) { L *= l; R *= r; res += a[i] * (R - L) * I[i + 1]; } return res; } int main() { I[1] = 1; for (int i = 2; i < 1000; i++) { I[i] = I[MOD % i] * (MOD - MOD / i); } int N; cin >> N; vector A(N), B(N), C; for (int i = 0; i < N; i++) { cin >> A[i] >> B[i]; C.push_back(A[i]); C.push_back(B[i]); } sort(C.begin(), C.end()); C.erase(unique(C.begin(), C.end()), C.end()); int M = C.size() - 1; { int l = lower_bound(C.begin(), C.end(), A[0]) - C.begin(); int r = lower_bound(C.begin(), C.end(), B[0]) - C.begin(); for (int i = l; i < r; i++) { dp[0][i][0] = modinv(B[0] - A[0]); } } for (int i = 1; i < N; i++) { int l = lower_bound(C.begin(), C.end(), A[i]) - C.begin(); int r = lower_bound(C.begin(), C.end(), B[i]) - C.begin(); mint s = 0; for (int j = 0; j < M; j++) { dp[i][j][0] += s; dp[i][j][0] -= f(dp[i - 1][j], 0, C[j]); for (int k = 0; k < MAX_N; k++) { dp[i][j][k + 1] += dp[i - 1][j][k] * I[k + 1]; } s += f(dp[i - 1][j], C[j], C[j + 1]); } if (i % 2 == 0) { for (int j = 0; j < M; j++) { for (int k = 0; k <= MAX_N; k++) { dp[i][j][k] *= MOD - 1; } dp[i][j][0] += s; } } mint v = modinv(B[i] - A[i]); for (int j = 0; j < M; j++) { for (int k = 0; k <= MAX_N; k++) { if (l <= j && j < r) { dp[i][j][k] *= v; } else { dp[i][j][k] = 0; } } } } mint ans = 0; for (int i = 0; i < M; i++) { ans += f(dp[N - 1][i], C[i], C[i + 1]); } cout << ans.n << '\n'; }