#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include using mint = atcoder::modint998244353; int main() { fast_io(); int n; cin >> n; vector l(n), r(n); for (int i = 0; i < n; i++) { cin >> l[i] >> r[i]; } mint ans = 1; for (int i = 1; i < n; i++) { if (r[0] < l[i]) { ans++; continue; } else if (r[i] < l[0]) { continue; } // 絶対に負け int lose_cnt = max(0, l[i] - r[0]); mint tmp = lose_cnt * mint(r[i] - l[i] + 1); int lb = max(l[0], l[i]), rb = min(r[0], r[i]); tmp += mint(2 * r[i] - lb - rb) * mint(rb - lb + 1) / 2; tmp /= mint(r[i] - l[i] + 1) * mint(r[0] - l[0] + 1); ans += tmp; } cout << ans.val() << endl; }