#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; using ll=long long; typedef pair P; template struct ModInt{ int x; ModInt(): x(0){} ModInt(ll y): x(y>=0 ? y%MOD : (MOD-(-y)%MOD)%MOD){} ModInt &operator+=(const ModInt &p){ if((x+=p.x)>=MOD) x-=MOD; return *this; } ModInt &operator-=(const ModInt &p){ if((x+=MOD-p.x)>=MOD) x-=MOD; return *this; } ModInt &operator*=(const ModInt &p){ x=(int)(1ll*x*p.x%MOD); return *this; } ModInt &operator/=(const ModInt &p){ *this*=p.inv(); return *this; } ModInt operator-() const{ return ModInt(-x);} ModInt operator+(const ModInt &p) const{ return ModInt(*this)+=p;} ModInt operator-(const ModInt &p) const{ return ModInt(*this)-=p;} ModInt operator*(const ModInt &p) const{ return ModInt(*this)*=p;} ModInt operator/(const ModInt &p) const{ return ModInt(*this)/=p;} bool operator==(const ModInt &p) const{ return x==p.x;} bool operator!=(const ModInt &p) const{ return x!=p.x;} ModInt pow(ll n) const{ ModInt ret(1), p(x); while(n){ if(n&1) ret*=p; p*=p; n>>=1; } return ret; } ModInt inv() const{ return pow(MOD-2); } }; const int MOD=1e9+7; using mint=ModInt; mint dp0[41][41]; mint f[41], invf[41]; int main() { int n, m, k; cin>>n>>m>>k; f[0]=invf[0]=mint(1); for(int i=1; i<=n; i++) f[i]=f[i-1]*mint(i), invf[i]=f[i].inv(); dp0[0][0]=mint(1); for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ for(int l=1; l<=j; l++){ dp0[i][j]+=dp0[i-1][j-l]*invf[l]; } } } auto comb=[&](int x, int y){ if(!(0<=y && y<=x)) return mint(0); mint res=invf[y]; for(int i=0; i> mp; for(int i=0; i>a[i]>>b[i]; for(int i=0; ib0) c++; else if(x==b0) myon=1; } for(int j=0; j<=n; j++){ for(int l=0; l<=m; l++){ if(dp[i][j][l].x==0) continue; for(int p=0; p<=n-j; p++){ if(myon && l+c-p<0) continue; dp[i+1][j+p][max(0, l+c-p)]+=dp[i][j][l]*calci[i+1][p]; } } } } for(int i=0; i<=m; i++) ans+=dp[m1][n][i]*f[n]*mint(b0); } mint s(0); for(int i=0; i