import sys import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 998_244_353 def is_balanced(A, Acum): for a, b in zip(A[1:], Acum[1:]): if a > b: return False return True def main(N, K, A): S = [0] + list(itertools.accumulate(A)) if not is_balanced(A, S): return 0 MAX = K + 10 # x 以下の数列は対策済 dp = [0] * (MAX + MAX + 1) v = A[-1] - 1 dp[v] = 1 for n in range(N - 2, -1, -1): newdp = [0] * (MAX + MAX + 1) imos = [0] * (MAX + MAX + 1) for v in range(-MAX, MAX + 1): if not dp[v]: continue if v < S[n] + A[n] - 1: low = A[n] else: low = -K L, R = low, min(A[n], v // 2 + 1) if L <= R: newdp[v // 2] += dp[v] * (R - L + 1) % MOD L, R = max(low, v // 2 + 2), A[n] L, R = L - 1, R - 1 if L <= R: imos[L] += dp[v] imos[R + 1] -= dp[v] for i in range(-MAX, MAX): imos[i] %= MOD imos[i + 1] += imos[i] newdp[i] += imos[i] newdp[i] %= MOD dp = newdp return sum(dp) % MOD N, K = map(int, readline().split()) A = list(map(int, readline().split())) print(main(N, K, A))