#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") //////////////////////////////////////////////////////////////////////////////// template struct ModInt { static constexpr unsigned M = M_; unsigned x; constexpr ModInt() : x(0U) {} constexpr ModInt(unsigned x_) : x(x_ % M) {} constexpr ModInt(unsigned long long x_) : x(x_ % M) {} constexpr ModInt(int x_) : x(((x_ %= static_cast(M)) < 0) ? (x_ + static_cast(M)) : x_) {} constexpr ModInt(long long x_) : x(((x_ %= static_cast(M)) < 0) ? (x_ + static_cast(M)) : x_) {} ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; } ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; } ModInt &operator*=(const ModInt &a) { x = (static_cast(x) * a.x) % M; return *this; } ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); } ModInt pow(long long e) const { if (e < 0) return inv().pow(-e); ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b; } ModInt inv() const { unsigned a = M, b = x; int y = 0, z = 1; for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast(q) * z; y = z; z = w; } assert(a == 1U); return ModInt(y); } ModInt operator+() const { return *this; } ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; } ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); } ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); } ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); } ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); } template friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); } template friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); } template friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); } template friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); } explicit operator bool() const { return x; } bool operator==(const ModInt &a) const { return (x == a.x); } bool operator!=(const ModInt &a) const { return (x != a.x); } friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; } }; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // M: prime, G: primitive root, 2^K | M - 1 template struct Fft { static_assert(2U <= M_, "Fft: 2 <= M must hold."); static_assert(M_ < 1U << 30, "Fft: M < 2^30 must hold."); static_assert(1 <= K_, "Fft: 1 <= K must hold."); static_assert(K_ < 30, "Fft: K < 30 must hold."); static_assert(!((M_ - 1U) & ((1U << K_) - 1U)), "Fft: 2^K | M - 1 must hold."); static constexpr unsigned M = M_; static constexpr unsigned M2 = 2U * M_; static constexpr unsigned G = G_; static constexpr int K = K_; ModInt FFT_ROOTS[K + 1], INV_FFT_ROOTS[K + 1]; ModInt FFT_RATIOS[K], INV_FFT_RATIOS[K]; Fft() { const ModInt g(G); for (int k = 0; k <= K; ++k) { FFT_ROOTS[k] = g.pow((M - 1U) >> k); INV_FFT_ROOTS[k] = FFT_ROOTS[k].inv(); } for (int k = 0; k <= K - 2; ++k) { FFT_RATIOS[k] = -g.pow(3U * ((M - 1U) >> (k + 2))); INV_FFT_RATIOS[k] = FFT_RATIOS[k].inv(); } assert(FFT_ROOTS[1] == M - 1U); } // as[rev(i)] <- \sum_j \zeta^(ij) as[j] void fft(ModInt *as, int n) const { assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K); int m = n; if (m >>= 1) { for (int i = 0; i < m; ++i) { const unsigned x = as[i + m].x; // < M as[i + m].x = as[i].x + M - x; // < 2 M as[i].x += x; // < 2 M } } if (m >>= 1) { ModInt prod = 1U; for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) { for (int i = i0; i < i0 + m; ++i) { const unsigned x = (prod * as[i + m]).x; // < M as[i + m].x = as[i].x + M - x; // < 3 M as[i].x += x; // < 3 M } prod *= FFT_RATIOS[__builtin_ctz(++h)]; } } for (; m; ) { if (m >>= 1) { ModInt prod = 1U; for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) { for (int i = i0; i < i0 + m; ++i) { const unsigned x = (prod * as[i + m]).x; // < M as[i + m].x = as[i].x + M - x; // < 4 M as[i].x += x; // < 4 M } prod *= FFT_RATIOS[__builtin_ctz(++h)]; } } if (m >>= 1) { ModInt prod = 1U; for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) { for (int i = i0; i < i0 + m; ++i) { const unsigned x = (prod * as[i + m]).x; // < M as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M as[i + m].x = as[i].x + M - x; // < 3 M as[i].x += x; // < 3 M } prod *= FFT_RATIOS[__builtin_ctz(++h)]; } } } for (int i = 0; i < n; ++i) { as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M as[i].x = (as[i].x >= M) ? (as[i].x - M) : as[i].x; // < M } } // as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)] void invFft(ModInt *as, int n) const { assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << K); int m = 1; if (m < n >> 1) { ModInt prod = 1U; for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) { for (int i = i0; i < i0 + m; ++i) { const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M as[i].x += as[i + m].x; // < 2 M as[i + m].x = (prod.x * y) % M; // < M } prod *= INV_FFT_RATIOS[__builtin_ctz(++h)]; } m <<= 1; } for (; m < n >> 1; m <<= 1) { ModInt prod = 1U; for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) { for (int i = i0; i < i0 + (m >> 1); ++i) { const unsigned long long y = as[i].x + M2 - as[i + m].x; // < 4 M as[i].x += as[i + m].x; // < 4 M as[i].x = (as[i].x >= M2) ? (as[i].x - M2) : as[i].x; // < 2 M as[i + m].x = (prod.x * y) % M; // < M } for (int i = i0 + (m >> 1); i < i0 + m; ++i) { const unsigned long long y = as[i].x + M - as[i + m].x; // < 2 M as[i].x += as[i + m].x; // < 2 M as[i + m].x = (prod.x * y) % M; // < M } prod *= INV_FFT_RATIOS[__builtin_ctz(++h)]; } } if (m < n) { for (int i = 0; i < m; ++i) { const unsigned y = as[i].x + M2 - as[i + m].x; // < 4 M as[i].x += as[i + m].x; // < 4 M as[i + m].x = y; // < 4 M } } const ModInt invN = ModInt(n).inv(); for (int i = 0; i < n; ++i) { as[i] *= invN; } } void fft(vector> &as) const { fft(as.data(), as.size()); } void invFft(vector> &as) const { invFft(as.data(), as.size()); } vector> convolve(vector> as, vector> bs) const { if (as.empty() || bs.empty()) return {}; const int len = as.size() + bs.size() - 1; int n = 1; for (; n < len; n <<= 1) {} as.resize(n); fft(as); bs.resize(n); fft(bs); for (int i = 0; i < n; ++i) as[i] *= bs[i]; invFft(as); as.resize(len); return as; } vector> square(vector> as) const { if (as.empty()) return {}; const int len = as.size() + as.size() - 1; int n = 1; for (; n < len; n <<= 1) {} as.resize(n); fft(as); for (int i = 0; i < n; ++i) as[i] *= as[i]; invFft(as); as.resize(len); return as; } // cs[k] = \sum[i-j=k] as[i] bs[j] (0 <= k <= m-n) vector> middle(vector> as, vector> bs) const { const int m = as.size(), n = bs.size(); assert(m >= n); assert(n >= 1); int len = 1; for (; len < m; len <<= 1) {} as.resize(len, 0); fft(as); std::reverse(bs.begin(), bs.end()); bs.resize(len, 0); fft(bs); for (int i = 0; i < len; ++i) as[i] *= bs[i]; invFft(as); as.resize(m); as.erase(as.begin(), as.begin() + (n - 1)); return as; } }; constexpr int MO = 120586241; using Mint = ModInt; const Fft FFT; const Mint W = Mint(6).pow((MO - 1) / 10); Mint WW[11]; int TEN[6]; int N, K; Int T; vector A; vector> R; void dft(vector &fs) { for (int n = 0; n < N; ++n) { for (int u0 = 0; u0 < TEN[N]; u0 += TEN[n + 1]) { for (int u = u0; u < u0 + TEN[n]; ++u) { Mint as[10] = {}, bs[10] = {}; for (int i = 0; i < 10; ++i) as[i] = fs[u + i * TEN[n]]; for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) bs[j] += WW[(i * j) % 10] * as[i]; for (int i = 0; i < 10; ++i) fs[u + i * TEN[n]] = bs[i]; } } } } using Poly = vector; Poly operator+(const Poly &as, const Poly &bs) { Poly cs(max(as.size(), bs.size()), 0); for (int i = 0; i < (int)as.size(); ++i) cs[i] += as[i]; for (int i = 0; i < (int)bs.size(); ++i) cs[i] += bs[i]; return cs; } Poly operator*(const Poly &as, const Poly &bs) { return FFT.convolve(as, bs); } pair solve(const vector &base, const vector &tar) { // f[n] = \sum[u] coef[u] base[u]^n const Mint invTen = Mint(TEN[N]).inv(); queue> que; for (int u = 0; u < TEN[N]; ++u) { Mint coef = invTen; for (int n = 0; n < N; ++n) { const int i = u / TEN[n] % 10; const int j = tar[n]; coef *= WW[10 - (i * j) % 10]; } que.emplace(Poly{coef}, Poly{1, -base[u]}); } for (; que.size() >= 2; ) { const auto a = que.front(); que.pop(); const auto b = que.front(); que.pop(); que.emplace(a.first * b.second + a.second * b.first, a.second * b.second); } return que.front(); } Mint divAt(vector ps, vector qs, Int n) { for (; n; n >>= 1) { Poly neg = qs; for (int i = 1; i < (int)neg.size(); i += 2) neg[i] = -neg[i]; Poly pps = ps * neg; Poly qqs = qs * neg; ps.clear(); qs.clear(); for (int i = n & 1; i < (int)pps.size(); i += 2) ps.push_back(pps[i]); for (int i = 0 ; i < (int)qqs.size(); i += 2) qs.push_back(qqs[i]); } return ps[0] / qs[0]; } int main() { for (int i = 0; i <= 10; ++i) WW[i] = W.pow(i); TEN[0] = 1; for (int i = 1; i <= 5; ++i) TEN[i] = TEN[i - 1] * 10; for (; ~scanf("%d%d%lld", &N, &K, &T); ) { A.resize(N); for (int n = 0; n < N; ++n) scanf("%d", &A[n]); R.assign(K, vector(N)); for (int k = 0; k < K; ++k) for (int n = 0; n < N; ++n) scanf("%d", &R[k][n]); const Mint invK = Mint(K).inv(); vector fs(TEN[N], 0); for (int k = 0; k < K; ++k) { int u = 0; for (int n = 0; n < N; ++n) u += R[k][n] * TEN[n]; fs[u] += invK; } dft(fs); const auto p = solve(fs, A); const auto q = solve(fs, vector(N, 0)); // [x^T] (1/(1-x)) (p/q) const Poly numer = p.first * q.second; const Poly denom = p.second * q.first * Poly{1, -1}; const Mint ans = divAt(numer, denom, T); printf("%u\n", ans.x); } return 0; }