#include /** * 上位は1の10乗根でアダマール変換をして、下位はNTTする? * 多変数FPSでexp.logを経てM乗を計算? * * X=(x_0,x_1,...,x_{T-1}), Y=(x_T,x_{T+1},...,x_{K-1}) * f(X,Y) = 上位K-T桁がYで、下位T桁がXである通り数みたいなFPS * Xについてはmultivariate convolution, YについてはF_10 plus convolution * https://nyaannyaan.github.io/library/ntt/multivariate-multiplication.hpp */ #pragma region Header 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 i32 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 IList = std::initializer_list; 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>; using NSec = std::chrono::nanoseconds; using USec = std::chrono::microseconds; using MSec = std::chrono::milliseconds; using Sec = std::chrono::seconds; 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(const int n) { return n == 0 ? T{1} : TEN(n - 1) * T{10}; } 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; } 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; } template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else { return false; } } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else { return false; } } template constexpr T floorDiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? x / y : (x - y + 1) / y; } template constexpr T ceilDiv(T x, T y) { if (y < T{}) { x = -x, y = -y; } return x >= T{} ? (x + y - 1) / y : x / y; } template constexpr T modPower(T v, I n, T mod) { T ans = 1 % mod; for (; n > 0; n >>= 1, (v *= v) %= mod) { if (n % 2 == 1) { (ans *= v) %= mod; } } return ans; } template constexpr T power(T v, I n) { T ans = 1; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template constexpr T power(T v, I n, const T& e) { T ans = e; for (; n > 0; n >>= 1, v *= v) { if (n % 2 == 1) { ans *= v; } } return ans; } template Vec operator+=(Vec& vs1, const Vec& vs2) { vs1.insert(vs1.end(), vs2.begin(), vs2.end()); return vs1; } template Vec operator+(const Vec& vs1, const Vec& vs2) { auto vs = vs1; vs += vs2; return vs; } template void fillAll(Vs& arr, const V& v) { if constexpr (std::is_convertible::value) { arr = v; } else { for (auto& subarr : arr) { fillAll(subarr, v); } } } template void sortAll(Vs& vs) { std::sort(std::begin(vs), std::end(vs)); } template void sortAll(Vs& vs, C comp) { std::sort(std::begin(vs), std::end(vs), comp); } template void reverseAll(Vs& vs) { std::reverse(std::begin(vs), std::end(vs)); } template 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 int minInd(const Vs& vs) { return std::min_element(std::begin(vs), std::end(vs)) - std::begin(vs); } template int maxInd(const Vs& vs) { return std::max_element(std::begin(vs), std::end(vs)) - std::begin(vs); } template int lbInd(const Vs& vs, const V& v) { return std::lower_bound(std::begin(vs), std::end(vs), v) - std::begin(vs); } template int ubInd(const Vs& vs, const V& v) { return std::upper_bound(std::begin(vs), std::end(vs), v) - std::begin(vs); } template Vec genVec(int n, F gen) { Vec ans; std::generate_n(std::back_insert_iterator(ans), n, gen); return ans; } Vec iotaVec(int n, int offset = 0) { Vec ans(n); std::iota(ans.begin(), ans.end(), offset); return ans; } constexpr int popcount(const u64 v) { return v ? __builtin_popcountll(v) : 0; } constexpr int log2p1(const u64 v) { return v ? 64 - __builtin_clzll(v) : 0; } constexpr int lsbp1(const u64 v) { return __builtin_ffsll(v); } constexpr int clog(const u64 v) { return v ? log2p1(v - 1) : 0; } constexpr u64 ceil2(const u64 v) { const int l = clog(v); return (l == 64) ? 0_u64 : (1_u64 << l); } constexpr u64 floor2(const u64 v) { return v ? (1_u64 << (log2p1(v) - 1)) : 0_u64; } constexpr bool ispow2(const u64 v) { return (v > 0) and ((v & (v - 1)) == 0); } constexpr bool btest(const u64 mask, const int ind) { return (mask >> ind) & 1_u64; } template struct Fix : F { Fix(F&& f) : F{std::forward(f)} {} template auto operator()(Args&&... args) const { return F::operator()(*this, std::forward(args)...); } }; class irange { private: struct itr { itr(i64 start = 0, i64 step = 1) : m_cnt{start}, m_step{step} {} bool operator!=(const itr& it) const { return m_cnt != it.m_cnt; } int operator*() { return m_cnt; } itr& operator++() { m_cnt += m_step; return *this; } i64 m_cnt, m_step; }; i64 m_start, m_end, m_step; public: irange(i64 start, i64 end, i64 step = 1) { assert(step != 0); const i64 d = std::abs(step); const i64 l = (step > 0 ? start : end); const i64 r = (step > 0 ? end : start); int n = (r - l) / d + ((r - l) % d ? 1 : 0); if (l >= r) { n = 0; } m_start = start; m_end = start + step * n; m_step = step; } itr begin() const { return itr{m_start, m_step}; } itr end() const { return itr{m_end, m_step}; } }; irange rep(int end) { return irange(0, end, 1); } irange per(int rend) { return irange(rend - 1, -1, -1); } #pragma COMMENT("[REFS] Xoshiro: https://prng.di.unimi.it") namespace xoshiro_impl { u64 x; u64 next() { uint64_t z = (x += 0x9e3779b97f4a7c15); z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; z = (z ^ (z >> 27)) * 0x94d049bb133111eb; return z ^ (z >> 31); } } // namespace xoshiro_impl class Xoshiro32 { public: using result_type = u32; using T = result_type; Xoshiro32(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return LIMMIN; } static constexpr T max() { return LIMMAX; } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (32 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 9; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 11); return ans; } T s[4]; }; class Xoshiro64 { public: using result_type = u64; using T = result_type; Xoshiro64(T seed = 0) { xoshiro_impl::x = seed; s[0] = xoshiro_impl::next(); s[1] = xoshiro_impl::next(); s[2] = xoshiro_impl::next(); s[3] = xoshiro_impl::next(); } static constexpr T min() { return LIMMIN; } static constexpr T max() { return LIMMAX; } T operator()() { return next(); } private: static constexpr T rotl(const T x, int k) { return (x << k) | (x >> (64 - k)); } T next() { const T ans = rotl(s[1] * 5, 7) * 9; const T t = s[1] << 17; s[2] ^= s[0]; s[3] ^= s[1]; s[1] ^= s[2]; s[0] ^= s[3]; s[2] ^= t; s[3] = rotl(s[3], 45); return ans; } T s[4]; }; template class RNG { public: using result_type = typename Rng::result_type; using T = result_type; static constexpr T min() { return Rng::min(); } static constexpr T max() { return Rng::max(); } RNG() : RNG(std::random_device{}()) {} RNG(T seed) : m_rng(seed) {} T operator()() { return m_rng(); } template T val(T min, T max) { return std::uniform_int_distribution(min, max)(m_rng); } template Pair pair(T min, T max) { return std::minmax({val(min, max), val(min, max)}); } template Vec vec(int n, T min, T max) { return genVec(n, [&]() { return val(min, max); }); } template Vec> vvec(int n, int m, T min, T max) { return genVec>(n, [&]() { return vec(m, min, max); }); } private: Rng m_rng; }; RNG rng; RNG rng64; RNG rng_xo; RNG rng_xo64; 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; }; 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) { dump(args...); return 0; } template int ln(const Args&... args) { dump(args...), m_os << '\n'; return 0; } template int el(const Args&... args) { dump(args...), m_os << std::endl; return 0; } private: template void dump(const T& v) { m_os << v; } template void dump(const Vec& vs) { for (const int i : rep(vs.size())) { m_os << (i ? " " : ""), dump(vs[i]); } } template void dump(const Vec>& vss) { for (const int i : rep(vss.size())) { m_os << (i ? "\n" : ""), dump(vss[i]); } } template int dump(const T& v, const Ts&... args) { dump(v), m_os << ' ', dump(args...); return 0; } Ostream& m_os; }; 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 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: 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) { modRef() = m; } 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 power(*this, n); } constexpr modint inv() const { return pow(mod() - 2); } static modint sinv(u32 n) { static Vec is{1, 1}; 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) { static Vec fs{1, 1}; for (u32 i = (u32)fs.size(); i <= n; i++) { fs.push_back(fs.back() * i); } return fs[n]; } static modint ifact(u32 n) { static Vec ifs{1, 1}; for (u32 i = (u32)ifs.size(); i <= n; i++) { ifs.push_back(ifs.back() * sinv(i)); } return ifs[n]; } static modint comb(int n, int k) { return k > n or k < 0 ? modint{0} : fact(n) * ifact(n - k) * ifact(k); } private: 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>; #pragma endregion constexpr int D = 10; constexpr int Ds[] = {1, 10, 100, 1000, 10000, 100000}; constexpr int ls[] = {1, 5, 8, 11, 15, 18}; constexpr int Ls[] = {2, 32, 256, 2048, 32768, 262144}; constexpr u32 MOD = (1_u32 << 20) * 115 + 1; constexpr u32 ROOT = 6; constexpr u32 MAX2P = 20; using mint = modint; const mint omega_10 = mint(ROOT).pow((MOD - 1) / 10); const mint omega_10s[] = {1, omega_10, omega_10.pow(2), omega_10.pow(3), omega_10.pow(4), omega_10.pow(5), omega_10.pow(6), omega_10.pow(7), omega_10.pow(8), omega_10.pow(9)}; const mint i_omega_10 = omega_10.inv(); const mint i_omega_10s[] = {1, i_omega_10, i_omega_10.pow(2), i_omega_10.pow(3), i_omega_10.pow(4), i_omega_10.pow(5), i_omega_10.pow(6), i_omega_10.pow(7), i_omega_10.pow(8), i_omega_10.pow(9)}; int N; i64 M; int K; // 桁数 int T; // (mod x^D)で計算する桁数、残りは(mod x^D-1)で計算 int X; // ceil2(2*D^T) int lx; // log2(X) int Y; // D^(K-T) int ly; // log10(Y)=K-T Vec ws{1}, iws{1}; void ensure_base() { for (int m = ws.size(); m < X / 2; m *= 2) { const mint dw = mint(ROOT).pow((MOD - 1) / (4 * m)); const mint dwinv = dw.inv(); ws.resize(m * 2), iws.resize(m * 2); for (int i : rep(m)) ws[m + i] = ws[i] * dw, iws[m + i] = iws[i] * dwinv; } } void init() { std::tie(N, K, M, T) = in.tup(); X = Ls[T]; lx = ls[T]; assert(X == (1 << lx)); Y = Ds[K - T]; ly = K - T; ensure_base(); } /** * Xの関数としてNTT */ void ntt(Vec>& f, const bool rev = false) { assert((int)f.size() == X); assert((int)f[0].size() == Y); if (not rev) { for (int y : rep(Y)) { for (int m = X; m >>= 1;) { for (int s = 0, k = 0; s < X; s += 2 * m, k++) { for (int i = s; i < s + m; i++) { const mint u = f[i][y], v = f[i + m][y] * ws[k]; f[i][y] = u + v, f[i + m][y] = u - v; } } } } } else { for (int y : rep(Y)) { for (int m = 1; m < X; m *= 2) { for (int s = 0, k = 0; s < X; s += 2 * m, k++) { for (int i = s; i < s + m; i++) { const mint u = f[i][y], v = f[i + m][y]; f[i][y] = u + v, f[i + m][y] = (u - v) * iws[k]; } } } } const mint n_inv = mint(X).inv(); for (auto& vs : f) { for (auto& v : vs) { v *= n_inv; } } } } /* xにおけるbaseに対応する桁 */ int btest_10(int x, int base) { return (x / base) % D; } /** * Yの関数としてFHT_10する */ void fht_10(Vec>& f, bool rev) { assert((int)f.size() == X); assert((int)f[0].size() == Y); for (int x : rep(X)) { for (int delta = 1; delta < Y; delta *= D) { for (int j : rep(Y)) { if (btest_10(j, delta) == 0) { Vec dps(D); for (int k : rep(D)) { dps[k] = f[x][j + delta * k]; f[x][j + delta * k] = 0; } for (int k : rep(D)) { for (int l : rep(D)) { f[x][j + delta * k] += (rev ? i_omega_10s[(k * l) % D] : omega_10s[(k * l) % D]) * dps[l]; } } } } } } if (rev) { const mint iN = mint(Y).inv(); for (auto& as : f) { for (auto& a : as) { a *= iN; } } } } /** * f(X,Y)を変換する */ void trans(Vec>& f, bool rev) { assert((int)f.size() == X); assert((int)f[0].size() == Y); ntt(f, rev); fht_10(f, rev); } /** * f(X,Y)*g(X,Y) */ Vec> multi_mul(const Vec>& f, const Vec>& g) { assert((int)f.size() == X); assert((int)f[0].size() == Y); assert((int)g.size() == X); assert((int)g[0].size() == Y); if (T == 0) { // 全部FHT_10 auto F = f, G = g; trans(F, false); trans(G, false); for (int x : rep(X)) { for (int y : rep(Y)) { F[x][y] *= G[x][y]; } } trans(F, true); return F; } else { Vec chi(X, 0); for (int x : rep(X)) { for (int k : irange(1, T)) { chi[x] += x / Ds[k]; } chi[x] %= T; // mod (t^T-1) } auto F = ndVec({T, X, Y}, 0); auto G = ndVec({T, X, Y}, 0); for (int y : rep(Y)) { for (int x : rep(X)) { F[chi[x]][x][y] += f[x][y]; G[chi[x]][x][y] += g[x][y]; } } for (int k : rep(T)) { trans(F[k], false); trans(G[k], false); } // F(t),G(t)の各点積 for (int y : rep(Y)) { for (int x : rep(X)) { Vec H_xy(T, 0); // H_xy(t) = F_xy(t)*G_xy(t) mod (t^T-1) for (int ki : rep(T)) { for (int kj : rep(T)) { H_xy[(ki + kj) % T] += F[ki][x][y] * G[kj][x][y]; } } for (int k : rep(T)) { F[k][x][y] = H_xy[k]; } } } for (int k : rep(T)) { trans(F[k], true); } auto h = ndVec({X, Y}, 0); for (int y : rep(Y)) { for (int x : rep(X / 2)) { h[x][y] += F[chi[x]][x][y]; } } return h; } } /** * f(X,Y)^M */ Vec> multi_pow(Vec> f, i64 M) { if (M == 1) { return f; } else if (M % 2 == 0) { return multi_pow(multi_mul(f, f), M / 2); } else { return multi_mul(f, multi_pow(f, M - 1)); } } int main() { init(); const auto as = in.vec(N); auto f = ndVec({X, Y}, 0); for (int i : rep(N)) { const int x = as[i] % Ds[T]; const int y = as[i] / Ds[T]; f[x][y] += 1; } const auto g = multi_pow(f, M); void(0); Vec ans(Ds[K], 0); for (int x : rep(Ds[T])) { for (int y : rep(Ds[K - T])) { ans[y * Ds[T] + x] += g[x][y]; } } for (auto an : ans) { out.ln(an); } return 0; }