#line 1 "a.cpp" #define PROBLEM "" #line 1 "/home/kuhaku/atcoder/github/algo/lib/fft/ntt.hpp" #include #include #include #include #line 2 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_fft.hpp" #include #line 4 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_fft.hpp" #include #line 2 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_bit.hpp" namespace internal { // @return same with std::bit::bit_ceil unsigned int bit_ceil(unsigned int n) { unsigned int x = 1; while (x < (unsigned int)(n)) x *= 2; return x; } // @param n `1 <= n` // @return same with std::bit::countl_zero int countl_zero(unsigned int n) { return __builtin_clz(n); } // @param n `1 <= n` // @return same with std::bit::countr_zero int countr_zero(unsigned int n) { return __builtin_ctz(n); } // @param n `1 <= n` // @return same with std::bit::countr_zero constexpr int countr_zero_constexpr(unsigned int n) { int x = 0; while (!(n & (1 << x))) x++; return x; } } // namespace internal #line 3 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_math.hpp" #include namespace internal { // @param m `1 <= m` // @return x mod m constexpr std::int64_t safe_mod(std::int64_t x, std::int64_t m) { x %= m; if (x < 0) x += m; return x; } // Fast modular multiplication by barrett reduction // Reference: https://en.wikipedia.org/wiki/Barrett_reduction // NOTE: reconsider after Ice Lake struct barrett { unsigned int _m; std::uint64_t im; // @param m `1 <= m` explicit barrett(unsigned int m) : _m(m), im((std::uint64_t)(-1) / m + 1) {} // @return m unsigned int umod() const { return _m; } // @param a `0 <= a < m` // @param b `0 <= b < m` // @return `a * b % m` unsigned int mul(unsigned int a, unsigned int b) const { std::uint64_t z = a; z *= b; std::uint64_t x = (std::uint64_t)(((__uint128_t)(z)*im) >> 64); std::uint64_t y = x * _m; return (unsigned int)(z - y + (z < y ? _m : 0)); } }; struct montgomery { std::uint64_t _m; std::uint64_t im; std::uint64_t r2; // @param m `1 <= m` explicit constexpr montgomery(std::uint64_t m) : _m(m), im(m), r2(-__uint128_t(m) % m) { for (int i = 0; i < 5; ++i) im = im * (2 - _m * im); im = -im; } // @return m constexpr std::uint64_t umod() const { return _m; } // @param a `0 <= a < m` // @param b `0 <= b < m` // @return `a * b % m` constexpr std::uint64_t mul(std::uint64_t a, std::uint64_t b) const { return mr(mr(a, b), r2); } constexpr std::uint64_t exp(std::uint64_t a, std::uint64_t b) const { std::uint64_t res = 1, p = mr(a, r2); while (b) { if (b & 1) res = mr(res, p); p = mr(p, p); b >>= 1; } return res; } constexpr bool same_pow(std::uint64_t x, int s, std::uint64_t n) const { x = mr(x, r2), n = mr(n, r2); for (int r = 0; r < s; r++) { if (x == n) return true; x = mr(x, x); } return false; } private: constexpr std::uint64_t mr(std::uint64_t x) const { return ((__uint128_t)(x * im) * _m + x) >> 64; } constexpr std::uint64_t mr(std::uint64_t a, std::uint64_t b) const { __uint128_t t = (__uint128_t)a * b; std::uint64_t inc = std::uint64_t(t) != 0; std::uint64_t x = t >> 64, y = ((__uint128_t)(a * b * im) * _m) >> 64; unsigned long long z = 0; bool f = __builtin_uaddll_overflow(x, y, &z); z += inc; return f ? z - _m : z; } }; constexpr bool is_SPRP32(std::uint32_t n, std::uint32_t a) { std::uint32_t d = n - 1, s = 0; while ((d & 1) == 0) ++s, d >>= 1; std::uint64_t cur = 1, pw = d; while (pw) { if (pw & 1) cur = (cur * a) % n; a = (std::uint64_t)a * a % n; pw >>= 1; } if (cur == 1) return true; for (std::uint32_t r = 0; r < s; r++) { if (cur == n - 1) return true; cur = cur * cur % n; } return false; } // given 2 <= n,a < 2^64, a prime, check whether n is a-SPRP constexpr bool is_SPRP64(const montgomery &m, std::uint64_t a) { auto n = m.umod(); if (n == a) return true; if (n % a == 0) return false; std::uint64_t d = n - 1; int s = 0; while ((d & 1) == 0) ++s, d >>= 1; std::uint64_t cur = m.exp(a, d); if (cur == 1) return true; return m.same_pow(cur, s, n - 1); } constexpr bool is_prime_constexpr(std::uint64_t x) { if (x == 2 || x == 3 || x == 5 || x == 7) return true; if (x % 2 == 0 || x % 3 == 0 || x % 5 == 0 || x % 7 == 0) return false; if (x < 121) return (x > 1); montgomery m(x); constexpr std::uint64_t bases[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022}; for (auto a : bases) { if (!is_SPRP64(m, a)) return false; } return true; } constexpr bool is_prime_constexpr(std::int64_t x) { if (x < 0) return false; return is_prime_constexpr(std::uint64_t(x)); } constexpr bool is_prime_constexpr(std::uint32_t x) { if (x == 2 || x == 3 || x == 5 || x == 7) return true; if (x % 2 == 0 || x % 3 == 0 || x % 5 == 0 || x % 7 == 0) return false; if (x < 121) return (x > 1); std::uint64_t h = x; h = ((h >> 16) ^ h) * 0x45d9f3b; h = ((h >> 16) ^ h) * 0x45d9f3b; h = ((h >> 16) ^ h) & 255; constexpr uint16_t bases[] = { 15591, 2018, 166, 7429, 8064, 16045, 10503, 4399, 1949, 1295, 2776, 3620, 560, 3128, 5212, 2657, 2300, 2021, 4652, 1471, 9336, 4018, 2398, 20462, 10277, 8028, 2213, 6219, 620, 3763, 4852, 5012, 3185, 1333, 6227, 5298, 1074, 2391, 5113, 7061, 803, 1269, 3875, 422, 751, 580, 4729, 10239, 746, 2951, 556, 2206, 3778, 481, 1522, 3476, 481, 2487, 3266, 5633, 488, 3373, 6441, 3344, 17, 15105, 1490, 4154, 2036, 1882, 1813, 467, 3307, 14042, 6371, 658, 1005, 903, 737, 1887, 7447, 1888, 2848, 1784, 7559, 3400, 951, 13969, 4304, 177, 41, 19875, 3110, 13221, 8726, 571, 7043, 6943, 1199, 352, 6435, 165, 1169, 3315, 978, 233, 3003, 2562, 2994, 10587, 10030, 2377, 1902, 5354, 4447, 1555, 263, 27027, 2283, 305, 669, 1912, 601, 6186, 429, 1930, 14873, 1784, 1661, 524, 3577, 236, 2360, 6146, 2850, 55637, 1753, 4178, 8466, 222, 2579, 2743, 2031, 2226, 2276, 374, 2132, 813, 23788, 1610, 4422, 5159, 1725, 3597, 3366, 14336, 579, 165, 1375, 10018, 12616, 9816, 1371, 536, 1867, 10864, 857, 2206, 5788, 434, 8085, 17618, 727, 3639, 1595, 4944, 2129, 2029, 8195, 8344, 6232, 9183, 8126, 1870, 3296, 7455, 8947, 25017, 541, 19115, 368, 566, 5674, 411, 522, 1027, 8215, 2050, 6544, 10049, 614, 774, 2333, 3007, 35201, 4706, 1152, 1785, 1028, 1540, 3743, 493, 4474, 2521, 26845, 8354, 864, 18915, 5465, 2447, 42, 4511, 1660, 166, 1249, 6259, 2553, 304, 272, 7286, 73, 6554, 899, 2816, 5197, 13330, 7054, 2818, 3199, 811, 922, 350, 7514, 4452, 3449, 2663, 4708, 418, 1621, 1171, 3471, 88, 11345, 412, 1559, 194}; return is_SPRP32(x, bases[h]); } // @param n `0 <= n` // @param m `1 <= m` // @return `(x ** n) % m` constexpr std::int64_t pow_mod_constexpr(std::int64_t x, std::int64_t n, int m) { if (m == 1) return 0; unsigned int _m = (unsigned int)(m); std::uint64_t r = 1; std::uint64_t y = safe_mod(x, m); while (n) { if (n & 1) r = (r * y) % _m; y = (y * y) % _m; n >>= 1; } return r; } // Reference: // M. Forisek and J. Jancina, // Fast Primality Testing for Integers That Fit into a Machine Word // @param n `0 <= n` 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; std::int64_t d = n - 1; while (d % 2 == 0) d /= 2; constexpr std::int64_t bases[3] = {2, 7, 61}; for (std::int64_t a : bases) { std::int64_t t = d; std::int64_t 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); // @param b `1 <= b` // @return pair(g, x) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g constexpr std::pair inv_gcd(std::int64_t a, std::int64_t b) { a = safe_mod(a, b); if (a == 0) return {b, 0}; std::int64_t s = b, t = a; std::int64_t m0 = 0, m1 = 1; while (t) { std::int64_t 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}; } // Compile time primitive root // @param m must be prime // @return primitive root (and minimum in now) 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; (std::int64_t)(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); } // namespace internal #line 3 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_type_traits.hpp" #include #line 5 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_type_traits.hpp" namespace internal { template using is_signed_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using is_unsigned_int128 = typename std::conditional::value || std::is_same::value, std::true_type, std::false_type>::type; template using make_unsigned_int128 = typename std::conditional::value, __uint128_t, unsigned __int128>; template using is_integral = typename std::conditional::value || is_signed_int128::value || is_unsigned_int128::value, std::true_type, std::false_type>::type; template using is_signed_int = typename std::conditional<(is_integral::value && std::is_signed::value) || is_signed_int128::value, std::true_type, std::false_type>::type; template using is_unsigned_int = typename std::conditional<(is_integral::value && std::is_unsigned::value) || is_unsigned_int128::value, std::true_type, std::false_type>::type; template using to_unsigned = typename std::conditional< is_signed_int128::value, make_unsigned_int128, typename std::conditional::value, std::make_unsigned, std::common_type>::type>::type; template using is_signed_int_t = std::enable_if_t::value>; template using is_unsigned_int_t = std::enable_if_t::value>; template using to_unsigned_t = typename to_unsigned::type; } // namespace internal #line 3 "/home/kuhaku/atcoder/github/algo/lib/math/modint.hpp" #include #line 7 "/home/kuhaku/atcoder/github/algo/lib/math/modint.hpp" namespace internal { struct modint_base {}; struct static_modint_base : modint_base {}; template using is_modint = std::is_base_of; template using is_modint_t = std::enable_if_t::value>; } // namespace internal template * = nullptr> struct static_modint : internal::static_modint_base { using mint = static_modint; public: static constexpr int mod() { return m; } static constexpr mint raw(int v) { mint x; x._v = v; return x; } constexpr static_modint() : _v(0) {} template * = nullptr> constexpr static_modint(T v) : _v(0) { std::int64_t x = (std::int64_t)(v % (std::int64_t)(umod())); if (x < 0) x += umod(); _v = (unsigned int)(x); } template * = nullptr> constexpr static_modint(T v) : _v(0) { _v = (unsigned int)(v % umod()); } constexpr unsigned int val() const { return _v; } constexpr mint &operator++() { _v++; if (_v == umod()) _v = 0; return *this; } constexpr mint &operator--() { if (_v == 0) _v = umod(); _v--; return *this; } constexpr mint operator++(int) { mint result = *this; ++*this; return result; } constexpr mint operator--(int) { mint result = *this; --*this; return result; } constexpr mint &operator+=(const mint &rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } constexpr mint &operator-=(const mint &rhs) { _v -= rhs._v; if (_v >= umod()) _v += umod(); return *this; } constexpr mint &operator*=(const mint &rhs) { std::uint64_t z = _v; z *= rhs._v; _v = (unsigned int)(z % umod()); return *this; } constexpr mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); } constexpr mint operator+() const { return *this; } constexpr mint operator-() const { return mint() - *this; } constexpr mint pow(std::int64_t n) const { assert(0 <= n); mint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } constexpr mint inv() const { if (prime) { assert(_v); return pow(umod() - 2); } else { auto eg = internal::inv_gcd(_v, m); assert(eg.first == 1); return eg.second; } } friend constexpr mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; } friend constexpr mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; } friend constexpr mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; } friend constexpr mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; } friend constexpr bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; } friend constexpr bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; } friend std::istream &operator>>(std::istream &is, mint &rhs) { std::int64_t t; is >> t; rhs = mint(t); return is; } friend constexpr std::ostream &operator<<(std::ostream &os, const mint &rhs) { return os << rhs._v; } private: unsigned int _v; static constexpr unsigned int umod() { return m; } static constexpr bool prime = internal::is_prime; }; template struct dynamic_modint : internal::modint_base { using mint = dynamic_modint; public: static int mod() { return (int)(bt.umod()); } static void set_mod(int m) { assert(1 <= m); bt = internal::barrett(m); } static mint raw(int v) { mint x; x._v = v; return x; } dynamic_modint() : _v(0) {} template * = nullptr> dynamic_modint(T v) { std::int64_t x = (std::int64_t)(v % (std::int64_t)(mod())); if (x < 0) x += mod(); _v = (unsigned int)(x); } template * = nullptr> dynamic_modint(T v) { _v = (unsigned int)(v % mod()); } unsigned int val() const { return _v; } mint &operator++() { _v++; if (_v == umod()) _v = 0; return *this; } mint &operator--() { if (_v == 0) _v = umod(); _v--; return *this; } mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint &operator+=(const mint &rhs) { _v += rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint &operator-=(const mint &rhs) { _v += mod() - rhs._v; if (_v >= umod()) _v -= umod(); return *this; } mint &operator*=(const mint &rhs) { _v = bt.mul(_v, rhs._v); return *this; } mint &operator/=(const mint &rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(std::int64_t n) const { assert(0 <= n); mint x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { auto eg = internal::inv_gcd(_v, mod()); assert(eg.first == 1); return eg.second; } friend mint operator+(const mint &lhs, const mint &rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint &lhs, const mint &rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint &lhs, const mint &rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint &lhs, const mint &rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint &lhs, const mint &rhs) { return lhs._v == rhs._v; } friend bool operator!=(const mint &lhs, const mint &rhs) { return lhs._v != rhs._v; } friend std::istream &operator>>(std::istream &is, mint &rhs) { std::int64_t t; is >> t; rhs = mint(t); return is; } friend constexpr std::ostream &operator<<(std::ostream &os, const mint &rhs) { return os << rhs._v; } private: unsigned int _v; static internal::barrett bt; static unsigned int umod() { return bt.umod(); } }; template internal::barrett dynamic_modint::bt(998244353); using modint998 = static_modint<998244353>; using modint107 = static_modint<1000000007>; using modint = dynamic_modint<-1>; namespace internal { template using is_static_modint = std::is_base_of; template using is_static_modint_t = std::enable_if_t::value>; template struct is_dynamic_modint : public std::false_type {}; template struct is_dynamic_modint> : public std::true_type {}; template using is_dynamic_modint_t = std::enable_if_t::value>; } // namespace internal #line 11 "/home/kuhaku/atcoder/github/algo/lib/internal/internal_fft.hpp" namespace internal { template , internal::is_static_modint_t * = nullptr> struct fft_info { static constexpr int rank2 = countr_zero_constexpr(mint::mod() - 1); std::array root, iroot; std::array rate2, irate2; std::array rate3, irate3; fft_info() { root[rank2] = mint(g).pow((mint::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 * = nullptr> void butterfly(std::vector &a) { int n = int(a.size()); int h = internal::countr_zero((unsigned int)n); static const fft_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], 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::mod() * mint::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 * = nullptr> void butterfly_inv(std::vector &a) { int n = int(a.size()); int h = internal::countr_zero((unsigned int)n); static const fft_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], r = a[i + offset + p]; a[i + offset] = l + r; a[i + offset + p] = (std::uint64_t)(mint::mod() + l.val() - r.val()) * 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::mod() + a2 - a3) * iimag.val()).val(); a[i + offset] = a0 + a1 + a2 + a3; a[i + offset + 1 * p] = (a0 + (mint::mod() - a1) + a2na3iimag) * irot.val(); a[i + offset + 2 * p] = (a0 + a1 + (mint::mod() - a2) + (mint::mod() - a3)) * irot2.val(); a[i + offset + 3 * p] = (a0 + (mint::mod() - a1) + (mint::mod() - a2na3iimag)) * irot3.val(); } if (s + 1 != (1 << (len - 2))) irot *= info.irate3[countr_zero(~(unsigned int)(s))]; } len -= 2; } } } template * = nullptr> 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 * = nullptr> 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; } } // namespace internal #line 2 "/home/kuhaku/atcoder/github/algo/lib/template/template.hpp" #pragma GCC target("sse4.2,avx2,bmi2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include template constexpr bool chmax(T &a, const U &b) { return a < (T)b ? a = (T)b, true : false; } template constexpr bool chmin(T &a, const U &b) { return (T)b < a ? a = (T)b, true : false; } constexpr std::int64_t INF = 1000000000000000003; constexpr int Inf = 1000000003; constexpr double EPS = 1e-7; constexpr double PI = M_PI; #line 7 "/home/kuhaku/atcoder/github/algo/lib/fft/ntt.hpp" /** * @brief 畳み込み * * @tparam mint * @param a * @param b * @return std::vector */ template * = nullptr> 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::mod() - 1) % z == 0); if (std::min(n, m) <= 60) return convolution_naive(a, b); return internal::convolution_fft(a, b); } template * = nullptr> 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::mod() - 1) % z == 0); if (std::min(n, m) <= 60) return convolution_naive(a, b); return internal::convolution_fft(a, b); } template ::value> * = nullptr> 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 = static_modint; int z = (int)internal::bit_ceil((unsigned int)(n + m - 1)); assert((mint::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 std::uint64_t MOD1 = 754974721; // 2^24 static constexpr std::uint64_t MOD2 = 167772161; // 2^25 static constexpr std::uint64_t MOD3 = 469762049; // 2^26 static constexpr std::uint64_t M2M3 = MOD2 * MOD3; static constexpr std::uint64_t M1M3 = MOD1 * MOD3; static constexpr std::uint64_t M1M2 = MOD1 * MOD2; static constexpr std::uint64_t M1M2M3 = MOD1 * MOD2 * MOD3; static constexpr std::uint64_t i1 = internal::inv_gcd(MOD2 * MOD3, MOD1).second; static constexpr std::uint64_t i2 = internal::inv_gcd(MOD1 * MOD3, MOD2).second; static constexpr std::uint64_t 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++) { std::uint64_t x = 0; x += (c1[i] * i1) % MOD1 * M2M3; x += (c2[i] * i2) % MOD2 * M1M3; x += (c3[i] * i3) % MOD3 * M1M2; std::int64_t diff = c1[i] - internal::safe_mod((std::int64_t)(x), (std::int64_t)(MOD1)); if (diff < 0) diff += MOD1; static constexpr std::uint64_t offset[5] = {0, 0, M1M2M3, 2 * M1M2M3, 3 * M1M2M3}; x -= offset[diff % 5]; c[i] = x; } return c; } #line 3 "/home/kuhaku/atcoder/github/algo/lib/template/macro.hpp" #define FOR(i, m, n) for (int i = (m); i < int(n); ++i) #define FORR(i, m, n) for (int i = (m)-1; i >= int(n); --i) #define FORL(i, m, n) for (int64_t i = (m); i < int64_t(n); ++i) #define rep(i, n) FOR (i, 0, n) #define repn(i, n) FOR (i, 1, n + 1) #define repr(i, n) FORR (i, n, 0) #define repnr(i, n) FORR (i, n + 1, 1) #define all(s) (s).begin(), (s).end() #line 3 "/home/kuhaku/atcoder/github/algo/lib/template/sonic.hpp" struct Sonic { Sonic() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(20); } constexpr void operator()() const {} } sonic; #line 5 "/home/kuhaku/atcoder/github/algo/lib/template/atcoder.hpp" using namespace std; using ll = std::int64_t; using ld = long double; template std::istream &operator>>(std::istream &is, std::pair &p) { return is >> p.first >> p.second; } template std::istream &operator>>(std::istream &is, std::vector &v) { for (T &i : v) is >> i; return is; } template std::ostream &operator<<(std::ostream &os, const std::pair &p) { return os << '(' << p.first << ',' << p.second << ')'; } template std::ostream &operator<<(std::ostream &os, const std::vector &v) { for (auto it = v.begin(); it != v.end(); ++it) { os << (it == v.begin() ? "" : " ") << *it; } return os; } template void co(Head &&head, Tail &&...tail) { if constexpr (sizeof...(tail) == 0) std::cout << head << '\n'; else std::cout << head << ' ', co(std::forward(tail)...); } template void ce(Head &&head, Tail &&...tail) { if constexpr (sizeof...(tail) == 0) std::cerr << head << '\n'; else std::cerr << head << ' ', ce(std::forward(tail)...); } template auto make_vector(T x, int arg, Args... args) { if constexpr (sizeof...(args) == 0) return std::vector(arg, x); else return std::vector(arg, make_vector(x, args...)); } void Yes(bool is_correct = true) { std::cout << (is_correct ? "Yes" : "No") << '\n'; } void No(bool is_not_correct = true) { Yes(!is_not_correct); } void YES(bool is_correct = true) { std::cout << (is_correct ? "YES" : "NO") << '\n'; } void NO(bool is_not_correct = true) { YES(!is_not_correct); } void Takahashi(bool is_correct = true) { std::cout << (is_correct ? "Takahashi" : "Aoki") << '\n'; } void Aoki(bool is_not_correct = true) { Takahashi(!is_not_correct); } #line 4 "a.cpp" using Mint = modint998; template std::vector inv(const std::vector &v) { return inv(v, v.size()); } template std::vector inv(const std::vector &v, int deg) { assert(!v.empty() && v[0] != mint(0)); std::vector res(deg); res[0] = v[0].inv(); for (int d = 1; d < deg; d <<= 1) { std::vector f(2 * d), g(2 * d); for (int j = 0; j < std::min((int)v.size(), 2 * d); j++) f[j] = v[j]; for (int j = 0; j < d; j++) g[j] = res[j]; internal::butterfly(f); internal::butterfly(g); for (int j = 0; j < 2 * d; j++) f[j] *= g[j]; internal::butterfly_inv(f); mint id = mint(2 * d).inv(); for (int i = 0; i < 2 * d; i++) f[i] *= id; for (int j = 0; j < d; j++) f[j] = 0; internal::butterfly(f); for (int j = 0; j < 2 * d; j++) f[j] *= g[j]; internal::butterfly_inv(f); for (int i = 0; i < 2 * d; i++) f[i] *= id; for (int j = d; j < std::min(2 * d, deg); j++) res[j] = -f[j]; } res.resize(deg); return res; } pair, vector> prod(const vector &a, int l, int r, int len) { if (l + 1 == r) { return {{1}, {1, -a[l]}}; } int m = (l + r) / 2; auto [lp, lq] = prod(a, l, m, len); auto [rp, rq] = prod(a, m, r, len); auto q = convolution(lq, rq); if (q.size() > len) q.resize(len); auto p1 = convolution(lp, rq); auto p2 = convolution(rp, lq); if (p1.size() > len) p1.resize(len); if (p2.size() > len) p2.resize(len); if (p1.size() >= p2.size()) { for (int i = 0; i < (int)p2.size(); ++i) { p1[i] += p2[i]; } return {p1, q}; } else { for (int i = 0; i < (int)p1.size(); ++i) { p2[i] += p1[i]; } return {p2, q}; } } int main(void) { int n, m; cin >> n >> m; vector a(n); cin >> a; auto [ap, aq] = prod(a, 0, n, m + 1); auto ans = convolution(ap, inv(aq, m + 1)); ans.resize(m + 1); ans.erase(ans.begin()); co(ans); return 0; }