#include using namespace std; using ll = long long; #include #include using mint = atcoder::modint; vector conv(vectora,vectorb){ int n = a.size(); int m = b.size(); vector res(n+m-1,0); for(int i = 0;i struct FPS:vector{ FPS(){} FPS(int n){ this->resize(n); } FPS(vectora){ *this = a; } FPS &operator+=(const FPS&r){ if(r.size()>this->size()) this->resize(r.size()); for(int i = 0;i<(int)r.size();i++) (*this)[i] += r[i]; return *this; } FPS &operator+=(const mint&r){ if(this->empty()) this->resize(1); (*this)[0] += r; return *this; } FPS &operator-=(const FPS&r){ if(r.size()>this->size()) this->resize(r.size()); for(int i = 0;i<(int)r.size();i++) (*this)[i] -= r[i]; return *this; } FPS &operator-=(const mint&r){ if(this->empty()) this->resize(1); (*this)[0] -= r; return *this; } FPS &operator*=(const FPS&r){ vector nxt = conv(*this,r); this->resize(nxt.size()); for(int i = 0;isize();i++) (*this)[i] *= r; return *this; } FPS operator+(const FPS&r) const {return FPS(*this)+=r;} FPS operator+(const mint&r) const {return FPS(*this)+=r;} FPS operator-(const FPS&r) const {return FPS(*this)-=r;} FPS operator-(const mint&r) const {return FPS(*this)-=r;} FPS operator*(const FPS&r) const {return FPS(*this)*=r;} void print(){ for(int i = 0;i<(int)this->size();i++){ if(i) cout<<" "; cout<<(*this)[i]; } cout<size()-1;} // f^-1 mod x^n FPS inv(int n){ assert((*this)[0].val()!=0); FPS g(1); g[0] = 1/(*this)[0]; ll now = 1; FPS tmp(1); tmp[0] = 2; while(nownow) g.resize(now); } g.resize(n); return g; } FPS diff(){ FPSg(this->size()-1); for(int i = 0;i+1size();i++) g[i] = mint(i+1) * (*this)[i+1]; return g; } FPS integral(){ FPSg(this->size()+1); g[0] = 0; for(int i = 1;i<=this->size();i++) g[i] = (*this)[i-1] / mint(i); return g; } FPS log(int n){ assert((*this)[0].val()==1); return ((*this).diff() * (*this).inv(n-1)).integral(); } FPS exp(int n){ assert((*this)[0].val()==0); FPS g(1); g[0] = 1; ll now = 1; FPS tmp(1); tmp[0] = 1; while(nownow) g.resize(now); } return g; } }; template < typename mint > FPS pow(FPS&a,ll k,int n){ FPS ans(n+1); ans[0] += 1; FPS tmp = a; tmp.resize(n+1); while(k){ if(k&1){ ans *= tmp; ans.resize(n+1); } tmp *= tmp; tmp.resize(n+1); k>>=1; } return ans; } //[x^n] P(x)/Q(x) template< typename mint > mint Bostan_Mori(FPS&p,FPS&q,ll n){ if(n==0) return p[0]; int d = q.deg(); assert(p.deg() qi = q; for(int i = 0;i FPS all_mul(vector>&fs){ while(true){ int n = fs.size(); if(n==1) break; int m = (n+1)/2; for(int i = 0;i>n>>m; vector> fs; for(int i = 0;i>a; FPS g(a+1); g[0] = 1; g[a] = -1; fs.push_back(g); } auto f = all_mul(fs); FPS g(1); g[0] = 1; cout<