#include #include #include #include using namespace std; #include template struct combination{ vectorfac,ifac; combination(size_t N=0):fac(1,1),ifac(1,1) { make_table(N); } void make_table(size_t N) { if(fac.size()>N)return; size_t now=fac.size(); N=max(N,now*2); fac.resize(N+1); ifac.resize(N+1); for(size_t i=now;i<=N;i++)fac[i]=fac[i-1]*i; ifac[N]=1/fac[N]; for(size_t i=N;i-->now;)ifac[i]=ifac[i+1]*(i+1); } T factorial(size_t n) { make_table(n); return fac[n]; } T invfac(size_t n) { make_table(n); return ifac[n]; } T P(size_t n,size_t k) { if(nC; mint comb(int A,int B) { assert(B>=0); if(A>H>>W; vectordp(1,1); for(int i=0;i>A>>B; vectornow(W+1); mint CB=comb(B+W,W); mint CA=comb(A-1+W,W); for(int j=0;j<=W;j++) { //CB=C(B+W,W+j) now[j]=CB-CA; mint iv=C.factorial(W+j)*C.invfac(W+j+1); CB=CB*(B-j)*iv; CA=CA*(A-1-j)*iv; now[j]*=C.invfac(j); } dp=atcoder::convolution(dp,now); dp.resize(W+1); } cout<<(dp[W]*C.factorial(W)).val()<