#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct NTT{ static constexpr int md = bmds(X); static constexpr int rt = brts(X); inline int add(int a,int b){ a+=b; if(a>=md) a-=md; return a; } inline int mul(int a,int b){ return 1LL*a*b%md; } inline int pow(int a,int b){ int res=1; while(b){ if(b&1) res=mul(res,a); a=mul(a,a); b>>=1; } return res; } inline int inv(int x){ return pow(x,md-2); } // assume md % 4 = 1 // if md % 4 == 3, then x = a^{(md+1)/4} inline int sqrt(int a){ if(a==0) return 0; if(pow(a,(md-1)/2)!=1) return -1; int q=md-1,m=0; while(~q&1) q>>=1,m++; mt19937 mt; int z=mt()%md; while(pow(z,(md-1)/2)!=md-1) z=mt()%md; int c=pow(z,q),t=pow(a,q),r=pow(a,(q+1)/2); while(m>1){ if(pow(t,1<<(m-2))!=1) r=mul(r,c),t=mul(t,mul(c,c)); c=mul(c,c); m--; } return r; } vector > rts,rrts; void ensure_base(int n){ if((int)rts.size()>=n) return; rts.resize(n);rrts.resize(n); for(int i=1;i &a,bool f,int n=-1){ if(n==-1) n=a.size(); assert((n&(n-1))==0); for(int i=0,j=1;j+1>1;k>(i^=k);k>>=1); if(i>j) swap(a[i],a[j]); } for(int i=1;i add(vector as,vector bs){ int sz=max(as.size(),bs.size()); vector cs(sz,0); for(int i=0;i<(int)as.size();i++) cs[i]=add(cs[i],as[i]); for(int i=0;i<(int)bs.size();i++) cs[i]=add(cs[i],bs[i]); return cs; } vector sub(vector as,vector bs){ int sz=max(as.size(),bs.size()); vector cs(sz,0); for(int i=0;i<(int)as.size();i++) cs[i]=add(cs[i],as[i]); for(int i=0;i<(int)bs.size();i++) cs[i]=add(cs[i],md-bs[i]); return cs; } vector multiply(vector as,vector bs){ int need=as.size()+bs.size()-1; int sz=1; while(sz f(sz),g(sz); for(int i=0;i<(int)as.size();i++) f[i]=as[i]; for(int i=0;i<(int)bs.size();i++) g[i]=bs[i]; ntt(f,0);ntt(g,0); for(int i=0;i divide(vector as,vector bs){ assert(bs!=vector(bs.size(),0)); assert(as.size()>=bs.size()); int need=as.size()-bs.size()+1; if(as==vector(as.size(),0)) return {0}; reverse(as.begin(),as.end()); reverse(bs.begin(),bs.end()); while(bs.back()==0){ assert(as.back()==0); as.pop_back(); bs.pop_back(); } reverse(as.begin(),as.end()); reverse(bs.begin(),bs.end()); int sz=1; vector rs({inv(bs[0])}); while(sz<(int)as.size()){ sz<<=1; rs=sub(add(rs,rs),multiply(multiply(rs,rs),bs)); rs.resize(sz); } while(as.back()==0) as.pop_back(); while(rs.back()==0) rs.pop_back(); auto cs=multiply(as,rs); cs.resize(need,0); return cs; } vector sqrt(vector as){ if(as==vector(as.size(),0)) return {0}; int dg=0; reverse(as.begin(),as.end()); while(as.back()==0){ dg++; as.pop_back(); assert(as.back()==0); as.pop_back(); } reverse(as.begin(),as.end()); int sz=1,inv2=inv(2); vector ss({sqrt(as[0])}); while(sz<(int)as.size()){ sz<<=1; vector ts(as); if((sz+sz/2)<(int)ts.size()) ts.resize(sz+sz/2); ss=add(ss,divide(ts,ss)); ss.resize(sz); for(int &x:ss) x=mul(x,inv2); } reverse(ss.begin(),ss.end()); for(int i=0;i ntt0; static NTT<1> ntt1; static NTT<2> ntt2; static constexpr int pow(int a,int b,int md){ int res=1; a=a%md; while(b){ if(b&1) res=(ll)res*a%md; a=(ll)a*a%md; b>>=1; } return res; } static constexpr int inv(int x,int md){ return pow(x,md-2,md); } inline void garner(vector< vector > &cs,int MOD){ static constexpr int r01=inv(ntt0.md,ntt1.md); static constexpr int r02=inv(ntt0.md,ntt2.md); static constexpr int r12=inv(ntt1.md,ntt2.md); int m01 =(ll)ntt0.md*ntt1.md%MOD; size_t sz=cs[0].size(); for(size_t i=0;i=MOD) cs[0][i]-=MOD; cs[0][i]+=(ll)cs[2][i]*m01%MOD; if(cs[0][i]>=MOD) cs[0][i]-=MOD; } } inline int add(int a,int b,int MOD){ a+=b; if(a>=MOD) a-=MOD; return a; } vector add(vector as,vector bs,int MOD){ int sz=max(as.size(),bs.size()); vector cs(sz,0); for(int i=0;i<(int)as.size();i++) cs[i]=add(cs[i],as[i],MOD); for(int i=0;i<(int)bs.size();i++) cs[i]=add(cs[i],bs[i],MOD); return cs; } vector sub(vector as,vector bs,int MOD){ int sz=max(as.size(),bs.size()); vector cs(sz,0); for(int i=0;i<(int)as.size();i++) cs[i]=add(cs[i],as[i],MOD); for(int i=0;i<(int)bs.size();i++) cs[i]=add(cs[i],MOD-bs[i],MOD); return cs; } vector multiply(vector as,vector bs,int MOD){ for(int& x:as) x%=MOD; for(int& x:bs) x%=MOD; vector< vector > cs(3); cs[0]=ntt0.multiply(as,bs); cs[1]=ntt1.multiply(as,bs); cs[2]=ntt2.multiply(as,bs); size_t sz=as.size()+bs.size()-1; for(auto& v:cs) v.resize(sz); garner(cs,MOD); return cs[0]; } vector divide(vector as,vector bs,int MOD){ assert(bs!=vector(bs.size(),0)); assert(as.size()>=bs.size()); int need=as.size()-bs.size()+1; if(as==vector(as.size(),0)) return {0}; reverse(as.begin(),as.end()); reverse(bs.begin(),bs.end()); while(bs.back()==0){ assert(as.back()==0); as.pop_back(); bs.pop_back(); } reverse(as.begin(),as.end()); reverse(bs.begin(),bs.end()); int sz=1; vector rs({inv(bs[0],MOD)}); while(sz<(int)as.size()){ sz<<=1; rs=sub(add(rs,rs,MOD),multiply(multiply(rs,rs,MOD),bs,MOD),MOD); rs.resize(sz); } while(as.back()==0) as.pop_back(); while(rs.back()==0) rs.pop_back(); auto cs=multiply(as,rs,MOD); cs.resize(need,0); return cs; } }; NTT<0> ArbitraryModConvolution::ntt0; NTT<1> ArbitraryModConvolution::ntt1; NTT<2> ArbitraryModConvolution::ntt2; //END CUT HERE template struct Mint{ T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;}; Mint operator-(Mint a) const{return Mint(v)-=a;}; Mint operator*(Mint a) const{return Mint(v)*=a;}; Mint operator/(Mint a) const{return Mint(v)/=a;}; Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v fact,finv,invs; static void init(int n){ int m=fact.size(); if(n=m;i--) finv[i-1]=finv[i]*Mint(i); for(int i=m;i<=n;i++) invs[i]=finv[i]*fact[i-1]; } static Mint C(int n,int k){ if(n vector > Mint::fact = vector >(); template vector > Mint::finv = vector >(); template vector > Mint::invs = vector >(); //INSERT ABOVE HERE signed YUKI_829(){ cin.tie(0); ios::sync_with_stdio(0); using ll = long long; int n,b; cin>>n>>b; vector s(n); for(Int i=0;i>s[i]; using M = Mint; M::init(3e5); vector cnt(n,0); for(int i=0;i > ; priority_queue

pq; pq.emplace(-1,vector(1,1)); int sum=0; for(int i=n-1;i>=0;i--){ if(cnt[i]==0) continue; M x=M::H(sum,cnt[i]); M y=M::H(sum+1,cnt[i])-x; x*=M::fact[cnt[i]]; y*=M::fact[cnt[i]]; pq.emplace(-2,vector({x.v,y.v})); sum+=cnt[i]; } const int MOD = 1e9+7; ArbitraryModConvolution arb; while(pq.size()>1u){ auto a=pq.top().second;pq.pop(); auto b=pq.top().second;pq.pop(); auto c=arb.multiply(a,b,MOD); pq.emplace(-(int)c.size(),c); } auto dp=pq.top().second; M ans(0),res(1); for(int j=0;j<(int)dp.size();j++){ ans+=M((ll)j*(ll)dp[j])*res; res*=M(b); } cout<>k>>n; vector xs(n); for(int i=0;i>xs[i]; const int MOD = 1e9+7; ArbitraryModConvolution arb; vector as(1<<18),bs(1<<17); as[0]=bs[0]=1; for(int x:xs) bs[x]=MOD-1; cout<