mod = 998244353 div2 = pow(2, mod-2, mod) def calc_ans(dp, k): ans = 0 for i in range(0, len(dp), k): ans += dp[i] ans % mod return (ans - 1) % mod def main(): N, M, K = map(int, input().split()) A = list(map(lambda x: int(x) % K, input().split())) U = (K - 1) * M dp = [0] * (U + 1) dp[0] = 1 for i in range(M): for j in range(A[i], U+1)[::-1]: dp[j] += dp[j-A[i]] dp[j] %= mod print(calc_ans(dp, K)) for i in range(M, N): for j in range(A[i], U+1)[::-1]: dp[j] += dp[j-A[i]] dp[j] %= mod if A[i-M] != 0: for j in range(A[i-M], U+1): dp[j] -= dp[j-A[i-M]] dp[j] %= mod else: for j in range(U + 1): dp[j] = dp[j] * div2 % mod print(calc_ans(dp, K)) main()