結果

問題 No.3852 Partition into 2-edge paths
コンテスト
ユーザー ryoku
提出日時 2026-12-04 21:59:38
言語 C++23(gnu拡張gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 375 ms / 2,000 ms
+ 139µs
コード長 57,803 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,237 ms
コンパイル使用メモリ 416,688 KB
実行使用メモリ 58,960 KB
最終ジャッジ日時 2026-12-04 22:00:06
合計ジャッジ時間 11,911 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//https://github.com/ryoku1020/lib
#ifdef TEMPLATE
#else
#define TEMPLATE
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<cassert>
using namespace std;
namespace ryoku{}
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using i128=__int128;
using u128=unsigned __int128;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
template<class T>using vvvc=vvc<vc<T>>;
template<class T>using smpq=priority_queue<T,vector<T>,greater<T>>;
template<class T>using bipq=priority_queue<T>;
using vi=vc<int>;
using vvi=vvc<int>;
using vl=vc<ll>;
using vvl=vvc<ll>;
#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<<s;
}
void scan(int&a){cin>>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<class A,class B>
void scan(pair<A,B>&p){
    scan(p.first);
    scan(p.second);
}
template<class C>void scan(C&a){for(auto&x:a)scan(x);}
void read(){}
template<class Head,class... Tail>void 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<type> name(__VA_ARGS__); read(name);
#define VVC(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__)); read(name);
template<class T>void print(T a){cout<<a;}
template<class T>void print(vector<T>a){for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}}
void PRT(){cout<<endl; return;}
template<class T>void PRT(T a){print(a); cout<<endl; return;}
template<class Head,class... Tail>void PRT(Head head,Tail... tail){print(head); cout<<" "; PRT(tail...); return;}
template<class T,class F>int chmin(T&x,F y){return x>y?(x=y,1):0;}
template<class T,class F>int chmax(T&x,F y){return x<y?(x=y,1):0;}
template<typename T>T floor(T a,T b){return a/b-(a%b&&((a<0)!=(b<0)));}
template<typename T>T ceil(T a,T b){return a/b+(a%b&&((a<0)==(b<0)));}
template<typename T>T bmod(T x,T y){return x-y*floor(x,y);}
template<typename T>
pair<T,T>divmod(T x,T y){
    T q=floor(x,y);
    return{q,x-q*y};
}
void YesNo(bool b){cout<<(b?"Yes":"No")<<endl;}void YESNO(bool b){cout<<(b?"YES":"NO")<<endl;}
void AliceBob(bool b){cout<<(b?"Alice":"Bob")<<endl;}
void Yes(){cout<<"Yes"<<endl;}void YES(){cout<<"YES"<<endl;}
void No(){cout<<"No"<<endl;}void NO(){cout<<"NO"<<endl;}

