import sys import numpy as np read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10**9 + 7 INF = 10 ** 9 + 1 N = int(readline()) m = map(int, read().split()) A,B = zip(*zip(m,m)) X = sorted(set((0,) + A + B + (INF,))) L = np.array(X[:-1]) R = np.array(X[1:]) inv = np.array([pow(x,MOD-2,MOD) for x in range(N+1)]) dx = R - L power = np.empty((len(X)-1,N+1),np.int64) power[:,0] = 1 for i in range(N): power[:,i+1] = power[:,i] * dx % MOD # 区間ごとに、累積分布関数を (x - L) の多項式で持つ F = np.zeros((len(X) - 1,N+1),np.int64) F[-1,0] = 1 p = 1 for k, (a, b) in enumerate(zip(A, B)): # 減少列の場合は全体から引く if k % 2 == 0: F *= (-1) F[:, 0] += p F %= MOD # [a,b] へ制限 i = np.searchsorted(L, a) j = np.searchsorted(L, b) F[:i] = 0 F[j:] = 0 # 積分することで累積分布を得る。まずは区間ごとに。 F[:, 1:] = F[:, :-1] * inv[1:][None, :] % MOD F[:, 0] = 0 # 左側の定積分を加える I = (F * power % MOD).sum(axis=1) np.cumsum(I, out=I) % MOD p = I[-1] F[1:, 0] += I[:-1] F[1:, 0] %= MOD # 幅で割る c = pow(b - a, MOD - 2, MOD) F = F * c % MOD p = p * c % MOD print(p)