#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000001 int main(){ int N; cin>>N; int L,R; cin>>L>>R; mint ans = 1; rep(i,N-1){ int l,r; cin>>l>>r; if(l>R)ans++; else if(L>=r)continue; else{ int sl = max(L,l), sr = min(R,r); mint pp = (R-L+1); pp *= (r-l+1); { mint n =sr-sl+1; mint cnt = n * (n-1)/2; ans += cnt / pp; } if(Lsr){ mint p = r-l+1; ans += mint(r-sr) / p; } } } cout<