#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } struct S{ int cnt; mint sum; S(int cnt, mint sum): cnt(cnt), sum(sum) {} }; S op(S x, S y){ return S(x.cnt+y.cnt, x.sum+y.sum); } S e(){ return S(0, mint(0)); } S mapping(mint f, S x){ return S(x.cnt, f*x.cnt+x.sum); } mint composition(mint f, mint g){ return f+g; } mint id(){ return mint(0); } using Seg = atcoder::lazy_segtree; template class Cumsum{ public: Cumsum(vector v): v(v){ n = v.size(); v_cumsum = vector(n+1, T(0)); for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i]; } /** * v[l] + ... + v[r-1] */ T sum(int l, int r){ if(r <= l) return T(0); if(r > n) r = n; if(l < 0) l = 0; return v_cumsum[r]-v_cumsum[l]; } private: int n; vector v; vector v_cumsum; }; template class Compress{ public: vector data; int offset; Compress(vector data_, int offset=0): offset(offset){ data = data_; sort(begin(data), end(data)); data.erase(unique(begin(data), end(data)), end(data)); }; int operator[](T x) { auto p = lower_bound(data.begin(), data.end(), x); assert(x == *p); return offset+(p-data.begin()); } T inv(int x){ return data[x-offset]; } int size(){ return data.size(); } }; #define N_MAX 200002 mint inv[N_MAX],fac[N_MAX],finv[N_MAX]; void init(){ const ll MOD = mint::mod(); fac[0]=1;fac[1]=1; finv[0]=1;finv[1]=1; inv[1]=1; for(int i=2;i> n; vector b(n), c(n); vector u; for(int i = 0; i < n; i++){ cin >> b[i] >> c[i]; b[i]--; u.push_back(b[i]); u.push_back(c[i]); } auto cp = Compress(u); int m = cp.size(); vector len(m-1); vector s; for(int i = 0; i < m-1; i++){ len[i] = cp.data[i+1]-cp.data[i]; s.push_back(S(len[i], mint(0))); } Seg seg(s); for(int i = 0; i < n; i++){ int l = cp[b[i]]; int r = cp[c[i]]; int len = c[i]-b[i]; mint p = mint(len).inv(); seg.apply(l, r, p); } mint ans = mint(n)*mint(n-1); for(int i = 0; i < n; i++){ int l = cp[b[i]]; int r = cp[c[i]]; int len = c[i]-b[i]; mint p = mint(len).inv(); mint tmp = seg.prod(l, r).sum*p; tmp -= p; ans -= tmp; } ans *= fac[n]/4; cout << ans << endl; }