#include // clang-format off using namespace std;constexpr int INF=1001001001;constexpr long long INFll=1001001001001001001;namespace viewer{template string f(T i){string s=(i==INF||i==INFll?"inf":to_string(i));s=string(max(0,3-int(s.size())),' ')+s;return s;} templateauto v(T&x,string end)->decltype(cerr<void v(const pair&p,string end="\n"){cerr<<"(";v(p.first,", ");v(p.second,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b]=t;cerr<<"(";v(a,", ");v(b,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b,c]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,")"+end);}templatevoid v(const tuple&t,string end="\n"){auto[a,b,c,d]=t;cerr<<"(";v(a,", ");v(b,", ");v(c,", ");v(d,")"+end);} templatevoid v(const vector&vx,string);templateauto ve(int,const vector&vx)->decltype(cerr<auto ve(bool,const vector &vx){cerr << "{\n";for(const T&x:vx)cerr<<" ",v(x,",");cerr<<"}\n";}templatevoid v(const vector&vx, string){ve(0,vx);} templatevoid v(const set&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const multiset&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const unordered_set&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const deque&s,string e){vectorz(s.begin(),s.end());v(z,e);}templatevoid v(const priority_queue&p,string e){priority_queueq=p;vectorz;while(!q.empty()){z.push_back(q.top());q.pop();}v(z,e);} templatevoid v(const map&m,string e){cerr<<"{"<<(m.empty()?"":"\n");for(const auto&kv:m){cerr<<" [";v(kv.first,"");cerr<<"] : ";v(kv.second,"");cerr<<"\n";}cerr<<"}"+e;} templatevoid _view(int n,string s,T&var){cerr<<"\033[1;32m"<void grid(T _){}void grid(const vector>&vvb){cerr<<"\n";for(const vector&vb:vvb){for(const bool&b:vb)cerr<<(b?".":"#");cerr<<"\n";}} void _debug(int, string){}templatevoid _debug(int n,string S,H h,T... t){int i=0,cnt=0;for(;i0){if(exp&1)ret*=base;base*=base;exp>>=1;}return ret;} mint modinv(mint base)noexcept{return modpow(base,base.getmod()-2);} /*mod must be a prime number*/mint modsqrt(mint a){long long p=mint::getmod();if(a<2)return a;if(modpow(a,(p-1)>>1)!=1)return -1;mint b=1,one=1;while(modpow(b,(p-1)>>1)==1)b+=one;long long m=p-1,e=0;while(m%2==0)m>>=1,e++;mint x=modpow(a,(m-1)>>1);mint y=a*x*x;x*=a;mint z=modpow(b,m);while(y!=1){long long j=0;mint t=y;while(t!=one)j++,t*=t;z=modpow(z,1ll<<(e-j-1));x*=z;z*=z;y*=z;e=j;}return x;} /*min x s.t. a^x ≡ b (mod m) or -1*/mint modlog(mint a, mint b){long long m=mint::getmod();long long lo=-1,hi=m;while(hi-lo>1){long long mi=(lo+hi)>>1;if(mi*mi>=m)hi=mi;else lo=mi;}long long sqrtM=hi;mapapow;mint rem=a;for(long long r=1;r0)return q*sqrtM;if(apow.find(rem)!=apow.end())return q*sqrtM+apow[rem];rem*=A;}return -1;} mint modfact(int n){if(int(mod_factorial.size())<=n){for(int i=mod_factorial.size();i<=n;i++){mint next=mod_factorial.back()*i;mod_factorial.push_back(next);}}return mod_factorial[n];} mint nCk(int n,int k){if(k<0||n roots, iroots, rate3, irate3; static int max_base; NumberTheoreticTransformFriendlyModInt() = default; static void init() { if (roots.empty()) { const unsigned mod = mint::getmod(); assert(mod >= 3 && mod % 2 == 1); auto tmp = mod - 1; max_base = 0; while (tmp % 2 == 0) tmp >>= 1, max_base++; mint root = 2; while (modpow(root, (mod - 1) >> 1) == 1) root += 1; assert(modpow(root, mod - 1) == 1); roots.resize(max_base + 1); iroots.resize(max_base + 1); rate3.resize(max_base + 1); irate3.resize(max_base + 1); roots[max_base] = modpow(root, (mod - 1) >> max_base); iroots[max_base] = mint(1) / roots[max_base]; for (int i = max_base - 1; i >= 0; i--) { roots[i] = roots[i + 1] * roots[i + 1]; iroots[i] = iroots[i + 1] * iroots[i + 1]; } { mint prod = 1, iprod = 1; for (int i = 0; i <= max_base - 3; i++) { rate3[i] = roots[i + 3] * prod; irate3[i] = iroots[i + 3] * iprod; prod *= iroots[i + 3]; iprod *= roots[i + 3]; } } } } static void ntt(vector &a) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); int h = __builtin_ctz(n); assert(h <= max_base); int len = 0; mint imag = roots[2]; if (h & 1) { int p = 1 << (h - 1); // mint rot = 1; 注記:元のライブラリではコメントアウトされず for (int i = 0; i < p; i++) { auto r = a[i + p]; a[i + p] = a[i] - r; a[i] += r; } len++; } for (; len + 1 < h; len += 2) { int p = 1 << (h - len - 2); { // s = 0 for (int i = 0; i < p; i++) { auto a0 = a[i]; auto a1 = a[i + p]; auto a2 = a[i + 2 * p]; auto a3 = a[i + 3 * p]; auto a1na3imag = (a1 - a3) * imag; auto a0a2 = a0 + a2; auto a1a3 = a1 + a3; auto a0na2 = a0 - a2; a[i] = a0a2 + a1a3; a[i + 1 * p] = a0a2 - a1a3; a[i + 2 * p] = a0na2 + a1na3imag; a[i + 3 * p] = a0na2 - a1na3imag; } } mint rot = rate3[0]; for (int s = 1; s < (1 << len); s++) { int offset = s << (h - len); mint rot2 = rot * rot; mint rot3 = rot2 * rot; for (int i = 0; i < p; i++) { auto a0 = a[i + offset]; auto a1 = a[i + offset + p] * rot; auto a2 = a[i + offset + 2 * p] * rot2; auto a3 = a[i + offset + 3 * p] * rot3; auto a1na3imag = (a1 - a3) * imag; auto a0a2 = a0 + a2; auto a1a3 = a1 + a3; auto a0na2 = a0 - a2; a[i + offset] = a0a2 + a1a3; a[i + offset + 1 * p] = a0a2 - a1a3; a[i + offset + 2 * p] = a0na2 + a1na3imag; a[i + offset + 3 * p] = a0na2 - a1na3imag; } rot *= rate3[__builtin_ctz(~s)]; } } } static void intt(vector &a, bool f = true) { init(); const int n = (int)a.size(); assert((n & (n - 1)) == 0); int h = __builtin_ctz(n); assert(h <= max_base); int len = h; mint iimag = iroots[2]; for (; len > 1; len -= 2) { int p = 1 << (h - len); { // s = 0 for (int i = 0; i < p; i++) { auto a0 = a[i]; auto a1 = a[i + 1 * p]; auto a2 = a[i + 2 * p]; auto a3 = a[i + 3 * p]; auto a2na3iimag = (a2 - a3) * iimag; auto a0na1 = a0 - a1; auto a0a1 = a0 + a1; auto a2a3 = a2 + a3; a[i] = a0a1 + a2a3; a[i + 1 * p] = (a0na1 + a2na3iimag); a[i + 2 * p] = (a0a1 - a2a3); a[i + 3 * p] = (a0na1 - a2na3iimag); } } mint irot = irate3[0]; for (int s = 1; s < (1 << (len - 2)); s++) { int offset = s << (h - len + 2); mint irot2 = irot * irot; mint irot3 = irot2 * irot; for (int i = 0; i < p; i++) { auto a0 = a[i + offset]; auto a1 = a[i + offset + 1 * p]; auto a2 = a[i + offset + 2 * p]; auto a3 = a[i + offset + 3 * p]; auto a2na3iimag = (a2 - a3) * iimag; auto a0na1 = a0 - a1; auto a0a1 = a0 + a1; auto a2a3 = a2 + a3; a[i + offset] = a0a1 + a2a3; a[i + offset + 1 * p] = (a0na1 + a2na3iimag) * irot; a[i + offset + 2 * p] = (a0a1 - a2a3) * irot2; a[i + offset + 3 * p] = (a0na1 - a2na3iimag) * irot3; } irot *= irate3[__builtin_ctz(~s)]; } } if (len >= 1) { int p = 1 << (h - 1); for (int i = 0; i < p; i++) { auto ajp = a[i] - a[i + p]; a[i] += a[i + p]; a[i + p] = ajp; } } if (f) { mint inv_sz = mint(1) / n; for (int i = 0; i < n; i++) a[i] *= inv_sz; } } static vector multiply(vector a, vector b) { int need = a.size() + b.size() - 1; int nbase = 1; while ((1 << nbase) < need) nbase++; int sz = 1 << nbase; a.resize(sz, 0); b.resize(sz, 0); ntt(a); ntt(b); mint inv_sz = mint(1) / sz; for (int i = 0; i < sz; i++) a[i] *= b[i] * inv_sz; intt(a, false); a.resize(need); return a; } }; vector NumberTheoreticTransformFriendlyModInt::roots = vector(); vector NumberTheoreticTransformFriendlyModInt::iroots = vector(); vector NumberTheoreticTransformFriendlyModInt::rate3 = vector(); vector NumberTheoreticTransformFriendlyModInt::irate3 = vector(); int NumberTheoreticTransformFriendlyModInt::max_base = 0; template struct FormalPowerSeriesFriendlyNTT : vector { using vector::vector; using P = FormalPowerSeriesFriendlyNTT; using NTT = NumberTheoreticTransformFriendlyModInt; P pre(int deg)const{return P(begin(*this),begin(*this)+min((int)this->size(),deg));} P rev(int deg=-1)const{P ret(*this);if(deg!=-1)ret.resize(deg,T(0));reverse(begin(ret),end(ret));return ret;} void shrink(){while(this->size()&&this->back()==T(0))this->pop_back();} P operator+(const P&r)const{return P(*this)+=r;} P operator+(const T&v)const{return P(*this)+=v;} P operator-(const P&r)const{return P(*this)-=r;} P operator-(const T&v)const{return P(*this)-=v;} P operator*(const P&r)const{return P(*this)*=r;} P operator*(const T&v)const{return P(*this)*=v;} P operator/(const P&r)const{return P(*this)/=r;} P operator%(const P&r)const{return P(*this)%=r;} P &operator+=(const P&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;} P &operator-=(const P&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;} // https://judge.yosupo.jp/problem/convolution_mod P &operator*=(const P&r){if(this->empty()||r.empty()){this->clear();return*this;}auto ret=NTT::multiply(*this,r);return*this={begin(ret),end(ret)};} P &operator/=(const P&r){if(this->size()clear();return*this;}int n=this->size()-r.size()+1;return*this=(rev().pre(n)*r.rev().inv(n)).pre(n).rev(n);} P &operator%=(const P&r){*this-=*this/r*r;shrink();return*this;} // https://judge.yosupo.jp/problem/division_of_polynomials pairdiv_mod(const P&r) {P q=*this/r;P x=*this-q*r;x.shrink();return make_pair(q,x);} P operator-()const{P ret(this->size());for(int i=0;i<(int)this->size();i++)ret[i]=-(*this)[i];return ret;} P&operator+=(const T&r){if(this->empty())this->resize(1);(*this)[0]+=r;return*this;} P&operator-=(const T&r){if(this->empty())this->resize(1);(*this)[0]-=r;return*this;} P&operator*=(const T&v){for(int i=0;i<(int)this->size();i++)(*this)[i]*=v;return*this;} P dot(P r)const{P ret(min(this->size(),r.size()));for(int i=0;i<(int)ret.size();i++)ret[i]=(*this)[i]*r[i];return ret;} P operator>>(int sz)const{if((int)this->size()<=sz)return{};P ret(*this);ret.erase(ret.begin(),ret.begin()+sz);return ret;} P operator<<(int sz)const{P ret(*this);ret.insert(ret.begin(), sz, T(0));return ret;} //operator(x): f(x)の値を評価して返す O(n) T operator()(T x) const{T r=0,w=1;for(auto&v:*this){r+=w*v;w*=x;}return r;} // diff(): f'(x)を返す O(n) P diff() const { const int n = (int)this->size(); P ret(max(0, n - 1)); for (int i = 1; i < n; i++) ret[i - 1] = (*this)[i] * T(i); return ret; } // integral(): ∫f(x)dxを返す O(n) P integral() const { const int n = (int)this->size(); P ret(n + 1); ret[0] = T(0); for (int i = 0; i < n; i++) ret[i + 1] = (*this)[i] / T(i + 1); return ret; } // inv(): 1/f(x)を返す f(0)!=0を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/inv_of_formal_power_series P inv(int deg = -1) const { assert(((*this)[0]) != T(0)); const int n = (int)this->size(); if (deg == -1) deg = n; P res(deg); res[0] = {T(1) / (*this)[0]}; for (int d = 1; d < deg; d <<= 1) { P f(2 * d), g(2 * d); for (int j = 0; j < min(n, 2 * d); j++) f[j] = (*this)[j]; for (int j = 0; j < d; j++) g[j] = res[j]; NTT::ntt(f); NTT::ntt(g); f = f.dot(g); NTT::intt(f); for (int j = 0; j < d; j++) f[j] = 0; NTT::ntt(f); for (int j = 0; j < 2 * d; j++) f[j] *= g[j]; NTT::intt(f); for (int j = d; j < min(2 * d, deg); j++) res[j] = -f[j]; } return res; } // log(): logf(x)を返す f(0)==1を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/log_of_formal_power_series P log(int deg = -1) const { assert((*this)[0] == T(1)); const int n = (int)this->size(); if (deg == -1) deg = n; return (this->diff() * this->inv(deg)).pre(deg - 1).integral(); } // sqrt(): √f(x)(i.e. g(x) s.t. g(x)*g(x)==f(x))を返す 存在しない場合は空配列を返す deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/sqrt_of_formal_power_series P sqrt(int deg = -1, const function &get_sqrt = [](T y) { return modsqrt(y); }) const { const int n = (int)this->size(); if (deg == -1) deg = n; if ((*this)[0] == T(0)) { for (int i = 1; i < n; i++) { if ((*this)[i] != T(0)) { if (i & 1) return {}; if (deg - i / 2 <= 0) break; auto ret = (*this >> i).sqrt(deg - i / 2, get_sqrt); if (ret.empty()) return {}; ret = ret << (i / 2); if ((int)ret.size() < deg) ret.resize(deg, T(0)); return ret; } } return P(deg, 0); } auto sqr = T(get_sqrt((*this)[0])); if (sqr * sqr != (*this)[0]) return {}; P ret{sqr}; T inv2 = T(1) / T(2); for (int i = 1; i < deg; i <<= 1) { ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2; } return ret.pre(deg); } P sqrt(const function &get_sqrt, int deg = -1) const { return sqrt(deg, get_sqrt); } // exp(): exp(f(x))を返す f(0)=0を要求する deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/exp_of_formal_power_series P exp(int deg = -1) const { if (deg == -1) deg = this->size(); assert((*this)[0] == T(0)); P inv; inv.reserve(deg + 1); inv.push_back(T(0)); inv.push_back(T(1)); auto inplace_integral = [&](P &F) -> void { const int n = (int)F.size(); auto mod = T::getmod(); while ((int)inv.size() <= n) { int i = inv.size(); inv.push_back((-inv[mod % i]) * (mod / i)); } F.insert(begin(F), T(0)); for (int i = 1; i <= n; i++) F[i] *= inv[i]; }; auto inplace_diff = [](P &F) -> void { if (F.empty()) return; F.erase(begin(F)); T coeff = 1, one = 1; for (int i = 0; i < (int)F.size(); i++) { F[i] *= coeff; coeff += one; } }; P b{1, 1 < (int)this->size() ? (*this)[1] : 0}, c{1}, z1, z2{1, 1}; for (int m = 2; m < deg; m *= 2) { auto y = b; y.resize(2 * m); NTT::ntt(y); z1 = z2; P z(m); for (int i = 0; i < m; ++i) z[i] = y[i] * z1[i]; NTT::intt(z); fill(begin(z), begin(z) + m / 2, T(0)); NTT::ntt(z); for (int i = 0; i < m; ++i) z[i] *= -z1[i]; NTT::intt(z); c.insert(end(c), begin(z) + m / 2, end(z)); z2 = c; z2.resize(2 * m); NTT::ntt(z2); P x(begin(*this), begin(*this) + min(this->size(), m)); inplace_diff(x); x.push_back(T(0)); NTT::ntt(x); for (int i = 0; i < m; ++i) x[i] *= y[i]; NTT::intt(x); x -= b.diff(); x.resize(2 * m); for (int i = 0; i < m - 1; ++i) x[m + i] = x[i], x[i] = T(0); NTT::ntt(x); for (int i = 0; i < 2 * m; ++i) x[i] *= z2[i]; NTT::intt(x); x.pop_back(); inplace_integral(x); for (int i = m; i < min(this->size(), 2 * m); ++i) x[i] += (*this)[i]; fill(begin(x), begin(x) + m, T(0)); NTT::ntt(x); for (int i = 0; i < 2 * m; ++i) x[i] *= y[i]; NTT::intt(x); b.insert(end(b), begin(x) + m, end(x)); } return P{begin(b), begin(b) + deg}; } // pow(k): f^k(x)を返す deg==-1の時、同じ次数で打ち切る // https://judge.yosupo.jp/problem/pow_of_formal_power_series P pow(int64_t k, int deg = -1) const { const int n = (int)this->size(); if (deg == -1) deg = n; for (int i = 0; i < n; i++) { if ((*this)[i] != T(0)) { T rev = T(1) / (*this)[i]; P ret = (((*this * rev) >> i).log() * k).exp() * (modpow((*this)[i],k)); if (i * k > deg) return P(deg, T(0)); ret = (ret << (i * k)).pre(deg); if ((int)ret.size() < deg) ret.resize(deg, T(0)); return ret; } } return *this; } // mod_pow(k,g): f^k(x) (mod g(x))を返す O(nlogklogdeg(f)) P mod_pow(int64_t k, P g) const { P modinv = g.rev().inv(); auto get_div = [&](P base) { if (base.size() < g.size()) { base.clear(); return base; } int n = base.size() - g.size() + 1; return (base.rev().pre(n) * modinv.pre(n)).pre(n).rev(n); }; P x(*this), ret{1}; while (k > 0) { if (k & 1) { ret *= x; ret -= get_div(ret) * g; ret.shrink(); } x *= x; x -= get_div(x) * g; x.shrink(); k >>= 1; } return ret; } //taylor_shift(c): g(x)=f(x+c)を満たすg(x)を返す // https://judge.yosupo.jp/problem/polynomial_taylor_shift P taylor_shift(T c) const { int n = (int)this->size(); vector fact(n), rfact(n); fact[0] = rfact[0] = T(1); for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * T(i); rfact[n - 1] = T(1) / fact[n - 1]; for (int i = n - 1; i > 1; i--) rfact[i - 1] = rfact[i] * T(i); P p(*this); for (int i = 0; i < n; i++) p[i] *= fact[i]; p = p.rev(); P bs(n, T(1)); for (int i = 1; i < n; i++) bs[i] = bs[i - 1] * c * rfact[i] * fact[i - 1]; p = (p * bs).pre(n); p = p.rev(); for (int i = 0; i < n; i++) p[i] *= rfact[i]; return p; } }; // clang-format on using FPS = FormalPowerSeriesFriendlyNTT; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector As(N - 1); vector fact(N),rfact(N); fact[0] = rfact[0] = 1; for (int i = 1; i < N; i++) fact[i] = fact[i - 1]*(mint)i; rfact[N - 1] = (mint)1/fact[N - 1]; for (int i = N - 1; i > 1; i--) rfact[i - 1] = rfact[i] * mint(i); for (int i = 0;i