//https://github.com/ryoku1020/lib #ifdef TEMPLATE #else #define TEMPLATE #pragma GCC optimize("O3") #include #include using namespace std; namespace ryoku{} using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; using u128=unsigned __int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; using vi=vc; using vvi=vvc; using vl=vc; using vvl=vvc; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=ll(n);i>=ll(m);i--) #define drep(i,n) for(ll i=(ll(n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp(...) make_pair(__VA_ARGS__) #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() istream& operator>>(istream&is,i128&x){ string s;if(!(is>>s))return is; u128 y=0; int i=0,neg=0; if(s[0]=='-'||s[0]=='+')neg=s[0]=='-',i=1; for(;i<(int)s.size();i++)y=y*10+s[i]-'0'; x=neg?(y?-(i128)(y-1)-1:0):(i128)y; return is; } ostream& operator<<(ostream&os,i128 x){ if(x==0)return os<<0; if(x<0)os<<"-"; u128 y=x<0?-(u128)x:(u128)x; string s; while(y)s.pb('0'+y%10),y/=10; reverse(all(s)); return os<>a;} void scan(ll&a){cin>>a;} void scan(i128&a){cin>>a;} void scan(string&a){cin>>a;} void scan(char&a){cin>>a;} void scan(uint&a){cin>>a;} void scan(ull&a){cin>>a;} void scan(bool&a){cin>>a;} void scan(ld&a){ cin>>a;} template void scan(pair&p){ scan(p.first); scan(p.second); } templatevoid scan(C&a){for(auto&x:a)scan(x);} void read(){} templatevoid read(Head&head,Tail&... tail){scan(head); read(tail...);} #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define VC(type,name,...) vector name(__VA_ARGS__); read(name); #define VVC(type,name,size,...) vector> name(size,vector(__VA_ARGS__)); read(name); templatevoid print(T a){cout<void print(vectora){for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}} void PRT(){cout<void PRT(T a){print(a); cout<void PRT(Head head,Tail... tail){print(head); cout<<" "; PRT(tail...); return;} templateint chmin(T&x,F y){return x>y?(x=y,1):0;} templateint chmax(T&x,F y){return xT floor(T a,T b){return a/b-(a%b&&((a<0)!=(b<0)));} templateT ceil(T a,T b){return a/b+(a%b&&((a<0)==(b<0)));} templateT bmod(T x,T y){return x-y*floor(x,y);} template pairdivmod(T x,T y){ T q=floor(x,y); return{q,x-q*y}; } void YesNo(bool b){cout<<(b?"Yes":"No")<stovi(const string&s,const string&S){ vcv(s.size()); rep(i,s.size()){ auto t=S.find(s[i]); assert(t!=string::npos); v[i]=t; } return v; } template T isqrt(T x){ T F=sqrtl(x); if(F*F>x)F--; return F; } templateC sorted(C a){ sort(all(a)); return a; } templateC reved(C a){ reverse(all(a)); return a; } template pair,vc>compress(const vc&a){ vcxs=a; sort(all(xs)); xs.erase(unique(all(xs)),xs.end()); vcb(a.size()); rep(i,a.size())b[i]=lower_bound(all(xs),a[i])-xs.begin(); return{b,xs}; } template auto make_vec(int n,T x){ return vc(n,x); } template auto make_vec(int n,Args...args){ return vc(n,make_vec(args...)); } templateT tri(T x){return x*(x-1)/2;} //[l,r) templateT tri(T l,T r){return (r-l)*(l+r-1)/2;} //n を先頭に持ってくる template C rot(C v,int n){ rotate(v.begin(),v.begin()+n,v.end()); return v; } template C concat(C a,const C&b){ a.insert(a.end(),b.begin(),b.end()); return a; } template auto rle(const Container&cv){ using T=typename Container::value_type; vc>res; for(const auto&x:cv){ if(res.empty()||res.back().fi!=x)res.pb({x,1}); else res.back().se++; } return res; } template vciota(int n){ vcv(n);rep(i,n)v[i]=i; return v; } template vcargsort(const C&a){ auto idx=iota(a.size()); sort(all(idx),[&](int i,int j){ return (minfirst?make_pair(a[i],i)make_pair(a[j],j)); }); return idx; } template auto trans(const C&a){ using T=typename C::value_type::value_type; assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vvcb(a[0].size(),vc(a.size())); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } vctrans(const vc&a){ assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vcb(a[0].size(),string(a.size(),0)); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } templatell sz(const C&a){return (int)a.size();} templateauto lb(const C&a,const T&x){return lower_bound(all(a),x);} templateauto ub(const C&a,const T&x){return upper_bound(all(a),x);} templateint popcount(T n){return __builtin_popcountll(n);} templateL sum(const C&a){return accumulate(all(a),L(0));} template struct subset_view{ T s; struct iterator{ T s,x; bool done; T operator*()const{return x;} iterator&operator++(){ if(x==0)done=true; else x=(x-1)&s; return*this; } bool operator!=(const iterator&r)const{return done!=r.done;} }; iterator begin()const{return{s,s,false};} iterator end()const{return{s,0,true};} }; template subset_viewsubset(T s){return{s};} templateauto max(const C&a){return *max_element(all(a));} templateauto min(const C&a){return *min_element(all(a));} templatell argmin(const C&a){return min_element(all(a))-a.begin();} templatell argmax(const C&a){return max_element(all(a))-a.begin();} template vcpresum(const C&a){ vcret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc&operator+=(vc&a,F b){ for(auto&v:a)v+=b; return a; } template vc&operator-=(vc&a,F b){ for(auto&v:a)v-=b; return a; } template vc&operator*=(vc&a,F b){ for(auto&v:a)v*=b; return a; } template array&operator+=(array&a,F b){ for(auto&v:a)v+=b; return a; } template array&operator-=(array&a,F b){ for(auto&v:a)v-=b; return a; } template array&operator*=(array&a,F b){ for(auto&v:a)v*=b; return a; } template constexpr T pow(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } template struct temporary{ T& x;T old; templatetemporary(T&x,U&&y):x(x),old(x){ x=std::forward(y); } ~temporary(){x=std::move(old);} temporary(const temporary&)=delete; }; template temporary(T&,U&&)->temporary; #define CAT_(a,b) a##b #define CAT(a,b) CAT_(a,b) #define WITH(x,y) temporary CAT(_tmp_,__COUNTER__)(x,y) constexpr ll two(ll a){return (1ll<(10,a);} templateconstexpr T inf=numeric_limits::max()/2-1; template<>constexpr pll inf ={inf,inf}; templateconstexpr T neg_inf=-inf; template<>constexpr pll neg_inf ={-inf,-inf}; templateC UNIQUE(C&a){ sort(all(a)); a.erase(unique(all(a)),a.end()); return a; } template int tbit(T x){ using U=make_unsigned_t; U y=(U)x; if(!y)return -1; if(sizeof(U)>sizeof(ull)&&(u128)y>>64)return 127-__builtin_clzll((ull)((u128)y>>64)); return 63-__builtin_clzll((ull)y); } template int lbit(T x){ using U=make_unsigned_t; U y=(U)x; if(!y)return -1; if((ull)y)return __builtin_ctzll((ull)y); return 64+__builtin_ctzll((ull)((u128)y>>64)); } template int tbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return -1; if(p>=W-1)return tbit(y); return tbit(y&((U(1)<<(p+1))-1)); } template int lbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return lbit(y); if(p>=W)return -1; return lbit(y&(~U(0)<sync_with_stdio(0); cout< struct edge{ int from,to,id; [[no_unique_address]]T cost; }; template struct static_graph{ constexpr static bool directed(){return is_directed;} using edge=::ryoku::edge; using cost_t=T; private: int n; mutable bool built=false,inv_built=false; vcedges; mutable vcstart,inv_start; mutable vccsr,inv_csr; public: static_graph(int n):n(n),start(n+1),inv_start(n+1){assert(n>=0);} static_graph(int n,int m):static_graph(n){assert(m>=0);edges.reserve(m);} void resize(int size){ assert(n<=size&&!built); assert(!inv_built); n=size; start.resize(n+1); inv_start.resize(n+1); } void add_edge(const edge&e){ assert(!built&&!inv_built); assert(0<=e.from&&e.from void input(int m){ assert(m>=0); rep(i,m){ INT(a,b); a-=substract;b-=substract; add_edge(a,b); } build(); } void build()const{ if(built)return; built=true; start.assign(n+1,0); for(auto&e:edges){ ++start[e.from]; if constexpr(!is_directed)++start[e.to]; } rep(i,n)start[i+1]+=start[i]; csr.resize(start[n]); for(auto it=edges.rbegin();it!=edges.rend();++it){ auto&e=*it; csr[--start[e.from]]=e; if constexpr(!is_directed)csr[--start[e.to]]={e.to,e.from,e.id,e.cost}; } } void buildinv()const{ if(inv_built)return; inv_start.assign(n+1,0); for(auto&e:edges){ ++inv_start[e.to]; if constexpr(!is_directed)++inv_start[e.from]; } rep(i,n)inv_start[i+1]+=inv_start[i]; inv_csr.resize(inv_start[n]); for(auto it=edges.rbegin();it!=edges.rend();++it){ auto&e=*it; inv_csr[--inv_start[e.to]]={e.to,e.from,e.id,e.cost}; if constexpr(!is_directed)inv_csr[--inv_start[e.from]]={e.from,e.to,e.id,e.cost}; } inv_built=true; } auto operator[](int u){ build(); assert(0<=u&&u(csr.data()+start[u],start[u+1]-start[u]); } auto operator[](int u)const{ build(); assert(0<=u&&u(csr.data()+start[u],start[u+1]-start[u]); } auto inv(int u){ buildinv(); assert(0<=u&&u(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]); } auto inv(int u)const{ buildinv(); assert(0<=u&&u(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]); } const vc&all_edges()const{return edges;} int edge_size()const{return edges.size();} edge get_edge(int id)const{ assert(0<=id&&id vvcadj()const{ vvcres(n,vc(n)); for(auto&e:edges){ res[e.from][e.to]=e.cost; if constexpr(!is_directed)res[e.to][e.from]=e.cost; } return res; } void clear(){ built=false; inv_built=false; edges.clear(); csr.clear(); inv_csr.clear(); start.assign(n+1,0); inv_start.assign(n+1,0); } template void sort(int i,F f){ build(); assert(0<=i&&i struct static_modint{ static_assert(0=0); static_modint mi; mi.val=v; return mi; } static_modint &operator+=(const static_modint&m){ u32 x=val+m.val-mod; val=x+(mod&-(x>>31)); return *this; } static_modint &operator-=(const static_modint&m){ u32 x=val-m.val; val=x+(mod&-(x>>31)); return *this; } static_modint &operator*=(const static_modint&m){ val=u64(val)*m.val%mod; return *this; } static_modint &operator/=(const static_modint&m){ val=u64(val)*m.inv().val%mod; return *this; } static_modint operator-() const{ return static_modint(mod-val); } static_modint operator+() const { return *this; } friend static_modint operator+(static_modint lhs, const static_modint& rhs){ return lhs+=rhs; } friend static_modint operator-(static_modint lhs, const static_modint& rhs){ return lhs-=rhs; } friend static_modint operator*(static_modint lhs, const static_modint& rhs){ return lhs*=rhs; } friend static_modint operator/(static_modint lhs,const static_modint&rhs){ return lhs/=rhs; } bool operator==(const static_modint&p) const{ return p.val==val; } bool operator!=(const static_modint&p) const{ return p.val!=val; } static_modint pow(int64_t n) const{ static_modint res(1),mul(val); while(n){ if(n%2)res*=mul; mul*=mul; n/=2; } return res; } friend ostream&operator<<(ostream&os,const static_modint&p){ os<>(istream&is,static_modint&p){ int64_t x; is>>x; p=static_modint(x); return is; } static_modint inv()const{ int64_t a=val,b=mod,u=1,v=0,t; while(b>0){ t=a/b; swap(a-=t*b,b); swap(u-=t*v,v); } return static_modint(u); } }; } #include #ifdef _MSC_VER #include #endif namespace atcoder { namespace internal { constexpr long long safe_mod(long long x, long long m) { x %= m; if (x < 0) x += m; return x; } struct barrett_reduction { unsigned int _m; unsigned long long im; explicit barrett_reduction(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {} unsigned int umod() const { return _m; } unsigned int mul(unsigned int a, unsigned int b) const { unsigned long long z = a; z *= b; #ifdef _MSC_VER unsigned long long x; _umul128(z, im, &x); #else unsigned long long x = (unsigned long long)(((unsigned __int128)(z)*im) >> 64); #endif unsigned long long y = x * _m; return (unsigned int)(z - y + (z < y ? _m : 0)); } }; constexpr long long pow_mod_constexpr(long long x, long long n, int m) { if (m == 1) return 0; unsigned int _m = (unsigned int)(m); unsigned long long r = 1; unsigned long long y = safe_mod(x, m); while (n) { if (n & 1) r = (r * y) % _m; y = (y * y) % _m; n >>= 1; } return r; } constexpr bool is_prime_constexpr(int n) { if (n <= 1) return false; if (n == 2 || n == 7 || n == 61) return true; if (n % 2 == 0) return false; long long d = n - 1; while (d % 2 == 0) d /= 2; constexpr long long bases[3] = {2, 7, 61}; for (long long a : bases) { long long t = d; long long y = pow_mod_constexpr(a, t, n); while (t != n - 1 && y != 1 && y != n - 1) { y = y * y % n; t <<= 1; } if (y != n - 1 && t % 2 == 0) { return false; } } return true; } template constexpr bool is_prime = is_prime_constexpr(n); constexpr std::pair inv_gcd(long long a, long long b) { a = safe_mod(a, b); if (a == 0) return {b, 0}; long long s = b, t = a; long long m0 = 0, m1 = 1; while (t) { long long u = s / t; s -= t * u; m0 -= m1 * u; auto tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } if (m0 < 0) m0 += b / s; return {s, m0}; } constexpr int primitive_root_constexpr(int m) { if (m == 2) return 1; if (m == 167772161) return 3; if (m == 469762049) return 3; if (m == 754974721) return 11; if (m == 998244353) return 3; int divs[20] = {}; divs[0] = 2; int cnt = 1; int x = (m - 1) / 2; while (x % 2 == 0) x /= 2; for (int i = 3; (long long)(i)*i <= x; i += 2) { if (x % i == 0) { divs[cnt++] = i; while (x % i == 0) { x /= i; } } } if (x > 1) { divs[cnt++] = x; } for (int g = 2;; g++) { bool ok = true; for (int i = 0; i < cnt; i++) { if (pow_mod_constexpr(g, (m - 1) / divs[i], m) == 1) { ok = false; break; } } if (ok) return g; } } template constexpr int primitive_root = primitive_root_constexpr(m); unsigned long long floor_sum_unsigned(unsigned long long n, unsigned long long m, unsigned long long a, unsigned long long b) { unsigned long long ans = 0; while (true) { if (a >= m) { ans += n * (n - 1) / 2 * (a / m); a %= m; } if (b >= m) { ans += n * (b / m); b %= m; } unsigned long long y_max = a * n + b; if (y_max < m) break; n = (unsigned long long)(y_max / m); b = (unsigned long long)(y_max % m); std::swap(m, a); } return ans; } } } namespace atcoder { long long pow_mod(long long x, long long n, int m) { assert(0 <= n && 1 <= m); if (m == 1) return 0; internal::barrett_reduction bt((unsigned int)(m)); unsigned int r = 1, y = (unsigned int)(internal::safe_mod(x, m)); while (n) { if (n & 1) r = bt.mul(r, y); y = bt.mul(y, y); n >>= 1; } return r; } long long inv_mod(long long x, long long m) { assert(1 <= m); auto z = internal::inv_gcd(x, m); assert(z.first == 1); return z.second; } std::pair crt(const std::vector& r, const std::vector& m) { assert(r.size() == m.size()); int n = int(r.size()); long long r0 = 0, m0 = 1; for (int i = 0; i < n; i++) { assert(1 <= m[i]); long long r1 = internal::safe_mod(r[i], m[i]), m1 = m[i]; if (m0 < m1) { std::swap(r0, r1); std::swap(m0, m1); } if (m0 % m1 == 0) { if (r0 % m1 != r1) return {0, 0}; continue; } long long g, im; std::tie(g, im) = internal::inv_gcd(m0, m1); long long u1 = (m1 / g); if ((r1 - r0) % g) return {0, 0}; long long x = (r1 - r0) / g % u1 * im % u1; r0 += x * m0; m0 *= u1; if (r0 < 0) r0 += m0; } return {r0, m0}; } long long floor_sum(long long n, long long m, long long a, long long b) { assert(0 <= n && n < (1LL << 32)); assert(1 <= m && m < (1LL << 32)); unsigned long long ans = 0; if (a < 0) { unsigned long long a2 = internal::safe_mod(a, m); ans -= 1ULL * n * (n - 1) / 2 * ((a2 - a) / m); a = a2; } if (b < 0) { unsigned long long b2 = internal::safe_mod(b, m); ans -= 1ULL * n * ((b2 - b) / m); b = b2; } return ans + internal::floor_sum_unsigned(n, m, a, b); } } #include #include #include #include #include #if __cplusplus >= 202002L #include #endif namespace atcoder { namespace internal { #if __cplusplus >= 202002L using std::bit_ceil; #else unsigned int bit_ceil(unsigned int n) { unsigned int x = 1; while (x < (unsigned int)(n)) x *= 2; return x; } #endif int countr_zero(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } constexpr int countr_zero_constexpr(unsigned int n) { int x = 0; while (!(n & (1 << x))) x++; return x; } } } namespace atcoder { namespace internal { template > struct fast_fourier_transform_info { static constexpr int rank2 = countr_zero_constexpr(mint::get_mod() - 1); std::array root; std::array iroot; std::array rate2; std::array irate2; std::array rate3; std::array irate3; fast_fourier_transform_info() { root[rank2] = mint(g).pow((mint::get_mod() - 1) >> rank2); iroot[rank2] = root[rank2].inv(); for (int i = rank2 - 1; i >= 0; i--) { root[i] = root[i + 1] * root[i + 1]; iroot[i] = iroot[i + 1] * iroot[i + 1]; } { mint prod = 1, iprod = 1; for (int i = 0; i <= rank2 - 2; i++) { rate2[i] = root[i + 2] * prod; irate2[i] = iroot[i + 2] * iprod; prod *= iroot[i + 2]; iprod *= root[i + 2]; } } { mint prod = 1, iprod = 1; for (int i = 0; i <= rank2 - 3; i++) { rate3[i] = root[i + 3] * prod; irate3[i] = iroot[i + 3] * iprod; prod *= iroot[i + 3]; iprod *= root[i + 3]; } } } }; template void butterfly(std::vector& a) { int n = int(a.size()); int h = internal::countr_zero((unsigned int)n); static const fast_fourier_transform_info info; int len = 0; while (len < h) { if (h - len == 1) { int p = 1 << (h - len - 1); mint rot = 1; for (int s = 0; s < (1 << len); s++) { int offset = s << (h - len); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p] * rot; a[i + offset] = l + r; a[i + offset + p] = l - r; } if (s + 1 != (1 << len)) rot *= info.rate2[countr_zero(~(unsigned int)(s))]; } len++; } else { int p = 1 << (h - len - 2); mint rot = 1, imag = info.root[2]; for (int s = 0; s < (1 << len); s++) { mint rot2 = rot * rot; mint rot3 = rot2 * rot; int offset = s << (h - len); for (int i = 0; i < p; i++) { auto mod2 = 1ULL * mint::get_mod() * mint::get_mod(); auto a0 = 1ULL * a[i + offset].val; auto a1 = 1ULL * a[i + offset + p].val * rot.val; auto a2 = 1ULL * a[i + offset + 2 * p].val * rot2.val; auto a3 = 1ULL * a[i + offset + 3 * p].val * rot3.val; auto a1na3imag = 1ULL * mint(a1 + mod2 - a3).val * imag.val; auto na2 = mod2 - a2; a[i + offset] = a0 + a2 + a1 + a3; a[i + offset + 1 * p] = a0 + a2 + (2 * mod2 - (a1 + a3)); a[i + offset + 2 * p] = a0 + na2 + a1na3imag; a[i + offset + 3 * p] = a0 + na2 + (mod2 - a1na3imag); } if (s + 1 != (1 << len)) rot *= info.rate3[countr_zero(~(unsigned int)(s))]; } len += 2; } } } template void butterfly_inv(std::vector& a) { int n = int(a.size()); int h = internal::countr_zero((unsigned int)n); static const fast_fourier_transform_info info; int len = h; while (len) { if (len == 1) { int p = 1 << (h - len); mint irot = 1; for (int s = 0; s < (1 << (len - 1)); s++) { int offset = s << (h - len + 1); for (int i = 0; i < p; i++) { auto l = a[i + offset]; auto r = a[i + offset + p]; a[i + offset] = l + r; a[i + offset + p] = (unsigned long long)((unsigned int)(l.val - r.val) + mint::get_mod()) * irot.val; ; } if (s + 1 != (1 << (len - 1))) irot *= info.irate2[countr_zero(~(unsigned int)(s))]; } len--; } else { int p = 1 << (h - len); mint irot = 1, iimag = info.iroot[2]; for (int s = 0; s < (1 << (len - 2)); s++) { mint irot2 = irot * irot; mint irot3 = irot2 * irot; int offset = s << (h - len + 2); for (int i = 0; i < p; i++) { auto a0 = 1ULL * a[i + offset + 0 * p].val; auto a1 = 1ULL * a[i + offset + 1 * p].val; auto a2 = 1ULL * a[i + offset + 2 * p].val; auto a3 = 1ULL * a[i + offset + 3 * p].val; auto a2na3iimag = 1ULL * mint((mint::get_mod() + a2 - a3) * iimag.val).val; a[i + offset] = a0 + a1 + a2 + a3; a[i + offset + 1 * p] = (a0 + (mint::get_mod() - a1) + a2na3iimag) * irot.val; a[i + offset + 2 * p] = (a0 + a1 + (mint::get_mod() - a2) + (mint::get_mod() - a3)) * irot2.val; a[i + offset + 3 * p] = (a0 + (mint::get_mod() - a1) + (mint::get_mod() - a2na3iimag)) * irot3.val; } if (s + 1 != (1 << (len - 2))) irot *= info.irate3[countr_zero(~(unsigned int)(s))]; } len -= 2; } } } template std::vector convolution_naive(const std::vector& a, const std::vector& b) { int n = int(a.size()), m = int(b.size()); std::vector ans(n + m - 1); if (n < m) { for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { ans[i + j] += a[i] * b[j]; } } } else { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[i + j] += a[i] * b[j]; } } } return ans; } template std::vector convolution_fft(std::vector a, std::vector b) { int n = int(a.size()), m = int(b.size()); int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); a.resize(z); internal::butterfly(a); b.resize(z); internal::butterfly(b); for (int i = 0; i < z; i++) { a[i] *= b[i]; } internal::butterfly_inv(a); a.resize(n + m - 1); mint iz = mint(z).inv(); for (int i = 0; i < n + m - 1; i++) a[i] *= iz; return a; } } template requires requires{mint::get_mod();} std::vector convolution(std::vector&& a, std::vector&& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); assert((mint::get_mod() - 1) % z == 0); if (std::min(n, m) <= 60) return internal::convolution_naive(std::move(a), std::move(b)); return internal::convolution_fft(std::move(a), std::move(b)); } template requires requires{mint::get_mod();} std::vector convolution(const std::vector& a, const std::vector& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); assert((mint::get_mod() - 1) % z == 0); if (std::min(n, m) <= 60) return internal::convolution_naive(a, b); return internal::convolution_fft(a, b); } template requires std::is_integral_v std::vector convolution(const std::vector& a, const std::vector& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; using mint = ryoku::static_modint; int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); assert((mint::get_mod() - 1) % z == 0); std::vector a2(n), b2(m); for (int i = 0; i < n; i++) { a2[i] = mint(a[i]); } for (int i = 0; i < m; i++) { b2[i] = mint(b[i]); } auto c2 = convolution(std::move(a2), std::move(b2)); std::vector c(n + m - 1); for (int i = 0; i < n + m - 1; i++) { c[i] = c2[i].val; } return c; } std::vector convolution_ll(const std::vector& a, const std::vector& b) { int n = int(a.size()), m = int(b.size()); if (!n || !m) return {}; static constexpr unsigned long long MOD1 = 754974721; static constexpr unsigned long long MOD2 = 167772161; static constexpr unsigned long long MOD3 = 469762049; static constexpr unsigned long long M2M3 = MOD2 * MOD3; static constexpr unsigned long long M1M3 = MOD1 * MOD3; static constexpr unsigned long long M1M2 = MOD1 * MOD2; static constexpr unsigned long long M1M2M3 = MOD1 * MOD2 * MOD3; static constexpr unsigned long long i1 = internal::inv_gcd(MOD2 * MOD3, MOD1).second; static constexpr unsigned long long i2 = internal::inv_gcd(MOD1 * MOD3, MOD2).second; static constexpr unsigned long long i3 = internal::inv_gcd(MOD1 * MOD2, MOD3).second; static constexpr int MAX_AB_BIT = 24; static_assert(MOD1 % (1ull << MAX_AB_BIT) == 1, "MOD1 isn't enough to support an array length of 2^24."); static_assert(MOD2 % (1ull << MAX_AB_BIT) == 1, "MOD2 isn't enough to support an array length of 2^24."); static_assert(MOD3 % (1ull << MAX_AB_BIT) == 1, "MOD3 isn't enough to support an array length of 2^24."); assert(n + m - 1 <= (1 << MAX_AB_BIT)); auto c1 = convolution(a, b); auto c2 = convolution(a, b); auto c3 = convolution(a, b); std::vector c(n + m - 1); for (int i = 0; i < n + m - 1; i++) { unsigned long long x = 0; x += (c1[i] * i1) % MOD1 * M2M3; x += (c2[i] * i2) % MOD2 * M1M3; x += (c3[i] * i3) % MOD3 * M1M2; long long diff = c1[i] - internal::safe_mod((long long)(x), (long long)(MOD1)); if (diff < 0) diff += MOD1; static constexpr unsigned long long offset[5] = { 0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3}; x -= offset[diff % 5]; c[i] = x; } return c; } } namespace ryoku{ template struct binom_has_get_mod:false_type{}; template struct binom_has_get_mod>:true_type{}; template struct binom{ private: static vector&fact_table(){static vectorv={1};return v;} static vector&invfact_table(){static vectorv={1};return v;} static vector&invs_table(){static vectorv={0};return v;} static int&built_mod(){static int mod=-1;return mod;} public: static void build(int n){ auto&_fact=fact_table(); auto&_invfact=invfact_table(); auto&_invs=invs_table(); if constexpr(binom_has_get_mod::value){ auto mod=mint::get_mod(); if(built_mod()!=mod){ _fact={1}; _invfact={1}; _invs={0}; built_mod()=mod; } } if(n<(int)_fact.size())return; int old=_fact.size(); _fact.resize(n+1); _invfact.resize(n+1); _invs.resize(n+1); if constexpr(binom_has_get_mod::value){ auto mod=mint::get_mod(); for(int i=old;i<=n;i++){ _fact[i]=_fact[i-1]*i; if(i==1)_invs[i]=1; else _invs[i]=-_invs[mod%i]*(mod/i); _invfact[i]=_invfact[i-1]*_invs[i]; } }else{ for(int i=old;i<=n;i++){ _fact[i]=_fact[i-1]*i; _invs[i]=mint(1)/i; _invfact[i]=_invfact[i-1]*_invs[i]; } } } static mint fact(int i){ assert(i>=0); build(i); return fact_table()[i]; } static mint invfact(int i){ assert(i>=0); build(i); return invfact_table()[i]; } static mint inv(int i){ assert(i>0); build(i); return invs_table()[i]; } static mint C(int a,int b){//aCb if(b==0)return 1; if(a<0||b<0||a-b<0)return mint(0); build(a); auto&_fact=fact_table(); auto&_invfact=invfact_table(); return _fact[a]*_invfact[b]*_invfact[a-b]; } static mint iC(int a,int b){//1/aCb if(b==0)return 1; if(a<0||b<0||a-b<0)return mint(0); build(a); auto&_fact=fact_table(); auto&_invfact=invfact_table(); return _fact[b]*_fact[a-b]*_invfact[a]; } static mint P(int a,int b){ if(a0); mod=mod_; m=(i128(1)<<64)/mod; } unsigned reduce(uint64_t x){ assert(mod>0); x-=(((i128)x*m)>>64)*mod; return x struct dynamic_modint{ using u32=uint32_t; using u64=uint64_t; u32 val; dynamic_modint():val(0){} dynamic_modint(ll x){ ll v=x%get_mod(); if(v<0)v+=get_mod(); val=v; } static dynamic_modint raw(int v){ assert(v>=0); dynamic_modint mi; mi.val=v; return mi; } dynamic_modint &operator+=(const dynamic_modint&m){ u32 md=get_mod(); u32 x=val+m.val-md; val=x+(md&-(x>>31)); return *this; } dynamic_modint &operator-=(const dynamic_modint&m){ u32 md=get_mod(); u32 x=val-m.val; val=x+(md&-(x>>31)); return *this; } dynamic_modint &operator*=(const dynamic_modint&m){ val=rem(u64(val)*m.val); return *this; } dynamic_modint &operator/=(const dynamic_modint&m){ val=rem(u64(val)*m.inv().val); return *this; } dynamic_modint operator-() const{ return dynamic_modint(val?get_mod()-val:0); } dynamic_modint operator+() const { return *this; } friend dynamic_modint operator+(dynamic_modint lhs, const dynamic_modint& rhs){ return lhs+=rhs; } friend dynamic_modint operator-(dynamic_modint lhs, const dynamic_modint& rhs){ return lhs-=rhs; } friend dynamic_modint operator*(dynamic_modint lhs, const dynamic_modint& rhs){ return lhs*=rhs; } friend dynamic_modint operator/(dynamic_modint lhs,const dynamic_modint&rhs){ return lhs/=rhs; } bool operator==(const dynamic_modint&p) const{ return p.val==val; } bool operator!=(const dynamic_modint&p) const{ return p.val!=val; } dynamic_modint pow(int64_t n) const{ dynamic_modint res(1),mul(val); while(n){ if(n%2)res*=mul; mul*=mul; n/=2; } return res; } friend ostream&operator<<(ostream&os,const dynamic_modint&p){ os<>(istream&is,dynamic_modint&p){ int64_t x; is>>x; p=dynamic_modint(x); return is; } dynamic_modint inv()const{ int64_t a=val,b=get_mod(),u=1,v=0,t; while(b>0){ t=a/b; swap(a-=t*b,b); swap(u-=t*v,v); } return dynamic_modint(u); } inline static u32 rem(u64 x){return barrett_reduction().reduce(x);} static inline int &get_mod(){ static int mod=0; return mod; } static void set_mod(int md){ assert(0 T extgcd(T a,T b,T &x,T &y){ T d=a; if(b!=0){ d=extgcd(b,a%b,y,x); y-=(a/b)*x; }else{ x=(a>=0?1:-1); y=0; d=(a>=0?a:-a); } return d; } template pair inv(T x,T m){ T a1,a2; T res=extgcd(x,m,a1,a2); T md=m/res; a1=(a1%md+md)%md; return {a1,md}; } template pair mod_solve(T a,T b,T m){//return x s.t. ax=b mod m a%=m,b%=m;if(a<0)a+=m;if(b<0)b+=m; T g=gcd(gcd(a,b),m); a/=g,b/=g,m/=g; if(gcd(a,m)>1)return {-1,-1}; return {(inv(a,m).first*b)%m,inv(a,m).second}; } //x^2 ≡ b (mod p) ll mod_sqrt(ll b,ll p){ static mt19937 mt(random_device{}()); b%=p;if(b<0)b+=p; if(b==0)return 0; if(p==2){ return b; } assert(p>=3); using mint=dynamic_modint<20260801>;mint::set_mod(p); if(mint(b).pow((p-1)/2)==-1){ return -1; } if(p%4==3){ return mint(b).pow((p+1)/4).val; } ll t=[&](){ ll w; while(1){ ll t=mt()%p; w=t*t-b; if(mint(w).pow((p-1)/2)==mint(-1)){ return t; } } assert(0); }(); mint w=mint(t*t-b); using T=pair; auto ml=[&](T a,T b)->T{ return T{a.first*b.first+a.second*b.second*w,a.second*b.first+a.first*b.second}; }; ll e=(p+1)/2; T ans={1,0}; T gy={t,1}; while(e){ if(e%2)ans=ml(ans,gy); gy=ml(gy,gy); e/=2; } return ans.first.val; } } namespace ryoku{ #ifndef FPS_STRUCT #define FPS_STRUCT template struct fps:vc{ #define BF atcoder::internal::butterfly #define IBF atcoder::internal::butterfly_inv using vc::vc; using vc::operator[]; fps(const vc&v):vc(v){} fps&operator=(const vc&v){vc::operator=(v);return *this;} fps&operator+=(const fps&g){ int n=g.size(); if(n>(int)this->size())this->resize(n); for(int i=0;i(int)this->size())this->resize(n); for(int i=0;iempty()||g.empty()){this->clear();return *this;} auto res=atcoder::convolution(*this,g); *this=fps(res.begin(),res.end()); return *this; } fps& operator+=(const mint&v){if(this->empty())this->resize(1);(*this)[0]+=v;return *this;} fps& operator-=(const mint&v){if(this->empty())this->resize(1);(*this)[0]-=v;return *this;} fps& operator*=(const mint&v){for(auto& x:*this)x*=v;return *this;} fps& operator/=(const mint&v){mint inv=v.inv();for(auto& x:*this)x*=inv;return *this;} fps& operator>>=(const ll&v){*this=fps(this->begin()+min(this->size(),v),this->end());return *this;} fps& operator<<=(const ll&v){fps np(v+this->size());rep(i,this->size())np[i+v]=(*this)[i];*this=np;return *this;} fps operator+(const fps&g)const{return fps(*this)+=g;} fps operator-(const fps&g)const{return fps(*this)-=g;} fps operator*(const fps&g)const{return fps(*this)*=g;} fps operator+(const mint&v)const{return fps(*this)+=v;} friend fps operator+(const mint&v,const fps&g){return fps(g)+=v;} fps operator-(const mint&v)const{return fps(*this)-=v;} friend fps operator-(const mint&v,const fps&g){return -g+=v;} fps operator*(const mint&v)const{return fps(*this)*=v;} friend fps operator*(const mint&v,const fps&g){return fps(g)*=v;} fps operator/(const mint&v)const{return fps(*this)/=v;} friend fps operator/(const mint&v,const fps&g){return fps(g)/=v;} fps operator>>(const ll&v)const{return fps(*this)>>=v;} fps operator<<(const ll&v)const{return fps(*this)<<=v;} fps operator-()const{ fps res=*this; for(auto&x:res)x=-x; return res; } fps pre(int sz)const{ return fps(this->begin(),this->begin()+min((int)this->size(),sz)); } //[0,n) fps inv(int deg=-1)const{ assert((*this).size()&&(*this)[0].val!=0); if(deg==-1)deg=this->size(); fps res{(*this)[0].inv()}; for(int len=1;lensize()+1); rep(i,this->size())res[i+1]=(*this)[i]*binom::inv(i+1); return res; } fps log(int deg=-1)const{ if(deg==-1)deg=this->size(); assert(this->size()&&(*this)[0]==1); return (this->diff().pre(deg)*this->inv(deg)).integral().pre(deg); } fps exp(int deg=-1)const{ assert((*this).size()&&(*this)[0]==0); if(deg==-1)deg=this->size(); fps res{1},h{1}; for(int len=1;lensize())f_prime[i]=(*this)[i+1]*(i+1); BF(f_prime); fps w_prime(nxt); rep(i,nxt)w_prime[i]=g_prime[i]*H[i]+f_prime[i]*V[i]; IBF(w_prime);w_prime*=inv; DREP(i,nxt-1,len){ mint fi=(i<(int)this->size())?(*this)[i]:0; w_prime[i]=fi-w_prime[i-1]*binom::inv(i); } rep(i,len)w_prime[i]=0; BF(w_prime); rep(i,nxt)G[i]*=w_prime[i]; IBF(G);G*=inv; res.resize(nxt); REP(i,len,nxt)res[i]=G[i]; if(nxtsize(); if(m==0){fps res(deg);res[0]=1;return res;} rep(i,this->size()){ if(m*i>=deg)return fps(deg); if((*this)[i].val){ auto target=(*this)>>i; mint coef=mint((*this)[i]); mint inv=1/coef; target*=inv; return ((m*target.log(deg-i*m)).exp(deg-i*m)*mint(coef).pow(m))<<(i*m); } } return fps(deg); } void extend(int n){ if(this->size()resize(n); } fps shrink(){ auto res=(*this); while(res.size()&&res.back()==0)res.pop_back(); return res; } pairdiv(fps f)const{ if(this->size()size()-f.size()+1; auto rthis=*this;reverse(all(rthis)); auto rf=f;reverse(all(rf)); auto rq=(rthis.pre(qsize)*rf.inv(qsize)).pre(qsize); reverse(all(rq)); return {rq,(*this-rq*f).shrink()}; } fps div_only(fps f)const{ if(this->size()size()-f.size()+1; auto rthis=*this;reverse(all(rthis)); auto rf=f;reverse(all(rf)); auto rq=(rthis.pre(qsize)*rf.inv(qsize)).pre(qsize); reverse(all(rq)); return rq; } optional sqrt(int deg=-1)const{ if(deg==-1)deg=this->size(); if((this)->size()==0)return fps(deg); if((*this)[0]==0){ REP(i,1,this->size()){ if((*this)[i].val){ if(i%2)return nullopt; if(deg-i/2<=0)break; auto res=((*this)>>i).sqrt(deg-i/2); if(!res.has_value())return nullopt; auto ret=res.value(); ret<<=(i/2); ret.resize(deg); return ret; } } return fps(deg); } ll s=mod_sqrt((*this)[0].val,mint::get_mod()); if(s==-1)return nullopt; fps res{s}; mint inv=1/mint(2); for(int i=1;i f(vx) fps substitute(mint v){ mint coef=1; fps nxt(*this);rep(i,nxt.size()){ nxt[i]*=coef; coef*=v; } return nxt; } }; #endif } namespace ryoku{ template fpsall_prod(vc>v){ assert(mint::get_mod()); using fps=fps; if(v.empty())return {1}; auto cmp=[&](auto&a,auto&b){return a.size()>b.size();}; priority_queue,decltype(cmp)>pq(cmp); for(auto&p:v)pq.push(std::move(p)); while(pq.size()>=2){ auto p1=std::move(pq.top());pq.pop(); auto p2=std::move(pq.top());pq.pop(); pq.push(std::move(p1*p2)); } return pq.top(); } } namespace ryoku{ template struct tree{ using Graph=static_graph<0,T>; using edge=typename Graph::edge; using cost_t=typename Graph::cost_t; mutable Graph g; mutable int built_hld=-1; int n; mutable vcin,out,head,size_,par,depth,ord,cp,cp_root; tree(int n):n(n),g(n,n-1){} void add_edge(const edge&e){ g.add_edge(e); } void add_edge(int a,int b,cost_t cost=1,int id=-1){ g.add_edge(a,b,cost,id); } bool is_to_par(auto&e)const{ return par[e.from]==e.to; } int size()const{ return n; } bool same(int a,int b)const{ assert(0<=a&&a void input(){ rep(i,n-1){ INT(a,b); a-=substract; b-=substract; g.add_edge(a,b); } } template void build(int root=0)const{ if(built_hld!=-1)return; assert(0<=root&&rootvoid{ cp[u]=c;depth[u]=d++; auto s=g[u]; int heavy=-1,par_id=-1,heavy_size=0; rep(i,s.size()){ auto&e=s[i]; if(e.to==v){par_id=i;continue;} par[e.to]=u; dfs(dfs,e.to,u,d,c); size_[u]+=size_[e.to]; if(size_[e.to]>heavy_size)heavy_size=size_[e.to],heavy=i; } if(heavy!=-1&&heavy!=0){ swap(s[heavy],s[0]); if(par_id==0)par_id=heavy; else if(par_id==heavy)par_id=0; } if(par_id!=-1&&par_id+1!=s.size())swap(s[par_id],s[s.size()-1]); }; auto visit=[&](int u){ int c=cp_root.size(); cp_root.pb(u);par[u]=-1;head[u]=u; dfs(dfs,u,-1,0,c); }; visit(root); rep(u,n)if(cp[u]==-1)visit(u); auto dfs2=[&](auto&dfs2,int u)->void{ in[u]=timer;ord[timer++]=u; auto s=g[u]; int ce=s.size()-(par[u]!=-1); if(ce){ head[s[0].to]=head[u]; dfs2(dfs2,s[0].to); REP(i,1,ce)head[s[i].to]=s[i].to,dfs2(dfs2,s[i].to); } if constexpr(disjoint)out[u]=timer++; else out[u]=timer; }; for(auto u:cp_root)dfs2(dfs2,u); } auto heavy_edge(int u)const{ assert(0<=u&&u{s.data(),s.data()}; return span{s.data(),s.data()+1}; } auto light_edges(int u)const{ assert(0<=u&&u{s.data(),s.data()}; return span{s.data()+1,s.data()+ce}; } int lca(int a,int b)const{ assert(0<=a&&a0){ int x=I[a]-I[H[a]]; if(x>=k){ return O[I[a]-k]; } k-=x+1; a=P[H[a]]; } return a; } int jump(int s,int t,int k)const{ assert(0<=s&&s=k){ return jumpup(s,k); }else{ return jumpup(t,D-k); } } int to(int x,int y)const{ assert(0<=x&&x>query(int s,int t,bool edge=false)const{ assert(0<=s&&s>rs,rt; while(h[s]!=h[t]){ if(d[h[s]]>d[h[t]]){ rs.push_back({I[s],I[h[s]]}); s=P[h[s]]; }else{ rt.push_back({I[h[t]],I[t]}); t=P[h[t]]; } } if(s!=t||!edge){ if(d[s]>d[t]){ rs.push_back({I[s],I[t]+edge}); }else{ rt.push_back({I[s]+edge,I[t]}); } } rs.reserve(rs.size()+rt.size()); for(auto it=rt.rbegin();it!=rt.rend();++it)rs.push_back(*it); return rs; } pairget_diameter(int v=0)const{ assert(n>0); assert(0<=v&&vint{ vcd(n),p(n,-2),st(1,from); p[from]=-1; int far=from; while(!st.empty()){ int u=st.back(); st.pop_back(); if(d[far],vc>get_explicit_path(int u,int v)const{ vcres; vces; auto dfs=[&](auto&dfs,int now,int pre)->int{ res.pb(now); if(now==v){ return 1; } for(auto&e:g[now]){ if(e.to==pre)continue; es.pb(e); if(dfs(dfs,e.to,now))return 1; es.pop_back(); } res.pop_back(); return 0; }; dfs(dfs,u,-1); return{res,es}; } }; } using namespace ryoku; using mint=static_modint<998244353>; using B=binom; using p=fps; void solve(){ INT(n); treeg(n*2+1);g.input<1>(); //(親への辺を使いません、使います) auto dfs=[&](auto&dfs,int u,int v)->p{ vc

ps; for(auto&e:g[u]){ if(e.to==v)continue; auto V=dfs(dfs,e.to,u); ps.pb({V[1],V[0]}); } if(ps.empty())return{1,0}; auto P=all_prod(ps); p res(2); rep(i,P.size()){ int match=i/2*2; mint way=1; if(match!=i){ if(u)way*=i; else way=0; } way*=B::fact(match)/mint(2).pow(match/2)*B::invfact(match/2); res[(i-match)]+=way*P[i]; } return res; }; ; auto ans=dfs(dfs,0,-1)[0]; PRT(ans); } signed main(){ int t=1; // cin >> t; while(t--)solve(); }