vc<int>stovi(const string&s,const string&S){
    vc<int>v(s.size());
    rep(i,s.size()){
        auto t=S.find(s[i]);
        assert(t!=string::npos);
        v[i]=t;
    }
    return v;
}
template<class T=ll>
T isqrt(T x){
    T F=sqrtl(x);
    if(F*F>x)F--;
    return F;
}
template<class C>C sorted(C a){
    sort(all(a));
    return a;
}
template<class C>C reved(C a){
    reverse(all(a));
    return a;
}
template<class T>
pair<vc<int>,vc<T>>compress(const vc<T>&a){
    vc<T>xs=a;
    sort(all(xs));
    xs.erase(unique(all(xs)),xs.end());
    vc<int>b(a.size());
    rep(i,a.size())b[i]=lower_bound(all(xs),a[i])-xs.begin();
    return{b,xs};
}
template<class T>
auto make_vec(int n,T x){
    return vc<T>(n,x);
}
template<class... Args>
auto make_vec(int n,Args...args){
    return vc(n,make_vec(args...));
}
template<class T>T tri(T x){return x*(x-1)/2;}
//[l,r)
template<class T>T tri(T l,T r){return (r-l)*(l+r-1)/2;}
//n を先頭に持ってくる
template<class C>
C rot(C v,int n){
    rotate(v.begin(),v.begin()+n,v.end());
    return v;
}
template<class C>
C concat(C a,const C&b){
    a.insert(a.end(),b.begin(),b.end());
    return a;
}
template<class Container>
auto rle(const Container&cv){
    using T=typename Container::value_type;
    vc<pair<T,int>>res;
    for(const auto&x:cv){
        if(res.empty()||res.back().fi!=x)res.pb({x,1});
        else res.back().se++;
    }
    return res;
}
template<class T>
vc<T>iota(int n){
    vc<T>v(n);rep(i,n)v[i]=i;
    return v;
}
template<class T,int minfirst,class C>
vc<int>argsort(const C&a){
    auto idx=iota<int>(a.size());
    sort(all(idx),[&](int i,int j){
        return (minfirst?make_pair(a[i],i)<make_pair(a[j],j):make_pair(a[i],i)>make_pair(a[j],j));
    });
    return idx;
}
template<class C>
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());
    vvc<T>b(a[0].size(),vc<T>(a.size()));
    rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j];
    return b;
}
vc<string>trans(const vc<string>&a){
    assert(a.size()&&a[0].size());
    rep(i,a.size())assert(a[i].size()==a[0].size());
    vc<string>b(a[0].size(),string(a.size(),0));
    rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j];
    return b;
}
template<class C>ll sz(const C&a){return (int)a.size();}
template<class C,class T>auto lb(const C&a,const T&x){return lower_bound(all(a),x);}
template<class C,class T>auto ub(const C&a,const T&x){return upper_bound(all(a),x);}
template<class T>int popcount(T n){return __builtin_popcountll(n);}
template<class T=void,class L=ll,class C>L sum(const C&a){return accumulate(all(a),L(0));}
template<class T>
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<class T>
subset_view<T>subset(T s){return{s};}
template<class C>auto max(const C&a){return *max_element(all(a));}
template<class C>auto min(const C&a){return *min_element(all(a));}
template<class C>ll argmin(const C&a){return min_element(all(a))-a.begin();}
template<class C>ll argmax(const C&a){return max_element(all(a))-a.begin();}
template<class L=ll,class C>
vc<L>presum(const C&a){
    vc<L>ret(a.size()+1);
    rep(i,a.size())ret[i+1]=ret[i]+a[i];
    return ret;
}
template<class T,class F>
vc<T>&operator+=(vc<T>&a,F b){
    for(auto&v:a)v+=b;
    return a;
}
template<class T,class F>
vc<T>&operator-=(vc<T>&a,F b){
    for(auto&v:a)v-=b;
    return a;
}
template<class T,class F>
vc<T>&operator*=(vc<T>&a,F b){
    for(auto&v:a)v*=b;
    return a;
}
template<class T,size_t N,class F>
array<T,N>&operator+=(array<T,N>&a,F b){
    for(auto&v:a)v+=b;
    return a;
}
template<class T,size_t N,class F>
array<T,N>&operator-=(array<T,N>&a,F b){
    for(auto&v:a)v-=b;
    return a;
}
template<class T,size_t N,class F>
array<T,N>&operator*=(array<T,N>&a,F b){
    for(auto&v:a)v*=b;
    return a;
}
template<class T=ll>
constexpr T pow(T a,T b){
    T res=1;
    while(b){
        if(b&1)res*=a;
        a*=a;
        b/=2;
    }
    return res;
}
template<class T>
struct temporary{
    T& x;T old;
    template<class U>temporary(T&x,U&&y):x(x),old(x){
        x=std::forward<U>(y);
    }
    ~temporary(){x=std::move(old);}
    temporary(const temporary&)=delete;
};
template<class T,class U>
temporary(T&,U&&)->temporary<T>;
#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<<a);}
constexpr ll ten(ll a){return pow<ll>(10,a);}
template<typename T>constexpr T inf=numeric_limits<T>::max()/2-1;
template<>constexpr pll inf<pll> ={inf<ll>,inf<ll>};
template<class T>constexpr T neg_inf=-inf<T>;
template<>constexpr pll neg_inf<pll> ={-inf<ll>,-inf<ll>};
template<class C>C UNIQUE(C&a){
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    return a;
}
template<class T>
int tbit(T x){
    using U=make_unsigned_t<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<class T>
int lbit(T x){
    using U=make_unsigned_t<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<class T>
int tbit(T x,int p){
    using U=make_unsigned_t<T>;
    constexpr int W=numeric_limits<U>::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<class T>
int lbit(T x,int p){
    using U=make_unsigned_t<T>;
    constexpr int W=numeric_limits<U>::digits;
    U y=(U)x;
    if(p<0)return lbit(y);
    if(p>=W)return -1;
    return lbit(y&(~U(0)<<p));
}
struct template_setup{
    template_setup(){
        cin.tie(0)->sync_with_stdio(0);
        cout<<fixed<<setprecision(20);
    }
};
static struct template_setup template_setup;
#endif
namespace ryoku{
struct unweighted{
    unweighted()=default;
    unweighted(int){}
    operator int()const{return 1;}
};
template<class T=unweighted>
struct edge{
    int from,to,id;
    [[no_unique_address]]T cost;
};
template<bool is_directed,class T=unweighted>
struct static_graph{
    constexpr static bool directed(){return is_directed;}
    using edge=::ryoku::edge<T>;
    using cost_t=T;
private:
    int n;
    mutable bool built=false,inv_built=false;
    vc<edge>edges;
    mutable vc<int>start,inv_start;
    mutable vc<edge>csr,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<n&&0<=e.to&&e.to<n);
        edges.pb(e);
    }
    void add_edge(int a,int b,cost_t cost=1,int id=-1){
        assert(!built&&!inv_built);
        assert(0<=a&&a<n&&0<=b&&b<n);
        if(id==-1)id=edges.size();
        edges.pb({a,b,id,cost});
    }
    template<int substract=0>
    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<n);
        return span<edge>(csr.data()+start[u],start[u+1]-start[u]);
    }

    auto operator[](int u)const{
        build();
        assert(0<=u&&u<n);
        return span<const edge>(csr.data()+start[u],start[u+1]-start[u]);
    }

    auto inv(int u){
        buildinv();
        assert(0<=u&&u<n);
        return span<edge>(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]);
    }

    auto inv(int u)const{
        buildinv();
        assert(0<=u&&u<n);
        return span<const edge>(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]);
    }

    const vc<edge>&all_edges()const{return edges;}
    int edge_size()const{return edges.size();}

    edge get_edge(int id)const{
        assert(0<=id&&id<edge_size());
        return edges[id];
    }
    int out_deg(int u)const{
        build();
        assert(0<=u&&u<n);
        return start[u+1]-start[u];
    }
    int in_deg(int u)const{
        buildinv();
        assert(0<=u&&u<n);
        return inv_start[u+1]-inv_start[u];
    }
    int deg(int u)const{return out_deg(u);}
    int size()const{return n;}
    template<class F>
    vvc<F>adj()const{
        vvc<F>res(n,vc<F>(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<class F>
    void sort(int i,F f){
        build();
        assert(0<=i&&i<n);
        std::sort(csr.begin()+start[i],csr.begin()+start[i+1],f);
    }
};

}

namespace ryoku{
template<uint32_t mod>
struct static_modint{
    static_assert(0<mod&&mod<=(1u<<31)-1);
    using u32=uint32_t;
    using u64=uint64_t;
    u32 val;
    static_modint():val(0){}
    static_modint(ll x){
        ll v=x%mod;
        if(v<0)v+=mod;
        val=v;
    }
    constexpr static uint32_t get_mod(){
        return mod;
    }
    static static_modint raw(int v){
        assert(v>=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<<p.val;
        return os;
    }
    friend istream&operator>>(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 <utility>
#ifdef _MSC_VER
#include <intrin.h>
#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 <int n> constexpr bool is_prime = is_prime_constexpr(n);
constexpr std::pair<long long, long long> 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 <int m> 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<long long, long long> crt(const std::vector<long long>& r,
                                    const std::vector<long long>& 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 <algorithm>
#include <array>
#include <cassert>
#include <type_traits>
#include <vector>
#if __cplusplus >= 202002L
#include <bit>
#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 <class mint,
          int g = internal::primitive_root<mint::get_mod()>>
struct fast_fourier_transform_info {
    static constexpr int rank2 = countr_zero_constexpr(mint::get_mod() - 1);
    std::array<mint, rank2 + 1> root;
    std::array<mint, rank2 + 1> iroot;
    std::array<mint, std::max(0, rank2 - 2 + 1)> rate2;
    std::array<mint, std::max(0, rank2 - 2 + 1)> irate2;
    std::array<mint, std::max(0, rank2 - 3 + 1)> rate3;
    std::array<mint, std::max(0, rank2 - 3 + 1)> 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 <class mint>
void butterfly(std::vector<mint>& a) {
    int n = int(a.size());
    int h = internal::countr_zero((unsigned int)n);
    static const fast_fourier_transform_info<mint> 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 <class mint>
void butterfly_inv(std::vector<mint>& a) {
    int n = int(a.size());
    int h = internal::countr_zero((unsigned int)n);
    static const fast_fourier_transform_info<mint> 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 <class mint>
std::vector<mint> convolution_naive(const std::vector<mint>& a,
                                    const std::vector<mint>& b) {
    int n = int(a.size()), m = int(b.size());
    std::vector<mint> 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 <class mint>
std::vector<mint> convolution_fft(std::vector<mint> a, std::vector<mint> 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 <class mint>
requires requires{mint::get_mod();}
std::vector<mint> convolution(std::vector<mint>&& a, std::vector<mint>&& 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 <class mint>
requires requires{mint::get_mod();}
std::vector<mint> convolution(const std::vector<mint>& a,
                              const std::vector<mint>& 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 <unsigned int mod = 998244353,
          class T>
requires std::is_integral_v<T>
std::vector<T> convolution(const std::vector<T>& a, const std::vector<T>& b) {
    int n = int(a.size()), m = int(b.size());
    if (!n || !m) return {};
    using mint = ryoku::static_modint<mod>;
    int z = (int)internal::bit_ceil((unsigned int)(n + m - 1));
    assert((mint::get_mod() - 1) % z == 0);
    std::vector<mint> 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<T> c(n + m - 1);
    for (int i = 0; i < n + m - 1; i++) {
        c[i] = c2[i].val;
    }
    return c;
}
std::vector<long long> convolution_ll(const std::vector<long long>& a,
                                      const std::vector<long long>& 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<MOD1>(a, b);
    auto c2 = convolution<MOD2>(a, b);
    auto c3 = convolution<MOD3>(a, b);
    std::vector<long long> 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<class,class=void>
struct binom_has_get_mod:false_type{};
template<class mint>
struct binom_has_get_mod<mint,void_t<decltype(mint::get_mod())>>:true_type{};
template<class mint>
struct binom{
private:
    static vector<mint>&fact_table(){static vector<mint>v={1};return v;}
    static vector<mint>&invfact_table(){static vector<mint>v={1};return v;}
    static vector<mint>&invs_table(){static vector<mint>v={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<mint>::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<mint>::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(a<b||b<0)return 0;
        build(a);
        auto&_fact=fact_table();
        auto&_invfact=invfact_table();
        return _fact[a]*_invfact[a-b];
    }
    static mint H(int a,int b){
        return C(a+b-1,b);
    }

};
}

namespace ryoku{
struct barrett{
    using u64=uint64_t;
    using u32=uint32_t;
    using i128=__int128_t;
    u64 m;
    int mod;
    void set(int mod_){
        assert(mod_>0);
        mod=mod_;
        m=(i128(1)<<64)/mod;
    }
    unsigned reduce(uint64_t x){
        assert(mod>0);
        x-=(((i128)x*m)>>64)*mod;
        return x<mod?x:x-mod;
    }
};

}
namespace ryoku{
template<int id>
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<<p.val;
        return os;
    }
    friend istream&operator>>(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<md&&md<=(1ll<<31)-1);
        get_mod()=md;
        barrett_reduction().set(md);
    }
    static inline barrett&barrett_reduction(){
        static barrett b;
        return b;
    }
};

}

namespace ryoku{
template<typename T>
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<class T>
pair<T,T> inv(T x,T m){
    T a1,a2;
    T res=extgcd<ll>(x,m,a1,a2);
    T md=m/res;
    a1=(a1%md+md)%md;
    return {a1,md};
}
template<class T>
pair<T,T> 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<ll>(a,m).first*b)%m,inv<ll>(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<mint,mint>;
    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<class mint>
struct fps:vc<mint>{
    #define BF atcoder::internal::butterfly
    #define IBF atcoder::internal::butterfly_inv
    using vc<mint>::vc;
    using vc<mint>::operator[];
    fps(const vc<mint>&v):vc<mint>(v){}
    fps&operator=(const vc<mint>&v){vc<mint>::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<n;i++)(*this)[i]+=g[i];
        return *this;
    }
    fps&operator-=(const fps&g){
        int n=g.size();
        if(n>(int)this->size())this->resize(n);
        for(int i=0;i<n;i++)(*this)[i]-=g[i];
        return *this;
    }
    fps&operator*=(const fps&g){
        if(this->empty()||g.empty()){this->clear();return *this;}
        auto res=atcoder::convolution<mint>(*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<int>(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;len<deg;len*=2){
            int nxt=len*2;
            auto F=(*this).pre(len*2);
            auto res2=res;
            F.resize(nxt);
            res2.resize(nxt);
            BF(F);
            BF(res2);
            rep(i,res2.size())F[i]*=res2[i];
            IBF(F);
            mint inv=1/mint(nxt);F*=inv;
            rep(i,len)F[i]=0;REP(i,len,len*2)F[i]=-F[i];
            BF(F);
            rep(i,res2.size())F[i]*=res2[i];
            IBF(F);
            F*=inv;
            res.resize(len*2);
            REP(i,len,len*2)res[i]=F[i];
        }
        res.resize(deg);
        return res;
    }
    fps diff()const{
        auto res=*this;
        rep(i,res.size())res[i]*=i;
        if(res.size())res.erase(res.begin());
        return res;
    }
    fps integral()const{
        fps res(this->size()+1);
        rep(i,this->size())res[i+1]=(*this)[i]*binom<mint>::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;len<deg;len*=2){
            int nxt=len*2;
            mint inv=1/mint(nxt);
            fps G=res;G.resize(nxt);BF(G);
            fps H=h;H.resize(nxt);BF(H);
            fps V=G;
            rep(i,nxt)V[i]*=H[i];
            IBF(V);rep(i,nxt)V[i]*=inv;
            rep(i,len)V[i]=0;REP(i,len,nxt)V[i]=-V[i];
            BF(V);
            fps g_prime(nxt);
            rep(i,len-1)g_prime[i]=res[i+1]*(i+1);
            BF(g_prime);
            fps f_prime(nxt);
            rep(i,len)if(i+1<(int)this->size())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<mint>::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(nxt<deg){
                rep(i,nxt)H[i]*=(V[i]-w_prime[i]);
                IBF(H);rep(i,nxt)H[i]*=inv;
                h.resize(nxt);
                REP(i,len,nxt)h[i]=H[i];
            }
        }
        res.resize(deg);
        return res;
    }
    fps pow(ll m,int deg=-1)const{
        if(deg==-1)deg=this->size();
        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()<n)this->resize(n);
    }
    fps shrink(){
        auto res=(*this);
        while(res.size()&&res.back()==0)res.pop_back();
        return res;
    }
    pair<fps,fps>div(fps f)const{
        if(this->size()<f.size()){ 
            return {{},(*this)}; 
        }
        int qsize=this->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()<f.size()){ 
            return {{}}; 
        }
        int qsize=this->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<fps> 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<deg;i*=2){
            res=(res+(*this).pre(i<<1)*res.inv(i<<1))*inv;
        }
        return res.pre(deg);
    }
    //f(x) -> 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<class mint>
fps<mint>all_prod(vc<fps<mint>>v){
    assert(mint::get_mod());
    using fps=fps<mint>;
    if(v.empty())return {1};
    auto cmp=[&](auto&a,auto&b){return a.size()>b.size();};
    priority_queue<fps,vc<fps>,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<class T=unweighted>
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 vc<int>in,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<n&&0<=b&&b<n);
        build();
        return cp[a]==cp[b];
    }
    auto operator[](int u)const{
        assert(0<=u&&u<n);
        return g[u];
    }
    auto operator[](int u){
        assert(0<=u&&u<n);
        return g[u];
    }
    template<int substract>
    void input(){
        rep(i,n-1){
            INT(a,b);
            a-=substract;
            b-=substract;
            g.add_edge(a,b);
        }
    }
    template<int disjoint=0>
    void build(int root=0)const{
        if(built_hld!=-1)return;
        assert(0<=root&&root<n);
        built_hld=disjoint;
        in.resize(n);out.resize(n);head.resize(n);size_.assign(n,1);par.resize(n);depth.resize(n);ord.assign(n*(disjoint+1),-1);cp.assign(n,-1);cp_root.clear();cp_root.reserve(n);
        int timer=0;
        auto dfs=[&](auto&dfs,int u,int v,int d,int c)->void{
            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<n);
        build();
        auto s=g[u];
        int sz=s.size(),ce=(par[u]==-1?sz:sz-1);
        if(ce<=0)return span<const edge>{s.data(),s.data()};
        return span<const edge>{s.data(),s.data()+1};
    }
    auto light_edges(int u)const{
        assert(0<=u&&u<n);
        build();
        auto s=g[u];
        int sz=s.size(),ce=(par[u]==-1?sz:sz-1);
        if(ce<=1)return span<const edge>{s.data(),s.data()};
        return span<const edge>{s.data()+1,s.data()+ce};
    }
    int lca(int a,int b)const{
        assert(0<=a&&a<n&&0<=b&&b<n);
        build();
        auto&h=head;
        auto&d=depth;
        auto&p=par;
        if(cp[a]!=cp[b])return -1;
        while(1){
            if(h[a]==h[b]){
                if(d[a]<d[b])return a;
                return b;
            }
            if(d[h[a]]<d[h[b]])swap(a,b);
            a=p[h[a]];
        }
    }
    int dist(int a,int b)const{
        assert(0<=a&&a<n&&0<=b&&b<n);
        build();
        int L=lca(a,b);
        if(L==-1)return -1;
        return depth[a]+depth[b]-2*depth[L];
    }
    int jumpup(int a,int k)const{
        assert(0<=a&&a<n);
        build();
        if(k<0||depth[a]<k)return -1;
        auto&I=in;
        auto&H=head;
        auto&P=par;
        auto&O=ord;
        while(k>0){ 
            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<n&&0<=t&&t<n);
        build();
        if(cp[s]!=cp[t]||k<0)return -1;
        int L=lca(s,t);
        int D=depth[s]+depth[t]-2*depth[L];
        if(D<k)return -1;
        if(depth[s]-depth[L]>=k){
            return jumpup(s,k);
        }else{
            return jumpup(t,D-k);
        }
    }   
    int to(int x,int y)const{
        assert(0<=x&&x<n&&0<=y&&y<n&&x!=y);
        build();
        if(cp[x]!=cp[y])return -1;
        if(in[y]<in[x]||out[x]<=in[y])return g[x].size()-1;
        auto s=g[x];
        int ce=s.size()-(par[x]!=-1);
        if(in[s[0].to]<=in[y]&&in[y]<out[s[0].to])return 0;
        int l=1,r=ce;
        while(l<r){
            int m=(l+r)/2;
            if(in[s[m].to]<=in[y])l=m+1;
            else r=m;
        }
        return l-1;
    }
    vc<pair<int,int>>query(int s,int t,bool edge=false)const{
        assert(0<=s&&s<n&&0<=t&&t<n);
        build();
        if(cp[s]!=cp[t])return {};
        auto&h=head;
        auto&d=depth;
        auto&I=in;
        auto&P=par;
        vc<pair<int,int>>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;
    }
    pair<int,int>get_diameter(int v=0)const{
        assert(n>0);
        assert(0<=v&&v<n);
        auto find_farthest=[&](int from)->int{
            vc<int>d(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]<d[u])far=u;
                for(auto&e:g[u])if(e.to!=p[u]){
                    p[e.to]=u;
                    d[e.to]=d[u]+1;
                    st.push_back(e.to);
                }
            }
            return far;
        };
        int v1=find_farthest(v);
        int v2=find_farthest(v1);
        return {v1,v2};
    }
    pair<vc<int>,vc<typename Graph::edge>>get_explicit_path(int u,int v)const{
        vc<int>res;
        vc<typename Graph::edge>es;
        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<mint>;
using p=fps<mint>;
void solve(){
    INT(n);
    tree<unweighted>g(n*2+1);g.input<1>();
    //(親への辺を使いません、使います)
    auto dfs=[&](auto&dfs,int u,int v)->p{
        vc<p>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();
}
0