#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n; cin>>n; vector b(n),c(n); vector t; rep(i,n){ cin>>b[i]>>c[i]; t.push_back(b[i]); t.push_back(c[i]+1); } sort(t.begin(),t.end()); t.erase(unique(t.begin(),t.end()),t.end()); vector> Ad(t.size()),De(t.size()); rep(i,n){ int d = distance(t.begin(),lower_bound(t.begin(),t.end(),b[i])); Ad[d].push_back(i); d = distance(t.begin(),lower_bound(t.begin(),t.end(),c[i]+1)); De[d].push_back(i); } mint s1 = 0,s2 = 0; mint ans = 0; rep(i,t.size()-1){ rep(j,Ad[i].size()){ int ii = Ad[i][j]; mint p = mint(c[ii]-b[ii]+1).inv(); s2 += s1 * p; s1 += p; } rep(j,De[i].size()){ int ii = De[i][j]; mint p = mint(c[ii]-b[ii]+1).inv(); s1 -= p; s2 -= s1 * p; } ans += s2 * (t[i+1] - t[i]); } mint tt = n; tt *= n-1; tt /= 2; ans = tt - ans; ans /= 2; rep(i,n)ans *= i+1; cout<