#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; template struct SegTreeLazy { using FX=function; using FA=function; using FM=function; int n; FX fx; FA fa; FM fm; const X ex; const M em; vector dat; vector lazy; SegTreeLazy(int n_,FX fx_,FA fa_,FM fm_,X ex_,M em_) : n(),fx(fx_),fa(fa_),fm(fm_),ex(ex_),em(em_),dat(n_*4,ex),lazy(n_*4,em) { int x=1; while (n_ > x) x *= 2; n=x; } void set(int i,X x) { dat[i+n-1]=x;} void build() { for (int k=n-2;k >= 0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]); } void eval(int k) { if(lazy[k] == em) return; if(k>n>>k; vector L(n),R(n); rep(i,n) cin>>L[i]>>R[i]; vector> P(n); rep(i,n) P[i]={L[i],R[i]}; sort(ALL(P)); using X=ll; using M=ll; auto fx=[](X x1,X x2) -> X { return max(x1,x2);}; auto fa=[](X x,M m) -> X { return x+m;}; auto fm=[](M m1,M m2) -> M { return m1+m2;}; X ex=0; M em=0; SegTreeLazy lseg(200200,fx,fa,fm,ex,em); ll tmp=k; rep(i,n){ int l=P[i].first,r=P[i].second; if(i>0){ auto t=lseg.query(l,r); if(t>=k) tmp=0; else tmp=tmp*(k-t)%MOD; } lseg.update(l,r,1); } cout<<(modpow(k,n)-tmp+MOD)%MOD<