#include #if __has_include() #include #endif namespace ttl{ using namespace std; using f80=long double; using i64=int64_t; using u64=uint64_t; template struct mymodint{ i64 vl; static constexpr i64 get_mod(){ return mod; } i64 val(){ return vl; } mymodint(i64 vl_=0):vl(vl_%mod){} mymodint operator-(){ return (vl==0)?0:mod-vl; } mymodint operator+(mymodint rhs){ return mymodint(*this)+=rhs; } mymodint operator-(mymodint rhs){ return mymodint(*this)-=rhs; } mymodint operator*(mymodint rhs){ return mymodint(*this)*=rhs; } mymodint operator/(mymodint rhs){ return mymodint(*this)/=rhs; } mymodint pow(i64 rhs){ mymodint res=1,now=(*this); while(rhs){ res*=((rhs&1)?now:1),now*=now,rhs>>=1; } return res; } mymodint& operator+=(mymodint rhs){ vl+=rhs.vl,vl-=((vl>=mod)?mod:0); return (*this); } mymodint& operator-=(mymodint rhs){ vl+=((vl using modint= #if __has_include() atcoder::static_modint; #else mymodint; #endif template std::ostream& operator<<(std::ostream& os,modint x){ return os<<(x.val()); } template std::istream& operator>>(std::istream& is,modint& x){ i64 t; is>>t,x=t; return is; } template void scn_(T& a){ cin>>a; } template void scn_(pair& a){ scn_(a.first),scn_(a.second); } template void scn_(vector& a){ for(auto& v:a){ scn_(v); } } template void scn_(vector>& a){ for(auto& v:a){ for(auto& u:v){ cin>>u; } } } void scn(){} template void scn(T& n,Args&... args){ scn_(n),scn(args...); } template void prt_(T a){ cout< void prt_(pair a){ cout<<"{"< void prt(vector a){ for(size_t i=0;i void prt(vector> a){ for(auto& v:a){ for(size_t i=0;i void prt(T a){ prt_(a),cout<<"\n"; } template void prt(T a,Args... args){ prt_(a),cout<<" ",prt(args...); } template struct multi_dim_vector{ using type=vector::type>; }; template struct multi_dim_vector{ using type=T; }; template vector mvec(int n,Arg&& arg){ return vector(n,arg); } template class multi_dim_vector::type mvec(int n,Args&&... args){ return typename multi_dim_vector::type(n,mvec(args...)); } template void rev(T& a){ reverse(a.begin(),a.end());} template void srt(T& a){ sort(a.begin(),a.end()); } template void rsrt(T& a){ sort(a.rbegin(),a.rend()); } template T revd(T a){ reverse(a.begin(),a.end()); return a; } template T srtd(T a){ sort(a.begin(),a.end()); return a; } template T rsrtd(T a){ sort(a.rbegin(),a.rend()); return a; } template T summ(vector a){ return accumulate(a.begin(),a.end(),T(0)); } template T maxi(vector a){ return *max_element(a.begin(),a.end()); } template T mini(vector a){ return *min_element(a.begin(),a.end()); } template void chmx(T& a,T b){ a=max(a,b); } template void chmn(T& a,T b){ a=min(a,b); } i64 ppcnt(u64 k){ return __builtin_popcountll(k); } template T powe(T a,i64 n){ T res=1; while(n){ if(n&1){ res*=a; } a*=a; n/=2; } return res; } i64 powe(i64 a,i64 n,i64 m){ i64 res=1; while(n){ if(n&1){ res=res*a%m; } a=a*a%m; n/=2; } return res; } template void zip(vector& a){ auto b=srtd(a); b.erase(unique(b.begin(),b.end()),b.end()); map mp; for(int i=0;i1){ i64 mid=(ok+ng)/2; (mid*mid<=n?ok:ng)=mid; } return ok; } i64 sqrc(i64 n){ i64 ok=1e9+5,ng=0; while(std::abs(ok-ng)>1){ i64 mid=(ok+ng)/2; (mid*mid>=n?ok:ng)=mid; } return ok; } i64 dvf(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a+b-1)/b; } return a/b; } i64 dvc(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a)/b; } return (a+b-1)/b; } vector bfs(vector> G,int v){ int N=G.size(); vector dst(N,-1); queue q; dst[v]=0; q.emplace(v); while(q.size()){ int t=q.front(); q.pop(); for(auto u:G[t]){ if(dst[u]==-1){ dst[u]=dst[t]+1; q.emplace(u); } } } return dst; } vector dijkstra(vector>>& G,int s){ int N=G.size(); vector dst(N,1e18); dst[s]=0; priority_queue,vector>,greater>> pq; pq.emplace(0,s); vector f(N); while(pq.size()){ auto [t,u]=pq.top(); pq.pop(); if(f[u]){ continue; } f[u]=1; for(auto [v,w]:G[u]){ if(dst[v]>dst[u]+w){ dst[v]=dst[u]+w; pq.emplace(dst[v],v); } } } return dst; } vector> pfct(i64 n){ vector> res; for(i64 i=2;i*i<=n;++i){ if(n%i!=0){ continue; } i64 ex=0; while(n%i==0){ ex++,n/=i; } res.emplace_back(i,ex); } if(n!=1){ res.emplace_back(n,1); } return res; } vector ediv(i64 n){ vector res; for(i64 i=1;i*i<=n;++i){ if(n%i!=0){ continue; } res.emplace_back(i); if(i*i!=n){ res.emplace_back(n/i); } } srt(res); return res; } template struct csm2d{ int n,m; vector> a,c; csm2d(vector> a_):n(a_.size()),m(a_[0].size()),a(a_){ auto b=mvec(n,m+1,0); for(int i=0;i(n+1,m+1,0); for(int j=0;j auto runlng(T a) -> vector>{ int n=a.size(); vector> res; typename decltype(a)::value_type now=a[0]; i64 l=1; for(int i=1;i struct cmb{ vector fac,ifac; cmb(int mx=3000000):fac(mx+1,1),ifac(mx+1,1){ for(int i=1;i<=mx;++i){ fac[i]=fac[i-1]*i; } ifac[mx]/=fac[mx]; for(int i=mx;i>0;--i){ ifac[i-1]=ifac[i]*i; } } T operator()(i64 n,i64 k){ if(n<0||k<0||n struct NTT{ static constexpr u64 mod0=1012924417; static constexpr u64 mod1=998244353; static constexpr u64 mod2=924844033; using mint0=modint; using mint1=modint; using mint2=modint; using mint3=modint; mint1 div1=mint1(1)/mod0; mint2 div2=mint2(1)/(mod0*mod1); mint3 garner_(mint0& r0,mint1& r1,mint2& r2){ mint1 x1=r0.val(); mint2 x2=r0.val(); mint3 x3=r0.val(); mint1 t0=(r1-x1)*div1; x2+=mint2(mod0)*t0.val(); x3+=mod0*t0.val(); mint2 t1=(r2-x2)*div2; x3+=mint3(mod0*mod1)*t1.val(); return x3; } vector operator()(vector a,vector b){ vector a0(a.size()),b0(b.size()),c0; vector a1(a.size()),b1(b.size()),c1; vector a2(a.size()),b2(b.size()),c2; for(size_t i=0;i res(a.size()+b.size()-1); for(size_t i=0;i ntt; template T Product(vector a){ int siz=1; while(siz res(siz*2-1,{1}); for(size_t i=0;i=0;--i){ res[i]=ntt(res[2*i+1],res[2*i+2]); } return res[0]; } int main(){ constexpr int mod=1000000007; using mint=modint; cmb Cb; int N,B; scn(N,B); vector S(N); scn(S); vector V(N); for(int i=0;i> f; int now=0; for(int i=N-1;i>=0;--i){ if(V[i]==0){ continue; } vector g; if(now==0){ g={0,1}; } else{ g={Cb(now-1+V[i],V[i]),Cb(now+V[i],V[i])-Cb(now-1+V[i],V[i])}; } now+=V[i]; f.emplace_back(g); } auto g=Product(f); mint ans=0,pw=1; for(int i=0;i