#include using namespace std; const int P = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, K; cin >> N >> M >> K; vector A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int Q = N - M + 1; vector ans(Q); vector> querys; for (int i = 0; i < Q; i++) { querys.emplace_back(i, i + M, i); } vector> dp(N + 1); auto dfs = [&](auto &dfs, int L, int R, const vector> &query) { vector> qL, qM, qR; int M = (L + R) / 2; for (auto &[l, r, i] : query) { if (l <= M && M <= r) { qM.emplace_back(l, r, i); } else if (r < M) { qL.emplace_back(l, r, i); } else { qR.emplace_back(l, r, i); } } for (int i = L; i <= R; i++) { for (int j = 0; j < K; j++) { dp[i][j] = 0; } } dp[M][0] = 1; for (int i = M - 1; i >= L; i--) { int w = A[i]; for (int j = 0; j < K; j++) { dp[i][(j + w) % K] = dp[i + 1][j]; } for (int j = 0; j < K; j++) { dp[i][j] += dp[i + 1][j]; if (dp[i][j] >= P) { dp[i][j] -= P; } } } for (int i = M; i < R; i++) { int w = A[i]; for (int j = 0; j < K; j++) { dp[i + 1][(j + w) % K] = dp[i][j]; } for (int j = 0; j < K; j++) { dp[i + 1][j] += dp[i][j]; if (dp[i + 1][j] >= P) { dp[i + 1][j] -= P; } } } for (auto [l, r, i] : qM) { long long res = 0; for (int j = 0; j < K; j++) { int k = (j == 0 ? 0 : K - j); res += 1ll * dp[l][j] * dp[r][k] % P; if (res >= P) { res -= P; } } ans[i] = res; } if (L + 1 == R) { return; } else { dfs(dfs, L, M, qL); dfs(dfs, M, R, qR); } }; dfs(dfs, 0, N, querys); for (int i = 0; i < Q; i++) { cout << ans[i] << " \n"[i + 1 == Q]; } }