#include using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using i128 = __int128_t; using u128 = __uint128_t; using f64 = double; using f80 = long double; using f128 = __float128; constexpr i32 operator"" _i32(u64 v) { return v; } constexpr u32 operator"" _u32(u64 v) { return v; } constexpr i64 operator"" _i64(u64 v) { return v; } constexpr u64 operator"" _u64(u64 v) { return v; } constexpr f64 operator"" _f64(f80 v) { return v; } constexpr f80 operator"" _f80(f80 v) { return v; } using Istream = std::istream; using Ostream = std::ostream; using Str = std::string; template using Lt = std::less; template using Gt = std::greater; template using BSet = std::bitset; template using Pair = std::pair; template using Tup = std::tuple; template using Arr = std::array; template using Deq = std::deque; template using Set = std::set; template using MSet = std::multiset; template using USet = std::unordered_set; template using UMSet = std::unordered_multiset; template using Map = std::map; template using MMap = std::multimap; template using UMap = std::unordered_map; template using UMMap = std::unordered_multimap; template using Vec = std::vector; template using Stack = std::stack; template using Queue = std::queue; template using MaxHeap = std::priority_queue; template using MinHeap = std::priority_queue, Gt>; constexpr bool LOCAL = false; constexpr bool OJ = not LOCAL; template static constexpr T OjLocal(T oj, T local) { return LOCAL ? local : oj; } template constexpr T LIMMIN = std::numeric_limits::min(); template constexpr T LIMMAX = std::numeric_limits::max(); template constexpr T INF = (LIMMAX - 1) / 2; template constexpr T PI = T{3.141592653589793238462643383279502884}; template constexpr T TEN(int n) { return n == 0 ? T{1} : TEN(n - 1) * T{10}; } template constexpr bool chmin(T& a, const T& b) { return (a > b ? (a = b, true) : false); } template constexpr bool chmax(T& a, const T& b) { return (a < b ? (a = b, true) : false); } template constexpr T floorDiv(T x, T y) { assert(y != 0); if (y < 0) { x = -x, y = -y; } return x >= 0 ? x / y : (x - y + 1) / y; } template constexpr T ceilDiv(T x, T y) { assert(y != 0); if (y < 0) { x = -x, y = -y; } return x >= 0 ? (x + y - 1) / y : x / y; } template constexpr T powerMonoid(T v, I n, const T& e) { assert(n >= 0); if (n == 0) { return e; } return (n % 2 == 1 ? v * powerMonoid(v, n - 1, e) : powerMonoid(v * v, n / 2, e)); } template constexpr T powerInt(T v, I n) { return powerMonoid(v, n, T{1}); } template constexpr void fillAll(Vs& arr, const V& v) { if constexpr (std::is_convertible::value) { arr = v; } else { for (auto& subarr : arr) { fillAll(subarr, v); } } } template constexpr void sortAll(Vs& vs) { std::sort(std::begin(vs), std::end(vs)); } template constexpr void sortAll(Vs& vs, C comp) { std::sort(std::begin(vs), std::end(vs), comp); } template constexpr void reverseAll(Vs& vs) { std::reverse(std::begin(vs), std::end(vs)); } template constexpr Vs reversed(const Vs& vs) { auto rvs = vs; reverseAll(rvs); return rvs; } template constexpr V sumAll(const Vs& vs) { if constexpr (std::is_convertible::value) { return static_cast(vs); } else { V ans = 0; for (const auto& v : vs) { ans += sumAll(v); } return ans; } } template constexpr int minInd(const Vs& vs) { return std::min_element(std::begin(vs), std::end(vs)) - std::begin(vs); } template constexpr int maxInd(const Vs& vs) { return std::max_element(std::begin(vs), std::end(vs)) - std::begin(vs); } template constexpr int lbInd(const Vs& vs, const V& v) { return std::lower_bound(std::begin(vs), std::end(vs), v) - std::begin(vs); } template constexpr int ubInd(const Vs& vs, const V& v) { return std::upper_bound(std::begin(vs), std::end(vs), v) - std::begin(vs); } template constexpr void plusAll(Vs& vs, const V& v) { for (auto& v_ : vs) { v_ += v; } } template constexpr void concat(Vs& vs1, const Vs& vs2) { std::copy(std::begin(vs2), std::end(vs2), std::back_inserter(vs1)); } template constexpr void concatted(const Vs& vs1, const Vs& vs2) { auto vs = vs1; concat(vs, vs2); return vs; } template constexpr Vec genVec(int n, F gen) { Vec ans; std::generate_n(std::back_inserter(ans), n, gen); return ans; } template constexpr Vec iotaVec(int n, T offset = 0) { Vec ans(n); std::iota(std::begin(ans), std::end(ans), offset); return ans; } inline Ostream& operator<<(Ostream& os, i128 v) { bool minus = false; if (v < 0) { minus = true, v = -v; } Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << (minus ? "-" : "") << ans; } inline Ostream& operator<<(Ostream& os, u128 v) { Str ans; if (v == 0) { ans = "0"; } while (v) { ans.push_back('0' + v % 10), v /= 10; } std::reverse(ans.begin(), ans.end()); return os << ans; } constexpr int popCount(u64 v) { return v ? __builtin_popcountll(v) : 0; } constexpr int topBit(u64 v) { return v == 0 ? -1 : 63 - __builtin_clzll(v); } constexpr int lowBit(u64 v) { return v == 0 ? 64 : __builtin_ctzll(v); } constexpr int bitWidth(u64 v) { return topBit(v) + 1; } constexpr u64 bitCeil(u64 v) { return v ? (1_u64 << bitWidth(v - 1)) : 1_u64; } constexpr u64 bitFloor(u64 v) { return v ? (1_u64 << topBit(v)) : 0_u64; } constexpr bool hasSingleBit(u64 v) { return (v > 0) and ((v & (v - 1)) == 0); } constexpr bool isBitOn(u64 mask, int ind) { return (mask >> ind) & 1_u64; } constexpr bool isBitOff(u64 mask, int ind) { return not isBitOn(mask, ind); } constexpr u64 bitMask(int bitWidth) { return (bitWidth == 64 ? ~0_u64 : (1_u64 << bitWidth) - 1); } constexpr u64 bitMask(int start, int end) { return bitMask(end - start) << start; } template struct Fix : F { constexpr Fix(F&& f) : F{std::forward(f)} {} template constexpr auto operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; class irange { private: struct itr { constexpr itr(i64 start = 0, i64 step = 1) : m_cnt{start}, m_step{step} {} constexpr bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; } constexpr i64 operator*() { return m_cnt; } constexpr itr& operator++() { return m_cnt += m_step, *this; } i64 m_cnt, m_step; }; i64 m_start, m_end, m_step; public: static constexpr i64 cnt(i64 start, i64 end, i64 step) { if (step == 0) { return -1; } const i64 d = (step > 0 ? step : -step); const i64 l = (step > 0 ? start : end); const i64 r = (step > 0 ? end : start); i64 n = (r - l) / d + ((r - l) % d ? 1 : 0); if (l >= r) { n = 0; } return n; } constexpr irange(i64 start, i64 end, i64 step = 1) : m_start{start}, m_end{m_start + step * cnt(start, end, step)}, m_step{step} { assert(step != 0); } constexpr itr begin() const { return itr{m_start, m_step}; } constexpr itr end() const { return itr{m_end, m_step}; } }; constexpr irange rep(i64 end) { return irange(0, end, 1); } constexpr irange per(i64 rend) { return irange(rend - 1, -1, -1); } class Scanner { public: Scanner(Istream& is = std::cin) : m_is{is} { m_is.tie(nullptr)->sync_with_stdio(false); } template T val() { T v; return m_is >> v, v; } template T val(T offset) { return val() - offset; } template Vec vec(int n) { return genVec(n, [&]() { return val(); }); } template Vec vec(int n, T offset) { return genVec(n, [&]() { return val(offset); }); } template Vec> vvec(int n, int m) { return genVec>(n, [&]() { return vec(m); }); } template Vec> vvec(int n, int m, const T offset) { return genVec>(n, [&]() { return vec(m, offset); }); } template auto tup() { return Tup{val()...}; } template auto tup(const Args&... offsets) { return Tup{val(offsets)...}; } private: Istream& m_is; }; inline Scanner in; class Printer { public: Printer(Ostream& os = std::cout) : m_os{os} { m_os << std::fixed << std::setprecision(15); } template int operator()(const Args&... args) { return dump(args...), 0; } template int ln(const Args&... args) { return dump(args...), m_os << '\n', 0; } template int el(const Args&... args) { return dump(args...), m_os << std::endl, 0; } int YES(bool b = true) { return ln(b ? "YES" : "NO"); } int NO(bool b = true) { return YES(not b); } int Yes(bool b = true) { return ln(b ? "Yes" : "No"); } int No(bool b = true) { return Yes(not b); } private: template void dump(const T& v) { m_os << v; } template void dump(const Vec& vs) { for (int i : rep(vs.size())) { m_os << (i ? " " : ""), dump(vs[i]); } } template void dump(const Vec>& vss) { for (int i : rep(vss.size())) { m_os << (i ? "\n" : ""), dump(vss[i]); } } template int dump(const T& v, const Ts&... args) { return dump(v), m_os << ' ', dump(args...), 0; } Ostream& m_os; }; inline Printer out; template auto ndVec(int const (&szs)[n], const T x = T{}) { if constexpr (i == n) { return x; } else { return std::vector(szs[i], ndVec(szs, x)); } } template inline T binSearch(T ng, T ok, F check) { while (std::abs(ok - ng) > 1) { const T mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; } template constexpr Pair extgcd(const T a, const T b) // [x,y] -> ax+by=gcd(a,b) { static_assert(std::is_signed_v, "Signed integer is allowed."); assert(a != 0 or b != 0); if (a >= 0 and b >= 0) { if (a < b) { const auto [y, x] = extgcd(b, a); return {x, y}; } if (b == 0) { return {1, 0}; } const auto [x, y] = extgcd(b, a % b); return {y, x - (a / b) * y}; } else { auto [x, y] = extgcd(std::abs(a), std::abs(b)); if (a < 0) { x = -x; } if (b < 0) { y = -y; } return {x, y}; } } template constexpr T inverse(const T a, const T mod) // ax=gcd(a,M) (mod M) { assert(a > 0 and mod > 0); auto [x, y] = extgcd(a, mod); if (x <= 0) { x += mod; } return x; } template class modint { template static U modRef() { static u32 s_mod = 0; return s_mod; } template static U rootRef() { static u32 s_root = 0; return s_root; } template static U max2pRef() { static u32 s_max2p = 0; return s_max2p; } public: static_assert(mod_ <= LIMMAX, "mod(signed int size) only supported!"); static constexpr bool isDynamic() { return (mod_ == 0); } template static constexpr std::enable_if_t mod() { return mod_; } template static std::enable_if_t mod() { return modRef(); } template static constexpr std::enable_if_t root() { return root_; } template static std::enable_if_t root() { return rootRef(); } template static constexpr std::enable_if_t max2p() { return max2p_; } template static std::enable_if_t max2p() { return max2pRef(); } template static void setMod(std::enable_if_t m) { assert(1 <= m and m <= LIMMAX); modRef() = m; sinvRef() = {1, 1}; factRef() = {1, 1}; ifactRef() = {1, 1}; } template static void setRoot(std::enable_if_t r) { rootRef() = r; } template static void setMax2p(std::enable_if_t m) { max2pRef() = m; } constexpr modint() : m_val{0} {} constexpr modint(i64 v) : m_val{normll(v)} {} constexpr void setRaw(u32 v) { m_val = v; } constexpr modint operator-() const { return modint{0} - (*this); } constexpr modint& operator+=(const modint& m) { m_val = norm(m_val + m.val()); return *this; } constexpr modint& operator-=(const modint& m) { m_val = norm(m_val + mod() - m.val()); return *this; } constexpr modint& operator*=(const modint& m) { m_val = normll((i64)m_val * (i64)m.val() % (i64)mod()); return *this; } constexpr modint& operator/=(const modint& m) { return *this *= m.inv(); } constexpr modint operator+(const modint& m) const { auto v = *this; return v += m; } constexpr modint operator-(const modint& m) const { auto v = *this; return v -= m; } constexpr modint operator*(const modint& m) const { auto v = *this; return v *= m; } constexpr modint operator/(const modint& m) const { auto v = *this; return v /= m; } constexpr bool operator==(const modint& m) const { return m_val == m.val(); } constexpr bool operator!=(const modint& m) const { return not(*this == m); } friend Istream& operator>>(Istream& is, modint& m) { i64 v; return is >> v, m = v, is; } friend Ostream& operator<<(Ostream& os, const modint& m) { return os << m.val(); } constexpr u32 val() const { return m_val; } template constexpr modint pow(I n) const { return powerInt(*this, n); } constexpr modint inv() const { return inverse(m_val, mod()); } static modint sinv(u32 n) { auto& is = sinvRef(); for (u32 i = (u32)is.size(); i <= n; i++) { is.push_back(-is[mod() % i] * (mod() / i)); } return is[n]; } static modint fact(u32 n) { auto& fs = factRef(); for (u32 i = (u32)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); } return fs[n]; } static modint ifact(u32 n) { auto& ifs = ifactRef(); for (u32 i = (u32)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); } return ifs[n]; } static modint perm(int n, int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k); } static modint comb(int n, int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k) * ifact(k); } private: static Vec& sinvRef() { static Vec is{1, 1}; return is; } static Vec& factRef() { static Vec fs{1, 1}; return fs; } static Vec& ifactRef() { static Vec ifs{1, 1}; return ifs; } static constexpr u32 norm(u32 x) { return x < mod() ? x : x - mod(); } static constexpr u32 normll(i64 x) { return norm(u32(x % (i64)mod() + (i64)mod())); } u32 m_val; }; using modint_1000000007 = modint<1000000007, 5, 1>; using modint_998244353 = modint<998244353, 3, 23>; template using modint_dynamic = modint<0, 0, id>; template class Graph { struct Edge { Edge() = default; Edge(int i, int t, T c) : id{i}, to{t}, cost{c} {} int id; int to; T cost; operator int() const { return to; } }; public: Graph(int n) : m_v{n}, m_edges(n) {} void addEdge(int u, int v, bool bi = false) { assert(0 <= u and u < m_v); assert(0 <= v and v < m_v); m_edges[u].emplace_back(m_e, v, 1); if (bi) { m_edges[v].emplace_back(m_e, u, 1); } m_e++; } void addEdge(int u, int v, const T& c, bool bi = false) { assert(0 <= u and u < m_v); assert(0 <= v and v < m_v); m_edges[u].emplace_back(m_e, v, c); if (bi) { m_edges[v].emplace_back(m_e, u, c); } m_e++; } const Vec& operator[](const int u) const { assert(0 <= u and u < m_v); return m_edges[u]; } Vec& operator[](const int u) { assert(0 <= u and u < m_v); return m_edges[u]; } int v() const { return m_v; } int e() const { return m_e; } friend Ostream& operator<<(Ostream& os, const Graph& g) { for (int u : rep(g.v())) { for (const auto& [id, v, c] : g[u]) { os << "[" << id << "]: "; os << u << "->" << v << "(" << c << ")\n"; } } return os; } Vec sizes(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ss(N, 1); Fix([&](auto dfs, int u, int p) -> void { for ([[maybe_unused]] const auto& [_temp_name_0, v, c] : m_edges[u]) { if (v == p) { continue; } dfs(v, u); ss[u] += ss[v]; } })(root, -1); return ss; } Vec depths(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ds(N, 0); Fix([&](auto dfs, int u, int p) -> void { for ([[maybe_unused]] const auto& [_temp_name_1, v, c] : m_edges[u]) { if (v == p) { continue; } ds[v] = ds[u] + c; dfs(v, u); } })(root, -1); return ds; } Vec parents(int root = 0) const { const int N = v(); assert(0 <= root and root < N); Vec ps(N, -1); Fix([&](auto dfs, int u, int p) -> void { for ([[maybe_unused]] const auto& [_temp_name_2, v, c] : m_edges[u]) { if (v == p) { continue; } ps[v] = u; dfs(v, u); } })(root, -1); return ps; } private: int m_v; int m_e = 0; Vec> m_edges; }; template class NumberTheoriticTransform { // DynamicModint 非対応 static_assert(not mint::isDynamic(), "class NTT: Not support dynamic modint."); private: static constexpr u32 MOD = mint::mod(); static constexpr u32 ROOT = mint::root(); static constexpr u32 L_MAX = mint::max2p(); static constexpr int N_MAX = (1 << L_MAX); public: static Vec convolute(Vec as, Vec bs) { const int AN = as.size(); const int BN = bs.size(); const int CN = AN + BN - 1; const int N = bitCeil(CN); as.resize(N, 0), bs.resize(N, 0); transform(as, false), transform(bs, false); for (int i : rep(N)) { as[i] *= bs[i]; } transform(as, true); as.resize(CN); return as; } static void transform(Vec& as, bool rev) { const int N = as.size(); assert(hasSingleBit(N)); if (N == 1) { return; } const int L = topBit(N); const auto l_range = (rev ? irange(1, L + 1, 1) : irange(L, 0, -1)); for (int l : l_range) { const int H = 1 << l; const int B = N / H; for (int b : rep(B)) { const mint W = zeta(l, rev); mint W_h = 1; for (int h : rep(H / 2)) { const int y1 = H * b + h; const int y2 = y1 + H / 2; const mint a1 = as[y1]; const mint a2 = as[y2]; const mint na1 = (rev ? a1 + a2 * W_h : a1 + a2); const mint na2 = (rev ? a1 - a2 * W_h : (a1 - a2) * W_h); as[y1] = na1; as[y2] = na2; W_h *= W; } } } if (rev) { const mint iN = mint::sinv(N); for (auto& a : as) { a *= iN; } } } private: static mint zeta(int i, bool rev) { static Vec zs; // zs[i] = 1の2^i乗根 static Vec izs; // izs[i] = zs[i]の逆元 if (zs.empty()) { zs.resize(L_MAX + 1, 1); izs.resize(L_MAX + 1, 1); zs[L_MAX] = mint(ROOT).pow((MOD - 1) / (1 << L_MAX)); izs[L_MAX] = zs[L_MAX].inv(); for (int l : per(L_MAX)) { zs[l] = zs[l + 1] * zs[l + 1]; izs[l] = izs[l + 1] * izs[l + 1]; } } return (rev ? izs[i] : zs[i]); } }; class Garner { public: template static mint restore_mod(const mint1& x1, const mint2& x2) { constexpr auto m1 = mint1::mod(); const auto [y0, y1] = coeff(x1, x2); return mint(y0.val()) + mint(y1.val()) * m1; } template static mint restore_mod(const mint1& x1, const mint2& x2, const mint3& x3) { constexpr auto m1 = mint1::mod(); constexpr auto m2 = mint2::mod(); const auto [y0, y1, y2] = coeff(x1, x2, x3); return mint(y0.val()) + mint(y1.val()) * m1 + mint(y2.val()) * m1 * m2; } template static i64 restore_i64(const mint1& x1, const mint2& x2) { constexpr u32 m1 = mint1::mod(); constexpr u32 m2 = mint2::mod(); const auto [y0, y1] = coeff(x1, x2); constexpr u64 MAX = 1_u64 << 63; const i128 M = (i128)m1 * m2; i128 S = i128(y0.val()) + i128(y1.val()) * m1; if (S >= MAX) { S -= M; } return (i64)S; } template static i64 restore_i64(const mint1& x1, const mint2& x2, const mint3& x3) { constexpr u32 m1 = mint1::mod(); constexpr u32 m2 = mint2::mod(); constexpr u32 m3 = mint3::mod(); const auto [y0, y1, y2] = coeff(x1, x2, x3); constexpr u64 MAX = 1_u64 << 63; const i128 M = (i128)m1 * m2 * m3; i128 S = i128(y0.val()) + i128(y1.val()) * m1 + i128(y2.val()) * m1 * m2; if (S >= MAX) { S -= M; } return (i64)S; } private: template static Pair coeff(const mint1& x1, const mint2& x2) { constexpr auto m1 = mint1::mod(); constexpr mint2 m1_inv = mint2(m1).inv(); const mint1 y0 = x1; const mint2 y1 = (x2 - mint2(y0.val())) * m1_inv; return {y0, y1}; } template static Tup coeff(const mint1& x1, const mint2& x2, const mint3& x3) { constexpr auto m1 = mint1::mod(); constexpr auto m2 = mint2::mod(); constexpr mint2 m1_inv = mint2(m1).inv(); constexpr mint3 m1m2_inv = (mint3(m1) * mint3(m2)).inv(); const mint1 y0 = x1; const mint2 y1 = (x2 - mint2(y0.val())) * m1_inv; const mint3 y2 = (x3 - mint3(y0.val()) - mint3(y1.val()) * m1) * m1m2_inv; return {y0, y1, y2}; } }; template Vec convolute_mod(const Vec& as, const Vec& bs) { constexpr u32 L_MAX = mint::max2p(); constexpr int N_MAX = (1 << L_MAX); const int AN = as.size(); const int BN = bs.size(); if (AN == 0 or BN == 0) { return {}; } if (AN > BN) { return convolute_mod(bs, as); } const int N = AN + BN - 1; if (AN * 2 <= BN) { Vec cs(N, 0); for (int sj : irange(0, BN, AN)) { const int tj = std::min(BN, sj + AN); const auto bbs = Vec(std::begin(bs) + sj, std::begin(bs) + tj); const auto bcs = convolute_mod(as, bbs); for (int dj : rep(bcs.size())) { cs[sj + dj] += bcs[dj]; } } return cs; } if (N <= N_MAX) { // mintはNTT Friendlyなのでそのまま畳み込み return NumberTheoriticTransform::convolute(as, bs); } else { assert(N <= (1 << 24)); using submint1 = modint<469762049, 3, 26>; using submint2 = modint<167772161, 3, 25>; using submint3 = modint<754974721, 11, 24>; // mod 3つでGarner復元 Vec as1(AN), bs1(BN); Vec as2(AN), bs2(BN); Vec as3(AN), bs3(BN); for (int i : rep(AN)) { as1[i] = as[i].val(), as2[i] = as[i].val(), as3[i] = as[i].val(); } for (int i : rep(BN)) { bs1[i] = bs[i].val(), bs2[i] = bs[i].val(), bs3[i] = bs[i].val(); } const auto cs1 = NumberTheoriticTransform::convolute(as1, bs1); const auto cs2 = NumberTheoriticTransform::convolute(as2, bs2); const auto cs3 = NumberTheoriticTransform::convolute(as3, bs3); Vec cs(N); for (int i : rep(N)) { cs[i] = Garner::restore_mod(cs1[i], cs2[i], cs3[i]); } return cs; } } template Vec convolute_i64(const Vec& as, const Vec& bs) { const int AN = as.size(); const int BN = bs.size(); if (AN == 0 or BN == 0) { return {}; } if (AN > BN) { return convolute_i64(bs, as); } const int N = AN + BN - 1; assert(N <= (1 << 24)); if (AN * 2 <= BN) { Vec cs(N, 0); for (int sj : irange(0, BN, AN)) { const int tj = std::min(BN, sj + AN); const auto bbs = Vec(std::begin(bs) + sj, std::begin(bs) + tj); const auto bcs = convolute_i64(as, bbs); for (int dj : rep(bcs.size())) { cs[sj + dj] += bcs[dj]; } } return cs; } using submint1 = modint<469762049, 3, 26>; using submint2 = modint<167772161, 3, 25>; using submint3 = modint<754974721, 11, 24>; // mod 3つでGarner復元 Vec as1(AN), bs1(BN); Vec as2(AN), bs2(BN); Vec as3(AN), bs3(BN); for (int i : rep(AN)) { as1[i] = as[i], as2[i] = as[i], as3[i] = as[i]; } for (int i : rep(BN)) { bs1[i] = bs[i], bs2[i] = bs[i], bs3[i] = bs[i]; } const auto cs1 = NumberTheoriticTransform::convolute(as1, bs1); const auto cs2 = NumberTheoriticTransform::convolute(as2, bs2); const auto cs3 = NumberTheoriticTransform::convolute(as3, bs3); Vec cs(N); for (int i : rep(N)) { cs[i] = Garner::restore_i64(cs1[i], cs2[i], cs3[i]); } return cs; } int main() { const auto N = in.val(); using mint = modint_998244353; const auto [B, C] = in.tup(); if (B % 2 != C % 2) { return out.ln(0); } if (B < C) { return out.ln(0); } Vec c0(N / 2 + 1, 0), c1(N / 2 + 1, 0); for (int i : irange(0, N + 1, 2)) { c0[i / 2] = mint::comb(N, i); } for (int i : irange(1, N + 1, 2)) { c1[i / 2] = mint::comb(N, i); } reverseAll(c0); reverseAll(c1); auto dp = Vec(N + 1, 0); dp[0] = 1; auto cdp0 = convolute_mod(dp, c0); auto cdp1 = convolute_mod(dp, c1); for (int i : per(60)) { auto ndp = Vec(N + 1, 0); for (i64 bd : rep(N + 1)) { const i64 b = (B >> i) - bd; const i64 c = C >> i; if (b < 0) { break; } if (b % 2 != c % 2) { continue; } if (c % 2 == 0) { const int bi = c0.size() - 1 + bd / 2; ndp[bd] = cdp0[bi]; } else { const int bi = c0.size() - 1 + (bd + 1) / 2; ndp[bd] = cdp1[bi]; } } std::swap(dp, ndp); cdp0 = convolute_mod(dp, c0); cdp1 = convolute_mod(dp, c1); } out.ln(dp[0]); return 0; }